def setUp(self): self.client = PureResponseClient() self.client.authenticate(USERNAME, PASSWORD)
from pyresponse import PureResponseClient as PureResponseClient def rand_email(): return rand_name(6).lower() + str(random.randint(100,999)) + '@example.com' def rand_name(N): return ''.join(random.choice(string.ascii_lowercase) for x in range(N)).capitalize() def rand_person(): return {'email' : rand_email(), 'name': rand_name(5) + ' ' + rand_name(7)} def rand_set_of_x(factory): return [factory() for x in range(3, random.randint(5,12))] api = PureResponseClient() print '------------------------------------------------' print 'Authenticate' try: print api.authenticate('username', 'password') except Exception as e: print e print '------------------------------------------------' print 'Create list with single person' try: print api.create_list('new_list_name_a', rand_person(), rand_email(), True) except Exception as e: print e print '------------------------------------------------' ##
class BasicTests(TestCase): def setUp(self): self.client = PureResponseClient() self.client.authenticate(USERNAME, PASSWORD) @pytest.mark.xfail # Cannot create list with empty recipients def test_create_empty_list(self): self.client.create_list(Name(), []) def test_create_list(self): self.client.create_list(Name(), {'email': '*****@*****.**', 'name': 'John Doe'}) def test_create_list_multiple(self): self.client.create_list(Name(), [{ 'email': '*****@*****.**', 'name': 'John Doe'}, {'email': '*****@*****.**', 'name': 'Jane Doe'} ]) def test_add_person_to_list(self): list_name = Name() self.client.create_list(list_name, [ {'email': '*****@*****.**', 'name': 'John Doe 1'}]) self.client.wait_for_list(list_name) self.client.add_person(list_name, {'email': '*****@*****.**', 'name': 'John Doe'}) def test_add_people_to_list(self): list_name = Name() self.client.create_list(list_name, [ {'email': '*****@*****.**', 'name': 'John Doe 1'}]) self.client.wait_for_list(list_name) self.client.add_people(list_name, [ {'email': '*****@*****.**', 'name': 'John Doe'}, {'email': '*****@*****.**', 'name': 'Jane Doe'} ]) def test_create_message(self): self.client.create_message( Name(), 'subject line', '<h1>Headline</h1><p>body of text</p>' ) def test_single_message(self): message_name = Name() self.client.create_message( message_name, 'subject line', '<h1>Headline</h1><p>body of text</p>' ) self.client.send_to_person( message_name, '*****@*****.**') def test_send_campaign_message(self): message_name = Name() list_name = Name() self.client.create_message( message_name, 'subject line', '<h1>Headline</h1><p>body of text</p>' ) self.client.create_list(list_name, [{ 'email': '*****@*****.**', 'name': 'John Doe'}, {'email': '*****@*****.**', 'name': 'Jane Doe'} ]) self.client.wait_for_list(list_name) self.client.send_to_list(message_name, list_name) def test_get_person(self): self.client.person_by_email('*****@*****.**') def test_get_list(self): list_name = Name() self.client.create_list(list_name, [{'email': '*****@*****.**', 'name': 'Jane Doe'}]) self.client.wait_for_list(list_name) self.client.list_by_name(list_name)