コード例 #1
0
def test_get_private_limit(request, connection):

    # Get the current number of public address books in case the account
    # has some data in that we need to take into consideration
    existing_books = AddressBook.get_all(address_book_type='Private')
    offset = len(existing_books)

    # Generate a number of address books
    new_address_books = []
    for x in range(1, 10):
        new_address_books.append(
            AddressBook(name='Address Book %s' % x,
                        visibility=constants.VISIBILITY_PRIVATE))
        new_address_books[-1].create()

    # Define a finalizer for the test request so we make sure we clean
    # up after ourselves
    def cleanup():
        for book in new_address_books:
            manually_delete_address_book(connection, book)

    request.addfinalizer(cleanup)

    books = AddressBook.get_private(select=5, skip=offset)

    for book in new_address_books[:5]:
        assert book in books
コード例 #2
0
ファイル: test_delete.py プロジェクト: tomscytale/dotmailer
def test_delete_protected_address_book(book_name):
    """
    Test to confirm that if the delete end point is called on one of the
    protected address books (All Contacts and Test), then the
    appropriate exception is raised.

    :param book_name:
    :return:
    """

    test_book = None

    # Get a list of all address books in the account.
    books = AddressBook.get_all()
    print books
    # Find the test address book and grab it's ID value
    for book in books:
        log.info("Address book: {}".format(book.name))
        print book.name
        if book.name == book_name:
            test_book = book
            break

    # Assert that the test book has been found, otherwise stop here
    assert test_book is not None

    # Confirm that the class method version raises the correct exception
    with pytest.raises(ErrorAddressbookNotwritable):
        AddressBook.delete(test_book.id)

    # Confirm that the instance method version raises the correct
    # exception
    with pytest.raises(ErrorAddressbookNotwritable):
        test_book.delete()
コード例 #3
0
ファイル: test_create.py プロジェクト: tomscytale/dotmailer
def test_create_invalid_address_book(test_data):
    """
    Test to confirm that when attempting to create an invalid address
    book, that an exception is raised.
     
    :param test_data: 
    :return: 
    """

    with pytest.raises((Exception, KeyError)):
        address_book = AddressBook(**test_data)
        address_book.create()
コード例 #4
0
ファイル: conftest.py プロジェクト: tomscytale/dotmailer
def sample_address_book(request, connection, sample_address_book_data):
    address_book = AddressBook(**sample_address_book_data)
    address_book.create()

    # Adding a finalizer so that we can remove the address book so that
    # it would foul up other test cases or test runs.
    def _finalizer():
        manually_delete_address_book(connection, address_book)

    request.addfinalizer(_finalizer)

    return address_book
コード例 #5
0
ファイル: test_create.py プロジェクト: tomscytale/dotmailer
def test_create_valid_address_book(connection, test_data):
    """
    Test to confirm that when submitting various different valid address
    books that they are created.
    
    :param connection: 
    :param test_data:
    :return: 
    """

    address_book = AddressBook(**test_data)
    address_book.create()
    assert address_book.id is not None

    # Attempt to delete the address book created by the test
    manually_delete_address_book(connection, address_book)
コード例 #6
0
def test_get_private(sample_address_book, sample_public_address_book):

    address_books = AddressBook.get_all(address_book_type='Private')
    for book in address_books:
        print book.id, book.name, book.visibility
    assert sample_address_book in address_books
    assert sample_public_address_book not in address_books
コード例 #7
0
ファイル: test_delete.py プロジェクト: tomscytale/dotmailer
def test_delete_valid_address_book(sample_address_book):
    """
    Test to confirm that the delete functionality for address books 
    behaves  correctly.  Calling the delete on an address book should 
    update the ID attribute of the address book to be null, whilst also
    triggering DotMailer to remove the address book from the account.
    
    :param sample_address_book: 
    :return: 
    """
    address_book_id = sample_address_book.id
    assert address_book_id is not None, 'Sample address book doesn\'t' \
                                        ' have an ID value.'

    # Tell DotMailer that you wish to delete the address book
    sample_address_book.delete()
    assert sample_address_book.id is None, 'Address book ID was not ' \
                                           'nulled'

    # Finally, confirm that address book doesn't exists any more
    with pytest.raises(ErrorAddressbookNotFound):
        AddressBook.get_by_id(address_book_id)
コード例 #8
0
ファイル: contacts.py プロジェクト: tomscytale/dotmailer
    def get_address_books(self, select=1000, skip=0):
        """
        Gets any address books that a contact is in

        :param select:
        :param skip:
        :return:
        """
        self.validate_id('Sorry, unable to get the address books that this'
                         'contact is in, due to no ID value being associated'
                         'with the contact.')

        response = connection.get('{}/{}/address-books'.format(
            self.end_point, self.id),
                                  query_params={
                                      'Select': select,
                                      'Skip': skip
                                  })
        return [AddressBook(**entry) for entry in response]
コード例 #9
0
def test_update_valid_address_book(sample_address_book, test_data):
    """
    Test function to confirm that submitting new values to an existing 
    address book, will result in the values on the server being updated.
    
    This test will not work if you are using the demo account creditials.
    :param sample_address_book: 
    :param test_data: 
    :return: 
    """
    address_book_id = _confirm_address_book_valid(sample_address_book)

    # Force an update of the address book
    sample_address_book._update_values(test_data)
    sample_address_book.update()

    # Finally query the server for the address book and confirm the new
    # values where stored.
    address_book = AddressBook.get_by_id(address_book_id)
    for key, value in test_data.items():
        assert getattr(address_book, key) == value
コード例 #10
0
def test_add_contact_invalid_address_book(sample_address_book_data,
                                          sample_contact):
    address_book = AddressBook(**sample_address_book_data)
    with pytest.raises(Exception):
        address_book.add_contact(sample_contact)
コード例 #11
0
def sample_address_book(connection, sample_address_book_data):
    sample_address_book = AddressBook(**sample_address_book_data)
    sample_address_book.create()
    return sample_address_book
コード例 #12
0
def test_valid_name(name, response):
    assert AddressBook.valid_name(name) == response
コード例 #13
0
ファイル: test_delete.py プロジェクト: tomscytale/dotmailer
def test_delete_invalid_address_book():
    with pytest.raises(ErrorAddressbookNotFound):
        AddressBook.delete(999999999)