def test_job_add_to_solr(self): job = JobFactory(owner=self.company, created_by=self.user) job.locations.add(JobLocationFactory()) job.add_to_solr() guids = " OR ".join(job.guids()) query = "guid:%s" % guids self.assertEqual(self.ms_solr.search(query).hits, 1)
def test_job_filter_by_sites(self): for x in range(8800, 8815): domain = 'testsite-%s.jobs' % x site = SeoSiteFactory(id=x, domain=domain, name=domain) site_package = SitePackageFactory(owner=self.company) site_package.make_unique_for_site(site) for y in range(1, 5): job = JobFactory(owner=self.company, created_by=self.user) job.site_packages.add(site_package) job.save() self.assertEqual(Job.objects.filter_by_sites([site]).count(), 4) self.assertEqual(Job.objects.all().count(), 60)
def test_job_filter_by_site_multiple_sites(self): site_in_both_packages = SeoSiteFactory(domain='secondsite.jobs', id=7) single_site_package = SitePackageFactory(owner=self.company) single_site_package.make_unique_for_site(site_in_both_packages) both_sites_package = SitePackageFactory(owner=self.company) both_sites_package.sites.add(site_in_both_packages) both_sites_package.sites.add(self.site) both_sites_package.save() job_on_both = JobFactory(owner=self.company, created_by=self.user) job_on_both.site_packages.add(both_sites_package) job_on_both.save() job_on_new_site = JobFactory(owner=self.company, created_by=self.user) job_on_new_site.site_packages.add(single_site_package) job_on_new_site.save() self.assertEqual(Job.objects.all().count(), 2) # Confirm that filtering by both sites gets both jobs. both_sites = [site_in_both_packages, self.site] count = Job.objects.filter_by_sites(both_sites).count() self.assertEqual(count, 2) # Confirm that filtering by the site that only has one job only # gets one job. self.assertEqual(Job.objects.filter_by_sites([self.site]).count(), 1) # Confirm that filtering by the site the site that has both jobs gets # both jobs. count = Job.objects.filter_by_sites([site_in_both_packages]).count() self.assertEqual(count, 2)
def test_job_remove_from_solr(self): job = JobFactory(owner=self.company, created_by=self.user) locations = JobLocationFactory.create_batch(2) job.locations = locations job.save() job.remove_from_solr() guids = " OR ".join(job.guids()) query = "guid:%s" % guids self.assertEqual(self.ms_solr.search(query).hits, 0)
def test_job_creation_and_deletion(self): locations = JobLocationFactory.create_batch(5) job = JobFactory(owner=self.company, created_by=self.user) job.locations = locations job.save() self.assertEqual(Job.objects.all().count(), 1) self.assertEqual(JobLocation.objects.all().count(), 5) job.delete() self.assertEqual(Job.objects.all().count(), 0) self.assertEqual(JobLocation.objects.all().count(), 0)
def test_add_remove_job_locations(self): """ Regression test, job locations that were removed from a job weren't being removed from Solr Tests that adding or removing locations results in Solr updates after a job save """ locations = JobLocationFactory.create_batch(2) job = JobFactory(owner=self.company, created_by=self.user, locations=locations) self.assertEqual(self.ms_solr.search('*:*').hits, 2) guid = locations[0].guid job.locations.remove(locations[0]) self.assertEqual(self.ms_solr.search('guid:%s' % guid).hits, 0) self.assertEqual( self.ms_solr.search('guid:%s' % locations[1].guid).hits, 1) job.locations.remove(locations[1]) self.assertEqual(self.ms_solr.search('*:*').hits, 0)