Пример #1
0
  def test_modify(self):
    """Test for modifying existing entity with ModelForm."""
    os.environ['REQUEST_METHOD'] = 'POST'
    local.request = Request(get_env())

    # first create a new entity
    f = TestModelForm()
    params = {"number": "12", "data_field": "data string",
              "is_active": "False", "string_list_field": "list"}
    self.assertEqual(f.validate(params), True)
    f.save()
    self.assertEqual(TestModel.all().count(), 1)
    entity = TestModel.all().get()
    self.assertEqual(entity.number, 12)

    # modify with TestModelForm
    f = TestModelForm(instance=entity)
    params = {"number": "13", "data_field": "modified data",
              "is_active": "True", "string_list_field": "line 1\nline 2"}
    self.assertEqual(f.validate(params), True)
    f.save()

    # check values
    self.assertEqual(TestModel.all().count(), 1)
    entity = TestModel.all().get()
    self.assertEqual(entity.number, 13)
    self.assertEqual(entity.data_field, "modified data")
    self.assertEqual(entity.is_active, True)
    self.assertEqual(entity.string_list_field, ["line 1", "line 2"])
Пример #2
0
 def setUp(self):
   super(FormTest, self).setUp()
   if TestModel.all().count() == 0:
     for i in range(10):
       t = TestModel(number=i, data_field='Test Data %02d' % i,
                     is_active=(i%2==0))
       t.put()
  def test_form(self):
    """Test for modifying existing entity with ModelForm."""

    # first create a new entity
    f = TestModelForm()
    params = {"number": "12", "data_field": "data string",
              "is_active": "False", "string_list_field": "list"}
    self.assertEqual(f.validate(params), True)
    f.save()
    self.assertEqual(TestModel.all().count(), 1)
    entity = TestModel.all().get()
    self.assertEqual(entity.number, 12)

    # modify with TestModelForm
    f = TestModelForm(instance=entity)
    params = {"number": "13", "data_field": "modified data",
              "is_active": "True", "string_list_field": "line 1\nline 2"}
    self.assertEqual(f.validate(params), True)
    f.save()

    # check values
    self.assertEqual(TestModel.all().count(), 1)
    entity = TestModel.all().get()
    self.assertEqual(entity.number, 13)
    self.assertEqual(entity.data_field, "modified data")
    self.assertEqual(entity.is_active, True)
    self.assertEqual(entity.string_list_field, ["line 1", "line 2"])

    """Form validation test with ModelForm."""
    os.environ['REQUEST_METHOD'] = 'POST'
    local.request = Request(get_env())
    f = TestModelForm()
    params = {"number": "12"}
    # In your view, you can validate the form data with:
    # f.validate(request.form)
    # or with(If you have FileField):
    # f.validate(request.form, request.files)
    self.assertEqual(f.validate(params), False)
    f.reset()
    params = {"number": "12",
              "data_field": "data string longer than 20 characters",
              "is_active": "False",
              "string_list_field": "test"}
    self.assertEqual(f.validate(params), False)

    f.reset()
    params = {"number": "12",
              "data_field": "data string",
              "is_active": "False",
              "string_list_field": ""}
    self.assertEqual(f.validate(params), False)

    # create a new entity
    f.reset()
    params = {"number": "12", "data_field": "data string",
              "is_active": "False", "string_list_field": "list"}
    self.assertEqual(f.validate(params), True)
    f.save()
    self.assertEqual(TestModel.all().count(), 2)
Пример #4
0
  def test_form(self):
    """Test for modifying existing entity with ModelForm."""

    # first create a new entity
    f = TestModelForm()
    params = {"number": "12", "data_field": "data string",
              "is_active": "False", "string_list_field": "list"}
    self.assertEqual(f.validate(params), True)
    f.save()
    self.assertEqual(TestModel.all().count(), 1)
    entity = TestModel.all().get()
    self.assertEqual(entity.number, 12)

    # modify with TestModelForm
    f = TestModelForm(instance=entity)
    params = {"number": "13", "data_field": "modified data",
              "is_active": "True", "string_list_field": "line 1\nline 2"}
    self.assertEqual(f.validate(params), True)
    f.save()

    # check values
    self.assertEqual(TestModel.all().count(), 1)
    entity = TestModel.all().get()
    self.assertEqual(entity.number, 13)
    self.assertEqual(entity.data_field, "modified data")
    self.assertEqual(entity.is_active, True)
    self.assertEqual(entity.string_list_field, ["line 1", "line 2"])

    """Form validation test with ModelForm."""
    os.environ['REQUEST_METHOD'] = 'POST'
    local.request = Request(get_env())
    f = TestModelForm()
    params = {"number": "12"}
    # In your view, you can validate the form data with:
    # f.validate(request.form)
    # or with(If you have FileField):
    # f.validate(request.form, request.files)
    self.assertEqual(f.validate(params), False)
    f.reset()
    params = {"number": "12",
              "data_field": "data string longer than 20 characters",
              "is_active": "False",
              "string_list_field": "test"}
    self.assertEqual(f.validate(params), False)

    f.reset()
    params = {"number": "12",
              "data_field": "data string",
              "is_active": "False",
              "string_list_field": ""}
    self.assertEqual(f.validate(params), False)

    # create a new entity
    f.reset()
    params = {"number": "12", "data_field": "data string",
              "is_active": "False", "string_list_field": "list"}
    self.assertEqual(f.validate(params), True)
    f.save()
    self.assertEqual(TestModel.all().count(), 2)
Пример #5
0
  def test_form(self):
    """Form validation test with ModelForm."""
    os.environ['REQUEST_METHOD'] = 'POST'
    local.request = Request(get_env())
    f = TestModelForm()
    params = {"number": "12"}
    # In your view, you can validate the form data with:
    # f.validate(request.form)
    # or with(If you have FileField):
    # f.validate(request.form, request.files)
    self.assertEqual(f.validate(params), False)
    f.reset()
    params = {"number": "12",
              "data_field": "data string longer than 20 characters",
              "is_active": "False",
              "string_list_field": "test"}
    self.assertEqual(f.validate(params), False)

    f.reset()
    params = {"number": "12",
              "data_field": "data string",
              "is_active": "False",
              "string_list_field": ""}
    self.assertEqual(f.validate(params), False)

    # create a new entity
    f.reset()
    params = {"number": "12", "data_field": "data string",
              "is_active": "False", "string_list_field": "list"}
    self.assertEqual(f.validate(params), True)
    f.save()
    self.assertEqual(TestModel.all().count(), 1)
Пример #6
0
 def test_form(self):
   """Form validation test with context_validate."""
   os.environ['REQUEST_METHOD'] = 'POST'
   local.request = Request(get_env())
   f = TestForm()
   params = {'username': '******'}
   self.assertEqual(f.validate(params), False)
   params = {
     'username': '******',
     'password': '******',
     'password_again': 'fugafuga',
     'string_list_field': 'hoge',
     'model_field': str(TestModel.all().get().key())
   }
   result = f.validate(params)
   self.assertEqual(result, True)
   params['password_again'] = 'moge'
   result = f.validate(params)
   self.assertEqual(result, False)
Пример #7
0
 def setUp(self):
   super(ModelFormTest, self).setUp()
   entries = TestModel.all().fetch(100)
   db.delete(entries)
Пример #8
0
 def tearDown(self):
   entries = TestModel.all().fetch(100)
   db.delete(entries)