コード例 #1
0
class SimpleClass(object):
  FIRST = 0
  SECOND = 1
  IGNORE = 'String'
  ME_TOO = 2.3

  strings = collections.OrderedDict(((FIRST, '1st'),
                                     (SECOND, '2nd')))


class TestMethods(crud_test.TestCase):

  def testClassAsJsonDict(self):
    self.assertSameStructure({'FIRST': 0, 'SECOND': 1},
                             crud_utils.ClassAsJsonDict(SimpleClass))

  def testDictAsArrayForNgOptions(self):
    self.assertSameStructure([{'key': 0, 'name': '1st'},
                              {'key': 1, 'name': '2nd'}],
                             crud_utils.DictAsArrayForNgOptions(
                                 SimpleClass.strings))

  def testGenerateRandomString(self):
    self.assertEqual(30, len(crud_utils.GenerateRandomString(30)))
    self.assertEqual(10, len(crud_utils.GenerateRandomString(10)))


if __name__ == '__main__':
  crud_test.main()
コード例 #2
0

class CrudHandlerTest(crud_test.TestCase):
  """Tests the CrudHandler."""

  def assertJsonReplyEqual(self, ans, expected):
    """Make sure that two json strings are the same."""
    self.assertTrue(ans.startswith(crud_handler.JSON_PREFIX))
    self.assertTrue(expected.startswith(crud_handler.JSON_PREFIX))

    ans = json.loads(ans[len(crud_handler.JSON_PREFIX):])
    expected = json.loads(expected[len(crud_handler.JSON_PREFIX):])
    self.assertSameStructure(ans, expected)

  def testGetNew(self):
    handler = crud_handler.GetCrudHandler(SampleNdb)()
    handler.request = {'id': 'new'}

    class MockResponse(object):
      out = cStringIO.StringIO()
      headers = {}
    handler.response = MockResponse()
    handler.get()
    ans = handler.response.out.getvalue()
    expected = """)]}',\n{"id": "new", "name": null, "count": null}"""
    self.assertJsonReplyEqual(ans, expected)


if __name__ == '__main__':
  crud_test.main()
コード例 #3
0
def main(*args, **kwargs):
  """Call the unit test framework."""
  crud_test.main(*args, **kwargs)