Exemplo n.º 1
0
  def test_canUpdateModelSingleField(self):
    response = requests.handle_request(
      MockRequest(
        method="POST",
        POST = {"number_field":42,
                "string_field":"test",
                "boolean_field":True,
                "float_field":42.1}),
      appname="testapp",
      modelname="TestModel",
      operation="create")

    id = int(response.content)

    response = requests.handle_request(
      MockRequest(
        method="POST",
        POST = {"id":id,
                "number_field":43}),
      appname="testapp",
      modelname="TestModel",
      operation="update")

    response = requests.handle_request(
      MockRequest(
        method="POST",
        POST = {"id":id}),
      appname="testapp",
      modelname="TestModel",
      operation="read")

    response_dictionary = json.loads(response.content)
    self.assertEquals(response_dictionary[u'number_field'],43)
Exemplo n.º 2
0
 def test_creationFailsIfPassInInvalidType(self):
   response = requests.handle_request(
     MockRequest(
       method="POST",
       POST = {"number_field":"this is not a number",
               "string_field":"test",
               "boolean_field":True,
               "float_field":42.1}),
     appname="testapp",
     modelname="TestModel",
     operation="create")
   self.assertEquals(type(response), HttpResponseBadRequest)
Exemplo n.º 3
0
  def test_updateFailsIfNoId(self):
    response = requests.handle_request(
      MockRequest(
        method="POST",
        POST = {"number_field":42,
                "string_field":"test",
                "boolean_field":True,
                "float_field":42.1}),
      appname="testapp",
      modelname="TestModel",
      operation="create")

    id = int(response.content)

    response = requests.handle_request(
      MockRequest(
        method="POST",
        POST = {"number_field":43}),
      appname="testapp",
      modelname="TestModel",
      operation="update")

    self.assertEquals(type(response),HttpResponseBadRequest)
Exemplo n.º 4
0
  def test_canReadModelWithFullParameters(self):
    response = requests.handle_request(
      MockRequest(
        method="POST",
        POST = {"number_field":42,
                "string_field":"test",
                "boolean_field":True,
                "float_field":42.1}),
      appname="testapp",
      modelname="TestModel",
      operation="create")

    id = int(response.content)

    response = requests.handle_request(
      MockRequest(
        method="POST",
        POST = {"id":id}),
      appname="testapp",
      modelname="TestModel",
      operation="read")

    response_dictionary = json.loads(response.content)
    self.assertEquals(response_dictionary,{u'id':id,u'number_field':42,u'string_field':u'test',u'boolean_field':True,u'float_field':42.1})
Exemplo n.º 5
0
  def test_canDeleteModel(self):
    response = requests.handle_request(
      MockRequest(
        method="POST",
        POST = {"number_field":42,
                "string_field":"test",
                "boolean_field":True,
                "float_field":42.1}),
      appname="testapp",
      modelname="TestModel",
      operation="create")

    id = int(response.content)

    response = requests.handle_request(
      MockRequest(
        method="POST",
        POST = {"id":id}),
      appname="testapp",
      modelname="TestModel",
      operation="delete")

    response = bool(response.content)
    self.assertTrue(response)
Exemplo n.º 6
0
 def test_canCreateNewModel(self):
   response = requests.handle_request(
     MockRequest(
       method="POST",
       POST = {"number_field":42,
               "string_field":"test",
               "boolean_field":True,
               "float_field":42.1}),
     appname="testapp",
     modelname="TestModel",
     operation="create")
   self.assertNotEquals(type(response), HttpResponseBadRequest)
   try:
     int(response.content)
   except:
     self.fail("Expecting ID in response, got [%s]"%response.content)
Exemplo n.º 7
0
 def test_operationOnInvalidModelReturnsBadRequest(self):
   response = requests.handle_request(MockRequest(method="POST"), appname="testapp", modelname="foo", operation="read")
   self.assertEquals(type(response), HttpResponseBadRequest)
Exemplo n.º 8
0
 def test_GETRequestReturnsBadRequest(self):
   response = requests.handle_request(MockRequest(method="GET"), appname="testapp", modelname="foo", operation="foo")
   self.assertEquals(type(response), HttpResponseBadRequest)
Exemplo n.º 9
0
 def test_invalidOperationReturnsBadRequest(self):
   response = requests.handle_request(MockRequest(), appname="testapp", modelname="foo", operation="invalid")
   self.assertEquals(type(response), HttpResponseBadRequest)