Exemplo n.º 1
0
 def test_parent_domain_context_variable_with_domain_switching(self):
     self.setup_superuser()
     parent_site = factories.SeoSiteFactory()
     child_site = factories.SeoSiteFactory()
     child_site.parent_site = parent_site
     child_site.domain = "parentchildtest"
     child_site.save()
     resp = self.client.get("/?domain=parentchildtest")
     self.assertEqual(resp.context['secure_blocks_domain'], parent_site)
Exemplo n.º 2
0
    def test_child_nonchainfk_works_in_valid_relationships(self):
        """
            Verify that a NonChainedForeignKey field will allow a typical
            one to many relationship with children elements.

            Uses SeoSite.parent_site as example field.
        """
        failed = False
        parent_site = factories.SeoSiteFactory()
        child_sites = [factories.SeoSiteFactory() for x in range(0,9)]
        for child in child_sites:
            child.parent_site = parent_site
            child.clean_fields()
            child.save()
Exemplo n.º 3
0
 def test_parent_domain_context_variable_visit_parent_site(self):
     child_site = factories.SeoSiteFactory()
     child_site.domain = "zz." + child_site.domain
     child_site.parent_site = self.site
     self.site.save()
     resp = self.client.get("/")
     self.assertEqual(resp.context['secure_blocks_domain'], self.site)
Exemplo n.º 4
0
    def setUp(self):
        super(QuerysetCopierTests, self).setUp()
        self.copy_to = factories.copy_to_database

        # Using SeoSite for the object being copied because it covers
        # most types of recursive relationships, foreign keys and
        # many to many relationships.
        self.seosite = factories.SeoSiteFactory()

        # copy_objects() expects a queryset
        self.seosites = models.SeoSite.objects.filter(pk=self.seosite.pk)

        # Many-to-manys
        tag = models.SiteTag.objects.create(site_tag='Copy Test')
        self.seosite.site_tags.add(tag)
        tag = models.SiteTag.objects.create(site_tag='Copy Test 2')
        self.seosite.site_tags.add(tag)
        buid = factories.BusinessUnitFactory(pk=123321)
        self.seosite.business_units.add(buid)
        company = factories.CompanyFactory()
        self.seosite.featured_companies.add(company)

        # Nullable Foreign Keys
        self.seosite.canonical_company = company

        self.seosite.save()

        self.site_foreign_key_field_names = ['site_ptr']
        self.site_null_foreign_key_field_names = ['group', 'canonical_company']
        self.site_many_to_many_field_names = ['site_tags', 'business_units',
                                              'featured_companies']
Exemplo n.º 5
0
    def test_parent_nonchainfk_cannot_become_child(self):
        """
            Verify that a NonChainedForeignKey field that has child sites cannot
            become the child of another NonChainedForeignKey field.

            Uses SeoSite.parent_site as example field.
        """
        initial_parent_site = factories.SeoSiteFactory()
        child_site = factories.SeoSiteFactory()
        super_parent_site = factories.SeoSiteFactory()
        child_site.parent_site = initial_parent_site
        child_site.save()
        initial_parent_site.parent_site = super_parent_site
        with self.assertRaises(ValidationError):
            initial_parent_site.clean_fields()
        with self.assertRaises(ValidationError):
            initial_parent_site.save()
Exemplo n.º 6
0
 def create_multiple_sites_for_company(self):
     sites = []
     for x in range(1, 15):
         site = factories.SeoSiteFactory()
         site.business_units.add(self.company_buid)
         site.save()
         sites.append(site)
     return sites
Exemplo n.º 7
0
    def test_child_nonchainfk_cant_have_children(self):
        """
            Verify that a NonChainedForeignKey field that has a parent_site entry
            cannot be made the parent of another NonChainedForeignKey field.

            Uses SeoSite.parent_site as example field.
        """
        parent_site = factories.SeoSiteFactory()
        child_site = factories.SeoSiteFactory()
        grandchild_site = factories.SeoSiteFactory()
        child_site.parent_site = parent_site
        child_site.save()
        grandchild_site.parent_site = child_site
        with self.assertRaises(ValidationError):
            grandchild_site.clean_fields()
        with self.assertRaises(ValidationError):
            grandchild_site.save()
