tests/pymox/README
author Lennard de Rijk <ljvderijk@gmail.com>
Sat, 14 Feb 2009 21:18:12 +0000
changeset 1328 cd175dddc15c
parent 1000 9af147fc1f1c
permissions -rw-r--r--
Added bulk acceptance and progress bar in review org applications view. In the list of organization applications for reviewing, if you click the button "click here" the whole first text line will fade out and the progress bar will fade in while starting to contact the server for the list of orgs to accept and then make synchronous calls for acceptance, while updating the progress bar, the name of the organization currently accepting and the number of orgs already accepted against the total. Inside the script, what's inside the parenthesis is converted due to regexp (in this case (link_id)) and then read the json_object.applications[index].link_id. By doing this with an eval(), you can use other names as well and the script will be reading for example json_object.applications[index].attribute_name if you insert "(attribute_name)" inside the link returned by {{ bulk_accept_link }}. Notes by Lennard: -Put Done outside the for-loop so that it also shows when there are 0 pre-accepted organizations. -Made some minor style fixes Patch by: Mario Ferraro Reviewed by: Lennard de Rijk
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1000
9af147fc1f1c Add pymox to tests folder.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     1
Mox is an open source mock object framework for Python, inspired by
9af147fc1f1c Add pymox to tests folder.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     2
the Java library EasyMock.
9af147fc1f1c Add pymox to tests folder.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     3
9af147fc1f1c Add pymox to tests folder.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     4
To install:
9af147fc1f1c Add pymox to tests folder.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     5
9af147fc1f1c Add pymox to tests folder.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     6
  $ python setup.py install
9af147fc1f1c Add pymox to tests folder.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     7
9af147fc1f1c Add pymox to tests folder.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     8
To run Mox's internal tests:
9af147fc1f1c Add pymox to tests folder.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     9
9af147fc1f1c Add pymox to tests folder.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    10
  $ python mox_test.py
9af147fc1f1c Add pymox to tests folder.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    11
9af147fc1f1c Add pymox to tests folder.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    12
Basic usage:
9af147fc1f1c Add pymox to tests folder.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    13
9af147fc1f1c Add pymox to tests folder.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    14
  import unittest
9af147fc1f1c Add pymox to tests folder.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    15
  import mox
9af147fc1f1c Add pymox to tests folder.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    16
9af147fc1f1c Add pymox to tests folder.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    17
  class PersonTest(mox.MoxTestBase):
9af147fc1f1c Add pymox to tests folder.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    18
9af147fc1f1c Add pymox to tests folder.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    19
    def testUsingMox(self):
9af147fc1f1c Add pymox to tests folder.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    20
      # Create a mock Person
9af147fc1f1c Add pymox to tests folder.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    21
      mock_person = self.mox.CreateMock(Person)
9af147fc1f1c Add pymox to tests folder.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    22
9af147fc1f1c Add pymox to tests folder.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    23
      test_person = ...
9af147fc1f1c Add pymox to tests folder.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    24
      test_primary_key = ...
9af147fc1f1c Add pymox to tests folder.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    25
      unknown_person = ...
9af147fc1f1c Add pymox to tests folder.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    26
9af147fc1f1c Add pymox to tests folder.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    27
      # Expect InsertPerson to be called with test_person; return
9af147fc1f1c Add pymox to tests folder.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    28
      # test_primary_key at that point
9af147fc1f1c Add pymox to tests folder.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    29
      mock_person.InsertPerson(test_person).AndReturn(test_primary_key)
9af147fc1f1c Add pymox to tests folder.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    30
9af147fc1f1c Add pymox to tests folder.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    31
      # Raise an exception when this is called
9af147fc1f1c Add pymox to tests folder.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    32
      mock_person.DeletePerson(unknown_person).AndRaise(UnknownPersonError())
9af147fc1f1c Add pymox to tests folder.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    33
9af147fc1f1c Add pymox to tests folder.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    34
      # Switch from record mode to replay mode
9af147fc1f1c Add pymox to tests folder.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    35
      self.mox.ReplayAll()
9af147fc1f1c Add pymox to tests folder.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    36
9af147fc1f1c Add pymox to tests folder.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    37
      # Run the test
9af147fc1f1c Add pymox to tests folder.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    38
      ret_pk = mock_person.InsertPerson(test_person)
9af147fc1f1c Add pymox to tests folder.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    39
      self.assertEquals(test_primary_key, ret_pk)
9af147fc1f1c Add pymox to tests folder.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    40
      self.assertRaises(UnknownPersonError, mock_person, unknown_person)
9af147fc1f1c Add pymox to tests folder.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    41
9af147fc1f1c Add pymox to tests folder.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    42
For more documentation, see:
9af147fc1f1c Add pymox to tests folder.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    43
9af147fc1f1c Add pymox to tests folder.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    44
  http://code.google.com/p/pymox/wiki/MoxDocumentation
9af147fc1f1c Add pymox to tests folder.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    45
9af147fc1f1c Add pymox to tests folder.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    46
For more information, see:
9af147fc1f1c Add pymox to tests folder.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    47
9af147fc1f1c Add pymox to tests folder.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    48
  http://code.google.com/p/pymox/
9af147fc1f1c Add pymox to tests folder.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    49
9af147fc1f1c Add pymox to tests folder.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    50
Our user and developer discussion group is:
9af147fc1f1c Add pymox to tests folder.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    51
9af147fc1f1c Add pymox to tests folder.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    52
  http://groups.google.com/group/mox-discuss
9af147fc1f1c Add pymox to tests folder.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    53
9af147fc1f1c Add pymox to tests folder.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    54
Mox is Copyright 2008 Google Inc, and licensed under the Apache
9af147fc1f1c Add pymox to tests folder.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    55
License, Version 2.0; see the file COPYING for details.  If you would
9af147fc1f1c Add pymox to tests folder.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    56
like to help us improve Mox, join the group.