Commit 2655b0cb authored by Guilhem Saurel's avatar Guilhem Saurel
Browse files

fix some tests

parent 40b52a05
from django.test import TestCase
from django.contrib.auth.models import User
from django.contrib.contenttypes.models import ContentType
from django.urls import reverse
from django.core.management import call_command
......@@ -8,7 +7,7 @@ from django.core.management.base import CommandError
from io import StringIO
from os import devnull
from .models import Corporation, Adhesion
from .models import Corporation, Adhesion, User
class AdhesionsMixin:
......@@ -26,16 +25,13 @@ class AdhesionsMixin:
corp1 = Corporation.objects.create(social_reason="GoodCorp")
corp1.members.add(user)
Corporation.objects.create(social_reason="EvilCorp")
Adhesion.objects.create(
adherent_type=ContentType.objects.get_for_model(Corporation),
adherent_id=corp1.pk,
)
# Adhesion.objects.create(corporation=corp1)
class ViewsTestCase(AdhesionsMixin, TestCase):
def test_adhesion_backend(self):
user = User.objects.get(username="user")
adhesion = user.profile.adhesion
adhesion = user.adhesion
self.assertFalse(
self.client.login(username="%d" % adhesion.pk, password="wrong")
)
......@@ -114,10 +110,8 @@ class ViewsTestCase(AdhesionsMixin, TestCase):
def test_adhesion_model(self):
user = User.objects.get(username="user")
adh1 = Adhesion.objects.get(
adherent_type=ContentType.objects.get_for_model(User), adherent_id=user.pk
)
self.assertEqual(user.profile.adhesion, adh1)
adh1 = Adhesion.objects.get(user=user)
self.assertEqual(user.adhesion, adh1)
self.assertTrue(adh1.is_physical())
self.assertFalse(adh1.is_moral())
self.assertEqual(adh1.get_adherent_name(), "first last")
......@@ -173,7 +167,7 @@ class ViewsTestCase(AdhesionsMixin, TestCase):
class CommandsTestCase(AdhesionsMixin, TestCase):
def test_list(self):
out = StringIO()
call_command("adherents", "list", stdout=out)
call_command("adherents", stdout=out)
result = out.getvalue()
self.assertNotRegex(result, "admin") # non adhérent
self.assertRegex(result, "first last")
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment