Example #1
0
 def test_use_test_browser(self):
     # TEMPORARY test. Make sure we can use a virtual browser.
     app = SampleApp()
     self.layer.getRootFolder()['app'] = app
     browser = Browser()
     browser.open("http://localhost/app/@@foo")
     assert browser.contents == 'Hi from SampleAppView, VARS: []'
Example #2
0
def setUpFunctional(global_config=None, **settings):
    from kotti import main
    from zope.testbrowser.wsgi import Browser
    from webtest import TestApp

    tearDown()

    _settings = {
        'sqlalchemy.url': testing_db_url(),
        'kotti.secret': 'secret',
        'kotti.site_title': 'Website des Kottbusser Tors',  # for mailing
        'kotti.populators': 'kotti.testing._populator',
        'mail.default_sender': 'kotti@localhost',
        'pyramid.includes': 'kotti.testing._functional_includeme',
    }
    _settings.update(settings)

    host, port = BASE_URL.split(':')[-2:]
    app = main({}, **_settings)
    Browser.pyquery = property(_zope_testbrowser_pyquery)

    return dict(
        Browser=lambda: Browser('http://{}:{}/'.format(host[2:], int(port)),
                                wsgi_app=app),
        browser=Browser('http://{}:{}/'.format(host[2:], int(port)),
                        wsgi_app=app),
        test_app=TestApp(app),
    )
Example #3
0
def setUpFunctional(global_config=None, **settings):
    from kotti import main
    from zope.testbrowser.wsgi import Browser
    from webtest import TestApp

    tearDown()

    _settings = {
        "sqlalchemy.url": testing_db_url(),
        "kotti.secret": "secret",
        "kotti.site_title": "Website des Kottbusser Tors",  # for mailing
        "kotti.populators": "kotti.testing._populator",
        "mail.default_sender": "kotti@localhost",
        "pyramid.includes": "kotti.testing._functional_includeme",
    }
    _settings.update(settings)

    host, port = BASE_URL.split(":")[-2:]
    app = main({}, **_settings)
    Browser.pyquery = property(_zope_testbrowser_pyquery)

    return dict(
        Browser=lambda: Browser("http://{}:{}/".format(host[2:], int(port)),
                                wsgi_app=app),
        browser=Browser("http://{}:{}/".format(host[2:], int(port)),
                        wsgi_app=app),
        test_app=TestApp(app),
    )
Example #4
0
 def test_use_test_browser(self):
     # TEMPORARY test. Make sure we can use a virtual browser.
     app = SampleApp()
     self.layer.getRootFolder()['app'] = app
     browser = Browser()
     browser.open("http://localhost/app/@@foo")
     assert browser.contents == 'Hi from SampleAppView, VARS: []'
Example #5
0
 def test_index_returns_empty_body(self):
     # if we deliver normal data we will return with an empty doc.
     receiver = PayPalIPNReceiver()
     receiver.validation_url = ''
     self.layer.getRootFolder()['app'] = receiver
     browser = Browser()
     browser.open('http://localhost/app/@@index')
     assert browser.contents == ''
Example #6
0
 def test_index_returns_200_Ok(self):
     # if we deliver normal data we will get a 200 Ok.
     receiver = PayPalIPNReceiver()
     receiver.validation_url = ''
     self.layer.getRootFolder()['app'] = receiver
     browser = Browser()
     browser.open('http://localhost/app/@@index')
     assert browser.headers.get("status") == "200 Ok"
Example #7
0
 def test_post_data(self):
     # TEMPORARY test. Make sure we can post data.
     app = SampleApp()
     self.layer.getRootFolder()['app'] = app
     browser = Browser()
     browser.post("http://localhost/app/@@foo", "x=1&y=2")
     assert browser.contents == (
         "Hi from SampleAppView, VARS: [(u'x', u'1'), (u'y', u'2')]")
