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 setUp(self): 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.site = Site.objects.create(hostname=RECRUITMENT_HOSTNAME, root_page=self.homepage)
def setUp(self): self.root_page = Page.objects.get(id=1) # Job site self.homepage = self.root_page.add_child( instance=RecruitmentHomePageFactory.build_with_fk_objs_committed( job_board=JOB_BOARD_CHOICES[0] ) ) self.site = Site.objects.create( hostname="jobs.example", port=80, root_page=self.homepage )
def setUp(self): root_page = Page.objects.get(id=1) self.homepage = HomePageFactory.build_with_fk_objs_committed() root_page.add_child(instance=self.homepage) self.main_site = Site.objects.create(hostname=MAIN_HOSTNAME, port=80, root_page=self.homepage) self.recruitment_homepage = root_page.add_child( instance=RecruitmentHomePageFactory.build_with_fk_objs_committed( title="Jobs")) self.recruitment_site = Site.objects.create( hostname=RECRUITMENT_HOSTNAME, port=80, root_page=self.recruitment_homepage) self.page_factories = [InformationPageFactory, IndexPageFactory]
def test_job_missing_from_import_are_deleted_only_if_from_same_board( self, mock_get_client): homepage_internal = RecruitmentHomePageFactory.build_with_fk_objs_committed( job_board=JOB_BOARD_CHOICES[1]) self.root_page.add_child(instance=homepage_internal) instant = datetime.datetime(2020, 1, 29, 12, 0, 0, tzinfo=datetime.timezone.utc) TalentLinkJobFactory( talentlink_id=1, job_number="AABBSAME", homepage=self.homepage, last_imported=instant, ) TalentLinkJobFactory( talentlink_id=2, job_number="CCDD", homepage=self.homepage, last_imported=instant, ) TalentLinkJobFactory( talentlink_id=3, job_number="AABBSAME", homepage=homepage_internal, last_imported=instant, ) self.assertEqual( TalentLinkJob.objects.filter(homepage=self.homepage).count(), 2) self.assertEqual( TalentLinkJob.objects.filter(homepage=homepage_internal).count(), 1) # Create mock client faking results for 2 boards board_external_advertisements = [ get_advertisement(talentlink_id=1, job_number="AABBSAME"), ] board_internal_advertisements = [ get_advertisement(talentlink_id=3, job_number="AABBSAME"), ] client = mock.Mock() client.service.getAdvertisementsByPage.side_effect = [ { "advertisements": { "advertisement": board_external_advertisements }, "totalResults": 143, }, no_further_pages_response, { "advertisements": { "advertisement": board_internal_advertisements }, "totalResults": 143, }, no_further_pages_response, ] mock_get_client.return_value = client call_command("import_jobs", import_categories=True, stdout=mock.MagicMock()) # Only one new job remains. Jobs not in import are deleted. self.assertEqual( TalentLinkJob.objects.filter(homepage=self.homepage).count(), 1) self.assertEqual( TalentLinkJob.objects.filter(homepage=homepage_internal).count(), 1)
def setUpRecruitmentHomePage(self): self.root_page = Page.objects.get(id=1) self.homepage = RecruitmentHomePageFactory.build_with_fk_objs_committed( ) self.root_page.add_child(instance=self.homepage)