コード例 #1
0
 def test_post_data_using_json(self):
     url = 'http://testserver/api/authors/'
     response = local_requests.post(url, json={
         'name': 'J.K. Rowling',
     })
     self.assertEqual(response.status_code, codes.created)
     data = response.json()
     self.assertEqual(data['name'], 'J.K. Rowling')
コード例 #2
0
 def test_sends_files(self):
     url = 'http://testserver/upload_file/'
     response = local_requests.post(url, files={
         'file': ('report.csv', 'ID,name\n1,Rocky'),
     })
     self.assertEqual(response.status_code, codes.ok)
     self.assertEqual(response.json(), {
         'name': 'report.csv',
         'content': 'ID,name\n1,Rocky',
     })