tests/test_functional.py
changeset 2317 0d4b4aa5b969
child 2318 594b55099fab
equal deleted inserted replaced
2314:0a0e603215d7 2317:0d4b4aa5b969
       
     1 #!/usr/bin/python2.5
       
     2 #
       
     3 # Copyright 2009 the Melange authors.
       
     4 #
       
     5 # Licensed under the Apache License, Version 2.0 (the "License");
       
     6 # you may not use this file except in compliance with the License.
       
     7 # You may obtain a copy of the License at
       
     8 #
       
     9 #   http://www.apache.org/licenses/LICENSE-2.0
       
    10 #
       
    11 # Unless required by applicable law or agreed to in writing, software
       
    12 # distributed under the License is distributed on an "AS IS" BASIS,
       
    13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
       
    14 # See the License for the specific language governing permissions and
       
    15 # limitations under the License.
       
    16 
       
    17 
       
    18 __authors__ = [
       
    19   '"Matthew Wilkes" <matthew@matthewwilkes.co.uk>',
       
    20   ]
       
    21 
       
    22 
       
    23 from gaeftest.test import FunctionalTestCase
       
    24 
       
    25 from zope.testbrowser import browser
       
    26 
       
    27 import os.path
       
    28 
       
    29 class MelangeFunctionalTestCase(FunctionalTestCase):
       
    30   """A base class for all functional tests in Melange.
       
    31 
       
    32   Tests MUST NOT be defined here, but the superclass requires a path
       
    33   attribute that points to the app.yaml.  Utility functions MAY be
       
    34   declared here to be shared by all functional tests, but any
       
    35   overridden unittest methods MUST call the superclass version.
       
    36   """
       
    37 
       
    38   path = os.path.abspath(__file__+"/../../app/app.yaml")
       
    39 
       
    40 
       
    41 class TestBranding(MelangeFunctionalTestCase):
       
    42   """Tests that ensure Melange properly displays attribution.
       
    43 
       
    44   Other notices, as required by the project and/or law, are tested
       
    45   here as well.
       
    46   """
       
    47 
       
    48   def test_attribution(self):
       
    49     """Ensure that the front page asserts that it is a Melange app.
       
    50     """
       
    51 
       
    52     tb = browser.Browser()
       
    53     tb.open("http://127.0.0.1:8080/site/show/site")
       
    54 
       
    55     self.assertTrue("Powered by Melange" in tb.contents)
       
    56 
       
    57 class TestLogin(MelangeFunctionalTestCase):
       
    58   """Tests that check the login system is functioning correctly.
       
    59 
       
    60   Also tests that users go through the correct registration workflow.
       
    61   """
       
    62 
       
    63   def test_firstLogin(self):
       
    64     """Ensure that new users are prompted to create a profile.
       
    65 
       
    66     Also test that only new users are prompted.
       
    67     """
       
    68 
       
    69     tb = browser.Browser()
       
    70     tb.open("http://127.0.0.1:8080")
       
    71 
       
    72     tb.getLink("Sign in").click()
       
    73     self.assertTrue("login" in tb.url)
       
    74 
       
    75     # fill in dev_appserver login form
       
    76     tb.getForm().getControl("Email").value = "newuser@example.com"
       
    77     tb.getForm().getControl("Login").click()
       
    78 
       
    79     self.assertTrue(tb.url.endswith("/show/site"))
       
    80     self.assertTrue('Please create <a href="/user/create_profile">'
       
    81         'User Profile</a> in order to view this page' in tb.contents)
       
    82 
       
    83     tb.getLink("User Profile").click()
       
    84 
       
    85     # fill in the user profile
       
    86     cp = tb.getForm(action="create_profile")
       
    87     cp.getControl(name="link_id").value = "exampleuser"
       
    88     cp.getControl(name="name").value = "Example user"
       
    89     cp.getControl("Save").click()
       
    90 
       
    91     # if all is well, we go to the edit page
       
    92     self.assertTrue("edit_profile" in tb.url)
       
    93 
       
    94     tb.open("http://127.0.0.1:8080")
       
    95 
       
    96     # call to action no longer on front page
       
    97     self.assertFalse('Please create <a href="/user/create_profile">'
       
    98         'User Profile</a> in order to view this page' in tb.contents)
       
    99