Skip to content

Commit

Permalink
Improve coverage level to 100%.
Browse files Browse the repository at this point in the history
  • Loading branch information
alainivars committed Jun 17, 2019
1 parent 7107b8b commit 3db1cef
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 18 deletions.
29 changes: 28 additions & 1 deletion my_api/rest/tests/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,25 @@ def test_api_file_with_token_good_key(self):
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(response.data, json_file_content)

def test_api_file_with_token_good_key_bad_param(self):
with open('./my_api/rest/tests/files/file_ok.json') as f:
file_content = f.read()
json_file_content = json.loads(file_content)
response = self.token_auth_post(
reverse('api_file'),
str(self.user.auth_token),
data=json_file_content
)
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
# data = response.data
response = self.token_auth_get(
reverse('api_file'),
str(self.user.auth_token),
data={}
)
self.assertEqual(response.status_code,
status.HTTP_422_UNPROCESSABLE_ENTITY)

def test_api_file_with_token_wrong_key(self):
with open('./my_api/rest/tests/files/file_ko.json') as f:
file_content = f.read()
Expand All @@ -114,14 +133,22 @@ def test_api_file_with_token_wrong_key(self):
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertEqual(response.data[0], "'file' is a required field.")

def test_icinga2(self):
def test_icinga(self):
response = self.basics_auth_get(
reverse('icinga'),
self.username,
self.password
)
self.assertEqual(response.status_code, status.HTTP_200_OK)

def test_icinga2(self):
response = self.basics_auth_get(
reverse('icinga2'),
self.username,
self.password
)
self.assertEqual(response.status_code, status.HTTP_200_OK)


if __name__ == '__main__':
unittest.main()
34 changes: 17 additions & 17 deletions my_api/rest/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ class FileAPI(APIView):
"""
Example API to push a json image on the server and get it by a key.
"""
def delete(self, request):
"""
Required that the client is authenticated,
This method delete a file on the disk (NotImplemented)
:param request: the key corresponding to that file.
:return: status
"""
raise NotImplemented()
# def delete(self, request):
# """
# Required that the client is authenticated,
# This method delete a file on the disk (NotImplemented)
# :param request: the key corresponding to that file.
# :return: status
# """
# raise NotImplemented()

def get(self, request):
"""
Expand Down Expand Up @@ -89,12 +89,12 @@ def post(self, request):
status=status.HTTP_201_CREATED)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

def put(self, request):
"""
Required that the client is authenticated,
This method load a file from the json and update it on the disk
(NotImplemented)
:param request: the key and the new file in json Base64 format
:return: the key to get to that file after.
"""
raise NotImplemented()
# def put(self, request):
# """
# Required that the client is authenticated,
# This method load a file from the json and update it on the disk
# (NotImplemented)
# :param request: the key and the new file in json Base64 format
# :return: the key to get to that file after.
# """
# raise NotImplemented()

0 comments on commit 3db1cef

Please sign in to comment.