This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| pytest |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| pytest a_directory # directory | |
| pytest test_something.py # tests file | |
| pytest test_something.py::single_test # single test function |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pytest | |
| from django.contrib.auth.models import User | |
| @pytest.mark.django_db | |
| def test_user_create(): | |
| User.objects.create_user('john', 'lennon@thebeatles.com', 'johnpassword') | |
| assert User.objects.count() == 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pytest | |
| from django.urls import reverse | |
| @pytest.mark.django_db | |
| def test_view(client): | |
| url = reverse('homepage-url') | |
| response = client.get(url) | |
| assert response.status_code == 200 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pytest | |
| from django.urls import reverse | |
| @pytest.mark.django_db | |
| def test_unauthorized(client): | |
| url = reverse('superuser-url') | |
| response = client.get(url) | |
| assert response.status_code == 401 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pytest | |
| from django.urls import reverse | |
| @pytest.mark.django_db | |
| def test_user_detail(client, django_user_model): | |
| user = django_user_model.objects.create( | |
| username='someone', password='password' | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pytest | |
| from django.urls import reverse | |
| @pytest.mark.django_db | |
| def test_superuser_detail(client, admin_user): | |
| url = reverse( | |
| 'superuser-detail-view', kwargs={'pk': admin_user.pk} | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import uuid | |
| import pytest | |
| @pytest.fixture | |
| def test_password(): | |
| return 'strong-test-pass' | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pytest | |
| from django.urls import reverse | |
| @pytest.mark.django_db | |
| def test_user_detail(client, create_user): | |
| user = create_user(username='someone') | |
| url = reverse('user-detail-view', kwargs={'pk': user.pk}) | |
| response = client.get(url) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pytest | |
| from django.urls import reverse | |
| @pytest.mark.django_db | |
| def test_send_report(auto_login_user, mailoutbox): | |
| client, user = auto_login_user() | |
| url = reverse('send-report-url') | |
| response = client.post(url) |