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

Adding some more tests. #106

Merged
merged 1 commit into from
Nov 8, 2023
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 cmp/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Rank(models.Model):
rank_class = models.CharField(max_length=2, blank=True, choices=rank_types,default='Other Rank')

def __str__(self):
return self.Name
return self.name


class PowCamp(models.Model):
Expand Down
58 changes: 56 additions & 2 deletions cmp/tests.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import pytest

from django.contrib.auth import get_user_model
from django.test import TestCase

from cmp.views import original_unit, belongsTo

from cmp.models import Rank

from cmp import views

class TestOriginalUnit(TestCase):

def test_original_unit_with_input_0(self):
Expand Down Expand Up @@ -78,8 +84,10 @@ def test_original_unit_with_input_22199408(self):
class UsersManagersTests(TestCase):
def test_create_user(self):
User = get_user_model()
user = User.objects.create_user(email="normal@user.com", password="foo")
self.assertEqual(user.email, "normal@user.com")
expected_email = "normal@user.com"
user = User.objects.create_user(email=expected_email, password="foo")
self.assertEqual(user.email, expected_email)
self.assertEqual(user.__str__(), expected_email)
self.assertTrue(user.is_active)
self.assertFalse(user.is_staff)
self.assertFalse(user.is_superuser)
Expand Down Expand Up @@ -115,3 +123,49 @@ def test_create_superuser(self):
User.objects.create_superuser(
email="super@user.com", password="foo", is_superuser=False
)
with self.assertRaises(ValueError):
User.objects.create_superuser(
email="super@user.com", password="foo", is_staff=False
)




@pytest.mark.django_db
class RankModelTest(TestCase):
def test_create_rank(self):
name = "Private"
abbreviation = "Pte"
rank_class = "Other Rank"
rank = Rank.objects.create(name=name, abbreviation=abbreviation, rank_class=rank_class)
self.assertEqual(rank.name, name)
self.assertEqual(rank.abbreviation, abbreviation)
self.assertEqual(rank.rank_class, rank_class)
self.assertEqual(str(rank), name)

@pytest.mark.django_db
class testViewsModule(TestCase):
def test_powcamps_view(self):
response = self.client.get("/pow-camps/")
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, "cmp/pow-camps.html")

def test_cemeteries_view(self):
response = self.client.get("/cemeteries/")
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, "cmp/cemeteries.html")

def test_ranks_view(self):
response = self.client.get("/ranks/")
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, "cmp/ranks.html")

def test_countries_view(self):
response = self.client.get("/countries/")
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, "cmp/countries.html")

def test_index_view(self):
response = self.client.get("/")
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, "cmp/index.html")