Example #8
0
 def test_index_returns_200_Ok(self):
     # if we deliver normal data we will get a 200 Ok.
     receiver = PayPalIPNReceiver()
     receiver.validation_url = ''
     self.layer.getRootFolder()['app'] = receiver
     browser = Browser()
     browser.open('http://localhost/app/@@index')
     assert browser.headers.get("status") == "200 Ok"
Example #9
0
 def test_index_returns_empty_body(self):
     # if we deliver normal data we will return with an empty doc.
     receiver = PayPalIPNReceiver()
     receiver.validation_url = ''
     self.layer.getRootFolder()['app'] = receiver
     browser = Browser()
     browser.open('http://localhost/app/@@index')
     assert browser.contents == ''
Example #10
0
 def test_post_data(self):
     # TEMPORARY test. Make sure we can post data.
     app = SampleApp()
     self.layer.getRootFolder()['app'] = app
     browser = Browser()
     browser.post("http://localhost/app/@@foo", "x=1&y=2")
     assert browser.contents == (
         "Hi from SampleAppView, VARS: [(u'x', u'1'), (u'y', u'2')]"
         )
Example #11
0
 def test_index_is_default_view(self):
     # the index view is called by default.
     receiver = ModifiedReceiver()
     receiver.validation_url = ''
     self.layer.getRootFolder()['app'] = receiver
     browser = Browser()
     # we do not give a view name here.
     browser.post("http://localhost/app", "got_it=1")
     assert receiver.call_args == 'got_it=1'
Example #12
0
 def test_index_is_default_view(self):
     # the index view is called by default.
     receiver = ModifiedReceiver()
     receiver.validation_url = ''
     self.layer.getRootFolder()['app'] = receiver
     browser = Browser()
     # we do not give a view name here.
     browser.post("http://localhost/app", "got_it=1")
     assert receiver.call_args == 'got_it=1'
Example #13
0
 def test_can_set_content_type(self):
     # TEMPORARY test. We can set the content type of a post request.
     app = SampleApp()
     self.layer.getRootFolder()['app'] = app
     browser = Browser()
     browser.handleErrors = False
     browser.post("http://localhost/app/@@bar", "x=1&y=2",
                  "application/x-javascript")
     assert browser.contents == ("INPUT: x=1&y=2 "
                                 "CONTENT-TYPE application/x-javascript")
Example #14
0
 def test_index_calls_store_notification(self):
     # the index view informs the receiver.
     receiver = ModifiedReceiver()
     receiver.validation_url = ''
     self.layer.getRootFolder()['app'] = receiver
     browser = Browser()
     browser.post("http://localhost/app/@@index", "y=1&x=2")
     assert receiver.call_args == 'y=1&x=2'
     browser.post("http://localhost/app/@@index", "x=1&y=2")
     assert receiver.call_args == 'x=1&y=2'
Example #15
0
 def test_can_set_content_type(self):
     # TEMPORARY test. We can set the content type of a post request.
     app = SampleApp()
     self.layer.getRootFolder()['app'] = app
     browser = Browser()
     browser.handleErrors = False
     browser.post("http://localhost/app/@@bar", "x=1&y=2",
                  "application/x-javascript")
     assert browser.contents == (
         "INPUT: x=1&y=2 "
         "CONTENT-TYPE application/x-javascript"
         )
Example #16
0
 def test_notify_view_validation_valid(self):
     # we can get successful validations with notify
     receiver = PayPalIPNReceiver()
     receiver.validation_url = self.layer.server.url
     root = self.layer.getRootFolder()
     root['app'] = receiver
     browser = Browser()
     browser.post('http://localhost/app/@@index', 'x=2')
     sent_body = self.layer.server.last_request_body
     assert browser.headers.get("status") == "200 Ok"
     assert sent_body == 'cmd=_notify-validate&x=2'
     assert len(list(receiver.keys())) == 1
     notification = receiver[receiver.keys()[0]]
     assert notification.final_verdict == u'VERIFIED'
