Fixed new tests to pass with new implementations
This commit is contained in:
parent
b815899101
commit
c696038321
13 changed files with 165 additions and 13 deletions
|
|
@ -1,6 +1,6 @@
|
|||
from django.forms import ModelForm, ModelChoiceField, Select, CharField, TextInput
|
||||
from django.forms import ModelForm, Select, TextInput
|
||||
|
||||
from housewars.models import Activity, Facilitator
|
||||
from housewars.models import Facilitator
|
||||
|
||||
|
||||
class FacilitatorForm(ModelForm):
|
||||
|
|
@ -15,7 +15,7 @@ class FacilitatorForm(ModelForm):
|
|||
}),
|
||||
'last_name': TextInput(attrs={
|
||||
'class': 'form-control',
|
||||
'id': 'first-name',
|
||||
'id': 'last-name',
|
||||
'placeholder': 'Last Name',
|
||||
}),
|
||||
'activity': Select(attrs={
|
||||
|
|
|
|||
19
housewars/migrations/0007_alter_facilitator_activity.py
Normal file
19
housewars/migrations/0007_alter_facilitator_activity.py
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
# Generated by Django 4.0.4 on 2022-09-07 22:30
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('housewars', '0006_facilitator'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='facilitator',
|
||||
name='activity',
|
||||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='housewars.activity'),
|
||||
),
|
||||
]
|
||||
14
housewars/migrations/0008_merge_20220907_2259.py
Normal file
14
housewars/migrations/0008_merge_20220907_2259.py
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
# Generated by Django 4.0.4 on 2022-09-07 22:59
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('housewars', '0005_alter_teacher_grade'),
|
||||
('housewars', '0007_alter_facilitator_activity'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
]
|
||||
|
|
@ -6,7 +6,7 @@ class Facilitator(models.Model):
|
|||
first_name = models.CharField(max_length=100)
|
||||
last_name = models.CharField(max_length=100)
|
||||
activity = models.ForeignKey(
|
||||
Activity, on_delete=models.CASCADE, blank=True, null=True)
|
||||
Activity, on_delete=models.CASCADE)
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
self.full_clean()
|
||||
|
|
|
|||
24
housewars/tests/forms/test_facilitator_form.py
Normal file
24
housewars/tests/forms/test_facilitator_form.py
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
from django.test import TestCase
|
||||
|
||||
from housewars.forms import FacilitatorForm
|
||||
from housewars.models import Activity
|
||||
|
||||
|
||||
class FacilitatorFormTest(TestCase):
|
||||
def setUp(self):
|
||||
self.activity = Activity.objects.create(name='Dodgeball', time=30)
|
||||
|
||||
def test_valid_input(self):
|
||||
form = FacilitatorForm(data={
|
||||
'first_name': 'Test',
|
||||
'last_name': 'User',
|
||||
'activity': self.activity.id
|
||||
})
|
||||
|
||||
self.assertTrue(form.is_valid())
|
||||
|
||||
def test_no_data(self):
|
||||
form = FacilitatorForm(data={})
|
||||
|
||||
self.assertFalse(form.is_valid())
|
||||
self.assertEquals(len(form.errors), 3)
|
||||
|
|
@ -4,7 +4,7 @@ from housewars.forms import PointsEntryForm
|
|||
from housewars.models import Activity, House, Award
|
||||
|
||||
|
||||
class ActivityFormTest(TestCase):
|
||||
class PointsEntryFormTest(TestCase):
|
||||
def setUp(self):
|
||||
self.house = House.objects.create(name='Hawk')
|
||||
self.activity = Activity.objects.create(name='Dodgeball', time=30)
|
||||
|
|
|
|||
|
|
@ -13,13 +13,16 @@ class UnpackValuesTest(TestCase):
|
|||
|
||||
def test_valid_row_headers(self):
|
||||
"""Correctly unpacks the headers into the first index"""
|
||||
values = unpack_values(self.test_queryset)
|
||||
headers = [field.name for field in House._meta.fields]
|
||||
|
||||
values = unpack_values(self.test_queryset, headers)
|
||||
self.assertEqual(
|
||||
values[0], [field.name for field in House._meta.fields])
|
||||
values[0], headers)
|
||||
|
||||
def test_complete_values(self):
|
||||
"""Maintains the complete queryset and returns it"""
|
||||
values = unpack_values(self.test_queryset)
|
||||
headers = [field.name for field in House._meta.fields]
|
||||
values = unpack_values(self.test_queryset, headers)
|
||||
queryset = list(self.test_queryset.values_list())
|
||||
for row in queryset:
|
||||
self.assertIn(list(row), values)
|
||||
|
|
|
|||
33
housewars/tests/views/test_facilitator_create.py
Normal file
33
housewars/tests/views/test_facilitator_create.py
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
from django.test import TestCase, Client
|
||||
from django.urls import reverse
|
||||
|
||||
from housewars.models import Activity
|
||||
|
||||
|
||||
class FacilitatorCreateViewTest(TestCase):
|
||||
def setUp(self):
|
||||
self.client = Client()
|
||||
self.url = reverse('housewars:facilitator')
|
||||
self.activity = Activity.objects.create(name='Dodgeball', time=30)
|
||||
|
||||
def test_GET(self):
|
||||
response = self.client.get(self.url)
|
||||
|
||||
self.assertEquals(response.status_code, 200)
|
||||
self.assertTemplateUsed(response, 'housewars/general_form.html')
|
||||
|
||||
def test_POST(self):
|
||||
response = self.client.post(self.url, {
|
||||
'first_name': 'Test',
|
||||
'last_name': 'User',
|
||||
'activity': self.activity.id
|
||||
})
|
||||
|
||||
self.assertEquals(response.status_code, 302)
|
||||
self.assertEquals(self.activity.facilitator_set.count(), 1)
|
||||
|
||||
def test_failed_POST(self):
|
||||
response = self.client.post(self.url)
|
||||
|
||||
self.assertEquals(response.status_code, 200)
|
||||
self.assertEquals(self.activity.facilitator_set.count(), 0)
|
||||
|
|
@ -16,7 +16,7 @@ class PointsEntryCreateViewTest(TestCase):
|
|||
response = self.client.get(self.url)
|
||||
|
||||
self.assertEquals(response.status_code, 200)
|
||||
self.assertTemplateUsed(response, 'housewars/pointsentry_form.html')
|
||||
self.assertTemplateUsed(response, 'housewars/general_form.html')
|
||||
|
||||
def test_POST(self):
|
||||
response = self.client.post(self.url, {
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@
|
|||
<main role="main" class="container max-height">
|
||||
<div class="row d-flex justify-content-center align-items-center max-height">
|
||||
<div class="card col-md-5 p-4 m-3">
|
||||
<h1 class="text-center mt-1 mb-4">{% if formtitle %}{{ formtitle }}{% endif %}</h1>
|
||||
<h1 id="header" class="text-center mt-1 mb-4">{% if formtitle %}{{ formtitle }}{% endif %}</h1>
|
||||
<!-- Main content -->
|
||||
{% block content %}{% endblock %}
|
||||
<div class="mt-3">
|
||||
|
|
|
|||
50
tests/test_facilitator.py
Normal file
50
tests/test_facilitator.py
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
from django.urls import reverse
|
||||
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
|
||||
|
||||
from selenium.webdriver import Chrome
|
||||
from selenium.webdriver.chrome.options import Options
|
||||
from selenium.webdriver.common.by import By
|
||||
from selenium.webdriver.support.wait import WebDriverWait
|
||||
from selenium.webdriver.support.select import Select
|
||||
from selenium.webdriver.support.expected_conditions import visibility_of
|
||||
from webdriver_manager.chrome import ChromeDriverManager
|
||||
|
||||
from housewars.models import Activity
|
||||
|
||||
|
||||
class UserEntryCreatePageTest(StaticLiveServerTestCase):
|
||||
def setUp(self):
|
||||
# Headless chrome driver test setup
|
||||
options = Options()
|
||||
options.add_argument('--headless')
|
||||
|
||||
self.browser = Chrome(
|
||||
ChromeDriverManager().install(), chrome_options=options)
|
||||
self.url = self.live_server_url + reverse('housewars:facilitator')
|
||||
|
||||
# Initial data setup
|
||||
self.activity = Activity.objects.create(
|
||||
name='Dodgeball', time=30)
|
||||
|
||||
def tearDown(self):
|
||||
self.browser.close()
|
||||
|
||||
def test_form_submission(self):
|
||||
self.browser.get(self.url)
|
||||
|
||||
# Wait until browser loads page before continuing
|
||||
WebDriverWait(self.browser, timeout=5).until(
|
||||
visibility_of(self.browser.find_element(By.ID, 'header')))
|
||||
|
||||
self.browser.find_element(By.ID, 'first-name').send_keys('Test')
|
||||
self.browser.find_element(By.ID, 'last-name').send_keys('User')
|
||||
Select(self.browser.find_element(By.ID, 'activity')
|
||||
).select_by_visible_text('Dodgeball (30)')
|
||||
self.browser.find_element(By.ID, 'submit').click()
|
||||
|
||||
# Assert that signup is successful
|
||||
success_text = self.browser.find_element(
|
||||
By.CSS_SELECTOR, 'div.alert.alert-success').text
|
||||
|
||||
self.assertEquals(
|
||||
success_text, 'Your facilitator signup has been submitted.')
|
||||
|
|
@ -14,13 +14,14 @@ from housewars.models import House, Activity, Award
|
|||
|
||||
class UserEntryCreatePageTest(StaticLiveServerTestCase):
|
||||
def setUp(self):
|
||||
# Headless chrome driver test setup
|
||||
options = Options()
|
||||
options.add_argument('--headless')
|
||||
|
||||
self.browser = Chrome(
|
||||
ChromeDriverManager().install(), chrome_options=options)
|
||||
self.url = self.live_server_url + reverse('housewars:add_points')
|
||||
|
||||
# Initial data setup
|
||||
self.house = House.objects.create(name='Hawk')
|
||||
self.activity = Activity.objects.create(name='Dodgeball', time=30)
|
||||
self.award = Award.objects.create(name='1st', activity=self.activity)
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ from housewars.models import House, Activity, UserEntry
|
|||
|
||||
class UserEntryCreatePageTest(StaticLiveServerTestCase):
|
||||
def setUp(self):
|
||||
# Headless chrome driver test setup
|
||||
options = Options()
|
||||
options.add_argument('--headless')
|
||||
|
||||
|
|
@ -22,6 +23,7 @@ class UserEntryCreatePageTest(StaticLiveServerTestCase):
|
|||
ChromeDriverManager().install(), chrome_options=options)
|
||||
self.url = self.live_server_url + reverse('housewars:signup')
|
||||
|
||||
# Initial data setup
|
||||
self.house = House.objects.create(name='Hawk')
|
||||
self.activity30 = Activity.objects.create(
|
||||
name='Dodgeball', time=30, default_quota=5)
|
||||
|
|
@ -40,8 +42,7 @@ class UserEntryCreatePageTest(StaticLiveServerTestCase):
|
|||
WebDriverWait(self.browser, timeout=5).until(
|
||||
visibility_of(self.browser.find_element(By.ID, 'header')))
|
||||
|
||||
self.assertEqual(self.browser.title, 'House Wars - Signup')
|
||||
|
||||
# Fill in form with valid inputs
|
||||
self.browser.find_element(By.ID, 'first-name').send_keys('Test')
|
||||
self.browser.find_element(By.ID, 'last-name').send_keys('User')
|
||||
self.browser.find_element(
|
||||
|
|
@ -62,11 +63,18 @@ class UserEntryCreatePageTest(StaticLiveServerTestCase):
|
|||
|
||||
self.browser.find_element(By.ID, 'submit').click()
|
||||
|
||||
# Verify signup is successful
|
||||
success_text = self.browser.find_element(
|
||||
By.CSS_SELECTOR, 'div.alert.alert-success').text
|
||||
|
||||
self.assertEquals(success_text, 'Your signup has been submitted.')
|
||||
|
||||
# Verify that activity detail cards are present
|
||||
activity_confirm = self.browser.find_elements(
|
||||
By.CSS_SELECTOR, 'div.alert.alert-success')
|
||||
|
||||
self.assertEquals(len(activity_confirm), 3)
|
||||
|
||||
def test_user_invalid_email(self):
|
||||
self.browser.get(self.live_server_url)
|
||||
|
||||
|
|
|
|||
Reference in a new issue