Exemplo n.º 8
0
    def setUp(self):
        super(TestRoles, self).setUp()

        self.user = factories.UserFactory()
        self.business_unit = factories.BusinessUnitFactory()
        self.company = factories.CompanyFactory()
        self.company.job_source_ids.add(self.business_unit)
        self.site = factories.SeoSiteFactory()
        self.site.business_units.add(self.business_unit)
Exemplo n.º 9
0
    def create_multiple_network_sites(self):
        network_tag, _ = SiteTag.objects.get_or_create(site_tag='network')

        sites = []
        for x in range(1, 15):
            site = factories.SeoSiteFactory()
            site.site_tags.add(network_tag)
            site.save()
            sites.append(site)
        return sites
Exemplo n.º 10
0
 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)
Exemplo n.º 11
0
 def test_seo_site_parent_cannot_become_child(self):
     """
         Ensure a child SEO Site cannot be a parent via the admin form
     """
     super_parent_seo_site = factories.SeoSiteFactory()
     parent_seo_site = factories.SeoSiteFactory()
     child_seo_site = factories.SeoSiteFactory()
     child_seo_site.parent_site = parent_seo_site
     child_seo_site.save()
     resp = self.client.post(reverse('admin:seo_seosite_change',args=(parent_seo_site.pk,)),
                             {'domain':'newdomain_testparentnochildbecome',
                             'name':parent_seo_site.name,
                             'group':parent_seo_site.group.pk,
                             'postajob_filter_type':parent_seo_site.postajob_filter_type,
                             'parent_site':super_parent_seo_site.pk})
     self.assertEqual(resp.status_code, 200)
     self.assertContains(resp, "field-parent_site errors")
     parent_site_refresh = SeoSite.objects.get(pk = parent_seo_site.pk)
     self.assertEqual(parent_site_refresh.parent_site, None)
Exemplo n.º 12
0
 def test_seo_site_cannot_be_child_of_child(self):
     """
         Ensure a child SEO Site cannot be a parent via the admin form
     """
     parent_seo_site = factories.SeoSiteFactory()
     child_seo_site = factories.SeoSiteFactory()
     child_seo_site.parent_site = parent_seo_site
     child_seo_site.save()
     group_for_new_site = factories.GroupFactory()
     resp = self.client.post(reverse('admin:seo_seosite_add'),
                             {'domain':'newdomain_testnochildchild',
                             'name':'new_name',
                             'group':group_for_new_site.pk,
                             'postajob_filter_type':'this site only',
                             'parent_site':child_seo_site.pk})
     self.assertEqual(resp.status_code, 200)
     self.assertContains(resp, "field-parent_site errors")
     with self.assertRaises(ObjectDoesNotExist):
         created_site = SeoSite.objects.get(domain='newdomain_testnochildchild')
Exemplo n.º 13
0
    def test_unique_redirect(self):
        """
        Test to ensure that we can't create a redirect for the same
        SeoSite more than once (enforcing the "unique_together"
        constraint on the SeoSiteRedirect model.

        """
        site = factories.SeoSiteFactory()
        factories.SeoSiteRedirectFactory(seosite=site)
        ssr2 = factories.SeoSiteRedirectFactory.build()
        self.assertRaises(IntegrityError, ssr2.save, ())
Exemplo n.º 14
0
    def test_nonchainfk_cant_be_its_own_parent(self):
        """
            Verify that a NonChainedForeignKey field cannot be its own parent.

            Uses SeoSite.parent_site as example field.
        """
        orphan_site = factories.SeoSiteFactory()
        orphan_site.parent_site = orphan_site
        with self.assertRaises(ValidationError):
            orphan_site.clean_fields()
        with self.assertRaises(ValidationError):
            orphan_site.save()