Example #17
0
 def test_notify_view_validation_valid(self):
     # we can get successful validations with notify
     receiver = PayPalIPNReceiver()
     receiver.validation_url = self.layer.server.url
     root = self.layer.getRootFolder()
     root['app'] = receiver
     browser = Browser()
     browser.post('http://localhost/app/@@index', 'x=2')
     sent_body = self.layer.server.last_request_body
     assert browser.headers.get("status") == "200 Ok"
     assert sent_body == 'cmd=_notify-validate&x=2'
     assert len(list(receiver.keys())) == 1
     notification = receiver[receiver.keys()[0]]
     assert notification.final_verdict == u'VERIFIED'
Example #18
0
def browser(db_session, request, setup_app):
    """returns an instance of `zope.testbrowser`.  The `kotti.testing.user`
    pytest marker (or `pytest.mark.user`) can be used to pre-authenticate
    the browser with the given login name: `@user('admin')`.
    """
    from zope.testbrowser.wsgi import Browser
    from kotti.testing import BASE_URL

    host, port = BASE_URL.split(":")[-2:]
    browser = Browser("http://{}:{}/".format(host[2:], int(port)), wsgi_app=setup_app)
    marker = request.node.get_closest_marker("user")
    if marker:
        # set auth cookie directly on the browser instance...
        from pyramid.security import remember
        from pyramid.testing import DummyRequest

        login = marker.args[0]
        environ = dict(HTTP_HOST=host[2:])
        for _, value in remember(DummyRequest(environ=environ), login):
            cookie, _ = value.split(";", 1)
            name, value = cookie.split("=")
            if name in browser.cookies:
                del browser.cookies[name]
            browser.cookies.create(name, value.strip('"'), path="/")
    return browser
Example #19
0
 def setUp(self):
     from moneypot import main
     self.browser = Browser(wsgi_app=main({},
                                          **{'sqlalchemy.url': "sqlite://",
                                             'debugmail': 'true',
                                             'mail.default_sender': '*****@*****.**',
                                             }))
Example #20
0
 def test_index_calls_store_notification(self):
     # the index view informs the receiver.
     receiver = ModifiedReceiver()
     receiver.validation_url = ''
     self.layer.getRootFolder()['app'] = receiver
     browser = Browser()
     browser.post("http://localhost/app/@@index", "y=1&x=2")
     assert receiver.call_args == 'y=1&x=2'
     browser.post("http://localhost/app/@@index", "x=1&y=2")
     assert receiver.call_args == 'x=1&y=2'
Example #21
0
 def test_can_access_post_data_line(self):
     # TEMPORARY test. We can access the body line with the post data.
     app = SampleApp()
     self.layer.getRootFolder()['app'] = app
     browser = Browser()
     browser.handleErrors = False
     browser.post("http://localhost/app/@@bar", "x=1&y=2")
     assert browser.contents == (
         "INPUT: x=1&y=2 "
         "CONTENT-TYPE application/x-www-form-urlencoded")
     browser.post("http://localhost/app/@@bar", "y=1&x=2")
     assert browser.contents == (
         "INPUT: y=1&x=2 "
         "CONTENT-TYPE application/x-www-form-urlencoded")
Example #22
0
 def test_can_access_post_data_line(self):
     # TEMPORARY test. We can access the body line with the post data.
     app = SampleApp()
     self.layer.getRootFolder()['app'] = app
     browser = Browser()
     browser.handleErrors = False
     browser.post("http://localhost/app/@@bar", "x=1&y=2")
     assert browser.contents == (
         "INPUT: x=1&y=2 "
         "CONTENT-TYPE application/x-www-form-urlencoded"
     )
     browser.post("http://localhost/app/@@bar", "y=1&x=2")
     assert browser.contents == (
         "INPUT: y=1&x=2 "
         "CONTENT-TYPE application/x-www-form-urlencoded"
     )
Example #23
0
from zope.testbrowser.ftests.wsgitestapp import WSGITestApplication
from zope.testbrowser.wsgi import Browser

