tests/test_functional.py
author Matthew Wilkes <matthew@matthewwilkes.co.uk>
Fri, 15 May 2009 18:01:43 +0200
changeset 2317 0d4b4aa5b969
child 2318 594b55099fab
permissions -rw-r--r--
Add some example function tests that use gaeftest
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
0d4b4aa5b969 Add some example function tests that use gaeftest
Matthew Wilkes <matthew@matthewwilkes.co.uk>
parents:
diff changeset
    29
class MelangeFunctionalTestCase(FunctionalTestCase):
0d4b4aa5b969 Add some example function tests that use gaeftest
Matthew Wilkes <matthew@matthewwilkes.co.uk>
parents:
diff changeset
    30
  """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
    31
0d4b4aa5b969 Add some example function tests that use gaeftest
Matthew Wilkes <matthew@matthewwilkes.co.uk>
parents:
diff changeset
    32
  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
    33
  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
    34
  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
    35
  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
    36
  """
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
  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
    39
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
class TestBranding(MelangeFunctionalTestCase):
0d4b4aa5b969 Add some example function tests that use gaeftest
Matthew Wilkes <matthew@matthewwilkes.co.uk>
parents:
diff changeset
    42
  """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
    43
0d4b4aa5b969 Add some example function tests that use gaeftest
Matthew Wilkes <matthew@matthewwilkes.co.uk>
parents:
diff changeset
    44
  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
    45
  here as well.
0d4b4aa5b969 Add some example function tests that use gaeftest
Matthew Wilkes <matthew@matthewwilkes.co.uk>
parents:
diff changeset
    46
  """
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
  def test_attribution(self):
0d4b4aa5b969 Add some example function tests that use gaeftest
Matthew Wilkes <matthew@matthewwilkes.co.uk>
parents:
diff changeset
    49
    """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
    50
    """
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
    tb = browser.Browser()
0d4b4aa5b969 Add some example function tests that use gaeftest
Matthew Wilkes <matthew@matthewwilkes.co.uk>
parents:
diff changeset
    53
    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
    54
0d4b4aa5b969 Add some example function tests that use gaeftest
Matthew Wilkes <matthew@matthewwilkes.co.uk>
parents:
diff changeset
    55
    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
    56
0d4b4aa5b969 Add some example function tests that use gaeftest
Matthew Wilkes <matthew@matthewwilkes.co.uk>
parents:
diff changeset
    57
class TestLogin(MelangeFunctionalTestCase):
0d4b4aa5b969 Add some example function tests that use gaeftest
Matthew Wilkes <matthew@matthewwilkes.co.uk>
parents:
diff changeset
    58
  """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
    59
0d4b4aa5b969 Add some example function tests that use gaeftest
Matthew Wilkes <matthew@matthewwilkes.co.uk>
parents:
diff changeset
    60
  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
    61
  """
0d4b4aa5b969 Add some example function tests that use gaeftest
Matthew Wilkes <matthew@matthewwilkes.co.uk>
parents:
diff changeset
    62
0d4b4aa5b969 Add some example function tests that use gaeftest
Matthew Wilkes <matthew@matthewwilkes.co.uk>
parents:
diff changeset
    63
  def test_firstLogin(self):
0d4b4aa5b969 Add some example function tests that use gaeftest
Matthew Wilkes <matthew@matthewwilkes.co.uk>
parents:
diff changeset
    64
    """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
    65
0d4b4aa5b969 Add some example function tests that use gaeftest
Matthew Wilkes <matthew@matthewwilkes.co.uk>
parents:
diff changeset
    66
    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
    67
    """
0d4b4aa5b969 Add some example function tests that use gaeftest
Matthew Wilkes <matthew@matthewwilkes.co.uk>
parents:
diff changeset
    68
0d4b4aa5b969 Add some example function tests that use gaeftest
Matthew Wilkes <matthew@matthewwilkes.co.uk>
parents:
diff changeset
    69
    tb = browser.Browser()
0d4b4aa5b969 Add some example function tests that use gaeftest
Matthew Wilkes <matthew@matthewwilkes.co.uk>
parents:
diff changeset
    70
    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
    71
0d4b4aa5b969 Add some example function tests that use gaeftest
Matthew Wilkes <matthew@matthewwilkes.co.uk>
parents:
diff changeset
    72
    tb.getLink("Sign in").click()
0d4b4aa5b969 Add some example function tests that use gaeftest
Matthew Wilkes <matthew@matthewwilkes.co.uk>
parents:
diff changeset
    73
    self.assertTrue("login" in tb.url)
0d4b4aa5b969 Add some example function tests that use gaeftest
Matthew Wilkes <matthew@matthewwilkes.co.uk>
parents:
diff changeset
    74
0d4b4aa5b969 Add some example function tests that use gaeftest
Matthew Wilkes <matthew@matthewwilkes.co.uk>
parents:
diff changeset
    75
    # fill in dev_appserver login form
0d4b4aa5b969 Add some example function tests that use gaeftest
Matthew Wilkes <matthew@matthewwilkes.co.uk>
parents:
diff changeset
    76
    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
    77
    tb.getForm().getControl("Login").click()
0d4b4aa5b969 Add some example function tests that use gaeftest
Matthew Wilkes <matthew@matthewwilkes.co.uk>
parents:
diff changeset
    78
0d4b4aa5b969 Add some example function tests that use gaeftest
Matthew Wilkes <matthew@matthewwilkes.co.uk>
parents:
diff changeset
    79
    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
    80
    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
    81
        '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
    82
0d4b4aa5b969 Add some example function tests that use gaeftest
Matthew Wilkes <matthew@matthewwilkes.co.uk>
parents:
diff changeset
    83
    tb.getLink("User Profile").click()
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
    # fill in the user profile
0d4b4aa5b969 Add some example function tests that use gaeftest
Matthew Wilkes <matthew@matthewwilkes.co.uk>
parents:
diff changeset
    86
    cp = tb.getForm(action="create_profile")
0d4b4aa5b969 Add some example function tests that use gaeftest
Matthew Wilkes <matthew@matthewwilkes.co.uk>
parents:
diff changeset
    87
    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
    88
    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
    89
    cp.getControl("Save").click()
0d4b4aa5b969 Add some example function tests that use gaeftest
Matthew Wilkes <matthew@matthewwilkes.co.uk>
parents:
diff changeset
    90
0d4b4aa5b969 Add some example function tests that use gaeftest
Matthew Wilkes <matthew@matthewwilkes.co.uk>
parents:
diff changeset
    91
    # 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
    92
    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
    93
0d4b4aa5b969 Add some example function tests that use gaeftest
Matthew Wilkes <matthew@matthewwilkes.co.uk>
parents:
diff changeset
    94
    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
    95
0d4b4aa5b969 Add some example function tests that use gaeftest
Matthew Wilkes <matthew@matthewwilkes.co.uk>
parents:
diff changeset
    96
    # 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
    97
    self.assertFalse('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
    98
        '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
    99