Exemplo n.º 15
0
    def test_this_site_only(self):
        network_sites = self.create_multiple_network_sites()
        self.create_multiple_sites_for_company()
        self.create_generic_sites()

        # 'this site only' is the default.
        new_site = factories.SeoSiteFactory()

        postajob_sites = new_site.postajob_site_list()
        postajob_site_ids = [site.id for site in postajob_sites]

        self.assertEqual(len(postajob_sites), 1)
        [self.assertNotIn(site.pk, postajob_site_ids) for site in network_sites]
        self.assertIn(new_site.pk, postajob_site_ids)
Exemplo n.º 16
0
    def test_network_sites_and_this_site(self):
        network_sites = self.create_multiple_network_sites()
        self.create_multiple_sites_for_company()
        self.create_generic_sites()

        kwargs = {'postajob_filter_type': 'network sites and this site'}
        new_site = factories.SeoSiteFactory(**kwargs)

        postajob_sites = new_site.postajob_site_list()
        postajob_site_ids = [site.id for site in postajob_sites]

        self.assertEqual(len(postajob_sites), len(network_sites)+1)
        [self.assertIn(site.pk, postajob_site_ids) for site in network_sites]
        self.assertIn(new_site.pk, postajob_site_ids)
Exemplo n.º 17
0
    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)
Exemplo n.º 18
0
    def test_all_sites(self):
        self.create_multiple_network_sites()
        self.create_multiple_sites_for_company()
        self.create_generic_sites()

        kwargs = {'postajob_filter_type': 'all sites'}
        new_site = factories.SeoSiteFactory(**kwargs)
        new_site.business_units.add(self.company_buid)
        new_site.save()

        postajob_sites = new_site.postajob_site_list()

        # postajob_sites = company_sites + network_sites + generic_sites +
        #                  new_site
        self.assertEqual(len(postajob_sites), SeoSite.objects.all().count())
Exemplo n.º 19
0
 def test_seo_site_can_be_child(self):
     """
         Ensure SEO Site can be added as a child via the admin form
     """
     parent_seo_site = factories.SeoSiteFactory()
     group_for_new_site = factories.GroupFactory()
     resp = self.client.post(reverse('admin:seo_seosite_add'),
                             {'domain':'newdomain_testnormal',
                             'name':'new_name',
                             'group':group_for_new_site.pk,
                             'postajob_filter_type':'this site only',
                             'parent_site':parent_seo_site.pk})
     self.assertEqual(resp.status_code, 302) # redirect on successful add
     self.assertFalse("field-parent_site errors" in resp)
     created_site = SeoSite.objects.get(domain='newdomain_testnormal')
     self.assertEqual(created_site.parent_site, parent_seo_site)
Exemplo n.º 20
0
    def test_company_sites(self):
        self.create_multiple_network_sites()
        company_sites = self.create_multiple_sites_for_company()
        self.create_generic_sites()

        kwargs = {'postajob_filter_type': 'sites associated with the company '
                                          'that owns this site'}
        new_site = factories.SeoSiteFactory(**kwargs)
        new_site.business_units.add(self.company_buid)
        new_site.save()

        postajob_sites = new_site.postajob_site_list()
        postajob_site_ids = [site.id for site in postajob_sites]

        # postajob_sites = company_sites + new_site
        self.assertEqual(len(postajob_sites), len(company_sites)+1)
        [self.assertIn(site.pk, postajob_site_ids) for site in company_sites]
Exemplo n.º 21
0
 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)
Exemplo n.º 22
0
    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))
Exemplo n.º 23
0
 def test_parent_domain_context_variable(self):
     parent_site = factories.SeoSiteFactory()
     self.site.parent_site = parent_site
     self.site.save()
     resp = self.client.get("/")
     self.assertEqual(resp.context['secure_blocks_domain'], parent_site)
Exemplo n.º 24
0
 def create_generic_sites(self):
     sites = []
     for x in range(1, 15):
         factories.SeoSiteFactory()
     return sites