def test_domain_switching_for_staff_context(self): self.setup_superuser() another_site = factories.SeoSiteFactory(id=2) another_site.domain = 'thisisatest' another_site.save() # create and test config for status 1 (non staff fallback) configuration_status_1 = factories.ConfigurationFactory(status=1) configuration_status_1.save() another_site.configurations.add(configuration_status_1) resp = self.client.get("/?domain=thisisatest") self.assertEqual(resp.context['site_config'], configuration_status_1) # create and test config for status 2 (non staff primary page) configuration_status_2 = factories.ConfigurationFactory(status=2) another_site.configurations.add(configuration_status_2) resp = self.client.get("/?domain=thisisatest") self.assertNotEqual(resp.context['site_config'], configuration_status_1) self.assertEqual(resp.context['site_config'], configuration_status_2)
def setUp(self): super(FiltersTestCase, self).setUp() self.request = DummyRequest() self.site = models.SeoSite.objects.first() settings.SITE = self.site settings.SITE_ID = self.site.pk self.config = factories.ConfigurationFactory(num_filter_items_to_show=5) for filter_type in filter_types: setattr(self.config, 'browse_%s_show' % filter_type, True) self.config.save()
def setUp(self): super(SiteTestCase, self).setUp() SeoSite.objects.all().delete() self.site = factories.SeoSiteFactory(id=1) settings.SITE = self.site settings.SITE_ID = self.site.pk self.configuration = factories.ConfigurationFactory(status=2) self.configuration.save() self.site.configurations.clear() self.site.configurations.add(self.configuration)
def setUp(self): super(SiteTestCase, self).setUp() self.conn = Solr('http://127.0.0.1:8983/solr/seo') self.conn.delete(q="*:*") self.businessunit = factories.BusinessUnitFactory(id=0) self.buid = self.businessunit.id self.filepath = os.path.join(import_jobs.DATA_DIR, 'dseo_feed_%s.xml' % self.buid) SeoSite.objects.all().delete() self.site = factories.SeoSiteFactory(id=1) self.configuration = factories.ConfigurationFactory(status=2) self.configuration.save() self.site.configurations.clear() self.site.configurations.add(self.configuration)
def test_clear_cache_on_bu_save(self): with patch_settings( CACHES={ 'default': { 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache' } }): site = factories.SeoSiteFactory() site.business_units.add(self.businessunit) config = factories.ConfigurationFactory( status=2, home_page_template='home_page/home_page_listing.html') config.save() site.configurations = [config] resp = self.client.get('/', HTTP_HOST=u'buckconsultants.jobs', follow=True) initial_jobs = resp.context['default_jobs'] self.assertEqual(resp.status_code, 200) self.assertGreater(len(initial_jobs), 0) self.assertEqual(len(initial_jobs), len(self.solr_docs)) for job in initial_jobs: self.assertContains(resp, job.guid) self.conn.delete(id=self.solr_docs[0]['id']) resp = self.client.get('/', HTTP_HOST=u'buckconsultants.jobs') self.assertEqual(resp.status_code, 200) self.assertEqual(resp.context, None) # Deleted job should still be on cached page self.assertEqual(len(initial_jobs), len(self.solr_docs)) for job in initial_jobs: self.assertContains(resp, job.guid) # Clear cache to reflect removed job task_clear_bu_cache(self.businessunit.id) resp = self.client.get('/', HTTP_HOST=u'buckconsultants.jobs') new_jobs = resp.context['default_jobs'] self.assertEqual(len(initial_jobs) - 1, len(new_jobs)) solr_jobs = self.conn.search('*:*') self.assertEqual(len(solr_jobs), len(new_jobs))
def test_configuration_get_template_is_v1(self, mock_get_template, mock_add_custom_param): """ Configurations on v1 should not get the v2 template, even if a v2 template is available. django.template.loader.get_template is patched to ensure that the requested template does exist. """ v1 = 'v1' template_string = 'this/does_not_exist' configuration = factories.ConfigurationFactory(template_version=v1) actual_template_string = configuration.get_template(template_string) self.assertEqual(template_string, actual_template_string) # New Relic should also be receiving the correct information. mock_add_custom_param.assert_called_with("template_version", v1)
def test_configuration_get_template_is_v2(self, mock_get_template, mock_add_custom_param): """ If a Configuration is on v2 and a v2 template is available, the v2 template string should be the the one returned. django.template.loader.get_template is patched to ensure that the requested template does exist. """ v2 = 'v2' template_string = 'this/does_not_exist' expected_template_string = "%s/%s" % (v2, template_string) configuration = factories.ConfigurationFactory(template_version=v2) actual_template_string = configuration.get_template(template_string) self.assertEqual(expected_template_string, actual_template_string) # New Relic should also be receiving the correct information. mock_add_custom_param.assert_called_with("template_version", v2)
def test_configuration_get_template_fail(self, mock_get_template, mock_add_custom_param): """ Configurations on v2 templates should still get the v1 template if no v2 template is available. django.template.loader.get_template is patched to ensure that the requested template does not exist. """ mock_get_template.side_effect = TemplateDoesNotExist v2 = 'v2' template_string = 'this/does_not_exist' configuration = factories.ConfigurationFactory(template_version=v2) self.assertEqual(configuration.template_version, v2) actual_template_string = configuration.get_template(template_string) self.assertEqual(template_string, actual_template_string) # New Relic should also be receiving the correct information. mock_add_custom_param.assert_called_with("template_version", "v1")
def setUp(self): super(QueryCountTests, self).setUp() settings.SOLR_QUERY_COUNTER = 0 # For each search page there should be at least 2 queries: # default jobs, total jobs # There can also be an additional two queries: # featured jobs, custom facets # For a total of at least 2 queries but at most 4 self.query_range = range(2, 4 + 1) # Make a valid non-dns-homepage configuration to use. site = SeoSite.objects.get() site.configurations.all().delete() site.configurations.add(factories.ConfigurationFactory(status=2)) site.business_units.add(0) # Insert extra jobs so we know the search pages # aren't iterating through all jobs for some reason. bulk_jobs = [] job = SOLR_FIXTURE[0] for i in range(5000, 5050): guid = str(i) * 8 new_job = dict(job) new_job['guid'] = guid new_job['uid'] = new_job['id'] = new_job['django_id'] = i bulk_jobs.append(new_job) self.conn.add(bulk_jobs) # Make sure there's not an id collision and we're really adding # all the jobs we think we just added. self.assertGreaterEqual(self.conn.search(q='*:*').hits, len(bulk_jobs)) # Two search terms that are guaranteed to yield results # including all the new jobs we just inserted. self.location = 'Indianapolis' self.q = 'description' self.path = '/usa/jobs/' self.feed_types = ['json', 'rss', 'xml', 'atom', 'indeed', 'jsonp']