Compare commits
3 Commits
master
...
first-test
Author | SHA1 | Date | |
---|---|---|---|
|
bca3faa597 | ||
|
822f7fb74c | ||
|
a47edbfa03 |
37
shynet/core/factories.py
Normal file
37
shynet/core/factories.py
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
from django.contrib.auth import get_user_model
|
||||||
|
import factory
|
||||||
|
from factory.django import DjangoModelFactory
|
||||||
|
from .models import Service
|
||||||
|
|
||||||
|
|
||||||
|
class UserFactory(DjangoModelFactory):
|
||||||
|
username = factory.Faker("user_name")
|
||||||
|
email = factory.Faker("email")
|
||||||
|
name = factory.Faker("name")
|
||||||
|
|
||||||
|
@post_generation
|
||||||
|
def password(self, create, extracted, **kwargs):
|
||||||
|
password = (
|
||||||
|
extracted
|
||||||
|
if extracted
|
||||||
|
else factory.Faker(
|
||||||
|
"password",
|
||||||
|
length=42,
|
||||||
|
special_chars=True,
|
||||||
|
digits=True,
|
||||||
|
upper_case=True,
|
||||||
|
lower_case=True,
|
||||||
|
).evaluate(None, None, extra={"locale": None})
|
||||||
|
)
|
||||||
|
self.set_password(password)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = get_user_model()
|
||||||
|
django_get_or_create = ["username"]
|
||||||
|
|
||||||
|
|
||||||
|
class ServiceFactory(DjangoModelFactory):
|
||||||
|
class Meta:
|
||||||
|
model = Service
|
||||||
|
|
||||||
|
name = factory.Faker("company")
|
1
shynet/core/tests/__init__.py
Normal file
1
shynet/core/tests/__init__.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
|
0
shynet/dashboard/tests/__init__.py
Normal file
0
shynet/dashboard/tests/__init__.py
Normal file
43
shynet/dashboard/tests/tests_dashboard_views.py
Normal file
43
shynet/dashboard/tests/tests_dashboard_views.py
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
from django.test import TestCase, RequestFactory
|
||||||
|
from django.conf import settings
|
||||||
|
from django.urls import reverse
|
||||||
|
from core.factories import UserFactory
|
||||||
|
|
||||||
|
from dashboard.views import DashboardView
|
||||||
|
|
||||||
|
|
||||||
|
class QuestionModelTests(TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
# Every test needs access to the request factory.
|
||||||
|
self.factory = RequestFactory()
|
||||||
|
self.user = UserFactory()
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def tests_unauthenticated_dashboard_view(self):
|
||||||
|
"""
|
||||||
|
GIVEN: Unauthenticated user
|
||||||
|
WHEN: Accessing the dashboard view
|
||||||
|
THEN: It's redirected to login page with NEXT url to dashboard
|
||||||
|
"""
|
||||||
|
login_url = settings.LOGIN_URL
|
||||||
|
response = self.client.get(reverse("dashboard:dashboard"))
|
||||||
|
|
||||||
|
self.assertEqual(response.status_code, 302)
|
||||||
|
self.assertEqual(
|
||||||
|
response.url, f"{login_url}?next={reverse('dashboard:dashboard')}"
|
||||||
|
)
|
||||||
|
|
||||||
|
def tests_authenticated_dashboard_view(self):
|
||||||
|
"""
|
||||||
|
GIVEN: Authenticated user
|
||||||
|
WHEN: Accessing the dashboard view
|
||||||
|
THEN: It should respond with 200 and render the view
|
||||||
|
"""
|
||||||
|
request = self.factory.get(reverse("dashboard:dashboard"))
|
||||||
|
request.user = self.user
|
||||||
|
|
||||||
|
# Use this syntax for class-based views.
|
||||||
|
response = DashboardView.as_view()(request)
|
||||||
|
self.assertEqual(response.status_code, 200)
|
@ -299,7 +299,7 @@ else:
|
|||||||
EMAIL_USE_TLS = os.environ.get("EMAIL_USE_TLS")
|
EMAIL_USE_TLS = os.environ.get("EMAIL_USE_TLS")
|
||||||
|
|
||||||
# Auto fields
|
# Auto fields
|
||||||
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
|
||||||
|
|
||||||
# NPM
|
# NPM
|
||||||
|
|
||||||
|
@ -1,16 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
|
|
||||||
<html>
|
|
||||||
|
|
||||||
<head>
|
|
||||||
<title>JS test</title>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<noscript>
|
|
||||||
<img src="http://localhost:8000/ingress/0ca733e8-c41f-462b-a11a-4ba0cea29948/pixel.gif">
|
|
||||||
</noscript>
|
|
||||||
<script defer src="http://localhost:8000/ingress/0ca733e8-c41f-462b-a11a-4ba0cea29948/script.js"></script>
|
|
||||||
</body>
|
|
||||||
|
|
||||||
</html>
|
|
@ -1,13 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
|
|
||||||
<html>
|
|
||||||
|
|
||||||
<head>
|
|
||||||
<title>Pixel test</title>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<img src="http://localhost:8000/ingress/9b2c4e2f-8d29-4418-82d4-b68e06795025/pixel.gif">
|
|
||||||
</body>
|
|
||||||
|
|
||||||
</html>
|
|
Loading…
Reference in New Issue
Block a user