Example #1
0
def language_menu(fixture):
    """A Nav can also be constructed to let a user choose to view the same page in 
       another of the supported languages."""
    class PanelWithMenu(Div):
        def __init__(self, view):
            super(PanelWithMenu, self).__init__(view)
            self.add_child(Menu(view).with_languages())
            self.add_child(P(view, text=_('This is an English sentence.')))

    wsgi_app = fixture.new_wsgi_app(child_factory=PanelWithMenu.factory())

    browser = Browser(wsgi_app)
    browser.open('/')

    vassert(
        browser.is_element_present(
            XPath.paragraph_containing('This is an English sentence.')))

    browser.click(XPath.link_with_text('Afrikaans'))
    vassert(
        browser.is_element_present(
            XPath.paragraph_containing('Hierdie is \'n sin in Afrikaans.')))

    browser.click(XPath.link_with_text('English (United Kingdom)'))
    vassert(
        browser.is_element_present(
            XPath.paragraph_containing('This is an English sentence.')))
Example #2
0
def edit_and_add_own(fixture):
    """The owner of an AddressBook can add and edit Addresses to the owned AddressBook."""
    browser = fixture.browser
    account = fixture.account
    address_book = fixture.address_book

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

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

    # add
    browser.click(XPath.link_with_text('Add address'))
    browser.type(XPath.input_labelled('Name'), 'Someone')
    browser.type(XPath.input_labelled('Email'), '*****@*****.**')
    browser.click(XPath.button_labelled('Save'))

    assert browser.is_element_present(
        XPath.paragraph_containing('Someone: [email protected]'))

    # 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_containing('Else: [email protected]'))
Example #3
0
    def views_with_parameters(self, fixture):
        """Views can have arguments that originate from code, or are parsed from the URL."""
        class UIWithParameterisedViews(UserInterface):
            def assemble(self):
                self.define_view('/aview',
                                 view_class=fixture.ParameterisedView,
                                 some_arg=fixture.argument)

        class MainUI(UserInterface):
            def assemble(self):
                self.define_page(HTML5Page).use_layout(
                    PageLayout(
                        contents_layout=ColumnLayout('main').with_slots()))
                self.define_user_interface('/a_ui',
                                           UIWithParameterisedViews,
                                           {'main': 'main'},
                                           name='myui')

        wsgi_app = fixture.new_wsgi_app(site_root=MainUI)
        browser = Browser(wsgi_app)

        if fixture.should_exist:
            browser.open(fixture.url)
            vassert(browser.title == 'View for: %s' % fixture.expected_value)
            vassert(
                browser.is_element_present(
                    XPath.paragraph_containing('content for %s' %
                                               fixture.expected_value)))
        else:
            browser.open(fixture.url, status=404)
