Skip to content

Commit

Permalink
Merge pull request #106 from gm3dmo/moretests
Browse files Browse the repository at this point in the history
Adding some more tests.
  • Loading branch information
gm3dmo authored Nov 8, 2023
2 parents 50f22d1 + db53349 commit df1611f
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 3 deletions.
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="[email protected]", password="foo")
self.assertEqual(user.email, "[email protected]")
expected_email = "[email protected]"
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="[email protected]", password="foo", is_superuser=False
)
with self.assertRaises(ValueError):
User.objects.create_superuser(
email="[email protected]", 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")

0 comments on commit df1611f

Please sign in to comment.