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