def test_create_new_interaction(self): interaction = InteractionFactory() new_interaction_data = { 'project': interaction.project.pk, 'channel': interaction.channel, 'manager': interaction.manager.pk, 'description': interaction.description, 'evaluation': interaction.evaluation } interaction.delete() response = self.client.post(reverse('interaction:create'), new_interaction_data) self.assertEqual(response.status_code, 302) self.assertEqual(new_interaction_data['description'], Interaction.objects.last().description)
def test_interaction_with_filter_by_project(self): project_1 = ProjectFactory() project_2 = ProjectFactory() for _ in range(2): InteractionFactory(project=project_1) InteractionFactory(project=project_2) response = self.client.get(f"{reverse('interaction:list')}?project={project_1.pk}") self.assertEqual(response.status_code, 200) self.assertEqual(response.context['interaction_list'].count(), 2) response = self.client.get(f"{reverse('interaction:list')}?project={project_2.pk}") self.assertEqual(response.status_code, 200) self.assertEqual(response.context['interaction_list'].count(), 1)
def test_interaction_with_filter_by_company(self): company_1 = CompanyFactory() company_2 = CompanyFactory() for _ in range(2): InteractionFactory(project=ProjectFactory(company=company_1)) InteractionFactory(project=ProjectFactory(company=company_2)) response = self.client.get(f"{reverse('interaction:list')}?company={company_1.pk}") self.assertEqual(response.status_code, 200) self.assertEqual(response.context['interaction_list'].count(), 2) response = self.client.get(f"{reverse('interaction:list')}?company={company_2.pk}") self.assertEqual(response.status_code, 200) self.assertEqual(response.context['interaction_list'].count(), 1)
def test_interaction_list_is_not_empty(self): for _ in range(3): InteractionFactory() response = self.client.get(reverse('interaction:list')) self.assertEqual(response.status_code, 200) self.assertNotContains(response, "Список взаимодействий пуст.") self.assertEqual(response.context['interaction_list'].count(), 3)
def test_create_interaction(self): interaction_from_factory = InteractionFactory() interaction_from_db = Interaction.objects.first() self.assertEqual(Interaction.objects.count(), 1) self.assertEqual(interaction_from_factory.project, interaction_from_db.project) self.assertEqual(interaction_from_factory.channel, interaction_from_db.channel) self.assertEqual(interaction_from_factory.manager, interaction_from_db.manager) self.assertEqual(interaction_from_factory.description, interaction_from_db.description) self.assertEqual(interaction_from_factory.evaluation, interaction_from_db.evaluation) self.assertEqual( reverse('interaction:detail', kwargs={'pk': interaction_from_factory.pk}), interaction_from_db.get_absolute_url() ) self.assertEqual( f"Взаимодействие с компанией {interaction_from_factory.project.company.name} #{interaction_from_factory.pk}", interaction_from_db.__str__() )
def setUpTestData(cls): UserModel.objects.create_user(username='******', password='******') for _ in range(3): InteractionFactory()