Skip to content
This repository has been archived by the owner on Jul 17, 2023. It is now read-only.

Commit

Permalink
update test
Browse files Browse the repository at this point in the history
  • Loading branch information
skoudoro committed Oct 18, 2021
1 parent f545c48 commit cf48627
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
16 changes: 14 additions & 2 deletions mailerlite/campaign.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -249,6 +249,8 @@ def cancel(self, campaign_id):
----------
campaign_id : int
campaign id
as_json : bool
return result as json format
Returns
-------
Expand All @@ -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.
Expand Down
7 changes: 5 additions & 2 deletions mailerlite/tests/test_campaign.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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"]

0 comments on commit cf48627

Please sign in to comment.