diff --git a/test.py b/test.py index 259b295..42f051b 100644 --- a/test.py +++ b/test.py @@ -33,18 +33,36 @@ def test_get_with_data(self): self.failUnless(result.status_code == 200) def test_get_with_action(self): - result_contact = self.client.contactslist.get(filters={'limit': 1}).json() - - if result_contact['Count'] != 0: - contact_id = result_contact['Data'][0]['ID'] + get_contact = self.client.contact.get(filters={'limit': 1}).json() + if get_contact['Count'] != 0: + contact_id = get_contact['Data'][0]['ID'] else: contact_random_email = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(10)) + '@mailjet.com' post_contact = self.client.contact.create(data={'Email': contact_random_email}) self.failUnless(post_contact.status_code == 201) contact_id = post_contact.json()['Data'][0]['ID'] + get_contact_list = self.client.contactslist.get(filters={'limit': 1}).json() + if get_contact_list['Count'] != 0: + list_id = get_contact_list['Data'][0]['ID'] + else: + contact_list_random_name = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(10)) + '@mailjet.com' + post_contact_list = self.client.contactslist.create(data={'Name': contact_list_random_name}) + self.failUnless(post_contact_list.status_code == 201) + list_id = post_contact_list.json()['Data'][0]['ID'] + + data = { + 'ContactsLists': [ + { + "ListID": list_id, + "Action": "addnoforce" + } + ] + } + result_add_list = self.client.contact_managecontactslists.create(id=contact_id, data=data) + self.failUnless(result_add_list.status_code == 201) + result = self.client.contact_getcontactslists.get(contact_id).json() - print result self.failUnless('Count' in result) def test_get_with_id_filter(self):