From 9eda1c7f1ffca9e4d9cb0f7f72821dac444fa47e Mon Sep 17 00:00:00 2001 From: Benni Baermann Date: Wed, 29 Sep 2021 15:53:53 +0200 Subject: [PATCH] broken test added --- input/models.py | 9 ++++++--- input/tests.py | 18 +++++++++++++++--- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/input/models.py b/input/models.py index 5203aee..8745a31 100644 --- a/input/models.py +++ b/input/models.py @@ -88,9 +88,12 @@ class Project(Volunteer): def save(self,*args,**kwargs): # is there a way to call super().save() only once? - super().save(*args,*kwargs) - self.pid = self.account + str(self.pk).zfill(3) - super().save(*args,*kwargs) + print(f'1: {self.id}') + super().save(*args,**kwargs) + print(f'2: {self.id}') + self.pid = str(self.account) + str(self.pk).zfill(3) + print(f'3: {self.id}') + super().save(*args,**kwargs) def __str__(self): return f"{self.pid} {self.name}" diff --git a/input/tests.py b/input/tests.py index 09bd73a..c4af97d 100644 --- a/input/tests.py +++ b/input/tests.py @@ -1,8 +1,8 @@ -from django.test import TestCase +from django.test import TestCase, Client from django.conf import settings from django.contrib.auth.models import User -from .models import HonoraryCertificate +from .models import HonoraryCertificate, Project, Account class TestWithoutLogin(TestCase): @@ -29,14 +29,26 @@ class TestWithoutLogin(TestCase): response = self.client.get('/intern', follow=True) self.assertContains(response,'password') + class TestWithLogin(TestCase): - # fixture = ['testfixture'] def setUp(self): User.objects.create_superuser('testuser', 'nomail@nomail.com', 'testpasswd') + self.client = Client() + self.user = User.objects.create_user('vladimir', 'vladimir@reiherzehe.com', 'reiherzehe') def test_access(self): '''test if /intern gives an answer''' self.assertEqual(self.client.login(username='testuser', password='testpasswd'), True) response = self.client.get('/intern') self.assertContains(response,'Übersicht aller Förderangebote') + + def test_project_pid(self): + ''' test if the project pid is resettet ad start of year''' + # self.client.login(username='vladimir', password='reiherzehe') + acc = Account.objects.create(code='1234', description='blabla') + #acc.save() + obj = Project.objects.create(account= acc, name='testproject', start='2022-01-01') + #obj.save() + print(obj.pid) + self.assertEqual(True,True)