def setUp(self): if TestModel2.all().count() == 0: def txn(d): e = TestModel2(**d) e.put() for i in range(10): db.run_in_transaction( txn, dict(number=i, data_field='Test Data %02d' % i, is_active=(i%2==0)))
def test_form(self): """Form validation test with context_validate.""" os.environ['REQUEST_METHOD'] = 'POST' local.request = Request(get_env()) f = TestForm() f.model_field.set_query(TestModel2.all().filter('is_active =', True)) params = {'username': '******'} self.assertEqual(f.validate(params), False) params = { 'username': '******', 'password': '******', 'password_again': 'fugafuga', 'string_list_field': 'hoge', 'model_field': str(TestModel2.all().filter('is_active =', True).get().key()) } result = f.validate(params) self.assertEqual(result, True) params['password_again'] = 'moge' result = f.validate(params) self.assertEqual(result, False)