You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To test test the overall functionality of the craft_api project and its containing apps, automated testing was implemented with the goal of testing all views, serializers, custom permissions and models which were created during the build. During the testing phase there was 92 tests passed, including 197 assertions. There are many more tests which could possibly be written and cover more situations, however, the goal with the current applicaiton scope was to simple cover as much functionality as possible using coverage as a testing tool.
Initially when building the testcases I had to learn the difference bewteen TestCase and APITestCase, however after reading the necessary documents it was clear that APITestCase would be useful for testing api endpoints therefore it was used for testiing views, serializers and permissions. TestCase was useful for testing the models as this doesnt rewuire the same functionality in the tests.
The written tests can be found in the <App>/tests/ files of all apps in the API.
Some resources I used to build knowledge and write tests can be found in README.md credits section.
I used coverage throughout the testing phase to measure the percentage of each apps covered code. Coverage highlighted which specific lines of code were not tested when running the html server. This enabled me to build more tests to target these lines of code. I seperated each apps tests into seperate files for clarity, each app had the folowing tests file structure:
After using coverage I was able to reach 100% of the code covered within all apps.
The main project file 'craft_api' only reached 90% coverage. This is due to wsgi.py and asgi.py files which are created by Django as entry points for different application servers and the settings.py file.
To run coverage for the entire application, type in command line:
coverage run manage.py test
To run coverage for each app, type in command line:
coverage run --source=<app_name> manage.py test <app_name>
To check for syntax errors in the project's Python code I used pycodestyle(formerly pep8). Using this I was able to test my code from inside the command line. Its a fast and easy way to heck the syntax as it returns the file name and lines of the error.
To install pycodestyle in the command line:
pip install pycodestyle
Then to test the files in the command line:
pycodestyle <file_name>
or
pycodestyle .
When initially running the linter there were a few errors which I addressed and corrected. After these corrections the only errors left were 'E501 line too long'. These were mostly found in the migration files automatically created during the makemigration command. After updating these there were no more errors within my files.
To accompany the automated testing, the Craft-API underwent manual testing on all custom endpoints, covering all CRUD functionality, serialised data, and checking to_representation methods. Below are the tests carried out at each API endpoint, they have been seperated by custom endpoint and details the HTTP method used for the test, and expected outcomes. If the test failed the action which was taken to ensure a Pass was made.
All tests include screenshots, in order for larger viewing they are seperate to the tests. To view the screenshot select the test number in the screenshots table below the main tests table for each endpoint.
Navigate to a profile details page using /profiles/1/ url as a logged out user
GET
Displays profile details of the profile with id: 1
200
Pass
-
6
Navigate to a profile details page using /profiles/1/ url as a logged in user
GET
Displays profile details of the profile with id: 1, if owner html update from displays.
200
Pass
-
7
Login and navigate to /profiles/1/ (owned profile) update the HTML form name field and click 'PUT'
PUT
The profiles JSON name field is updated with the updated name
200
Pass
-
8
Login and navigate to /profiles/1/ (owned profile) update the HTML form name field with 'Christopher Alexander Harrington III Esquire Jr.' (more than 75 characters) and click 'PUT'
PUT
Validation error is raised with message 'Ensure this field has no more than 75 characters.'
400
Pass
-
9
Login and navigate to /profiles/1/ (owned profile) update the HTML form bio field and click 'PUT'
PUT
The profiles JSON bio field is updated with the updated information
200
Pass
-
10
Login and navigate to /profiles/1/ (owned profile) update the HTML form bio field with more than 200 characters and click 'PUT'
PUT
Validation error is raised with message 'Ensure this field has no more than 200 characters.'
400
Pass
-
11
Login and navigate to /profiles/1/ (owned profile) update the HTML form job field and click 'PUT'
PUT
The profiles JSON job field is updated with the updated information
200
Pass
-
12
Login and navigate to /profiles/1/ (owned profile) update the HTML form job field with more than 75 characters and click 'PUT'
PUT
Validation error is raised with message 'Ensure this field has no more than 75 characters.'
400
Pass
-
13
Login and navigate to /profiles/1/ (owned profile) update the image file field with a valid new image and click 'PUT'
PUT
The profiles JSON image field is updated with the updated information
200
Pass
-
14
Login and navigate to /profiles/1/ (owned profile) update the image file field with a file which is not an image file type and click 'PUT'
PUT
Validation error is raised with message 'Upload a valid image. The file you uploaded was either not an image or a corrupted image.'
400
Pass
-
15
Login and navigate to /profiles/1/ (owned profile) update the HTML form employer field by selecting an option form the dropdown and click 'PUT'
PUT
The profiles JSON employer field is updated with the updated employer information
200
Pass
-
16
Login and navigate to /profiles/1/ (owned profile) update the HTML form employer field with the '-----' (none) option and click 'PUT'
Navigate to the '/comments/' url as a logged out user
GET
Returns a lists of all site comments, including count field and pagination urls.
200
Pass
-
37
Log in and navigate to the '/comments/' url
GET
Returns a lists of all site profiles, including a create comment HTML form.
200
Pass
-
38
Log in and navigate to the '/comments/' url, locate the is_owner field.
GET
The logged in user should see the is_owner field populated with 'true' if they own the comment
200
Pass
-
39
In the create comment HTML form create a comment by selecting a post from the dropdown and write a message in the content field.
POST
Creates a comment instance, redirects the user to the related comment details page, the comment details match the input details. Comment can also be found in the comments list.
Navigate to the '/companies/' url as a logged out user
GET
Returns a list of all company instances from the site, including a count field and the pagination url extensions.
200
Pass
-
49
Navigate to the '/companies/' url as a logged in user
GET
Returns a list of all company instances from the site, including a count field and the pagination url extensions, the create company HTML form is available below.
200
Pass
-
50
Submit the create company form with no data
POST
Validation error is raised.
400
Pass
-
51
Submit the create company form with no data in the 'name' field
POST
Validation error is raised with message: "This field may not be blank.".
400
Pass
-
52
Submit the create company form with only name data
POST
Company instance is created.
201
Pass
-
53
Create a company with duplicate name and location fields as an already created company.
POST
Validation error raised with message: "A company with that title and location already exists."
400
Pass
-
54
Create a company with the name field longer that 100 characters.
POST
Validation error raised name too long.
400
Pass
-
55
Create a company with the location field longer that 100 characters.
POST
Validation error raised location too long.
400
Pass
-
56
Create a company with the type field longer that 100 characters.
POST
Validation error raised type too long.
400
Pass
-
57
Create a new company by filling out the html form with valid data
POST
Company is created, redirecting user to the company details, all relevant details are present, the company can be found in the companies list.
201
Pass
-
58
As a new user attempt to create a 4th company.
POST
Validation error is raised, users can only create a maximum of three companies per profile. The message is "You have reached the max profile limit of 3 companies."
400
Pass
-
59
Create a new company and then navigate to owned profile details, locate the employer dropdown.
GET
The newly created company should be displayed in the employer dropdown list.
200
Pass
-
60
Navigate to a company instance owned by the user and delete.
DELETE
Deletion confirmation modal is displayed, if confirmed the company instance is deleted.
Navigate to a company details page for example '/companies/12/'
GET
Displays the relevant company details, the company id field matches the url input.
200
Pass
-
62
Login and navigate to company details page of a company owned by the user.
GET
Displays the relevant company details, the company id field matches the url input, additionally the is_owner field is set to 'true', Delete button and HTML update form visible.
200
Pass
-
63
Update the company details with the name field longer that 100 characters, click 'PUT'.
PUT
Validation error raised name too long.
400
Pass
-
64
Update the company details with the location field longer that 100 characters, click 'PUT'.
PUT
Validation error raised location too long.
400
Pass
-
65
Update the company details with the type field longer that 100 characters, click 'PUT'.
PUT
Validation error raised type too long.
400
Pass
-
66
Update the company with duplicate name and location fields as an already created company.
POST
Validation error raised with message: "A company with that title and location already exists."
400
Fail
Pass - In order to check for duplicate instances on PUT request, the update generic view was overriden with a perform_update method. The logic was copied from the perform_create and validation methods used in the create generic view in companies/views.py. With this update the company is correctly validated on PUT request.
67
Update profiles employer field with the a company instance, then navigate to this companies details url.
PUT/GET
Companies employee_count field has increased by 1
200
Pass
-
68
Update profiles employer field with the no company instance '--------', then navigate to this companies details url.
PUT/GET
Companies employee_count field has decreased by 1
200
Pass
-
69
Set profile employer field to company instance, then delete this company instance
DELETE
The profiles employer instance should be automatically set to 'null' after the company is deleted.
Navigate to the '/followers/' url as a logged out user
GET
Displays list of all follower instances, including count and pagination fields.
200
Pass
-
92
Navigate to the '/followers/' url as a logged in user
GET
Displays list of likes, including create follower HTML form.
200
Pass
-
93
Create a follower instance by selecting a profile username from the dropdown menu, click 'POST'.
POST
Follower instance is created
201
Pass
-
94
Create a follower by selecting the logged in users username, click 'POST'.
POST
Validation error is raised: "Possible Duplicate".
400
Fail - Follower instance created, users should not be able to follow themselves.
Pass - create a 'perform_create' validation method which checks and raises a validation error if the request.user is equal to the 'followed' fields data (followers/views.py)
95
Create a follower instance using the a profile already 'followed', click 'POST'.
POST
Validation error is raised: "Possible duplicate."
400
Pass
-
96
Attempt to create an approval with valid JSON data { "followed": <profile.id> }, click 'POST'.
POST
The like is created.
201
Pass
-
97
After creating a follower check the followed profiles 'follower_count' has incremented by 1.
POST
follower_count of the related profile has increased by 1.
201
Pass
-
98
After creating a follower check the users profile 'following_count' has incremented by 1.
POST
following_count of the users profile has increased by 1.