~maddevelopers/mg5amcnlo/WWW_tg

« back to all changes in this revision

Viewing changes to madgraph3/tests/functional/test_root.py

  • Committer: John Doe
  • Date: 2013-03-25 20:27:02 UTC
  • Revision ID: john.doe@gmail.com-20130325202702-5sk3t1r8h33ca4p4
first clean version

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
"""
 
3
Functional test suite for the root controller.
 
4
 
 
5
This is an example of how functional tests can be written for controllers.
 
6
 
 
7
As opposed to a unit-test, which test a small unit of functionality,
 
8
functional tests exercise the whole application and its WSGI stack.
 
9
 
 
10
Please read http://pythonpaste.org/webtest/ for more information.
 
11
 
 
12
"""
 
13
from nose.tools import assert_true
 
14
 
 
15
from madgraph3.tests import TestController
 
16
 
 
17
 
 
18
class TestRootController(TestController):
 
19
    """Tests for the method in the root controller."""
 
20
 
 
21
    def test_index(self):
 
22
        """The front page is working properly"""
 
23
        response = self.app.get('/')
 
24
        msg = 'TurboGears 2 is rapid web application development toolkit '\
 
25
              'designed to make your life easier.'
 
26
        # You can look for specific strings:
 
27
        assert_true(msg in response)
 
28
 
 
29
        # You can also access a BeautifulSoup'ed response in your tests
 
30
        # (First run $ easy_install BeautifulSoup
 
31
        # and then uncomment the next two lines)
 
32
 
 
33
        #links = response.html.findAll('a')
 
34
        #print links
 
35
        #assert_true(links, "Mummy, there are no links here!")
 
36
 
 
37
    def test_environ(self):
 
38
        """Displaying the wsgi environ works"""
 
39
        response = self.app.get('/environ.html')
 
40
        assert_true('The keys in the environment are: ' in response)
 
41
 
 
42
    def test_data(self):
 
43
        """The data display demo works with HTML"""
 
44
        response = self.app.get('/data.html?a=1&b=2')
 
45
        expected1 = """<td>a</td>
 
46
                <td>1</td>"""
 
47
        expected2 = """<td>b</td>
 
48
                <td>2</td>"""
 
49
 
 
50
        assert expected1 in response, response
 
51
        assert expected2 in response, response
 
52
 
 
53
    def test_data_json(self):
 
54
        """The data display demo works with JSON"""
 
55
        resp = self.app.get('/data.json?a=1&b=2')
 
56
        assert '"a": "1", "b": "2"' in resp, resp
 
57
 
 
58
    def test_secc_with_manager(self):
 
59
        """The manager can access the secure controller"""
 
60
        # Note how authentication is forged:
 
61
        environ = {'REMOTE_USER': 'manager'}
 
62
        resp = self.app.get('/secc', extra_environ=environ, status=200)
 
63
        assert 'Secure Controller here' in resp.body, resp.body
 
64
 
 
65
    def test_secc_with_editor(self):
 
66
        """The editor cannot access the secure controller"""
 
67
        environ = {'REMOTE_USER': 'editor'}
 
68
        self.app.get('/secc', extra_environ=environ, status=403)
 
69
        # It's enough to know that authorization was denied with a 403 status
 
70
 
 
71
    def test_secc_with_anonymous(self):
 
72
        """Anonymous users must not access the secure controller"""
 
73
        self.app.get('/secc', status=401)
 
74
        # It's enough to know that authorization was denied with a 401 status