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.", )
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.", )
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_attachments_are_not_deleted_if_another_job_uses_them( self, mock_get_client): job_1 = TalentLinkJobFactory(talentlink_id=1, homepage=self.homepage) doc_1 = DocumentFactory(talentlink_attachment_id=111) doc_2 = DocumentFactory(talentlink_attachment_id=222) job_1.attachments.add(doc_1) job_1.attachments.add(doc_2) job_1.save() job_2 = TalentLinkJobFactory(talentlink_id=2, homepage=self.homepage) job_2.attachments.add(doc_1) job_2.save() job = TalentLinkJob.objects.get(talentlink_id=1) doc = CustomDocument.objects.get(talentlink_attachment_id=111) self.assertEqual(doc.jobs.all().count(), 2) 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(), 1, msg= "attached document should be not deleted if it is being used elsewhere", ) self.assertEqual(doc[0].jobs.all().count(), 1) job_2 = TalentLinkJob.objects.get(talentlink_id=2) self.assertEqual(job_2.attachments.first(), doc[0])
def test_get_categories_summary_respects_job_board(self): self.categories[1].subcategories.add( self.subcategories[1] ) # this subcategory has 1 job summary = JobCategory.get_categories_summary(homepage=self.homepage) self.assertEqual(summary.count(), 1) # Should return nothing since the jobs in setup are all external jobs (JOB_BOARD_CHOICES[0]) summary = JobCategory.get_categories_summary(homepage=self.homepage_internal) self.assertEqual(summary.count(), 0) # Create internal job job = TalentLinkJobFactory(homepage=self.homepage_internal) job.subcategory = self.subcategories[1] job.save() summary = JobCategory.get_categories_summary(homepage=self.homepage_internal) self.assertEqual(summary.count(), 1)
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", )