示例#1
0
    def test_crud_finding(self):
        # Create
        project = ProjectFactory(codename="S3kr3t Codename")

        # Read
        self.assertEqual(project.codename, "S3kr3t Codename")
        self.assertEqual(project.pk, project.id)
        self.assertQuerysetEqual(
            self.Project.objects.all(),
            [
                f"<Project: {project.start_date} {project.client} {project.project_type} (S3kr3t Codename)>"
            ],
        )

        # Update
        project.codename = "New Name"
        project.save()
        self.assertQuerysetEqual(
            self.Project.objects.all(),
            [
                f"<Project: {project.start_date} {project.client} {project.project_type} (New Name)>"
            ],
        )

        # Delete
        project.delete()
        assert not self.Project.objects.all().exists()
示例#2
0
    def test_checkout_adjustment_signal(self):
        yesterday = date.today() - timedelta(days=1)

        project = ProjectFactory(
            start_date=date.today() - timedelta(days=14),
            end_date=date.today() + timedelta(days=14),
        )

        domain_checkout = HistoryFactory(start_date=project.start_date,
                                         end_date=project.end_date,
                                         project=project)
        exp_domain_checkout = HistoryFactory(start_date=project.start_date,
                                             end_date=yesterday,
                                             project=project)
        server_checkout = ServerHistoryFactory(start_date=project.start_date,
                                               end_date=project.end_date,
                                               project=project)
        exp_server_checkout = ServerHistoryFactory(
            start_date=project.start_date, end_date=yesterday, project=project)

        new_start = project.start_date - timedelta(days=7)
        new_end = project.end_date + timedelta(days=7)

        project.start_date = new_start
        project.end_date = new_end
        project.save()

        domain_checkout.refresh_from_db()
        exp_domain_checkout.refresh_from_db()
        server_checkout.refresh_from_db()
        exp_server_checkout.refresh_from_db()

        self.assertEqual(domain_checkout.start_date, new_start)
        self.assertEqual(server_checkout.start_date, new_start)
        self.assertEqual(domain_checkout.end_date, new_end)
        self.assertEqual(server_checkout.end_date, new_end)
        self.assertEqual(exp_domain_checkout.end_date, yesterday)
        self.assertEqual(exp_server_checkout.end_date, yesterday)