def test_make_call(self): responses.add(responses.GET, urljoin(EMARSYS_URI, 'api/v2/settings'), json=EMARSYS_SETTINGS_RESPONSE, status=200, content_type='application/json') connection = SyncConnection(TEST_USERNAME, TEST_SECRET, EMARSYS_URI) response = connection.make_call('GET', 'api/v2/settings') assert response == EMARSYS_SETTINGS_RESPONSE
def test_last_change(self): responses.add( responses.GET, urljoin( EMARSYS_URI, '{}/{}'.format( CONTACT_ENDPOINT, 'last_change/?key_id=3&[email protected]' '&field_id=1' ) ), json=EMARSYS_CONTACT_FIELDS_LAST_CHANGE, status=200, content_type='application/json', match_querystring=True ) connection = SyncConnection(TEST_USERNAME, TEST_SECRET) contact_fields = ContactField(connection) response = contact_fields.last_change( 3, '*****@*****.**', 1 ) assert response == EMARSYS_CONTACT_FIELDS_LAST_CHANGE
def test_create(self): responses.add( responses.POST, urljoin(EMARSYS_URI, CONTACT_LIST_ENDPOINT), json=EMARSYS_CONTACT_LIST_CREATE_RESPONSE, status=200, content_type="application/json", ) connection = SyncConnection(TEST_USERNAME, TEST_SECRET) contact_list = ContactList(connection) response = contact_list.create("test_list") assert response == EMARSYS_CONTACT_LIST_CREATE_RESPONSE
def test_create(self): responses.add( responses.POST, urljoin(EMARSYS_URI, CONTACT_ENDPOINT), json=EMARSYS_CONTACTS_CREATE_RESPONSE, status=200, content_type='application/json' ) connection = SyncConnection(TEST_USERNAME, TEST_SECRET) contacts = Contact(connection) response = contacts.create({'3': '*****@*****.**'}) assert response == EMARSYS_CONTACTS_CREATE_RESPONSE
def test_list(self): responses.add( responses.GET, urljoin(EMARSYS_URI, CONTACT_FIELDS_ENDPOINT), json=EMARSYS_CONTACT_FIELDS_LIST_RESPONSE, status=200, content_type='application/json' ) connection = SyncConnection(TEST_USERNAME, TEST_SECRET) contact_fields = ContactField(connection) response = contact_fields.list() assert response == EMARSYS_CONTACT_FIELDS_LIST_RESPONSE
def test_create(self): responses.add( responses.POST, urljoin(EMARSYS_URI, CONTACT_FIELDS_ENDPOINT), json=EMARSYS_CONTACT_FIELDS_CREATE_RESPONSE, status=200, content_type='application/json' ) connection = SyncConnection(TEST_USERNAME, TEST_SECRET) contact_fields = ContactField(connection) response = contact_fields.create('squirrel_field', 'longtext') assert response == EMARSYS_CONTACT_FIELDS_CREATE_RESPONSE
def test_add_contacts(self): responses.add( responses.POST, urljoin(EMARSYS_URI, ADD_TO_CONTACT_LIST_ENDPOINT), json=EMARSYS_ADD_TO_CONTACT_LIST_RESPONSE, status=200, content_type="application/json", ) connection = SyncConnection(TEST_USERNAME, TEST_SECRET) contact_list = ContactList(connection) response = contact_list.add_contacts(1, ["*****@*****.**"]) assert response == EMARSYS_ADD_TO_CONTACT_LIST_RESPONSE
def test_delete(self): responses.add( responses.POST, urljoin(EMARSYS_URI, '{}/{}/'.format(CONTACT_ENDPOINT, 'delete')), json=EMARSYS_CONTACTS_DELETE_RESPONSE, status=200, content_type='application/json' ) connection = SyncConnection(TEST_USERNAME, TEST_SECRET) contacts = Contact(connection) response = contacts.delete( {'3': '*****@*****.**'}, ) assert response == EMARSYS_CONTACTS_DELETE_RESPONSE
def test_update(self): responses.add( responses.PUT, urljoin(EMARSYS_URI, CONTACT_ENDPOINT), json=EMARSYS_CONTACTS_CHECK_IDS_RESPONSE, status=200, content_type='application/json' ) connection = SyncConnection(TEST_USERNAME, TEST_SECRET) contacts = Contact(connection) response = contacts.update( {'3': '*****@*****.**', '1': 'Squirrel'}, key_id=1 ) assert response == EMARSYS_CONTACTS_CHECK_IDS_RESPONSE
def test_check_ids(self): responses.add( responses.POST, urljoin( EMARSYS_URI, '{}/{}/'.format(CONTACT_ENDPOINT, 'checkids') ), json=EMARSYS_CONTACTS_CHECK_IDS_RESPONSE, status=200, content_type='application/json' ) connection = SyncConnection(TEST_USERNAME, TEST_SECRET) contacts = Contact(connection) response = contacts.check_ids('1', ['Squirrel1', 'Squirrel2'], True) assert response == EMARSYS_CONTACTS_CHECK_IDS_RESPONSE
def test_get_data(self): responses.add( responses.POST, urljoin(EMARSYS_URI, '{}/{}/'.format(CONTACT_ENDPOINT, 'getdata')), json=EMARSYS_CONTACTS_GET_DATA_RESPONSE, status=200, content_type='application/json' ) connection = SyncConnection(TEST_USERNAME, TEST_SECRET) contacts = Contact(connection) response = contacts.get_data( '3', ['*****@*****.**', '*****@*****.**'], [1, 2, 3] ) assert response == EMARSYS_CONTACTS_GET_DATA_RESPONSE
def test_get_history(self): responses.add( responses.POST, urljoin( EMARSYS_URI, '{}/{}/'.format(CONTACT_ENDPOINT, 'getcontacthistory') ), json=EMARSYS_CONTACTS_GET_CONTACT_HISTORY_RESPONSE, status=200, content_type='application/json' ) connection = SyncConnection(TEST_USERNAME, TEST_SECRET) contacts = Contact(connection) response = contacts.get_history( [723005829] ) assert response == EMARSYS_CONTACTS_GET_CONTACT_HISTORY_RESPONSE
def test_list_choice(self): responses.add( responses.GET, urljoin( EMARSYS_URI, '{}/{}/{}'.format( CONTACT_FIELDS_ENDPOINT, 5, 'choice' ) ), json=EMARSYS_CONTACT_FIELDS_LIST_CHOICE_RESPONSE, status=200, content_type='application/json' ) connection = SyncConnection(TEST_USERNAME, TEST_SECRET) contact_fields = ContactField(connection) response = contact_fields.list_choice(5) assert response == EMARSYS_CONTACT_FIELDS_LIST_CHOICE_RESPONSE
def test_update_many(self): responses.add( responses.PUT, urljoin(EMARSYS_URI, CONTACT_ENDPOINT), json=EMARSYS_CONTACTS_UPDATE_MANY_RESPONSE, status=200, content_type='application/json' ) connection = SyncConnection(TEST_USERNAME, TEST_SECRET) contacts = Contact(connection) response = contacts.update_many( '3', [ {'3': '*****@*****.**', '1': 'Squirrel 1 New Name'}, {'3': '*****@*****.**', '1': 'Squirrel 2 New Name'}, ] ) assert response == EMARSYS_CONTACTS_UPDATE_MANY_RESPONSE
def test_list_data(self): responses.add( responses.GET, urljoin( EMARSYS_URI, '{}/{}'.format( CONTACT_ENDPOINT, 'query/?return=3&limit=2&1=Squirrel' ) ), json=EMARSYS_CONTACTS_LIST_DATA_RESPONSE, status=200, content_type='application/json', match_querystring=True ) connection = SyncConnection(TEST_USERNAME, TEST_SECRET) contacts = Contact(connection) response = contacts.query( 3, query_tuple=(1, 'Squirrel'), limit=2 ) assert response == EMARSYS_CONTACTS_LIST_DATA_RESPONSE
def test_get_internal_id(self): responses.add( responses.GET, urljoin( EMARSYS_URI, '{}/{}'.format( CONTACT_ENDPOINT, '[email protected]' ) ), json=EMARSYS_CONTACTS_FETCH_INTERNAL_ID_RESPONSE, status=200, content_type='application/json', match_querystring=True ) connection = SyncConnection(TEST_USERNAME, TEST_SECRET) contacts = Contact(connection) response = contacts.get_internal_id( 3, '*****@*****.**' ) assert response == EMARSYS_CONTACTS_FETCH_INTERNAL_ID_RESPONSE
def test_init(self): connection = SyncConnection(TEST_USERNAME, TEST_SECRET, EMARSYS_URI) assert connection.username == TEST_USERNAME assert connection.secret == TEST_SECRET assert connection.uri == EMARSYS_URI
def test_init_no_exception(self): connection = SyncConnection(TEST_USERNAME, TEST_SECRET) client = Emarsys(connection) isinstance(client.connection, SyncConnection) isinstance(client.contacts, Contact)
def test_init_no_exception(self): connection = SyncConnection(TEST_USERNAME, TEST_SECRET) ContactList(connection)