Skip to content
Merged
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: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
command: |
. venv/bin/activate
cd backend
py.test --cov-report xml --cov=.
py.test --cov-report xml --cov=. --cov-fail-under 100

- run:
name: upload codacy report
Expand Down
5 changes: 5 additions & 0 deletions backend/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# PYCON

[![Updates](https://pyup.io/repos/github/patrick91/pycon/shield.svg?token=1fa644e7-367a-431d-b906-0cfa23ddda9c)](https://pyup.io/repos/github/patrick91/pycon/) [![Python 3](https://pyup.io/repos/github/patrick91/pycon/python-3-shield.svg?token=1fa644e7-367a-431d-b906-0cfa23ddda9c)](https://pyup.io/repos/github/patrick91/pycon/) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/7472f142f7624ba4b7b735f90ad518f6)](https://www.codacy.com/app/simobasso/pycon?utm_source=github.com&utm_medium=referral&utm_content=patrick91/pycon&utm_campaign=Badge_Grade)


# Test

`py.test --cov=. --cov-fail-under 100`
59 changes: 59 additions & 0 deletions backend/tests/users/test_managers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
from django.contrib.auth import authenticate, get_user_model

import pytest
from users.models import User
from users.managers import UserManager


@pytest.mark.django_db
def test_create_user_empty_email():
with pytest.raises(ValueError) as error:
user = UserManager().create_user('', 'johnpassword')

assert 'The given email must be set' in str(error.value)


@pytest.mark.django_db
def test_create_user_with_email_and_password():
user = User.objects.create_user('lennon@thebeatles.com', 'johnpassword')

assert user.email == 'lennon@thebeatles.com'
assert not user.is_superuser
assert not user.is_staff


@pytest.mark.django_db
def test_create_user_superuser_with_email_and_password():
user = User.objects.create_user(
'lennon@thebeatles.com',
'johnpassword',
is_superuser=True
)

assert user.email == 'lennon@thebeatles.com'
assert user.is_superuser
assert not user.is_staff


@pytest.mark.django_db
def test_cannot_create_superuser_not_superuser_flag():
with pytest.raises(ValueError) as error:
user = User.objects.create_superuser(
'lennon@thebeatles.com',
'johnpassword',
is_superuser=False
)

assert 'Superuser must have is_superuser=True.' in str(error.value)


@pytest.mark.django_db
def test_create_superuser_with_email_and_password():
user = User.objects.create_superuser(
'lennon@thebeatles.com',
'johnpassword'
)

assert user.email == 'lennon@thebeatles.com'
assert user.is_staff
assert user.is_superuser
28 changes: 9 additions & 19 deletions backend/tests/users/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,15 @@

import pytest
from users.models import User
from users.managers import UserManager


def test_that_get_user_model_returns_correct_model():
assert get_user_model() == User


@pytest.mark.django_db
def test_create_user_with_email_and_password():
user = User.objects.create_user('lennon@thebeatles.com', 'johnpassword')

assert user.email == 'lennon@thebeatles.com'
assert not user.is_superuser
assert not user.is_staff


@pytest.mark.django_db
def test_create_superuser_with_email_and_password():
user = User.objects.create_superuser(
'lennon@thebeatles.com',
'johnpassword'
)

assert user.email == 'lennon@thebeatles.com'
assert user.is_staff
assert user.is_superuser
def test_user_manager():
assert isinstance(User.objects, UserManager)


@pytest.mark.django_db
Expand All @@ -39,3 +23,9 @@ def test_create_user_and_authenticate():
)

assert user == authenticated_user

@pytest.mark.django_db
def test_user_get_short_name():
user = User.objects.create_user('lennon@thebeatles.com', 'johnpassword')

assert 'lennon@thebeatles.com' == user.get_short_name()
26 changes: 26 additions & 0 deletions backend/tests/users/test_views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import pytest
from django.urls import reverse
from users.models import User


def test_post_login_view(client):
url = reverse('post-login')
response = client.get(url)

assert response.status_code == 200

assert b'Something went wrong.' in response.content


@pytest.mark.django_db
def test_post_login_view_as_logged(client):
user = User.objects.create_user('lennon@thebeatles.com', 'johnpassword')

client.login(username='lennon@thebeatles.com', password='johnpassword')

url = reverse('post-login')
response = client.get(url)

assert response.status_code == 200

assert b'lennon@thebeatles.com' in response.content
2 changes: 1 addition & 1 deletion backend/users/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
path('post-login', post_login_view, name='post-login'),
]

if settings.DEBUG:
if settings.DEBUG: # pragma: no cover
from django.views.generic import TemplateView

urlpatterns += [
Expand Down