Skip to content
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
31 changes: 31 additions & 0 deletions front/tests/fixtures.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import pytest


@pytest.fixture(scope='function')
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

django gives you a client object if you subclass django.test.TestCase

def get_client(client):
return client


@pytest.fixture(scope='function')
def create_user(django_user_model):
username = "testuser"
password = "testpassword"
django_user_model.objects.create_user(username=username, password=password)

return username, password


@pytest.fixture(scope='function')
def load_game_data(db):
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

might be better to just use pure fixturized data instead of trying to use our "production data".


import compile_configs

return True


@pytest.fixture(scope='function')
def logged_in_client(create_user, client):
username, password = create_user
client.login(username=username, password=password)

return client
27 changes: 27 additions & 0 deletions front/tests/test_game_view.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from django.urls import reverse
import pytest
from .fixtures import logged_in_client, load_game_data, create_user, get_client

class TestGameView:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

subclass django.test.TestCase


def test_list_game_without_login_fails(self, client):
response = client.get(reverse('game', args=(1,)))
assert response.status_code == 302

def test_list_game_succeeds(self, load_game_data, logged_in_client):
response = logged_in_client.get(reverse('game', args=(1,)))

assert response.status_code == 200
assert response.template_name[0] == 'front/game.html'
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I would also check to make sure the expected values render in the template.

assert f'{game.title}' in response.content



# class TestModuleView:
#
# def test_list_game_succeeds(self, load_game_data, logged_in_client):
# response = logged_in_client.get(reverse('module', args=(1,)))
#
# assert response.status_code == 200
# assert response.template_name[0] == 'front/game.html'