Example #1
0
    def test_standard_requests(self):
        response = http(POST, json.dumps({}))
        self.assertEqual(response.status, INVALID)

        response = http(POST, json.dumps({'required_field': 'text'}))
        self.assertEqual(response.status, OK)

        content = json.loads(response.content)
        self.assertIsInstance(content, dict)
        self.assertIn('id', content)

        id = content['id']
        self.assertIsInstance(id, int)

        response = http(GET, resource='example/%d' % id)
        self.assertEqual(response.status, OK)
        self.assertEqual(json.loads(response.content), {'id': id, 'required_field': 'text', 'default_field': 1})

        response = http(POST, json.dumps({'default_field': 3}), resource='example/%d' % id)
        self.assertEqual(response.status, OK)
        self.assertEqual(json.loads(response.content), {'id': id})

        response = http(GET, 'exclude=[required_field]', resource='example/%d' % id)
        self.assertEqual(response.status, OK)
        self.assertEqual(json.loads(response.content), {'id': id, 'default_field': 3})
        
        response = http(DELETE, resource='example/%d' % id)
        self.assertEqual(response.status, OK)
        self.assertEqual(json.loads(response.content), {'id': id})

        response = http(GET, resource='example/%d' % id)
        self.assertEqual(response.status, GONE)
Example #2
0
 def test_json_request(self):
     data = {'required_field': 'text'}
     response = http(POST, json.dumps(data))
     self.assertEqual(response.status, OK)
     
     content = json.loads(response.content)
     self.assertIsInstance(content, dict)
     self.assertIn('id', content)
     self.assertIsInstance(content['id'], int)
Example #3
0
    def test_json_request(self):
        data = {'required_field': 'text'}
        response = http(POST, json.dumps(data))
        self.assertEqual(response.status, OK)

        content = json.loads(response.content[0])
        self.assertIsInstance(content, dict)
        self.assertIn('id', content)
        self.assertIsInstance(content['id'], int)
Example #4
0
    def test_standard_requests(self):
        response = http(POST, json.dumps({}))
        self.assertEqual(response.status, INVALID)

        response = http(POST, json.dumps({'required_field': 'text'}))
        self.assertEqual(response.status, OK)

        content = json.loads(response.content[0])
        self.assertIsInstance(content, dict)
        self.assertIn('id', content)

        id = content['id']
        self.assertIsInstance(id, int)

        response = http(GET, resource='example/%d' % id)
        self.assertEqual(response.status, OK)
        self.assertEqual(json.loads(response.content[0]), {
            'id': id,
            'required_field': 'text',
            'default_field': 1
        })

        response = http(POST,
                        json.dumps({'default_field': 3}),
                        resource='example/%d' % id)
        self.assertEqual(response.status, OK)
        self.assertEqual(json.loads(response.content[0]), {'id': id})

        response = http(GET,
                        'exclude=[required_field]',
                        resource='example/%d' % id)
        self.assertEqual(response.status, OK)
        self.assertEqual(json.loads(response.content[0]), {
            'id': id,
            'default_field': 3
        })

        response = http(DELETE, resource='example/%d' % id)
        self.assertEqual(response.status, OK)
        self.assertEqual(json.loads(response.content[0]), {'id': id})

        response = http(GET, resource='example/%d' % id)
        self.assertEqual(response.status, GONE)
Example #5
0
 def test_not_found(self):
     for attempt in ('/primary/1.0/wrong', '/primary/10.0/example', '/wrong/1.0/example'):
         response = http(GET, path=attempt)
         self.assertEqual(response.status, NOT_FOUND)
Example #6
0
 def test_not_found(self):
     for attempt in ('/primary/1.0/wrong', '/primary/10.0/example',
                     '/wrong/1.0/example'):
         response = http(GET, path=attempt)
         self.assertEqual(response.status, NOT_FOUND)