def test_company_contact_person_not_informed(self): """ tests if company has not been added twice to EmailInformedUsers list """ self.company_contact_person.save() self.company_contact_person = CompanyContactPerson( first_name='example', last_name='example', email='*****@*****.**') informed_users = EmailInformedUsers.objects.filter( email__icontains='example').count() self.assertEquals(informed_users, 1)
class TestCompanyContactPersonContentSignalTestCase(TestCase): """ tests if signal was properly triggered with args""" def setUp(self): self.company_contact_person = CompanyContactPerson( first_name='example', last_name='example', email='*****@*****.**') def test_signal_with_arguments(self, **kwargs): with CatchSignal(company_contact_person_email_changed) as handler: self.company_contact_person.save() handler.assert_called_once_with( company_contact_person=self.company_contact_person, sender=mock.ANY, signal=company_contact_person_email_changed) def tearDown(self): CompanyContactPerson.objects.all().delete()
class CompanyContactPersonSignalTriggeredTestCase(TestCase): """ tests if signal was properly triggered""" def setUp(self): self.company_contact_person = CompanyContactPerson( first_name='example', last_name='example', email='*****@*****.**') @mock.patch('company.models.CompanyContactPerson.save') def test_company_creation_signal_triggered(self, mocked): """ tests if singal was propely triggered """ self.company_contact_person.save() self.assertTrue(mocked.called) self.assertEqual(mocked.call_count, 1) @mock.patch('company.models.CompanyContactPerson.save') def test_company_creation_signal_not_triggered(self, mocked): """ tests if singal was not triggered with wrong parameters """ try: with transaction.atomic(): self.company_contact_person.email = "" self.company_contact_person.full_clean() self.company_contact_person.save() except ValidationError as e: print(e) self.assertFalse(mocked.called) self.assertEqual(mocked.call_count, 0) def tearDown(self): CompanyContactPerson.objects.all().delete()
class TestCompanyContactPersonEmailSendTestCase(TestCase): """ tests if email parameters are correct """ def setUp(self): self.company_contact_person = CompanyContactPerson( first_name='example', last_name='example', email='*****@*****.**') def test_company_contact_person_informed(self): """ tests if company is in the EmailInformedUsers list """ self.company_contact_person.save() informed = EmailInformedUsers.objects.get(email='*****@*****.**') self.assertIsNotNone(informed) def test_company_contact_person_not_informed(self): """ tests if company has not been added twice to EmailInformedUsers list """ self.company_contact_person.save() self.company_contact_person = CompanyContactPerson( first_name='example', last_name='example', email='*****@*****.**') informed_users = EmailInformedUsers.objects.filter( email__icontains='example').count() self.assertEquals(informed_users, 1) def test_email_with_parameters(self): """ tests if email contains proper parameters """ self.company_contact_person.save() self.assertEqual(len(mail.outbox), 1) self.assertEqual( mail.outbox[0].subject, ' Powiadomienie o gromadzeniu danych osobowych uzytkownika ' + self.company_contact_person.first_name) def tearDown(self): CompanyContactPerson.objects.all().delete()
def setUp(self): self.company_contact_person = CompanyContactPerson( first_name='example', last_name='example', email='*****@*****.**')