def test_model_creation(self): """Should successfully create an instance of Company in the database""" self.assertEqual(Company.objects.count(), 0) company = CompanyFactory.create() self.assertEqual(Company.objects.count(), 1) retrieved_company = Company.objects.first() self.assertEqual(company.name, retrieved_company.name) self.assertEqual(company.cnpj, retrieved_company.cnpj) self.assertEqual(company.owner, retrieved_company.owner) self.assertEqual(company.ddd, retrieved_company.ddd) self.assertEqual(company.phone, retrieved_company.phone)
def test_model_creation_duplicate_cnpj(self): """ Should fail to create multiple instances of Company in the database with the same CNPJ """ self.assertEqual(Company.objects.count(), 0) company = CompanyFactory.create() self.assertEqual(Company.objects.count(), 1) company_two = CompanyFactory.build() company_two.cnpj = company.cnpj expected_messages = { "cnpj": ["Company with this Cnpj already exists."] } with self.assertRaises(ValidationError) as raised: company_two.save() self.assertEqual(raised.exception.message_dict, expected_messages)