def test_post_job_as_owner(self): """ Ensures that a company user of the site owner can post jobs for free and verify that they have been posted. PD-1463 Task - posting a job and verifying it is live (as site owner) - listing jobs """ with patch_settings(**self.OVERRIDES): num_jobs = Job.objects.count() self.login(self.admin) self.get(reverse('job_add')) self.make_job(for_admin=True) self.assertEqual(Job.objects.count(), num_jobs + 1) # If the previous bit was successfully added to solr, the following # page will have a job matching its description. self.get(reverse('all_jobs')) # We could easily .click() this but that would not properly append # the domain override. job_link = self.browser.find_element_by_link_text( self.job['id_title']).get_attribute('href') job = Job.objects.get(title=self.job['id_title'], description=self.job['id_description']) location = job.locations.get() self.TEST_OBJECTS.extend([location, job]) self.assertTrue(location.guid in job_link) self.get(job_link) element = self.browser.find_element_by_id( 'direct_jobDescriptionText') self.assertEqual(element.text, job.description) self.logout() # Trying this with a normal user fails. self.login(self.user) self.get(reverse('job_add')) with self.assertRaises(NoSuchElementException): self.browser.find_element_by_id( 'id_site_packages_add_link') self.logout() # Trying this instead with another company user is successful. # Due to the way one of the decorators works, this grabs the user's # company. Posting will not post to the current site, but to a site # determined by that company. Fixing this is outside the scope of # writing Selenium tests. self.login(self.admin_2) self.get(reverse('job_add')) with self.assertRaises(NoSuchElementException): self.browser.find_element_by_xpath( '//option[@value={site_pk}]'.format( site_pk=self.seo_site.pk)) self.browser.find_element_by_xpath( '//option[@value={site_pk}]'.format( site_pk=self.seo_site_2.pk))
def test_show_job_admin(self): """ Ensures that the main postajob admin is functional. A company user for the site owner should be able to see all options. A company user for a third party or a non-company-user should not. PD-1463 Task - jobs admin display """ with patch_settings(**self.OVERRIDES): for user, accessible in [(self.admin, True), (self.admin_2, False), (self.user, False)]: self.login(user) self.get(reverse('purchasedmicrosite_admin_overview')) for selector, expected in [ ('product-listing', 'Product Listing'), ('our-postings', 'Posted Jobs'), ('posting-admin', 'Partner Microsite')]: try: element = self.browser.find_element_by_id(selector) except NoSuchElementException: # If the user is not a company user for the owner, this # is expected; if not, we should reraise and fail. if accessible: raise else: self.assertEqual(element.text, expected) self.logout()
def tearDownClass(cls): """ Deletes all objects created during setup. """ cls.browser.quit() with patch_settings(**cls.OVERRIDES): cls.remove_objects() super(JobPostingTests, cls).tearDownClass()
def setUpClass(cls): """ Sets up the test environment, overriding settings and modifying the db. """ environment = os.environ.get('SETTINGS', '').lower() if environment == 'qc': print 'Running test_posting with QC settings' cls.test_url = 'qc.www.my.jobs' qc = imp.load_source('settings.myjobs_qc', 'deploy/settings.myjobs_qc.py') cls.OVERRIDES = vars(qc) elif environment == 'staging': print 'Running test_posting with staging settings' cls.test_url = 'staging.www.my.jobs' staging = imp.load_source('settings.myjobs_staging', 'deploy/settings.myjobs_staging.py') cls.OVERRIDES = vars(staging) else: production = imp.load_source('settings.myjobs_prod', 'deploy/settings.myjobs_prod.py') assert (settings.DATABASES['default']['HOST'] != production.DATABASES['default']['HOST']), \ 'Running test_posting with production settings is unsupported' print 'Running test_posting with settings.py' # Assuming local; I have to pick a port and runserver defaults to # 8000, so... cls.test_port = ':8000' cls.browser = webdriver.PhantomJS() super(JobPostingTests, cls).setUpClass() with patch_settings(**cls.OVERRIDES): try: cls.setup_objects() except: # If anything happens during setup (someone cancels the # process, db issues, whatever), we need to roll back. Delete # everything we created and reraise the exception. cls.remove_objects() raise
def tearDown(self): self.logout() with patch_settings(**self.OVERRIDES): for obj in self.TEST_OBJECTS[::-1]: obj.delete() super(JobPostingTests, self).tearDown()