def setUp(self): #global server_process #logger.info('TestPyDotMailer Starting and initialising API server. ') # run the server process that we need for our tests. #dir_test_code = os.path.dirname(__file__) # directory containing the current .py #self.start_server_process(['node', '%s/../../node/personServer/personServer.js' % (dir_test_code),'-n test_personServer','--debug','-r testserver', '-i 0']) #self.start_server_process(['python', self.resolve_relative_path(__file__,'../tms_api/tms_api_server_base.py' ),'-n test_api_server','--debug','-r testserver', '-i 0', '-s 18001', '-e 18199']) self.dot_mailer = PyDotMailer(api_username=Secrets.api_username, api_password=Secrets.api_password) self.address_book_id = Secrets.address_book_id # comes from dotmailer UI, under Contacts, Edit Address Book. Look for the field with label "id" # must be an address book specially created for your test purposes, cannot use the built-in address books like "test" pass
def setUp(self): #global server_process #logger.info('TestPyDotMailer Starting and initialising API server. ') # run the server process that we need for our tests. #dir_test_code = os.path.dirname(__file__) # directory containing the current .py #self.start_server_process(['node', '%s/../../node/personServer/personServer.js' % (dir_test_code),'-n test_personServer','--debug','-r testserver', '-i 0']) #self.start_server_process(['python', self.resolve_relative_path(__file__,'../tms_api/tms_api_server_base.py' ),'-n test_api_server','--debug','-r testserver', '-i 0', '-s 18001', '-e 18199']) self.dot_mailer = PyDotMailer(api_username = Secrets.api_username, api_password=Secrets.api_password ) self.address_book_id = Secrets.address_book_id # comes from dotmailer UI, under Contacts, Edit Address Book. Look for the field with label "id" # must be an address book specially created for your test purposes, cannot use the built-in address books like "test" pass
class TestPyDotMailer(TMSBaseTestCase): def setUp(self): #global server_process #logger.info('TestPyDotMailer Starting and initialising API server. ') # run the server process that we need for our tests. #dir_test_code = os.path.dirname(__file__) # directory containing the current .py #self.start_server_process(['node', '%s/../../node/personServer/personServer.js' % (dir_test_code),'-n test_personServer','--debug','-r testserver', '-i 0']) #self.start_server_process(['python', self.resolve_relative_path(__file__,'../tms_api/tms_api_server_base.py' ),'-n test_api_server','--debug','-r testserver', '-i 0', '-s 18001', '-e 18199']) self.dot_mailer = PyDotMailer(api_username=Secrets.api_username, api_password=Secrets.api_password) self.address_book_id = Secrets.address_book_id # comes from dotmailer UI, under Contacts, Edit Address Book. Look for the field with label "id" # must be an address book specially created for your test purposes, cannot use the built-in address books like "test" pass def test_add_contacts_to_address_book(self): """ Test function to test add_contacts_to_address_book. """ logger.info("test_api_tokens starting") contacts_filename = "fixtures/test_contacts.csv" s_contacts = open( self.resolve_relative_path(__file__, contacts_filename), 'r').read() dict_result = self.dot_mailer.add_contacts_to_address_book( address_book_id=self.address_book_id, s_contacts=s_contacts, wait_to_complete_seconds=60) if not dict_result.get('ok'): logger.error("Failure return: %s" % (dict_result)) self.assertTrue(dict_result.get('ok'), 'add_contacts_to_address_book returned failure ') # ======= def test_add_and_send_single(self): """ test function to test single contact functions e.g. get_contact_by_email and send_campaign_to_contact """ logger.info("test_add_and_send_single starting") email = Secrets.test_address merge_vars = {'Postcode': 'arfle'} # first ensure this address is in an address book. ## dict_result = self.dot_mailer.add_contacts_to_address_book(address_book_id=self.address_book_id, s_contacts='email\n%s\n' % email, wait_to_complete_seconds=60) dict_result = self.dot_mailer.add_contact_to_address_book( address_book_id=self.address_book_id, email_address=email, d_fields=merge_vars) self.assertTrue(dict_result.get('ok'), "creating test address failed") # now get the ID for this address. dict_result = self.dot_mailer.get_contact_by_email(email) # dict_result.get('result') is of type 'instance' and contains an APIContact record. See pydotmailer function definition for details. campaign_id = Secrets.campaign_id contact_id = dict_result.get('result').ID dict_result = self.dot_mailer.send_campaign_to_contact( campaign_id=campaign_id, contact_id=contact_id) # , send_date=send_date) self.assertTrue(dict_result.get('ok'), "sending single message failed") logger.info('All done, exiting. ') def test_add_contact_to_address_book(self): """ Test function to test add_contact_to_address_book. """ logger.info("test_add_contact_to_address_book starting") s_contact = "*****@*****.**" # todo email = Secrets.test_address test_postcode = "%s" % random.randint(0, 100000) dict_result = self.dot_mailer.add_contact_to_address_book( address_book_id=self.address_book_id, email_address=email, d_fields={ 'firstname': 'mike', 'lastname': 'austin', 'postcode': test_postcode }) if not dict_result.get('ok'): logger.error("Failure return: %s" % (dict_result)) self.assertTrue(dict_result.get('ok'), 'test_add_contact_to_address_book returned failure ') # Now retrieve the record from dotMailer and check that the data has been set correctly. dict_result = self.dot_mailer.get_contact_by_email(email) self.assertTrue(dict_result.get('ok'), 'get_contact_by_email returned failure ') self.assertEqual( dict_result.get('d_fields').get('POSTCODE'), test_postcode) pass # def test_get_contact_functions(self): # first create a test contact s_contact = "*****@*****.**" # todo email = Secrets.test_address test_postcode = "%s" % random.randint(0, 100000) dict_result = self.dot_mailer.add_contact_to_address_book( address_book_id=self.address_book_id, email_address=email, d_fields={ 'firstname': 'mike', 'lastname': 'austin', 'postcode': test_postcode }) # Now try retrieving it by email address dict_result = self.dot_mailer.get_contact_by_email(email) self.assertTrue(dict_result.get('ok')) contact_id = dict_result.get('contact_id') self.assertIsNotNone(contact_id) self.assertEqual(dict_result.get('email'), email) # Now retrieving it by contact_id dict_result = self.dot_mailer.get_contact_by_id(contact_id) self.assertIsNotNone(dict_result.get( 'd_fields')) # case 3903 ensure it's unpacked the fields ok. self.assertTrue(dict_result.get('ok')) self.assertEqual(dict_result.get('email'), email)
class TestPyDotMailer(TMSBaseTestCase): def setUp(self): #global server_process #logger.info('TestPyDotMailer Starting and initialising API server. ') # run the server process that we need for our tests. #dir_test_code = os.path.dirname(__file__) # directory containing the current .py #self.start_server_process(['node', '%s/../../node/personServer/personServer.js' % (dir_test_code),'-n test_personServer','--debug','-r testserver', '-i 0']) #self.start_server_process(['python', self.resolve_relative_path(__file__,'../tms_api/tms_api_server_base.py' ),'-n test_api_server','--debug','-r testserver', '-i 0', '-s 18001', '-e 18199']) self.dot_mailer = PyDotMailer(api_username = Secrets.api_username, api_password=Secrets.api_password ) self.address_book_id = Secrets.address_book_id # comes from dotmailer UI, under Contacts, Edit Address Book. Look for the field with label "id" # must be an address book specially created for your test purposes, cannot use the built-in address books like "test" pass def test_add_contacts_to_address_book(self): """ Test function to test add_contacts_to_address_book. """ logger.info("test_api_tokens starting") contacts_filename = "fixtures/test_contacts.csv" s_contacts = open(self.resolve_relative_path(__file__,contacts_filename), 'r').read() dict_result = self.dot_mailer.add_contacts_to_address_book(address_book_id=self.address_book_id, s_contacts=s_contacts, wait_to_complete_seconds=60) if not dict_result.get('ok'): logger.error("Failure return: %s" % (dict_result) ) self.assertTrue(dict_result.get('ok'), 'add_contacts_to_address_book returned failure ') # ======= def test_add_and_send_single(self): """ test function to test single contact functions e.g. get_contact_by_email and send_campaign_to_contact """ logger.info("test_add_and_send_single starting") email = Secrets.test_address merge_vars = {'Postcode':'arfle'} # first ensure this address is in an address book. ## dict_result = self.dot_mailer.add_contacts_to_address_book(address_book_id=self.address_book_id, s_contacts='email\n%s\n' % email, wait_to_complete_seconds=60) dict_result = self.dot_mailer.add_contact_to_address_book(address_book_id=self.address_book_id, email_address=email, d_fields=merge_vars) self.assertTrue(dict_result.get('ok'), "creating test address failed") # now get the ID for this address. dict_result = self.dot_mailer.get_contact_by_email(email) # dict_result.get('result') is of type 'instance' and contains an APIContact record. See pydotmailer function definition for details. campaign_id = Secrets.campaign_id contact_id = dict_result.get('result').ID dict_result = self.dot_mailer.send_campaign_to_contact(campaign_id=campaign_id, contact_id=contact_id) # , send_date=send_date) self.assertTrue(dict_result.get('ok'), "sending single message failed") logger.info('All done, exiting. ') def test_add_contact_to_address_book(self): """ Test function to test add_contact_to_address_book. """ logger.info("test_add_contact_to_address_book starting") s_contact = "*****@*****.**" # todo email = Secrets.test_address test_postcode = "%s" % random.randint(0,100000) dict_result = self.dot_mailer.add_contact_to_address_book(address_book_id=self.address_book_id, email_address=email, d_fields= { 'firstname': 'mike', 'lastname': 'austin', 'postcode': test_postcode}) if not dict_result.get('ok'): logger.error("Failure return: %s" % (dict_result) ) self.assertTrue(dict_result.get('ok'), 'test_add_contact_to_address_book returned failure ') # Now retrieve the record from dotMailer and check that the data has been set correctly. dict_result = self.dot_mailer.get_contact_by_email(email) self.assertTrue(dict_result.get('ok'), 'get_contact_by_email returned failure ') self.assertEqual(dict_result.get('d_fields').get('POSTCODE'), test_postcode) pass # def test_get_contact_functions(self): # first create a test contact s_contact = "*****@*****.**" # todo email = Secrets.test_address test_postcode = "%s" % random.randint(0,100000) dict_result = self.dot_mailer.add_contact_to_address_book(address_book_id=self.address_book_id, email_address=email, d_fields= { 'firstname': 'mike', 'lastname': 'austin', 'postcode': test_postcode}) # Now try retrieving it by email address dict_result = self.dot_mailer.get_contact_by_email(email) self.assertTrue(dict_result.get('ok')) contact_id = dict_result.get('contact_id') self.assertIsNotNone(contact_id) self.assertEqual(dict_result.get('email'), email) # Now retrieving it by contact_id dict_result = self.dot_mailer.get_contact_by_id(contact_id) self.assertIsNotNone(dict_result.get('d_fields')) # case 3903 ensure it's unpacked the fields ok. self.assertTrue(dict_result.get('ok')) self.assertEqual(dict_result.get('email'), email)