

def test_posts(self):
    request = HttpRequest()
    post_data = '{"name": "Ball", "artnr": "12345"}'
    request._raw_post_data = post_data
    resp = self.client.post('/api/v1/products/', data=post_data, content_type='application/json')
    self.assertEqual(resp.status_code, 201)
    self.assertEqual(resp['location'], 'http://testserver/api/v1/products/12345/')
    resp = self.client.get('/api/v1/products/12345/', data={
        'format': 'json',
    })
    self.assertEqual(resp.status_code, 200)
    obj = json.loads(resp.content)
    self.assertEqual(obj['name'], 'Ball')
    self.assertEqual(obj['artnr'], '12345')
    request = HttpRequest()
    post_data = '{"name": "Ball 2", "artnr": "12345ABC"}'
    request._raw_post_data = post_data
    resp = self.client.post('/api/v1/products/', data=post_data, content_type='application/json')
    self.assertEqual(resp.status_code, 201)
    self.assertEqual(resp['location'], 'http://testserver/api/v1/products/12345ABC/')
    resp = self.client.get('/api/v1/products/12345ABC/', data={
        'format': 'json',
    })
    self.assertEqual(resp.status_code, 200)
    obj = json.loads(resp.content)
    self.assertEqual(obj['name'], 'Ball 2')
    self.assertEqual(obj['artnr'], '12345ABC')
    request = HttpRequest()
    post_data = '{"name": "Ball 3", "artnr": "WK12345"}'
    request._raw_post_data = post_data
    resp = self.client.post('/api/v1/products/', data=post_data, content_type='application/json')
    self.assertEqual(resp.status_code, 201)
    self.assertEqual(resp['location'], 'http://testserver/api/v1/products/WK12345/')
    resp = self.client.get('/api/v1/products/WK12345/', data={
        'format': 'json',
    })
    self.assertEqual(resp.status_code, 200)
    obj = json.loads(resp.content)
    self.assertEqual(obj['name'], 'Ball 3')
    self.assertEqual(obj['artnr'], 'WK12345')
    request = HttpRequest()
    post_data = '{"name": "Bigwheel", "artnr": "76123/03"}'
    request._raw_post_data = post_data
    resp = self.client.post('/api/v1/products/', data=post_data, content_type='application/json')
    self.assertEqual(resp.status_code, 201)
    self.assertEqual(resp['location'], 'http://testserver/api/v1/products/76123/03/')
    resp = self.client.get('/api/v1/products/76123/03/', data={
        'format': 'json',
    })
    self.assertEqual(resp.status_code, 200)
    obj = json.loads(resp.content)
    self.assertEqual(obj['name'], 'Bigwheel')
    self.assertEqual(obj['artnr'], '76123/03')
    request = HttpRequest()
    post_data = '{"name": "Trampolin", "artnr": "WS65150/02"}'
    request._raw_post_data = post_data
    resp = self.client.post('/api/v1/products/', data=post_data, content_type='application/json')
    self.assertEqual(resp.status_code, 201)
    self.assertEqual(resp['location'], 'http://testserver/api/v1/products/WS65150/02/')
    resp = self.client.get('/api/v1/products/WS65150/02/', data={
        'format': 'json',
    })
    self.assertEqual(resp.status_code, 200)
    obj = json.loads(resp.content)
    self.assertEqual(obj['name'], 'Trampolin')
    self.assertEqual(obj['artnr'], 'WS65150/02')

dataset/ETHPy150Open mozilla/inventory/vendor-local/src/django-tastypie/tests/alphanumeric/tests/views.py ViewsTestCase.test_posts/original