Exemplo n.º 1
0
def test_separate_address_books(sql_alchemy_fixture, access_domain_fixture):
    """An Address is created in a particular AddressBook, which is owned by a SystemAccount."""

    account = access_domain_fixture.account
    address_book = access_domain_fixture.address_book
    other_address_book = access_domain_fixture.other_address_book

    # AddressBooks are owned
    assert address_book.owner is account
    assert other_address_book.owner is access_domain_fixture.other_account

    # Addresses live in specific AddressBooks
    assert address_book.addresses == []
    assert other_address_book.addresses == []

    address1 = Address(address_book=address_book,
                       email_address='*****@*****.**',
                       name='Friend1')
    address2 = Address(address_book=address_book,
                       email_address='*****@*****.**',
                       name='Friend2')

    address3 = Address(address_book=other_address_book,
                       email_address='*****@*****.**',
                       name='Friend3')

    for address in [address1, address2, address3]:
        address.save()

    assert address_book.addresses == [address1, address2]
    assert other_address_book.addresses == [address3]
Exemplo n.º 2
0
 def edit_address_in_other_address_book(self):
     address = Address(address_book=self.other_address_book,
                       email_address='*****@*****.**',
                       name='Friend')
     address.save()
     Session.flush()
     self.url = '/edit_address/%s' % address.id
     self.get = True
Exemplo n.º 3
0
def test_edit_other(web_fixture, access_domain_fixture, access_ui_fixture):
    """If you may only edit (not add) an address, then you may only edit the email address, not the name."""


    browser = access_ui_fixture.browser
    address_book = access_domain_fixture.address_book
    account = access_domain_fixture.account

    other_address_book = access_domain_fixture.other_address_book
    other_address_book.allow(account, can_edit_addresses=True, can_add_addresses=True)
    Address(address_book=other_address_book, email_address='*****@*****.**', name='Friend').save()

    web_fixture.log_in(browser=browser, system_account=account)
    browser.open('/')

    browser.click(XPath.link().with_text('Address book of [email protected]'))
    browser.click(XPath.button_labelled('Edit'))

    # Case: may edit name
    assert browser.is_element_enabled(XPath.input_labelled('Name'))
    assert browser.is_element_enabled(XPath.input_labelled('Email'))

    # Case: may not edit name
    other_address_book.allow(account, can_edit_addresses=True, can_add_addresses=False  )
    browser.refresh()
    assert not browser.is_element_enabled(XPath.input_labelled('Name'))
    assert browser.is_element_enabled(XPath.input_labelled('Email'))

    browser.type(XPath.input_labelled('Email'), '*****@*****.**')
    browser.click(XPath.button_labelled('Update'))

    assert browser.is_element_present(XPath.paragraph().including_text('Friend: [email protected]'))
Exemplo n.º 4
0
def test_see_other(web_fixture, access_domain_fixture, access_ui_fixture):
    """If allowed, an account may see another account's AddressBook, and could edit or add Addresses,
       depending on the allowed rights."""

    browser = access_ui_fixture.browser
    account = access_domain_fixture.account
    address_book = access_domain_fixture.address_book

    other_address_book = access_domain_fixture.other_address_book
    other_address_book.allow(account)
    Address(address_book=other_address_book,
            email_address='*****@*****.**',
            name='Friend').save()

    web_fixture.log_in(browser=browser, system_account=account)
    browser.open('/')

    browser.click(XPath.link().with_text('Address book of [email protected]'))

    assert browser.is_element_present(
        XPath.paragraph().including_text('Friend: [email protected]'))

    # Case: can only see
    assert not browser.is_element_enabled(
        XPath.link().with_text('Add address'))
    assert not browser.is_element_enabled(XPath.button_labelled('Edit'))

    # Case: can edit only
    other_address_book.allow(account,
                             can_edit_addresses=True,
                             can_add_addresses=False)
    browser.refresh()
    assert not browser.is_element_enabled(
        XPath.link().with_text('Add address'))
    assert browser.is_element_enabled(XPath.button_labelled('Edit'))

    # Case: can add, and therefor also edit
    other_address_book.allow(account, can_add_addresses=True)
    browser.refresh()
    assert browser.is_element_enabled(XPath.link().with_text('Add address'))
    assert browser.is_element_enabled(XPath.button_labelled('Edit'))

    browser.click(XPath.button_labelled('Edit'))
    browser.type(XPath.input_labelled('Name'), 'Else')
    browser.type(XPath.input_labelled('Email'), '*****@*****.**')
    browser.click(XPath.button_labelled('Update'))

    assert browser.is_element_present(
        XPath.paragraph().including_text('Else: [email protected]'))
