def test_add_contact(sample_address_book):

    contact = Contact(email='*****@*****.**')
    sample_address_book.add_contact(contact)
    assert contact.id is not None

    # Clean up by removing the contact afterwards
    contact.delete()
def test_delete_contact(connection):
    contact = Contact(
        email='*****@*****.**'
    )
    contact.create()
    contact.delete()

    contact.create()
    Contact.delete(contact.id)
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)
Exemple #4
0
def sample_contact(request, connection, sample_contact_data):
    contact = Contact(**sample_contact_data)
    contact.create()

    def _finalizer():
        manually_delete_contact(connection, contact)

    request.addfinalizer(_finalizer)

    return contact
def test_create_valid_contact(connection, test_data):
    """
    Test that creating a contact creates and updates the ID value of
    the contact object correctly.
    
    :param connection: 
    :param test_data: 
    :return: 
    """
    contact = Contact(**test_data)
    assert contact.id is None
    contact.create()
    assert contact.id is not None
    for key, value in test_data.items():
        assert getattr(contact, key) == value
def test_get_by_email(sample_contact):
    returned_contact = Contact.get_by_email(sample_contact.email)

    attribs = ['id', 'email', 'opt_in_type', 'email_type', 'data_fields']
    for attrib in attribs:
        assert getattr(returned_contact, attrib) == getattr(sample_contact,
                                                            attrib)
Exemple #7
0
def test_create_valid_contact(request, connection, test_data):
    """
    Test that creating a contact creates and updates the ID value of
    the contact object correctly.

    :param connection:
    :param test_data:
    :return:
    """
    contact = Contact(**test_data)
    assert contact.id is None
    contact.create()
    # This way even if the test fails the test should clean up anything it
    # created for us
    def cleanup():
        manually_delete_contact(connection, contact)
    request.addfinalizer(cleanup)

    assert contact.id is not None
    for key, value in test_data.items():
        assert getattr(contact, key) == value
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
Exemple #9
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]
Exemple #10
0
def sample_contact(sample_contact_data):
    sample_contact = Contact(**sample_contact_data)
    sample_contact.create()
    return sample_contact
Exemple #11
0
def test_create_invalid_contact(connection, test_data):
    with pytest.raises(KeyError):
        contact = Contact(**test_data)
        contact.create()
def test_delete_invalid_contact(connection):
    with pytest.raises(ErrorContactNotFound):
        Contact.delete(999999999)
Exemple #13
0
def test_delete_contact_invalid_contact(sample_address_book,
                                        sample_contact_data):
    contact = Contact(**sample_contact_data)
    with pytest.raises(Exception):
        sample_address_book.delete_contact(contact)