def test_put_inplace(self): """ Test PUT where item already exists """ test = Test() test.url = self.prefix + "/api/person/1/" test.method = u"PUT" test.body = '{"first_name": "Gaius","id": 1,"last_name": "Baltar","login": "******"}' test.headers = {u"Content-Type": u"application/json"} test_response = resttest.run_test(test) self.assertEqual(True, test_response.passed) self.assertEqual(200, test_response.response_code)
def test_patch(self): """ Basic local get test """ test = Test() test.url = self.prefix + "/api/person/2/" test.method = "PATCH" test.body = '{"login":"******"}' test.headers = {u"Content-Type": u"application/json", u"X-HTTP-Method-Override": u"PATCH"} test.expected_status = [202, 400] # Django issues give a 400, sigh test_response = resttest.run_test(test) self.assertTrue(test_response.passed)
def test_put_inplace(self): """ Test PUT where item already exists """ test = Test() test.url = self.prefix + '/api/person/1/' test.method = u'PUT' test.body = '{"first_name": "Gaius","id": 1,"last_name": "Baltar","login": "******"}' test.headers = {u'Content-Type': u'application/json'} test_response = resttest.run_test(test) self.assertEqual(True, test_response.passed) self.assertEqual(200, test_response.response_code)
def test_patch(self): """ Basic local get test """ test = Test() test.url = self.prefix + '/api/person/2/' test.method = 'PATCH' test.body = '{"login":"******"}' test.headers = { u'Content-Type': u'application/json', u'X-HTTP-Method-Override': u'PATCH' } test.expected_status = [202] # Django returns 202 test_response = resttest.run_test(test) self.assertTrue(test_response.passed)
def test_post(self): """ Test POST to create an item """ test = Test() test.url = self.prefix + "/api/person/" test.method = u"POST" test.expected_status = [200, 201, 204] test.body = '{"first_name": "Willim","last_name": "Adama","login": "******"}' test.headers = {u"Content-Type": u"application/json"} test_response = resttest.run_test(test) self.assertEqual(True, test_response.passed) self.assertEqual(201, test_response.response_code) # Test user was created test2 = Test() test2.url = self.prefix + "/api/person/?login=theadmiral" test_response2 = resttest.run_test(test2) self.assertTrue(test_response2.passed) obj = json.loads(str(test_response2.body)) print(json.dumps(obj))
def test_put_created(self): """ Test PUT where item DOES NOT already exist """ test = Test() test.url = self.prefix + "/api/person/100/" test.method = u"PUT" test.expected_status = [200, 201, 204] test.body = '{"first_name": "Willim","last_name": "Adama","login":"******", "id": 100}' test.headers = {u"Content-Type": u"application/json"} test_response = resttest.run_test(test) self.assertEqual(True, test_response.passed) self.assertEqual(201, test_response.response_code) # Test it was actually created test2 = Test() test2.url = test.url test_response2 = resttest.run_test(test2) self.assertTrue(test_response2.passed) self.assertTrue(u'"last_name": "Adama"' in test_response2.unicode_body()) self.assertTrue(u'"login": "******"' in test_response2.unicode_body())
def test_post(self): """ Test POST to create an item """ test = Test() test.url = self.prefix + '/api/person/' test.method = u'POST' test.expected_status = [200, 201, 204] test.body = '{"first_name": "Willim","last_name": "Adama","login": "******"}' test.headers = {u'Content-Type': u'application/json'} test_response = resttest.run_test(test) self.assertEqual(True, test_response.passed) self.assertEqual(201, test_response.response_code) # Test user was created test2 = Test() test2.url = self.prefix + '/api/person/?login=theadmiral' test_response2 = resttest.run_test(test2) self.assertTrue(test_response2.passed) obj = json.loads(str(test_response2.body)) print(json.dumps(obj))
def test_put_created(self): """ Test PUT where item DOES NOT already exist """ test = Test() test.url = self.prefix + '/api/person/100/' test.method = u'PUT' test.expected_status = [200,201,204] test.body = '{"first_name": "Willim","last_name": "Adama","login":"******", "id": 100}' test.headers = {u'Content-Type':u'application/json'} test_response = resttest.run_test(test) self.assertEqual(True, test_response.passed) self.assertEqual(201, test_response.response_code) # Test it was actually created test2 = Test() test2.url = test.url test_response2 = resttest.run_test(test2) self.assertTrue(test_response2.passed) self.assertTrue(u'"last_name": "Adama"' in test_response2.unicode_body()) self.assertTrue(u'"login": "******"' in test_response2.unicode_body())
def test_post(self): """ Test POST to create an item """ test = Test() test.url = self.prefix + '/api/person/' test.method = u'POST' test.expected_status = [200, 201, 204] test.body = '{"first_name": "Willim","last_name": "Adama","login": "******"}' test.headers = {u'Content-Type': u'application/json'} test_response = resttest.run_test(test) self.assertEqual(True, test_response.passed) self.assertEqual(201, test_response.response_code) # Test user was created test2 = Test() test2.url = self.prefix + '/api/person/?login=theadmiral' test_response2 = resttest.run_test(test2) self.assertTrue(test_response2.passed) # Test JSON load/dump round trip on body bod = test_response2.body if isinstance(bod, binary_type): bod = text_type(bod, 'utf-8') print(json.dumps(json.loads(bod)))