wsgi_app = WSGITestApplication()

browser = Browser('http://localhost/@@/testbrowser/simple.html',
                  wsgi_app=wsgi_app)
print(browser.url)
Example #24
0
 def test_bla(self):
     browser = Browser()
Example #25
0
def browser(app):
    """
    A ``zope.testbrowser.wsgi.Browser`` instance for integration testing.
    """
    return Browser('http://localhost/', wsgi_app=app.wsgi_app)
Example #26
0
 def setup_browser(self, frontend):
     self.browser = Browser('http://localhost/', wsgi_app=frontend.wsgi_app)
Example #27
0
class FunctionalTest(unittest.TestCase):
    '''
    Test the web interface:
        * create a pot
        * add expense
        * invite user
        * invited user adds expense
    test: correct result is shown
    '''

    SITE = 'http://localhost/'

    def setUp(self):
        from moneypot import main
        self.browser = Browser(wsgi_app=main({},
                                             **{'sqlalchemy.url': "sqlite://",
                                                'debugmail': 'true',
                                                'mail.default_sender': '*****@*****.**',
                                                }))

    def tearDown(self):
        testing.tearDown()

    def invite_bob(self, email=''):
        '''
        start on pot site
        invite bob
        and return link for bob
        '''
        link = self.browser.getLink('Invite')
        link.click()
        name = self.browser.getControl(name='Participant--name')
        mail = self.browser.getControl(name='Participant--email')
        name.value = 'Bob'
        mail.value = email
        submit = self.browser.getControl(name='submit')
        submit.click()

        #now look for link for bob
        soup = BeautifulSoup(self.browser.contents)
        boblink = soup.find('div', 'alert').a['href']  # the link is inside the first "alert" (where messages are presented)
        return boblink

    def create_pot(self):
        self.browser.open(self.SITE)
        #Create Pot
        potinput = self.browser.getControl(name="HomeForm--potname")
        nameinput = self.browser.getControl(name="HomeForm--yourname")
        nameinput.value = "Alice"
        potinput.value = "My New Cool Pot"
        submit = self.browser.getControl(name='submit')
        submit.click()

    def add_expense(self, amount="42.0"):
        '''adds an expese'''
        description = self.browser.getControl(name='Expense--description')
        expense = self.browser.getControl(name='Expense--amount')
        description.value = "my very first test expense"
        expense.value = amount

        submit = self.browser.getControl(name='submit')
        submit.click()

    def remove_expense(self):
        pass

    def register(self):
        '''register Alice'''
        username = self.browser.getControl(name='RegisterForm--username')
        email = self.browser.getControl(name='RegisterForm--yourmail')
        password = self.browser.getControl(name='RegisterForm--password')
        password_confirm = self.browser.getControl(name='RegisterForm--password_confirm')

        username.value = 'alice'
        email.value = '*****@*****.**'
        password.value = 'secret'
        password_confirm.value = 'secret'

        submit = self.browser.getControl(name='submit')
        submit.click()

    def login(self, username='******', password='******'):
        '''login Alice'''
        username_control = self.browser.getControl(name='LoginForm--username')
        password_control = self.browser.getControl(name='LoginForm--password')

        username_control.value = username
        password_control.value = password

        submit = self.browser.getControl(name='submit')
        submit.click()

    def test_create_pot(self):
        self.create_pot()

    def test_invite_bob(self):
        self.create_pot()
        boblink = self.invite_bob('*****@*****.**')
        #try to call this site
        self.browser.open(boblink)
        #try to remove someone
        link = self.browser.getLink(url="remove")
        link.click()

    def test_add_expense(self):
        self.create_pot()
        self.add_expense()
        soup = BeautifulSoup(self.browser.contents)
        expense_text = soup.find('td', text="42.00")
        self.assertIsNotNone(expense_text)

    def test_remove_expense(self):
        self.create_pot()
        self.add_expense()
        soup = BeautifulSoup(self.browser.contents)
        expense_text = soup.find('td', text="42.00")
        self.assertIsNotNone(expense_text)
        self.remove_expense()
        amount_text = soup.find('td', text="0.00")
        self.assertIsNotNone(amount_text)

    def test_register_login_logout(self):
        '''
        go to login page, from there follow "register" link.
        register alice and go back to login page
        login
        then try to logout (logout link is only visible if login was successfull)
        '''
        self.browser.open(self.SITE)
        login_link = self.browser.getLink('Login')
        login_link.click()
        register_link = self.browser.getLink('Registration')
        register_link.click()
        self.register()
        login_link = self.browser.getLink('Login')
        login_link.click()
        self.login()
        logout_link = self.browser.getLink('Logout')
        logout_link.click()

    def test_change_password(self):
        '''
        go to login page, from there follow "register" link.
        register alice and go back to login page
        login
        change alices password
        logout and
        login with new password
        '''
        self.browser.open(self.SITE)
        #go to login page
        login_link = self.browser.getLink('Login')
        login_link.click()
        #follow registration link
        register_link = self.browser.getLink('Registration')
        register_link.click()
        #register alice with password secret
        self.register()
        #log her in
        login_link = self.browser.getLink('Login')
        login_link.click()
        self.login()

        #try to change her password
        change_password_link = self.browser.getLink('Change Password')
        change_password_link.click()

        old_password = self.browser.getControl(name='ChangePasswordForm--old_password')
        new_password = self.browser.getControl(name='ChangePasswordForm--password')
        confirm_password = self.browser.getControl(name='ChangePasswordForm--confirm_password')

        old_password.value = 'secret'
        new_password.value = 'newsecret'
        confirm_password.value = 'newsecret'
        submit = self.browser.getControl(name='submit')
        submit.click()

        self.assertIn('changed password', self.browser.contents)

        #logout
        logout_link = self.browser.getLink('Logout')
        logout_link.click()

        #login with new password
        login_link = self.browser.getLink('Login')
        login_link.click()
        self.login(password='******')
        #try if login was successfull: logout link is only visible when logged in
        logout_link = self.browser.getLink('Logout')

        #change back
        change_password_link = self.browser.getLink('Change Password')
        change_password_link.click()

        old_password = self.browser.getControl(name='ChangePasswordForm--old_password')
        new_password = self.browser.getControl(name='ChangePasswordForm--password')
        confirm_password = self.browser.getControl(name='ChangePasswordForm--confirm_password')

        old_password.value = 'newsecret'
        new_password.value = 'secret'
        confirm_password.value = 'secret'
        submit = self.browser.getControl(name='submit')
        submit.click()

        self.assertIn('changed password', self.browser.contents)

    def test_overview(self):
        '''
        log in as registered user, check in the overview page for newly created pots
        '''
        self.test_register_login_logout()
        login_link = self.browser.getLink('Login')
        login_link.click()
        self.login()
        #now we should directly be redirected to overview page
        self.assertIn('Overview', self.browser.contents)
        self.assertIn('alice', self.browser.contents)

        #now create new pot
        new_pot_link = self.browser.getLink('New Pot')
        new_pot_link.click()
        #name and email should be set automatically
        potname = self.browser.getControl(name='HomeForm--potname')
        potname.value = 'testpot'
        submit = self.browser.getControl(name='submit')
        submit.click()

        #go to overview
        overview_link = self.browser.getLink('Overview')
        overview_link.click()

        self.assertIn('testpot', self.browser.contents)

        archive_link = self.browser.getLink(url='archive')
        archive_link.click()

        #need to check that the pot was moved in the archive
        #just try to unarchive it

        unarchive_link = self.browser.getLink(url='unarchive')
        unarchive_link.click()
Example #28
0
    def setUp(self):
        """Method called by nose before running each test"""
        clean_db_and_bootstrap()

        self.browser = Browser('http://localhost/', wsgi_app=app.wsgi_app)