Merge branch 'master' into api
This commit is contained in:
commit
e2d438134a
37
.github/workflows/run-tests.yml
vendored
Normal file
37
.github/workflows/run-tests.yml
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
name: Run tests
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
services:
|
||||
db:
|
||||
image: postgres:12.3-alpine
|
||||
env:
|
||||
POSTGRES_USER: shynet_db_user
|
||||
POSTGRES_PASSWORD: shynet_db_user_password
|
||||
POSTGRES_DB: shynet_db
|
||||
ports:
|
||||
- 5432:5432
|
||||
strategy:
|
||||
max-parallel: 4
|
||||
matrix:
|
||||
python-version: [3.9]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/setup-python@v2
|
||||
with:
|
||||
python-version: ${{ matrix.python-version }}
|
||||
- name: Run image
|
||||
uses: abatilo/actions-poetry@v2.0.0
|
||||
with:
|
||||
poetry-version: 1.1.6
|
||||
- name: Install dependencies
|
||||
run: poetry install
|
||||
|
||||
- name: Django Testing project
|
||||
run: |
|
||||
cp TEMPLATE.env .env
|
||||
poetry run ./shynet/manage.py test
|
1258
poetry.lock
generated
1258
poetry.lock
generated
File diff suppressed because it is too large
Load Diff
@ -27,6 +27,14 @@ django-npm = "^1.0.0"
|
||||
python-dotenv = "^0.18.0"
|
||||
django-debug-toolbar = "^3.2.1"
|
||||
|
||||
[tool.poetry.dev-dependencies]
|
||||
pytest-sugar = "^0.9.4"
|
||||
factory-boy = "^3.2.0"
|
||||
pytest-django = "^4.4.0"
|
||||
django-coverage-plugin = "^2.0.0"
|
||||
django-stubs = "^1.8.0"
|
||||
mypy = "^0.910"
|
||||
|
||||
[build-system]
|
||||
requires = ["poetry-core>=1.0.0"]
|
||||
build-backend = "poetry.core.masonry.api"
|
||||
|
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)
|
@ -300,7 +300,7 @@ else:
|
||||
EMAIL_USE_TLS = os.environ.get("EMAIL_USE_TLS")
|
||||
|
||||
# Auto fields
|
||||
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
||||
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
|
||||
|
||||
# NPM
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user