Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds in sample pytest #30

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[pytest]
DJANGO_SETTINGS_MODULE = config.settings
18 changes: 18 additions & 0 deletions {{cookiecutter.project_slug}}/common/test/test_sample.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import pytest
from django.urls import reverse, resolve

from common import views


class TestClass:

@pytest.mark.parametrize(
"url_name, url, view_class",
[
("index", "/", views.IndexView),
],
)
def test_urls(self, url_name, url, view_class):
resolver = resolve(url)
assert resolver.view_name == url_name
assert resolver.func.view_class == view_class
Comment on lines +7 to +18
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This definitely handles the use case of giving people a sample to follow, but it would be more ideal to have a sample that 1. uses the database, and 2. tests something that is code we've written and not django code

Maybe we can create a new view that uses LoginRequiredMixin and test access that requires the use of factories and making database calls?

4 changes: 2 additions & 2 deletions {{cookiecutter.project_slug}}/common/urls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.conf import settings
from django.conf.urls import url
from django.urls import re_path
from django.urls import include, path

from common import views
Expand Down Expand Up @@ -30,7 +30,7 @@
import debug_toolbar

urlpatterns += [
url(r'^__debug__/', include(debug_toolbar.urls)),
re_path(r'^__debug__/', include(debug_toolbar.urls)),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think path might be more appropriate (and remove the regex components): https://django-debug-toolbar.readthedocs.io/en/latest/installation.html#add-the-urls

]
{%- if cookiecutter.feature_annotations == "on" %}
# END_FEATURE debug_toolbar
Expand Down
5 changes: 5 additions & 0 deletions {{cookiecutter.project_slug}}/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ To run the test suite:
python manage.py test
```

To run pytest tests:
```bash
pytest
```

To get a test coverage report:
```bash
coverage run --source='.' manage.py test; coverage report
Expand Down
1 change: 1 addition & 0 deletions {{cookiecutter.project_slug}}/requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ django-environ
django-extensions
requests
psycopg2
pytest
{%- if cookiecutter.feature_annotations == "on" %}
Comment on lines +6 to 7
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we also need pytest-django


####### OPTIONAL FEATURES #######
Expand Down