def test_delete_valid_contact(sample_contact):
    sample_contact_id = sample_contact.id
    assert sample_contact_id is not None

    sample_contact.delete()
    assert sample_contact.id is None

    with pytest.raises(ErrorContactNotFound):
        Contact.get_by_id(sample_contact_id)
def test_get_by_id(sample_contact):
    returned_contact = Contact.get_by_id(sample_contact.id)

    attribs = ['id', 'email', 'opt_in_type', 'email_type', 'data_fields']
    for attrib in attribs:
        assert getattr(returned_contact, attrib) == getattr(sample_contact,
                                                            attrib)
def test_update_valid_contact(sample_contact, test_data):

    sample_contact_id = sample_contact.id
    assert sample_contact_id is not None

    sample_contact._update_values(test_data)
    sample_contact.update()

    # Build a list of all keys we should have values for and need to test
    contact = Contact.get_by_id(sample_contact_id)
    for key, value in test_data.items():
        assert getattr(contact, key) == value
Beispiel #4
0
    def get_contacts(cls, id):
        """
        Gets contacts for a given address book

        :param id:
        :return:
        """
        from dotmailer.contacts import Contact

        # Cast the ID parameter to an integer
        id = int(id)

        # Check that the ID parameter is greater than zero, if not raise
        # an exception.
        if id < 1:
            raise Exception()

        response = connection.get('{}/{}/contacts'.format(cls.end_point, id))
        return [Contact.get_by_id(entry['id']) for entry in response]