def setUp(self): """ Set up 5 subcategories and 2 categories """ self.talentlinkjobs = [] self.subcategories = [] self.categories = [] self.root_page = Page.objects.get(id=1) self.homepage = RecruitmentHomePageFactory.build_with_fk_objs_committed( job_board=JOB_BOARD_CHOICES[0] ) self.root_page.add_child(instance=self.homepage) self.homepage_internal = RecruitmentHomePageFactory.build_with_fk_objs_committed( job_board=JOB_BOARD_CHOICES[1] ) self.root_page.add_child(instance=self.homepage_internal) for i in range(4): subcat = JobSubcategoryFactory.build() subcat.save() # Add jobs for each subcategory according to its index (eg. self.subcategories[2] gets 2 jobs) for j in range(i): job = TalentLinkJobFactory.build(homepage=self.homepage) job.subcategory = subcat job.save() self.talentlinkjobs.append(job) self.subcategories.append(subcat) for i in range(2): cat = JobCategoryFactory.build() cat.save() self.categories.append(cat)
def get_mocked_client(self, advertisements=None, attachments=None, logos=None, category_titles=None): if advertisements is None: advertisements = [get_advertisement()] if category_titles is None: category_titles = [FIXTURE_JOB_SUBCATEGORY_TITLE] for title in category_titles: # create matching category JobSubcategoryFactory(title=title) client = mock.Mock() client.service.getAdvertisementsByPage.side_effect = [ { "advertisements": { "advertisement": advertisements }, "totalResults": 143 }, no_further_pages_response, ] # Attachments if attachments is None: # Add empty getAttachments response for each advertisement client.service.getAttachments.side_effect = [ dict() for _ in range(len(advertisements)) ] else: client.service.getAttachments.side_effect = attachments # Logos if logos is None: # Add empty getAdvertisementImages response for each advertisement client.service.getAdvertisementImages.side_effect = [ dict() for _ in range(len(advertisements)) ] else: client.service.getAdvertisementImages.side_effect = logos return client
def test_case_subcategory_matching_is_space_insensitive_with_existing_categories( self, mock_get_client): JobSubcategoryFactory(title="My Spacey Cat") advertisements = [ get_advertisement(talentlink_id=1, title="New title 1", job_group=" my spacey cat ") ] mock_get_client.return_value = self.get_mocked_client( advertisements, category_titles=[]) out = StringIO() call_command("import_jobs", "--import_categories", stdout=out) out.seek(0) output = out.read() self.assertIn("0 existing jobs updated", output) self.assertIn("1 new jobs created", output) self.assertEqual( JobSubcategory.objects.all().count(), 1, msg="JobSubcategory matching should be case insensitive", ) self.assertEqual(JobSubcategory.objects.first().title, "My Spacey Cat")
def setUp(self): ImportTestMixin.setUpRecruitmentHomePage(self) # create matching category JobSubcategoryFactory(title=FIXTURE_JOB_SUBCATEGORY_TITLE)