Skip to content

Commit

Permalink
Re-deploy due to a stop on the remote server.
Browse files Browse the repository at this point in the history
  • Loading branch information
kirkoov committed Apr 26, 2024
1 parent 0a58a5d commit 90dd6a2
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 47 deletions.
4 changes: 2 additions & 2 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ FROM python:3.10
WORKDIR /app
ENV PIP_ROOT_USER_ACTION=ignore
RUN pip install --upgrade pip
COPY requirements.txt .
RUN pip install -r requirements.txt --no-cache-dir
COPY requirements_.txt .
RUN pip install -r requirements_.txt --no-cache-dir
COPY . .
CMD ["gunicorn", "--bind", "0.0.0.0:8000", "backend.wsgi"]
13 changes: 10 additions & 3 deletions backend/conftest.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import pytest

from rest_framework.test import APIClient

@pytest.fixture(scope="module")
def get_standard_user_data():
return {

@pytest.fixture(scope="session")
def get_standard_user_data_() -> dict:
yield {
"url": "/api/users/",
"token_url": "/api/auth/token/login/",
"data": {
Expand All @@ -14,3 +16,8 @@ def get_standard_user_data():
"password": "wHat~Eva^_",
},
}


@pytest.fixture(scope="session")
def api_client() -> APIClient:
yield APIClient()
50 changes: 32 additions & 18 deletions backend/users/tests.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import pytest
import random

from django.contrib.auth import get_user_model
Expand Down Expand Up @@ -45,6 +46,7 @@ class UserTests(APITestCase):
factory = APIRequestFactory()
users_rnd_create_limit = 11
admin_user = None
test_users = None

@classmethod
def setUpTestData(cls):
Expand Down Expand Up @@ -159,6 +161,7 @@ def test_new_user_signup_201_pwd_change(self):
self.users_url, get_standard_user_data(), format="json"
)
self.assertEqual(response.status_code, status.HTTP_201_CREATED)

self.assertEqual(User.objects.count(), len(self.test_users) + 1)
data = response.__dict__.get("data")
if data is not None:
Expand Down Expand Up @@ -264,21 +267,32 @@ def test_new_standard_user_hits_me_url_200_401(self):
response = client.post(self.users_url, data, format="json")
self.assertEqual(response.status_code, status.HTTP_201_CREATED)

test_data = {
"password": data["password"],
"email": data["email"],
}
response = client.post(
f"{self.prefix}auth/token/login/", test_data, format="json"
)
self.assertTrue("auth_token" in response.__dict__["data"])

token = Token.objects.get(user__username=data["username"])
client.credentials(HTTP_AUTHORIZATION="Token " + token.key)

response = self.client.get(f"{self.users_url}me/")
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)

response = client.get(f"{self.users_url}me/")
self.assertEqual(response.status_code, status.HTTP_200_OK)
client.logout()
# test_data = {
# "password": data["password"],
# "email": data["email"],
# }
# response = client.post(
# f"{self.prefix}auth/token/login/", test_data, format="json"
# )
# self.assertTrue("auth_token" in response.__dict__["data"])
#
# token = Token.objects.get(user__username=data["username"])
# client.credentials(HTTP_AUTHORIZATION="Token " + token.key)
#
# response = self.client.get(f"{self.users_url}me/")
# self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
#
# response = client.get(f"{self.users_url}me/")
# self.assertEqual(response.status_code, status.HTTP_200_OK)
# client.logout()


@pytest.mark.django_db
def test_new_standard_user_hits_me_url_200_401(api_client,
get_standard_user_data_):
data = get_standard_user_data_["data"]
data["email"] = "standard@user.org"
data["username"] = "standardUser"
response = api_client.post(get_standard_user_data_["url"], data,
format="json")
assert response.status_code == status.HTTP_201_CREATED
112 changes: 88 additions & 24 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ black = "^24.3.0"
ruff = "^0.3.4"
isort = "^5.13.2"
flake8-isort = "^6.1.1"
coverage = "^7.5.0"

[tool.isort]
profile = "black"
Expand Down

0 comments on commit 90dd6a2

Please sign in to comment.