Skip to content

Commit

Permalink
fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
DGclasher committed Jul 12, 2023
1 parent 38ecd5c commit db94a73
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
7 changes: 2 additions & 5 deletions .github/workflows/api-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
uses: actions/checkout@v2

- name: setup python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: '3.10'

Expand All @@ -23,12 +23,9 @@ jobs:
- name: start application locally
run: |
make serve-bg
sleep 10
sleep 5
- name: run tests
env:
TEST_USER: ${{ secrets.TEST_USER }}
TEST_PASS: ${{ secrets.TEST_PASS }}
run: pytest -vk test_unauth

- name: stop background process
Expand Down
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@ serve-bg:
python3 manage.py runserver &

test:
python3 -m pytest -v
python3 -m pytest -v

stop:
kill $(lsof -t -i:8000)
Binary file modified backend/restless/quotes/quotes.db
Binary file not shown.
16 changes: 9 additions & 7 deletions tests/test_auth_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import requests
from decouple import config


ENDPOINT = "http://127.0.0.1:8000/api"


Expand All @@ -16,6 +17,7 @@ def initialize():
token = response["token"]
header = {"Authorization": f"Token {token}",
"Content-Type": "application/json"}
return header


def get_random_quote_for_testing():
Expand All @@ -33,7 +35,7 @@ def get_random_quote_for_testing():
return id, author, quote["quoteText"]


def create_test_quote(quote, author_name, id):
def create_test_quote(quote, author_name, id, header):
payload = {
"quote": quote,
"author_id": id,
Expand All @@ -47,7 +49,7 @@ def create_test_quote(quote, author_name, id):


def test_can_create_quote():
initialize()
header = initialize()
id, author_name, quote = get_random_quote_for_testing()
payload = {
"quote": quote,
Expand All @@ -63,15 +65,15 @@ def test_can_create_quote():


def test_can_create_author():
initialize()
header = initialize()
name = "test author"
response = requests.post(ENDPOINT + "/create/author/",
json={"name": name}, headers=header)
assert response.status_code == 201


def test_can_update_author():
initialize()
header = initialize()
new_name = "test author"
response = requests.get(ENDPOINT + "/fetch/author/",
params={"name": new_name})
Expand All @@ -83,14 +85,14 @@ def test_can_update_author():


def test_can_delete_quote():
initialize()
header = initialize()
quote = "this is a test quote"
author = "test author"
response = requests.get(ENDPOINT + "/fetch/author/",
params={"name": author})
response = json.loads(response.text)
author_id = response["id"]
create_test_quote(quote, author, author_id)
create_test_quote(quote, author, author_id, header)
response = requests.get(ENDPOINT+"/fetch/author/",
params={"id": author_id})
response = json.loads(response.text)
Expand All @@ -102,7 +104,7 @@ def test_can_delete_quote():


def test_can_delete_author():
initialize()
header = initialize()
response = requests.get(ENDPOINT + "/fetch/author/",
params={"name": "test author"})
response = json.loads(response.text)
Expand Down

0 comments on commit db94a73

Please sign in to comment.