Example #4
0
def see_other(fixture):
    """If allowed, an account may see another account's AddressBook, and could edit or add Addresses, 
       depending on the allowed rights."""
    browser = fixture.browser
    account = fixture.account
    address_book = fixture.address_book

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

    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_containing('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_containing('Else: [email protected]'))
Example #5
0
def test_addressbook1(fixture):
    john = addressbook1.Address(name='John', email_address='*****@*****.**')
    john.save()

    browser = Browser(fixture.wsgi_app)
    browser.open('/')

    vassert(
        browser.is_element_present(
            XPath.paragraph_containing('John: [email protected]')))
Example #6
0
def test_addressbook2(fixture):
    browser = Browser(fixture.wsgi_app)
    browser.open('/')

    browser.type(XPath.input_labelled('Name'), 'John')
    browser.type(XPath.input_labelled('Email'), '*****@*****.**')
    browser.click(XPath.button_labelled('Save'))

    vassert(
        browser.is_element_present(
            XPath.paragraph_containing('John: [email protected]')))
Example #7
0
def logging_in(fixture):
    """A user can log in by going to the Log in page.
       The name of the currently logged in user is displayed on the home page."""

    browser = fixture.browser
    account = fixture.account

    browser.open('/')
    browser.click(XPath.link_with_text('Log in'))

    browser.type(XPath.input_labelled('Email'), '*****@*****.**')
    browser.type(XPath.input_labelled('Password'), 'topsecret')
    browser.click(XPath.button_labelled('Log in'))

    browser.click(XPath.link_with_text('Home'))
    assert browser.is_element_present(
        XPath.paragraph_containing('Welcome [email protected]'))
Example #8
0
def test_pageflow2(fixture):
    browser = Browser(fixture.wsgi_app)
    browser.open('/')

    vassert(browser.is_element_present('//ul[contains(@class,"nav")]'))

    browser.click(XPath.link_with_text('Add an address'))
    vassert(browser.location_path == '/add')

    browser.type(XPath.input_labelled('Name'), 'John')
    browser.type(XPath.input_labelled('Email'), '*****@*****.**')
    browser.click(XPath.button_labelled('Save'))

    vassert(browser.location_path == '/')
    vassert(
        browser.is_element_present(
            XPath.paragraph_containing('John: [email protected]')))
Example #9
0
def test_parameterised1(fixture):
    browser = Browser(fixture.wsgi_app)
    browser.open('/')

    browser.click(XPath.link_with_text('Add an address'))
    browser.type(XPath.input_labelled('Name'), 'John')
    browser.type(XPath.input_labelled('Email'), '*****@*****.**')
    browser.click(XPath.button_labelled('Save'))

    vassert(browser.location_path == '/')
    browser.click(XPath.link_with_text('edit'))

    john = Session.query(parameterised1bootstrap.Address).one()
    vassert(browser.location_path == '/edit/%s' % john.id)
    browser.type(XPath.input_labelled('Name'), 'Johnny')
    browser.type(XPath.input_labelled('Email'), '*****@*****.**')
    browser.click(XPath.button_labelled('Update'))

    vassert(browser.location_path == '/')
    vassert(
        browser.is_element_present(
            XPath.paragraph_containing('Johnny: [email protected]')))
def adding_an_address(fixture):
    """To add a new address, a user clicks on "Add Address" link on the menu, then supplies the 
       information for the new address and clicks the Save button. Upon successful addition of the
       address, the user is returned to the home page where the new address is now listed."""

    browser = fixture.browser

    browser.open('/')
    browser.click(XPath.link_with_text('Add an address'))

    actual_title = browser.title
    assert actual_title == 'Add an address', 'Expected to be on the Add an address page'

    browser.type(XPath.input_labelled('Name'), 'John Doe')
    browser.type(XPath.input_labelled('Email'), '*****@*****.**')
    
    browser.click(XPath.button_labelled('Save'))
    
    actual_title = browser.title
    assert actual_title == 'Addresses', 'Expected to be back on the home page after editing'
            
    assert browser.is_element_present(XPath.paragraph_containing('John Doe: [email protected]')), \
           'Expected the newly added address to be listed on the home page'
Example #11
0
def edit_other(fixture):
    """If you may only edit (not add) an address, then you may only edit the email address, not the name."""
    browser = fixture.browser
    account = fixture.account
    address_book = fixture.address_book

    other_address_book = 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()

    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_containing('Friend: [email protected]'))
Example #12
0
 def is_email_listed(self, email):
     return self.browser.is_element_present(XPath.paragraph_containing(email))
Example #13
0
 def text_shows_selected(self, expected_selected):
     return self.browser.is_element_present(XPath.paragraph_containing('You selected link number %s' % expected_selected))
Example #14
0
 def panel_is_expanded(self):
     return self.is_expanded(XPath.paragraph_containing('Peek-A-Boo'))
Example #15
0
 def address_is_listed_as(self, name, email_address):
     return self.browser.is_element_present(
         XPath.paragraph_containing('%s: %s' % (name, email_address)))
Example #16
0
 def panel_is_visible(self):
     return self.driver_browser.is_visible(
         XPath.paragraph_containing('Peek-A-Boo'))
Example #17
0
 def address_is_listed_as(self, name, email_address, is_new):
     new = ' (new)' if is_new else ''
     return self.browser.is_element_present(XPath.paragraph_containing('%s: %s%s' % (name, email_address, new)))
Example #18
0
 def is_state_labelled_now(self, label, state):
     return self.driver_browser.is_element_present(
         XPath.paragraph_containing('%s is now %s' % (label, state)))