Esempio n. 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)
Esempio n. 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)
Esempio n. 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"))
Esempio n. 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)
Esempio n. 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)
Esempio n. 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)
Esempio n. 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)