Open tabathadelane opened 4 years ago
Is there a way we can test this on our laptops? I have both Docker for Windows and Docker on Linux. I also have Postman on Linux - perhaps we could use newman
scripts to test it.
I used windows for this. I don't know what the next steps should be.
I used windows for this. I don't know what the next steps should be.
If you can point me at the Postman testing instructions I'll try to make a newman
script to reproduce it. Then we can integrate it somehow for future tests.
This was in the README:
You can get an authentication token by sending a POST request to http://localhost:8000/api-token-auth/ with the superuser credentials in a formdata labeled username and password.
For example, you can send the POST request as a cURL request:
curl --location --request POST 'localhost:8000/api-token-auth/' \
--header 'Content-Type: multipart/form-data' \
--form 'username=
Awesome! Are you using the libraries that Emily installed to create a temporary user, or do you want regular Django commands?
I can use Emily's libraries if there's some documentation that tells me how to do it - no point in adding code or documentation if it's there already somewhere.
Okay. This package is a lot, but it is implemented in /users/factories.py. It's called Factory Boy. I imported into my test_headers.py, but I guess a new Admin class should be created and then used for this test.
Here is the official documentation: https://factoryboy.readthedocs.io/en/latest/internals.html#internals
Also, the top answer here seems to using a really simplified method of creating a superuser. https://stackoverflow.com/questions/15616277/how-can-you-create-an-admin-user-with-factory-boy
I overlooked the superuser requirement. I hadn't gotten this far. I can't get the actual tests to run. the Django shell says it successfully ran 0 tests, 0 failures. I tried "nosetests," but it says it is invalid. I couldn't find any other command online that would run.
name: Adding CORS Support to the API about: Implementing django-cors-headers package and testing it.
What does this do and why?
As mentioned in Issue https://github.com/Pand-Aid/pandaid-api/issues/13, our API needs to set the correct headers to be accessible to the front end.
I added the
django-cors-headers
package to requirements.txt and followed the setup detailed at https://github.com/adamchainz/django-cors-headers/blob/master/README.rstAdditional notes for reviewers
The response headers should be set to
ACCESS-CONTROL-ALLOW-ORIGIN: "*"
I attempted to write a test to prove this. I've never written a test for this before, as I usually trouble-shoot CORS in the browser terminal or Postman. I sent up a test designed to replicate that by sending aPOST
request to 'api-token-auth/" as is mentioned in the main README setup. https://github.com/Pand-Aid/pandaid-api/blob/master/README.mdI followed the format of the previously written tests within the User module. It implemented
UserFactory
for temporary test users as well asNosetests
. I did my best putting a test together using these libraries.However, I cannot get the tests to run to see if they are being used correctly.
I also wrote a very simple test that is designed to fail, so I could easily see when tests were running.
Commands Used and Terminal Feedback:
The test command returns this in the bash terminal:
and triggers this is the Docker terminal:
Pre-Review Tasks
Place an ‘x’ between the brackets.
[ x] I wrote tests covering these changes
[ ] I reviewed my own PR before asking for review from others
[ ] I added PR comments providing additional context for reviewers where appropriate, or calling attention to especially sensitive changes.
[ ] If deps were added, I verified the licenses