def test_promote_to_admin_different_company(self): admin = UserFactory(is_company_admin=True) user = UserFactory() url = reverse('accounts:promote', kwargs={'user_pk': user.id}) subdomain_get(self.app, url, user=admin, status=404)
def test_promote_to_admin_without_being_admin(self): fake_admin = UserFactory() user = UserFactory(company=fake_admin.company) url = reverse('accounts:promote', kwargs={'user_pk': user.id}) subdomain_get(self.app, url, user=fake_admin, status=404)
def test_publish_another_company_opening(self): opening = OpeningFactory( company=self.user.company, published_date=datetime.now() ) user2 = UserFactory() url = reverse('openings:publish_opening', args=(opening.id,)) subdomain_get(self.app, url, user=user2, status=404)
def test_can_only_rate_own_company_opening(self): application = ApplicationFactory(opening=self.opening) other_user = UserFactory() url = reverse( 'applications:rate', args=(application.pk, -1,) ) subdomain_get(self.app, url, other_user, status=404)
def test_close_opening_valid(self): opening = OpeningFactory(title='DevOps', company=self.user.company) url = reverse('openings:publish_opening', args=(opening.id, )) subdomain_get(self.app, url, user=self.user) self.assertEqual( Opening.objects.filter(published_date__isnull=True).count(), 0)
def test_unpublish_opening(self): opening = OpeningFactory(company=self.user.company, published_date=datetime.now()) url = reverse('openings:publish_opening', args=(opening.id, )) subdomain_get(self.app, url, user=self.user) self.assertIsNone(Opening.objects.get().published_date)
def test_promote_to_admin_valid(self): admin = UserFactory(is_company_admin=True) user = UserFactory(company=admin.company) url = reverse('accounts:promote', kwargs={'user_pk': user.id}) subdomain_get(self.app, url, user=admin) self.assertTrue(CustomUser.objects.get(id=user.id).is_company_admin)
def test_close_opening_valid(self): opening = OpeningFactory(title='DevOps', company=self.user.company) url = reverse('openings:publish_opening', args=(opening.id,)) subdomain_get(self.app, url, user=self.user) self.assertEqual( Opening.objects.filter(published_date__isnull=True).count(), 0 )
def test_unpublish_opening(self): opening = OpeningFactory( company=self.user.company, published_date=datetime.now() ) url = reverse('openings:publish_opening', args=(opening.id,)) subdomain_get(self.app, url, user=self.user) self.assertIsNone(Opening.objects.get().published_date)
def test_delete_user_valid(self): admin = UserFactory(is_company_admin=True) user = UserFactory(company=admin.company) url = reverse('accounts:delete', kwargs={'user_pk': user.id}) subdomain_get(self.app, url, user=admin) self.assertEqual(len(CustomUser.objects.filter(id=user.id)), 0)
def test_get_applicant_details_different_company(self): application = ApplicationFactory(opening=self.opening) user = UserFactory(email='*****@*****.**') url = reverse( 'applications:application_detail', args=(application.id,) ) subdomain_get(self.app, url, user=user, status=404)
def test_get_logout_while_logged_out(self): """ GET the logout view while logged out Should redirect to the home page since it's not allowed to access this page without being logged in """ subdomain_get(self.app, reverse('auth:logout')) self.assertTemplateUsed('accounts/login.html')
def test_post_password_confirm_success(self): """ POST the reset password confirmation page Should change the password and redirects to home page """ user = UserFactory() uidb36 = int_to_base36(user.pk) token = default_token_generator.make_token(user) page = subdomain_get( self.app, reverse( 'auth:confirm_reset_password', kwargs={ 'uidb36': uidb36, 'token': token } ) ) form = page.forms[0] form['new_password1'] = 'password' form['new_password2'] = 'password' response = form.submit().follow() user_found = CustomUser.objects.get() self.assertTemplateUsed(response, 'accounts/login.html') self.assertTrue(user_found.check_password('password')) self.assertFalse(user_found.check_password('bob'))
def test_hire_applicant(self): InterviewStageFactory(tag='HIRED', company=CompanyFactory()) hired_stage = InterviewStageFactory(tag='HIRED', company=self.user.company) EmailTemplateFactory(code="candidate_hired", company=self.user.company, subject="Congrats {{ applicant_first_name }}") application = ApplicationFactory(opening=self.opening) url = reverse( 'applications:application_detail', args=(application.pk,) ) response = subdomain_get(self.app, url, user=self.user) form = response.forms['transition-form'] form['stage'] = '%s' % hired_stage.pk response = form.submit().follow() self.assertEqual(len(mail.outbox), 1) email, = mail.outbox self.assertTrue("Bilbon" in email.subject) application = Application.objects.get(pk=application.pk) self.assertEqual(application.current_stage, hired_stage) transition = application.stage_transitions.get() self.assertEqual(transition.user, self.user) self.assertEqual(transition.stage, hired_stage)
def test_already_logged_in(self): """ Testing that logged in users get redirected to the dashboard """ user = UserFactory() response = subdomain_get(self.app, reverse('auth:login'), user=user) self.assertTemplateUsed(response, 'dashboard/dashboard.html')
def test_get_company(self): url = reverse("companies:create") page = subdomain_get(self.app, url, user=self.user) self.assertEqual(page.status_code, 200) self.assertIn(0, page.forms)
def test_discuss_an_application(self): application = ApplicationFactory(opening=self.opening) colleague = UserFactory( email='*****@*****.**', company=self.user.company ) url = reverse( 'applications:application_detail', args=(application.id,) ) response = subdomain_get(self.app, url, user=self.user) form = response.forms['new-message-form'] form['body'] = 'This guy is good' form['parent'] = '' response = form.submit().follow() self.assertContains(response, "This guy is good") parent_message = ApplicationMessage.objects.get() self.assertEqual(self.user, parent_message.user) form = response.forms['new-message-form'] form['body'] = "I beg to differ" form['parent'] = parent_message.pk response = form.submit(user=colleague).follow(user=colleague) self.assertContains(response, "This guy is good") self.assertContains(response, "I beg to differ") new_message = ApplicationMessage.objects.get(parent=parent_message) self.assertEqual(colleague, new_message.user)
def test_get_demo_login_view(self): response = subdomain_get(self.app, reverse('auth:login'), data=dict(demo=1)) self.assertEqual(response.status_code, 200) form = response.forms[0] self.assertEqual(form['username'].value, "demo") self.assertEqual(form['password'].value, "demo")
def test_get_company(self): url = reverse('companies:create') page = subdomain_get(self.app, url, user=self.user) self.assertEqual(page.status_code, 200) self.assertIn(0, page.forms)
def test_list_stages(self): url = reverse('companysettings:list_stages') stage = InterviewStageFactory(company=self.user.company) page = subdomain_get(self.app, url, user=self.user) self.assertContains(page, stage.name)
def test_post_password_confirm_failure_password_mismatch(self): """ POST the reset password confirmation page Should not change the password and shows the errors """ user = UserFactory() uidb36 = int_to_base36(user.pk) token = default_token_generator.make_token(user) page = subdomain_get( self.app, reverse( 'auth:confirm_reset_password', kwargs={ 'uidb36': uidb36, 'token': token } ) ) form = page.forms[0] form['new_password1'] = 'password' form['new_password2'] = 'wrong' response = form.submit() user_found = CustomUser.objects.get() self.assertContains(response, 'The two password fields') self.assertFalse(user_found.check_password('password')) self.assertTrue(user_found.check_password('bob'))
def test_post_password_confirm_failure_password_mismatch(self): """ POST the reset password confirmation page Should not change the password and shows the errors """ user = UserFactory() uidb36 = int_to_base36(user.pk) token = default_token_generator.make_token(user) page = subdomain_get( self.app, reverse('auth:confirm_reset_password', kwargs={ 'uidb36': uidb36, 'token': token })) form = page.forms[0] form['new_password1'] = 'password' form['new_password2'] = 'wrong' response = form.submit() user_found = CustomUser.objects.get() self.assertContains(response, 'The two password fields') self.assertFalse(user_found.check_password('password')) self.assertTrue(user_found.check_password('bob'))
def test_vote_application_invalid(self): application = ApplicationFactory(opening=self.opening) url = reverse( 'applications:rate', args=(application.pk, -42,) ) page = subdomain_get(self.app, url, user=self.user) self.assertTemplateUsed(page, 'applications/application_detail.html') self.assertContains(page, 'class="alert-error"')
def test_get_invalid_activation(self): """ GET the activation page with an invalid activation key Should raise a 404, using client instead of app since app would fail """ url = reverse('accounts:activate', args=('FAKE', )) response = subdomain_get(self.app, url, status=404) self.assertEqual(response.status_code, 404)
def test_invalid_interest_email_error(self): url = reverse('public:landing-page') form = subdomain_get(self.app, url).form form['email'] = 'astonmartin.com' response = form.submit().follow() self.assertEqual(Interest.objects.count(), 0) self.assertContains(response, 'invalid')
def test_get_widget_view(self): url = reverse('companysettings:widget') page = subdomain_get(self.app, url, user=self.user) self.assertContains( page, '%s.hizard.com/embed.js' % self.user.company.subdomain )
def test_get_company_with_already_a_company(self): """Should be redirect to dashboard""" user = UserFactory(email="*****@*****.**") url = reverse('companies:create') page = subdomain_get(self.app, url, user=user) self.assertTemplateUsed(page, 'dashboard/dashboard.html')
def test_get_invalid_activation(self): """ GET the activation page with an invalid activation key Should raise a 404, using client instead of app since app would fail """ url = reverse('accounts:activate', args=('FAKE',)) response = subdomain_get(self.app, url, status=404) self.assertEqual(response.status_code, 404)
def test_get_company_with_already_a_company(self): """Should be redirect to dashboard""" user = UserFactory(email="*****@*****.**") url = reverse("companies:create") page = subdomain_get(self.app, url, user=user) self.assertTemplateUsed(page, "dashboard/dashboard.html")
def test_get_registration_view(self): """ Simple GET to the registration view that should use the correct template and have form in its context """ response = subdomain_get(self.app, reverse('accounts:register')) self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'accounts/registration_form.html') self.failUnless(isinstance(response.context['form'], UserCreationForm))
def test_get_password_reset(self): """ GET the reset password page """ response = subdomain_get(self.app, reverse('auth:reset_password')) self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'accounts/password_reset_form.html') self.failUnless(isinstance(response.context['form'], PasswordResetForm))
def test_post_create_company_invalid(self): url = reverse('companies:create') page = subdomain_get(self.app, url, user=self.user) form = page.forms[0] form['name'] = '' response = form.submit() self.assertEqual(response.status_code, 200) self.assertFormError(response, 'form', 'name', self.required)
def test_get_valid_activation(self): user = UserFactory(is_active=False, company=None) url = reverse('accounts:activate', args=(user.activation_key, )) response = subdomain_get(self.app, url) user_found = CustomUser.objects.get() self.assertEqual(response.status_code, 200) self.assertContains(response, 'You can now login') self.assertTrue(user_found.is_active)
def test_get_valid_activation(self): user = UserFactory(is_active=False, company=None) url = reverse('accounts:activate', args=(user.activation_key,)) response = subdomain_get(self.app, url) user_found = CustomUser.objects.get() self.assertEqual(response.status_code, 200) self.assertContains(response, 'You can now login') self.assertTrue(user_found.is_active)
def test_get_logout_while_logged_in(self): """ GET the logout view while logged in Should redirect to the login page and be logged out """ user = UserFactory() response = subdomain_get(self.app, reverse('auth:logout'), user=user) self.assertEqual(response.request.path, reverse("auth:login")) self.assertTemplateUsed(response, 'accounts/login.html') self.assertNotIn('_auth_user_id', self.app.session)
def test_list_emails(self): template = EmailTemplateFactory( company=self.user.company, code="application_received", name="Application received" ) response = subdomain_get(self.app, reverse("customisable_emails:list"), user=self.user) self.assertEqual(response.status_code, 200) self.assertContains(response, "Application received") edit_email_url = reverse("customisable_emails:edit", args=[template.pk]) self.assertContains(response, edit_email_url)
def test_opening_delete(self): opening = OpeningFactory(title='DevOps', company=self.user.company) url = reverse('openings:delete_opening', args=(opening.id, )) response = subdomain_get(self.app, url, user=self.user) self.assertEqual(response.status_code, 200) self.assertEqual(response.request.path, reverse('openings:list_openings')) self.assertNotContains(response, 'DevOps') self.assertContains(response, 'Opening deleted.')
def test_get_login_view(self): """ GET the login auth view (from django itself) """ response = subdomain_get(self.app, reverse('auth:login')) self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'accounts/login.html') self.failUnless( isinstance(response.context['form'], AuthenticationForm))
def test_post_create_company_invalid(self): url = reverse("companies:create") page = subdomain_get(self.app, url, user=self.user) form = page.forms[0] form["name"] = "" response = form.submit() self.assertEqual(response.status_code, 200) self.assertFormError(response, "form", "name", self.required)
def test_listing_all_applicants(self): application = ApplicationFactory.create(opening=self.opening) url = reverse('applications:list_applications') response = subdomain_get(self.app, url, user=self.user) self.assertEqual(response.status_code, 200) self.assertContains(response, application.applicant.first_name) self.assertContains(response, application.applicant.last_name)
def test_get_change_password(self): """ GET the change password page (accessible only while logged in) """ user = UserFactory() response = subdomain_get(self.app, reverse('accounts:change_details'), user=user) self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'accounts/change_details_form.html')
def test_modify_company_information_invalid(self): url = reverse('companysettings:update_information') page = subdomain_get(self.app, url, user=self.user) form = page.forms[0] form['website'] = 'goog' form['description'] = 'Cool stuff.' response = form.submit() self.assertEqual(response.status_code, 200) self.assertFormError(response, 'form', 'website', 'Enter a valid URL.')
def test_opening_edit(self): opening = OpeningFactory(title='DevOps', company=self.user.company) url = reverse('openings:update_opening', args=(opening.id, )) page = subdomain_get(self.app, url, user=self.user) form = page.forms[0] form['title'] = 'Software Developer' response = form.submit().follow() self.assertEqual(response.status_code, 200) self.assertContains(response, 'Software Developer') self.assertNotContains(response, 'DevOps')
def test_reorder_stage_valid_up(self): stage1 = InterviewStageFactory(company=self.user.company, position=1) stage2 = InterviewStageFactory(company=self.user.company, position=2) url = reverse('companysettings:reorder_stage', args=(stage2.id, -1)) response = subdomain_get(self.app, url, user=self.user) self.assertEqual( response.request.path, reverse('companysettings:list_stages') ) self.assertEqual(InterviewStage.objects.get(id=1).position, 2)
def test_list_emails(self): template = EmailTemplateFactory(company=self.user.company, code="application_received", name="Application received") response = subdomain_get(self.app, reverse('customisable_emails:list'), user=self.user) self.assertEqual(response.status_code, 200) self.assertContains(response, "Application received") edit_email_url = reverse("customisable_emails:edit", args=[template.pk]) self.assertContains(response, edit_email_url)
def test_get_expired_activation(self): """ GET the activation page with an expired activation key Should raise a 404, using client instead of app since app would fail """ user = UserFactory( is_active=False, created=datetime.datetime.now() - datetime.timedelta(days=settings.ACCOUNT_ACTIVATION_DAYS + 1), company=None) url = reverse('accounts:activate', args=(user.activation_key, )) response = subdomain_get(self.app, url, status=404) self.assertEqual(response.status_code, 404)
def test_delete_stage(self): InterviewStageFactory(company=self.user.company) stage = InterviewStageFactory( name='Interview youhou', company=self.user.company ) url = reverse('companysettings:delete_stage', args=(stage.id,)) response = subdomain_get(self.app, url, user=self.user) self.assertEqual(response.request.path, reverse('companysettings:list_stages')) self.assertNotContains(response, stage.name) self.assertContains(response, "Stage deleted.")
def test_post_password_reset_failure(self): """ POST the reset password page Should ask for a confirmation """ UserFactory() page = subdomain_get(self.app, reverse('auth:reset_password')) form = page.forms[0] form['email'] = '*****@*****.**' response = form.submit().follow() self.assertTemplateUsed(response, 'accounts/login.html') self.assertEqual(len(mail.outbox), 0)