diff --git a/mailerlite/campaign.py b/mailerlite/campaign.py index 5eab9e9..7229022 100644 --- a/mailerlite/campaign.py +++ b/mailerlite/campaign.py @@ -240,7 +240,7 @@ def send(self, campaign_id): url = client.build_url('campaigns', campaign_id, "actions/send") return client.post(url, headers=self.headers) - def cancel(self, campaign_id): + def cancel(self, campaign_id, as_json=False): """Cancel a campaign which is in outbox. https://developers.mailerlite.com/reference#campaign-actions-and-triggers @@ -249,6 +249,8 @@ def cancel(self, campaign_id): ---------- campaign_id : int campaign id + as_json : bool + return result as json format Returns ------- @@ -258,7 +260,17 @@ def cancel(self, campaign_id): """ # TODO: Check if campaign is in Outbox otherwise raise an issue url = client.build_url('campaigns', campaign_id, "actions/cancel") - return client.post(url, headers=self.headers) + code, res_json = client.post(url, headers=self.headers) + + # TODO: Check new attribute to campaign object. + # if as_json or not res_json or code != 200: + # return res_json + + # res_json['opened'] = Stats(**res_json.pop('opened')) + # res_json['clicked'] = Stats(**res_json.pop('clicked')) + + # return Campaign(**res_json) + return code, res_json def delete(self, campaign_id): """Remove a campaign. diff --git a/mailerlite/tests/test_campaign.py b/mailerlite/tests/test_campaign.py index ca80457..706fadc 100644 --- a/mailerlite/tests/test_campaign.py +++ b/mailerlite/tests/test_campaign.py @@ -9,6 +9,7 @@ @pytest.fixture def header(): headers = {'content-type': "application/json", + "X-MailerLite-ApiDocs": "true", 'x-mailerlite-apikey': API_KEY_TEST } return headers @@ -42,9 +43,11 @@ def campaign_data_ab(): def test_wrong_headers(campaign_data): headers_1 = {'content-type': "app", + "X-MailerLite-ApiDocs": "true", 'x-mailerlite-apikey': API_KEY_TEST } headers_2 = {'content-type': "application/json", + "X-MailerLite-ApiDocs": "true", 'x-mailerlite-apikey': 'FAKE_KEY' } headers_3 = {'content-type': "application/json", @@ -145,5 +148,5 @@ def test_cancel_send_campaign(header): assert res[0].status == 'outbox' code, res_2 = campaign_obj.cancel(res[0].id) assert code == 200 - assert res_2.status == 'draft' - assert res[0].id == res_2.id + assert res_2["status"] == 'draft' + assert res[0].id == res_2["id"]