Пример #1
0
 def test_user_endpoint_method_wrong(self):
     data = json.dumps({"username": "******", "password": "******"})
     response = login(testCase.mock_request(self, "POST", content=data))
     authen = response['Authorization']
     headers = {
         "Content-Type": "application/json",
         "Authorization": str(authen)
     }
     endpoint_response = user_endpoint(
         testCase.mock_request(self, "VIEW", header=headers), "name001")
     self.assertEquals(endpoint_response.status_code, 405)
Пример #2
0
 def test_user_endpoint_GET_user_not_exist(self):
     # get with user not exist
     data = json.dumps({"username": "******", "password": "******"})
     response = login(testCase.mock_request(self, "POST", content=data))
     authen = response['Authorization']
     headers = {
         "Content-Type": "application/json",
         "Authorization": str(authen)
     }
     endpoint_response = user_endpoint(
         testCase.mock_request(self, "GET", header=headers), "username002")
     self.assertEquals(endpoint_response.status_code, 404)
Пример #3
0
 def test_user_endpoint_GET_pass(self):
     # test GET request
     # get authen
     user = User.objects.get(username="******")
     data = json.dumps({"username": "******", "password": "******"})
     response = login(testCase.mock_request(self, "POST", content=data))
     authen = response['Authorization']
     headers = {
         "Content-Type": "application/json",
         "Authorization": str(authen)
     }
     endpoint_response = user_endpoint(
         testCase.mock_request(self, "GET", header=headers), "name001")
     self.assertEquals(endpoint_response.status_code, 200)
     self.assertIn(user.username, endpoint_response.content.decode("utf-8"))
Пример #4
0
 def test_user_endpoint_PUT_username_fail(self):
     # test 401
     data = json.dumps({"username": "******", "password": "******"})
     response = login(testCase.mock_request(self, "POST", content=data))
     authen = response['Authorization']
     data = json.dumps({
         "firstName": "name001-2",
         "lastName": "lastname",
         "birthDate": str(datetime(2000, 12, 30)),
         "job": "Author"
     })
     headers = {
         "Content-Type": "application/json",
         "Authorization": str(authen)
     }
     endpoint_response = user_endpoint(
         testCase.mock_request(self, "PUT", content=data, header=headers),
         "username002")
     self.assertEquals(endpoint_response.status_code, 401)
Пример #5
0
 def test_login_user_not_exist(self):
     # test 401
     data = json.dumps({"username": "******", "password": "******"})
     response = login(testCase.mock_request(self, "POST", content=data))
     self.assertEquals(response.status_code, 401)
Пример #6
0
 def test_login_pass(self):
     # test 200 OK
     data = json.dumps({"username": "******", "password": "******"})
     response = login(testCase.mock_request(self, "POST", content=data))
     self.assertEquals(response.status_code, 200)
Пример #7
0
 def test_login_method_not_POST(self):
     # test method not POST
     data = json.dumps({"username": "******", "password": "******"})
     response = login(testCase.mock_request(self, "GET", content=data))
     self.assertEquals(response.status_code, 405)