Exemplo n.º 5
0
def demo_setup(sql_alchemy_fixture, access_domain_fixture):
    sql_alchemy_fixture.commit = True

    access_domain_fixture.address_book
    john = access_domain_fixture.account
    jane = access_domain_fixture.new_account(email='*****@*****.**')
    jane_book = access_domain_fixture.new_address_book(owner=jane)
    someone = access_domain_fixture.new_account(email='*****@*****.**')
    someone_book = access_domain_fixture.new_address_book(owner=someone)
    someone_else = access_domain_fixture.new_account(
        email='*****@*****.**')
    someone_else_book = access_domain_fixture.new_address_book(
        owner=someone_else)

    jane_book.allow(john, can_add_addresses=True, can_edit_addresses=True)
    someone_book.allow(john, can_add_addresses=False, can_edit_addresses=True)
    someone_else_book.allow(john,
                            can_add_addresses=False,
                            can_edit_addresses=False)

    Address(address_book=jane_book,
            email_address='*****@*****.**',
            name='Friend1').save()
    Address(address_book=jane_book,
            email_address='*****@*****.**',
            name='Friend2').save()
    Address(address_book=jane_book,
            email_address='*****@*****.**',
            name='Friend3').save()
    Address(address_book=jane_book,
            email_address='*****@*****.**',
            name='Friend4').save()

    Address(address_book=someone_book,
            email_address='*****@*****.**',
            name='Friend11').save()
    Address(address_book=someone_book,
            email_address='*****@*****.**',
            name='Friend12').save()
    Address(address_book=someone_book,
            email_address='*****@*****.**',
            name='Friend13').save()
    Address(address_book=someone_book,
            email_address='*****@*****.**',
            name='Friend14').save()

    Address(address_book=someone_else_book,
            email_address='*****@*****.**',
            name='Friend21').save()
    Address(address_book=someone_else_book,
            email_address='*****@*****.**',
            name='Friend22').save()
    Address(address_book=someone_else_book,
            email_address='*****@*****.**',
            name='Friend23').save()
    Address(address_book=someone_else_book,
            email_address='*****@*****.**',
            name='Friend24').save()
Exemplo n.º 6
0
    def do_demo_setup(self):
        self.address_book
        john = self.account
        jane = self.new_account(email='*****@*****.**')
        jane_book = self.new_address_book(owner=jane)
        someone = self.new_account(email='*****@*****.**')
        someone_book = self.new_address_book(owner=someone)
        someone_else = self.new_account(email='*****@*****.**')
        someone_else_book = self.new_address_book(owner=someone_else)

        jane_book.allow(john, can_add_addresses=True, can_edit_addresses=True)
        someone_book.allow(john,
                           can_add_addresses=False,
                           can_edit_addresses=True)
        someone_else_book.allow(john,
                                can_add_addresses=False,
                                can_edit_addresses=False)

        Address(address_book=jane_book,
                email_address='*****@*****.**',
                name='Friend1').save()
        Address(address_book=jane_book,
                email_address='*****@*****.**',
                name='Friend2').save()
        Address(address_book=jane_book,
                email_address='*****@*****.**',
                name='Friend3').save()
        Address(address_book=jane_book,
                email_address='*****@*****.**',
                name='Friend4').save()

        Address(address_book=someone_book,
                email_address='*****@*****.**',
                name='Friend11').save()
        Address(address_book=someone_book,
                email_address='*****@*****.**',
                name='Friend12').save()
        Address(address_book=someone_book,
                email_address='*****@*****.**',
                name='Friend13').save()
        Address(address_book=someone_book,
                email_address='*****@*****.**',
                name='Friend14').save()

        Address(address_book=someone_else_book,
                email_address='*****@*****.**',
                name='Friend21').save()
        Address(address_book=someone_else_book,
                email_address='*****@*****.**',
                name='Friend22').save()
        Address(address_book=someone_else_book,
                email_address='*****@*****.**',
                name='Friend23').save()
        Address(address_book=someone_else_book,
                email_address='*****@*****.**',
                name='Friend24').save()
        Session.flush()
        Session.commit()