def test_on_sites_by_buid(self): business_unit = BusinessUnitFactory(pk=77) results = DEv2JobFeed('seo/tests/data/dseo_feed_0.xml', jsid=business_unit.id, markdown=business_unit.enable_markdown) jobs = results.solr_jobs() for job in jobs: self.assertItemsEqual(job['on_sites'], [0]) site_package = SitePackageFactory(owner=self.company) business_unit.site_packages.add(site_package) results = DEv2JobFeed('seo/tests/data/dseo_feed_0.xml', jsid=business_unit.id, markdown=business_unit.enable_markdown) jobs = results.solr_jobs() for job in jobs: self.assertItemsEqual(job['on_sites'], [site_package.pk]) site_package2 = SitePackageFactory(owner=self.company) business_unit.site_packages.add(site_package2) results = DEv2JobFeed('seo/tests/data/dseo_feed_0.xml', jsid=business_unit.id, markdown=business_unit.enable_markdown) jobs = results.solr_jobs() for job in jobs: self.assertItemsEqual(job['on_sites'], [site_package.pk, site_package2.pk]) site_package2.delete() site_package.delete() business_unit.delete()
def setUp(self): super(LoadETLTestCase, self).setUp() self.zipfile = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data', '0812fe95-e7cb-4eb5-813c-55c9180f6bd7.zip') with open(self.zipfile) as zf: self.jobs = list(get_jobs_from_zipfile(zf, "0812fe95-e7cb-4eb5-813c-55c9180f6bd7")) self.businessunit = BusinessUnitFactory(id=0) self.buid = self.businessunit.id self.guid = '0812fe95-e7cb-4eb5-813c-55c9180f6bd7' self.name = "Test"
def setUp(self): super(JobsFStoJsonTest, self).setUp() self.document = path.join( path.dirname(__file__), 'data/789274C9-D0AA-49D6-8257-A8E977576183.xml') self.bu = BusinessUnitFactory() import_jobs.add_company(self.bu)
def test_no_markdown_newline_breaks(self): # Test that non-markdown businessunits have newlines converted to breaks no_markdown_bu = BusinessUnitFactory.build(id=5, enable_markdown=False) results = DEv2JobFeed( 'seo/tests/data/dseo_feed_0.xml', jsid=no_markdown_bu.id, markdown=no_markdown_bu.enable_markdown) jobs = results.solr_jobs() self.assertNotEqual(jobs[0]['html_description'].find('Operations<br />'), -1)
class LoadETLTestCase(DirectSEOBase): def setUp(self): self.zipfile = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data', 'ActiveDirectory_ce2ca701-eeca-4c13-96ba-e6bde9cb7060.zip') with open(self.zipfile) as zf: self.jobs = list(get_jobs_from_zipfile(zf, "ce2ca701-eeca-4c13-96ba-e6bde9cb7060")) self.businessunit = BusinessUnitFactory(id=0) def tearDown(self): pass def test_filtering_on_includeinindex_bit(self): """Test that filtering on the include_in_index bit works""" #Prove we have the expected number of jobs in the zipfile itself. self.assertEqual(len(self.jobs), 39, "Expected to find 0 jobs in the test zipfile, instead found %s" % len(self.jobs)) # Prove that filtering works. filtered_jobs = list(filter_current_jobs(self.jobs, self.businessunit)) self.assertEqual(len(filtered_jobs), 38, "filter_current_jobs should rmeove jobs with the includeinindex bit set, " "it's expected to return %s. Instead it returned %s" % (38, len(filtered_jobs))) def test_businessunit_ignore_includeinindex(self): """Test that filtering on the include_in_index bit can be overridden on a per business unit basis.""" # Set ignore_includeinindex on the test BusinessUnit self.businessunit.ignore_includeinindex = True self.businessunit.save() #Prove we have the expected number of jobs in the zipfile itself. self.assertEqual(len(self.jobs), 39, "Expected to find 0 jobs in the test zipfile, instead found %s" % len(self.jobs)) # Prove that filtering works. filtered_jobs = list(filter_current_jobs(self.jobs, self.businessunit)) self.assertEqual(len(filtered_jobs), 39, "filter_current_jobs should ignore the includeinindex bit, returning 39 jobs. " "Instead returned %s." % len(filtered_jobs))
def setUp(self): self.zipfile = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data', 'ActiveDirectory_ce2ca701-eeca-4c13-96ba-e6bde9cb7060.zip') with open(self.zipfile) as zf: self.jobs = list(get_jobs_from_zipfile(zf, "ce2ca701-eeca-4c13-96ba-e6bde9cb7060")) self.businessunit = BusinessUnitFactory(id=0)
def test_company_slug(self): bu = BusinessUnitFactory(title_slug='test-bu', id=7, title='Test') path = '/%s/%s/' % (bu.title_slug, settings.SLUG_TAGS['company_slug']) self.filters['company_slug'] = bu.title_slug jobs = [] query_dict = QueryDict('') breadbox = Breadbox(path, self.filters, jobs, query_dict) self.assertEqual(breadbox.company_breadcrumb.display_title, bu.title)
def setUp(self): super(LoadETLTestCase, self).setUp() self.zipfile = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data', 'ActiveDirectory_ce2ca701-eeca-4c13-96ba-e6bde9cb7060.zip') with open(self.zipfile) as zf: self.jobs = list(get_jobs_from_zipfile(zf, "ce2ca701-eeca-4c13-96ba-e6bde9cb7060")) self.businessunit = BusinessUnitFactory(id=0) self.buid = self.businessunit.id self.guid = 'ce2ca701-eeca-4c13-96ba-e6bde9cb7060' self.name = "Test"
def test_subsidiary_rename(self): company1 = CompanyFactory() company1.save() bu1 = self.businessunit bu1.title = "Acme corp" bu2 = BusinessUnitFactory(title=bu1.title) bu2.save() self.businessunit.company_set.add(company1) # Test that a company was created for both business units add_company(bu1) companies = bu1.company_set.all() self.assertEqual(len(companies), 1) co = companies[0] self.assertEqual(co.name, bu1.title) # Add the 2nd business unit add_company(bu2) # Both units should be attached to that company self.assertEqual(bu1.company_set.all()[0], bu2.company_set.all()[0]) self.assertEqual(bu1.company_set.all().count(), 1) self.assertIn(bu1, co.job_source_ids.all()) self.assertIn(bu2, co.job_source_ids.all()) self.assertEqual(co.name, bu1.title) self.assertEqual(co.name, bu2.title) bu2.title = "New company name" add_company(bu1) add_company(bu2) self.assertEqual(len(co.job_source_ids.all()), 1) self.assertNotEqual(bu1.company_set.all(), bu2.company_set.all()) self.assertEqual(co.name, bu1.title) self.assertEqual(len(bu2.company_set.all()), 1) co2 = bu2.company_set.all()[0] self.assertEqual(co2.name, bu2.title) self.assertNotEqual(co2.name, bu1.title) self.assertNotEqual(co.name, bu2.title)
def test_subsidiary_rename(self): company1 = CompanyFactory() bu1 = self.businessunit bu1.title = "Acme corp" bu2 = BusinessUnitFactory(title=bu1.title) bu2.save() self.businessunit.company_set.add(company1) # Test that a company was created for both business units add_company(bu1) companies = bu1.company_set.all() self.assertEqual(len(companies), 1) co = companies[0] self.assertEqual(co.name, bu1.title) # Add the 2nd business unit add_company(bu2) # Both units should be attached to that company self.assertEqual(bu1.company_set.all()[0], bu2.company_set.all()[0]) self.assertEqual(bu1.company_set.all().count(), 1) self.assertIn(bu1, co.job_source_ids.all()) self.assertIn(bu2, co.job_source_ids.all()) self.assertEqual(co.name, bu1.title) self.assertEqual(co.name, bu2.title) bu2.title = "New company name" add_company(bu1) add_company(bu2) self.assertEqual(len(co.job_source_ids.all()), 1) self.assertNotEqual(bu1.company_set.all(), bu2.company_set.all()) self.assertEqual(co.name, bu1.title) self.assertEqual(len(bu2.company_set.all()), 1) co2 = bu2.company_set.all()[0] self.assertEqual(co2.name, bu2.title) self.assertNotEqual(co2.name, bu1.title) self.assertNotEqual(co.name, bu2.title)
def setUp(self): super(DirectSEOTestCase, self).setUp() self.solr_docs = solr_settings.SOLR_FIXTURE self.conn.add(self.solr_docs) # uids and numjobs in feed file for test business unit 0 self.feed_uids = [ 57621597, 57311147, 60351047, 59891656, 58867671, 57495178, 59773973, 59326433, 57311143, 57311166 ] self.feed_numjobs = 14 self.businessunit = BusinessUnitFactory(id=0) self.buid_id = self.businessunit.id # Ensure DATA_DIR used by import_jobs.download_feed_file exists data_path = DATA_DIR if not os.path.exists(data_path): os.mkdir(data_path)
def setUp(self): self.solr_settings = { 'default': {'URL': 'http://127.0.0.1:8983/solr/seo'} } self.solr = Solr(settings.HAYSTACK_CONNECTIONS['default']['URL']) self.solr.delete(q="*:*") self.zipfile = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data', 'ActiveDirectory_ce2ca701-eeca-4c13-96ba-e6bde9cb7060.zip') with open(self.zipfile) as zf: self.jobs = list(get_jobs_from_zipfile(zf, "ce2ca701-eeca-4c13-96ba-e6bde9cb7060")) self.businessunit = BusinessUnitFactory(id=0) self.buid = self.businessunit.id self.guid = 'ce2ca701-eeca-4c13-96ba-e6bde9cb7060' self.name = "Test"
def setUp(self): super(JobFeedTestCase, self).setUp() self.businessunit = BusinessUnitFactory(id=0) self.buid_id = self.businessunit.id self.numjobs = 14 self.testdir = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'data') self.company = CompanyFactory() self.company.job_source_ids.add(self.businessunit) self.company.save() self.conn = Solr("http://127.0.0.1:8983/solr/seo") self.emptyfeed = os.path.join(self.testdir, "dseo_feed_0.no_jobs.xml") self.malformed_feed = os.path.join(self.testdir, 'dseo_malformed_feed_0.xml') self.invalid_feed = os.path.join(self.testdir, 'dseo_invalid_feed_0.xml') self.unused_field_feed = os.path.join(self.testdir, 'dseo_feed_1.xml') self.no_onet_feed = os.path.join(self.testdir, 'dseo_feed_no_onets.xml') # Ensures DATA_DIR used by import_jobs.download_feed_file exists data_path = DATA_DIR if not os.path.exists(data_path): os.mkdir(data_path)
def setUp(self): super(ModelTests, self).setUp() self.user = User.objects.create(email='*****@*****.**') self.company = CompanyFactory() CompanyProfile.objects.create(company=self.company) self.site = SeoSiteFactory() #domain='buckconsoltants.jobs') self.bu = BusinessUnitFactory() self.site.business_units.add(self.bu) self.site.save() self.company.job_source_ids.add(self.bu) self.company.save() # Use the newly created site for testing instead of secure.my.jobs. settings.SITE = self.site self.request_data = { 'title': 'title', 'company': self.company.id, 'reqid': '1', 'description': 'sadfljasdfljasdflasdfj', 'link': 'www.google.com', 'on_sites': '0', 'apply_info': '', } self.request_location = { 'city': 'Indianapolis', 'state': 'Indiana', 'state_short': 'IN', 'country': 'United States', 'country_short': 'USA', 'zipcode': '46268', } self.site_package_data = { 'name': 'Test Site Package', }
class LoadETLTestCase(DirectSEOBase): fixtures = ["countries.json"] def setUp(self): super(LoadETLTestCase, self).setUp() self.zipfile = os.path.join( os.path.dirname(os.path.abspath(__file__)), "data", "ActiveDirectory_ce2ca701-eeca-4c13-96ba-e6bde9cb7060.zip", ) with open(self.zipfile) as zf: self.jobs = list(get_jobs_from_zipfile(zf, "ce2ca701-eeca-4c13-96ba-e6bde9cb7060")) self.businessunit = BusinessUnitFactory(id=0) self.buid = self.businessunit.id self.guid = "ce2ca701-eeca-4c13-96ba-e6bde9cb7060" self.name = "Test" def tearDown(self): super(LoadETLTestCase, self).tearDown() @patch("import_jobs.get_jobsfs_zipfile") def test_update_job_source(self, mock_jobsfs): mock_jobsfs.return_value = open(self.zipfile, "rb") count = self.conn.search("*:*").hits self.assertEqual(count, 0, "Jobs for buid in solr before the test. Cannot guarantee correct behavior.") self.assertEqual(self.businessunit.associated_jobs, 4, "Initial Job Count does not match the factory") update_job_source(self.guid, self.buid, self.name) count = self.conn.search("buid:%s" % self.buid).hits # Note the job count being one low here is due to one job being filtered out due to include_in_index_bit self.assertEqual(count, 38, "38 Jobs not in solr after call to update job source. Found %s" % count) self.assertEqual( BusinessUnit.objects.get(id=self.buid).associated_jobs, 38, "Job Count not updated after imports: Should be 38 was %s" % self.businessunit.associated_jobs, ) def test_filtering_on_includeinindex_bit(self): """Test that filtering on the include_in_index bit works""" # Prove we have the expected number of jobs in the zipfile itself. self.assertEqual( len(self.jobs), 39, "Expected to find 0 jobs in the test zipfile, instead found %s" % len(self.jobs) ) # Prove that filtering works. filtered_jobs = list(filter_current_jobs(self.jobs, self.businessunit)) self.assertEqual( len(filtered_jobs), 38, "filter_current_jobs should rmeove jobs with the includeinindex bit set, " "it's expected to return %s. Instead it returned %s" % (38, len(filtered_jobs)), ) def test_businessunit_ignore_includeinindex(self): """Test that filtering on the include_in_index bit can be overridden on a per business unit basis.""" # Set ignore_includeinindex on the test BusinessUnit self.businessunit.ignore_includeinindex = True self.businessunit.save() # Prove we have the expected number of jobs in the zipfile itself. self.assertEqual( len(self.jobs), 39, "Expected to find 0 jobs in the test zipfile, instead found %s" % len(self.jobs) ) # Prove that filtering works. filtered_jobs = list(filter_current_jobs(self.jobs, self.businessunit)) self.assertEqual( len(filtered_jobs), 39, "filter_current_jobs should ignore the includeinindex bit, returning 39 jobs. " "Instead returned %s." % len(filtered_jobs), )
def setUp(self): super(BlocksTestBase, self).setUp() self.site = SeoSite.objects.get() self.config = Configuration.objects.get(status=2) self.config.browse_facet_show = True self.config.save() # Can't do a get_or_create here because we don't # care about the date_crawled/date_updated fields, # but if the BusinessUnit doesn't exist they will need # to be supplied. try: self.buid = BusinessUnit.objects.get(pk=0) except BusinessUnit.DoesNotExist: self.buid = BusinessUnitFactory(id=0) self.site.business_units.add(0) self.commitment = SpecialCommitmentFactory() self.site.special_commitments.add(self.commitment) self.site.save() self.tag = SiteTag.objects.create(site_tag='Test tag') self.site.site_tags.add(self.tag) self.site.save() self.job = SOLR_FIXTURE[1] self.conn.add([self.job]) self.user = UserFactory() url = reverse('all_jobs') self.search_results_request = RequestFactory().get(url) self.search_results_request.user = self.user self.q_kwargs = {'q': self.job['title']} url = build_url(reverse('all_jobs'), self.q_kwargs) self.search_results_with_q_request = RequestFactory().get(url) self.search_results_with_q_request.user = self.user self.facet = CustomFacetFactory(show_production=True, name='%s' % self.job['title'], name_slug='%s' % self.job['title_slug'], querystring='*', blurb='Test') self.bad_facet = CustomFacetFactory(show_production=True, name='Bad Facet', name_slug='bad-facet', querystring='asfljasdlfjsadfsdf', blurb='Test', always_show=True) SeoSiteFacetFactory(customfacet=self.facet, seosite=self.site) SeoSiteFacetFactory(customfacet=self.bad_facet, seosite=self.site) url = '%s/new-jobs/' % self.job['title_slug'] self.search_results_with_custom_facet = RequestFactory().get(url) self.search_results_with_custom_facet.user = self.user self.job_detail_kwargs = { 'job_id': self.job['guid'], 'title_slug': self.job['title_slug'], 'location_slug': slugify(self.job['location']), } url = reverse('job_detail_by_location_slug_title_slug_job_id', kwargs=self.job_detail_kwargs) self.job_detail_request = RequestFactory().get(url) self.job_detail_request.user = self.user kwargs = {'job_id': self.job['guid']} url = reverse('job_detail_by_job_id', kwargs=kwargs) self.job_detail_redirect_request = RequestFactory().get(url) self.job_detail_redirect_request.user = self.user # Send a request through middleware so all the required # settings (from MultiHostMiddleware) actually get set. self.client.get('/')
def setUp(self): super(ImportJobsTestCase, self).setUp() self.businessunit = BusinessUnitFactory(id=0) self.buid_id = self.businessunit.id self.filepath = os.path.join(DATA_DIR, '0', 'dseo_feed_%s.xml' % self.buid_id)
class LoadETLTestCase(DirectSEOBase): fixtures = ['countries.json'] def setUp(self): super(LoadETLTestCase, self).setUp() self.zipfile = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data', '0812fe95-e7cb-4eb5-813c-55c9180f6bd7.zip') with open(self.zipfile) as zf: self.jobs = list(get_jobs_from_zipfile(zf, "0812fe95-e7cb-4eb5-813c-55c9180f6bd7")) self.businessunit = BusinessUnitFactory(id=0) self.buid = self.businessunit.id self.guid = '0812fe95-e7cb-4eb5-813c-55c9180f6bd7' self.name = "Test" def tearDown(self): super(LoadETLTestCase, self).tearDown() @patch('import_jobs.get_jobsfs_zipfile') def test_update_job_source(self, mock_jobsfs): mock_jobsfs.return_value = open(self.zipfile, 'rb') count = self.conn.search('*:*').hits self.assertEqual(count, 0, "Jobs for buid in solr before the test. Cannot guarantee correct behavior.") self.assertEqual(self.businessunit.associated_jobs, 4, "Initial Job Count does not match the factory") update_job_source(self.guid, self.buid, self.name) count = self.conn.search('buid:%s' % self.buid).hits # Note the job count being one low here is due to one job being filtered out due to include_in_index_bit self.assertEqual(count, 27, "38 Jobs not in solr after call to update job source. Found %s" % count) self.assertEqual(BusinessUnit.objects.get(id=self.buid).associated_jobs, 27, "Job Count not updated after imports: Should be 38 was %s" % self.businessunit.associated_jobs) def test_salted_date_is_based_on_date_new(self): add_company(self.businessunit) transformed_job = hr_xml_to_json(self.jobs[0], self.businessunit) print "\nTRANSFORMED: %s\n" % transformed_job['guid'] expected = datetime.datetime.strptime("2016-07-02", "%Y-%m-%d").date() actual = transformed_job['salted_date'].date() self.assertEqual(expected, actual, "'Salted_date' is expected to be the same date as date_new, it is not. %s is not %s" % (actual, expected)) def test_filtering_on_includeinindex_bit(self): """Test that filtering on the include_in_index bit works""" # Prove we have the expected number of jobs in the zipfile itself. self.assertEqual(len(self.jobs), 28, "Expected to find 28 jobs in the test zipfile, instead found %s" % len(self.jobs)) # Prove that filtering works. filtered_jobs = list(filter_current_jobs(self.jobs, self.businessunit)) self.assertEqual(len(filtered_jobs), 27, "filter_current_jobs should rmeove jobs with the includeinindex bit set, " "it's expected to return %s. Instead it returned %s" % (27, len(filtered_jobs))) def test_businessunit_ignore_includeinindex(self): """Test that filtering on the include_in_index bit can be overridden on a per business unit basis.""" # Set ignore_includeinindex on the test BusinessUnit self.businessunit.ignore_includeinindex = True self.businessunit.save() # Prove we have the expected number of jobs in the zipfile itself. self.assertEqual(len(self.jobs), 28, "Expected to find 0 jobs in the test zipfile, instead found %s" % len(self.jobs)) # Prove that filtering works. filtered_jobs = list(filter_current_jobs(self.jobs, self.businessunit)) self.assertEqual(len(filtered_jobs), 28, "filter_current_jobs should ignore the includeinindex bit, returning 39 jobs. " "Instead returned %s." % len(filtered_jobs))
class LoadETLTestCase(DirectSEOBase): fixtures = ['countries.json'] def setUp(self): self.solr_settings = { 'default': {'URL': 'http://127.0.0.1:8983/solr/seo'} } self.solr = Solr(settings.HAYSTACK_CONNECTIONS['default']['URL']) self.solr.delete(q="*:*") self.zipfile = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data', 'ActiveDirectory_ce2ca701-eeca-4c13-96ba-e6bde9cb7060.zip') with open(self.zipfile) as zf: self.jobs = list(get_jobs_from_zipfile(zf, "ce2ca701-eeca-4c13-96ba-e6bde9cb7060")) self.businessunit = BusinessUnitFactory(id=0) self.buid = self.businessunit.id self.guid = 'ce2ca701-eeca-4c13-96ba-e6bde9cb7060' self.name = "Test" def tearDown(self): pass @patch('import_jobs.get_jobsfs_zipfile') def test_update_job_source(self, mock_jobsfs): mock_jobsfs.return_value = open(self.zipfile, 'rb') count = self.solr.search('*:*').hits self.assertEqual(count, 0, "Jobs for buid in solr before the test. Cannot guarantee correct behavior.") self.assertEqual(self.businessunit.associated_jobs, 4, "Initial Job Count does not match the factory") update_job_source(self.guid, self.buid, self.name) count = self.solr.search('buid:%s' % self.buid).hits # Note the job count being one low here is due to one job being filtered out due to include_in_index_bit self.assertEqual(count, 38, "38 Jobs not in solr after call to update job source. Found %s" % count) self.assertEqual(BusinessUnit.objects.get(id=self.buid).associated_jobs, 38, "Job Count not updated after imports: Should be 38 was %s" % self.businessunit.associated_jobs) def test_filtering_on_includeinindex_bit(self): """Test that filtering on the include_in_index bit works""" #Prove we have the expected number of jobs in the zipfile itself. self.assertEqual(len(self.jobs), 39, "Expected to find 0 jobs in the test zipfile, instead found %s" % len(self.jobs)) # Prove that filtering works. filtered_jobs = list(filter_current_jobs(self.jobs, self.businessunit)) self.assertEqual(len(filtered_jobs), 38, "filter_current_jobs should rmeove jobs with the includeinindex bit set, " "it's expected to return %s. Instead it returned %s" % (38, len(filtered_jobs))) def test_businessunit_ignore_includeinindex(self): """Test that filtering on the include_in_index bit can be overridden on a per business unit basis.""" # Set ignore_includeinindex on the test BusinessUnit self.businessunit.ignore_includeinindex = True self.businessunit.save() #Prove we have the expected number of jobs in the zipfile itself. self.assertEqual(len(self.jobs), 39, "Expected to find 0 jobs in the test zipfile, instead found %s" % len(self.jobs)) # Prove that filtering works. filtered_jobs = list(filter_current_jobs(self.jobs, self.businessunit)) self.assertEqual(len(filtered_jobs), 39, "filter_current_jobs should ignore the includeinindex bit, returning 39 jobs. " "Instead returned %s." % len(filtered_jobs))
def setUp(self): super(UpdatesTests, self).setUp() self.user = UserFactory() self.key = settings.BUID_API_KEY self.existing_bu = BusinessUnitFactory()