def test_enable_posting(self): """ Attempting to automatically enable posting for a company should result in a valid site package owned by that company. """ AppAccessFactory(name='Posting') company = CompanyFactory(name='Posting Company') site = SeoSite.objects.create(domain='somewhere.jobs') # sanity checks self.assertIsNone(site.canonical_company) self.assertEqual(company.enabled_access, []) package = enable_posting(company, site) # Django caches model instances company = Company.objects.get(pk=company.pk) site = SeoSite.objects.get(pk=site.pk) self.assertEqual(site.canonical_company, company) self.assertIn("Posting", company.enabled_access) self.assertIn(site, package.sites.all()) self.assertTrue( LoginBlock.objects.filter( name="Posting Company Login Block").exists())
def setUp(self): super(TestViewLevelActivities, self).setUp() self.app_access = AppAccessFactory() # this role will be populated by activities on a test-by-test basis self.role.activities.clear() # login the user so that we don't read redirected to the login page self.client = TestClient(HTTP_X_REQUESTED_WITH='XMLHttpRequest') self.client.login_user(self.user)
def test_enabled_access(self): """ `Company.enabled_access` should return list of app access names. """ self.assertItemsEqual(self.company.enabled_access, []) app_access = AppAccessFactory(name='Test Access') self.company.app_access.add(app_access) self.assertItemsEqual(self.company.enabled_access, ['Test Access'])
def setUp(self): super(MyJobsBase, self).setUp() settings.ROOT_URLCONF = "myjobs_urls" settings.PROJECT = "myjobs" self.app_access = AppAccessFactory() self.activities = [ ActivityFactory(name=activity, app_access=self.app_access) for activity in [ "create communication record", "create contact", "create partner saved search", "create partner", "create role", "create tag", "create user", "delete tag", "delete partner", "delete role", "delete user", "read contact", "read communication record", "read partner saved search", "read partner", "read role", "read user", "read tag", "update communication record", "update contact", "update partner", "update role", "update tag", "update user", "read outreach email address", "create outreach email address", "delete outreach email address", "update outreach email address", "read outreach record", "convert outreach record", "view analytics" ] ] self.company = CompanyFactory(app_access=[self.app_access]) # this role will be populated by activities on a test-by-test basis self.role = RoleFactory(company=self.company, name="Admin") self.user = UserFactory(roles=[self.role], is_staff=True) cache.clear() clear_url_caches() self.ms_solr = Solr(settings.SOLR['seo_test']) self.ms_solr.delete(q='*:*') self.base_context_processors = settings.TEMPLATE_CONTEXT_PROCESSORS context_processors = self.base_context_processors + ( 'mymessages.context_processors.message_lists', ) setattr(settings, 'TEMPLATE_CONTEXT_PROCESSORS', context_processors) setattr(settings, 'MEMOIZE', False) self.patcher = patch('urllib2.urlopen', return_file()) self.mock_urlopen = self.patcher.start() self.client = TestClient() self.client.login_user(self.user)
def test_app_access_names_unique(self): """App access levels should have unique names.""" with self.assertRaises(IntegrityError): AppAccessFactory(name=self.app_access.name)