Пример #1
0
    def test_logo_is_deleted_when_the_job_is(self, mock_import_image_from_url,
                                             mock_get_client):
        job_1 = TalentLinkJobFactory(talentlink_id=1)
        job_2 = TalentLinkJobFactory(talentlink_id=2)
        logo_1 = ImageFactory()
        logo_2 = ImageFactory()
        job_1.logo = logo_1
        job_2.logo = logo_2
        job_1.save()
        job_2.save()

        self.assertEqual(
            TalentLinkJob.objects.get(talentlink_id=1).logo,
            CustomImage.objects.get(id=logo_1.id),
        )

        job_1.delete()

        self.assertEqual(
            CustomImage.objects.filter(id=logo_1.id).count(),
            0,
            msg="Logo 1 should be deleted when Job 1 is.",
        )
        self.assertEqual(
            TalentLinkJob.objects.get(talentlink_id=2).logo,
            CustomImage.objects.get(id=logo_2.id),
            msg=
            "Job 2 and Logo 2 should be unaffected when Job 1 and Logo 1 is deleted.",
        )
Пример #2
0
    def test_logo_is_not_deleted_if_another_job_is_using_it(
            self, mock_import_image_from_url, mock_get_client):
        job_1 = TalentLinkJobFactory(talentlink_id=1)
        job_2 = TalentLinkJobFactory(talentlink_id=2)
        logo = ImageFactory()
        job_1.logo = logo
        job_2.logo = logo
        job_1.save()
        job_2.save()

        self.assertEqual(
            TalentLinkJob.objects.get(talentlink_id=1).logo,
            CustomImage.objects.get(id=logo.id),
        )
        self.assertEqual(
            TalentLinkJob.objects.get(talentlink_id=2).logo,
            CustomImage.objects.get(id=logo.id),
        )

        job_1.delete()

        self.assertEqual(
            CustomImage.objects.filter(id=logo.id).count(),
            1,
            msg="Logo should not be deleted if it is still in use.",
        )
        self.assertEqual(
            TalentLinkJob.objects.get(talentlink_id=2).logo,
            CustomImage.objects.get(id=logo.id),
            msg=
            "Job 2 and its logo should be unaffected when Job 1 is deleted.",
        )
Пример #3
0
    def test_attachments_are_deleted_when_the_job_is(self, mock_get_client):
        job = TalentLinkJobFactory(talentlink_id=1, homepage=self.homepage)
        doc = DocumentFactory(talentlink_attachment_id=111)
        job.attachments.add(doc)
        job.save()

        job = TalentLinkJob.objects.filter(talentlink_id=1)
        doc = CustomDocument.objects.filter(talentlink_attachment_id=111)

        self.assertEqual(job.count(), 1)
        self.assertEqual(doc.count(), 1)

        job.delete()
        job = TalentLinkJob.objects.filter(talentlink_id=1)
        doc = CustomDocument.objects.filter(talentlink_attachment_id=111)

        self.assertEqual(job.count(), 0)
        self.assertEqual(
            doc.count(),
            0,
            msg="attached document should be deleted if its job is deleted",
        )