예제 #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_job_logo_is_removed_if_removed_in_import(
            self, mock_import_image_from_url, mock_get_client):
        job = TalentLinkJobFactory(talentlink_id=1)
        logo = ImageFactory(talentlink_image_id="aaa")
        job.logo = logo
        job.save()

        advertisements = [
            get_advertisement(talentlink_id=1, title="New title 1"),
        ]
        logos = [
            {},
        ]

        mock_get_client.return_value = self.get_mocked_client(advertisements,
                                                              logos=logos)
        out = StringIO()
        call_command("import_jobs", stdout=out)
        out.seek(0)
        output = out.read()

        self.assertIn("1 existing jobs updated", output)
        self.assertIn("0 new images imported", output)
        self.assertEqual(
            TalentLinkJob.objects.get(talentlink_id=1).logo,
            None,
        )
        self.assertEqual(
            CustomImage.objects.filter(talentlink_image_id="aaa").count(),
            0,
        )
    def test_fis_page_in_search_results(self):
        image = ImageFactory()
        hit_page = self.fis_homepage.add_child(
            instance=fixtures.CategoryTypeOnePageFactory.build(
                title="screwdrivers", banner_image=image,
            )
        )

        response = self.client.get(reverse("search") + "?query=screwdrivers")

        self.assertIn(
            Page.objects.get(pk=hit_page.pk), response.context["search_results"]
        )
    def build_with_fk_objs_committed(cls, **kwargs):
        from bc.images.tests.fixtures import ImageFactory

        image = ImageFactory()
        return cls.build(hero_image=image, logo=image, **kwargs)