Esempio n. 1
0
 def test_paid_jobs(self):
     job = Job(title='Software Developer',
               description='Test description',
               application_info='test', category_id=self.category.id,
               company_id=self.company.id, site_id=1, user_id=self.user.id,
               city='Toronto', state='Ontario',
               email='*****@*****.**')
     job.full_clean()
     job.save()
     self.assertEqual(len(self.company.paid_jobs()), 0)
     job.activate()
     self.assertEqual(len(self.company.paid_jobs()), 1)
Esempio n. 2
0
 def test_paid_jobs(self):
     job = Job(title='Software Developer',
               description='Test description',
               application_info='test', category_id=self.category.id,
               company_id=self.company.id, site_id=1, user_id=self.user.id,
               city='Toronto', state='Ontario',
               email='*****@*****.**')
     job.full_clean()
     job.save()
     self.assertEqual(len(self.company.paid_jobs()), 0)
     job.activate()
     self.assertEqual(len(self.company.paid_jobs()), 1)
Esempio n. 3
0
class JobViewAuthdTests(TestCase):
    def setUp(self):
        password = '******'
        owner = User(username='******')
        owner.set_password(password)
        owner.full_clean()
        owner.save()

        other = User(username='******')
        other.set_password(password)
        other.full_clean()
        other.save()

        country = Country(name='Canada')
        country.full_clean()
        country.save()

        company = Company(name='Tramcar',
                          site_id=1,
                          user_id=owner.id,
                          url='http://www.tramcar.org')
        company.full_clean()
        company.save()

        category = Category(name='Software Development', site_id=1)
        category.full_clean()
        category.save()

        self.job1 = Job(title='Software Developer',
                        description='Test description',
                        application_info='test',
                        category_id=category.id,
                        company_id=company.id,
                        site_id=1,
                        user_id=owner.id,
                        city='Toronto',
                        state='Ontario',
                        email='*****@*****.**')
        self.job1.full_clean()
        self.job1.save()
        self.job1.activate()

        self.job2 = Job(title='QA Engineer',
                        description='Test description',
                        application_info='test',
                        category_id=category.id,
                        company_id=company.id,
                        site_id=1,
                        user_id=other.id,
                        city='Toronto',
                        state='Ontario',
                        email='*****@*****.**')
        self.job2.full_clean()
        self.job2.save()
        self.job2.activate()

        self.job3 = Job(title='DevOps Engineer',
                        description='Test description',
                        application_info='test',
                        category_id=category.id,
                        company_id=company.id,
                        site_id=1,
                        user_id=other.id,
                        city='Toronto',
                        state='Ontario',
                        email='*****@*****.**')
        self.job3.full_clean()
        self.job3.save()

        self.job4 = Job(title='Growth Hacker',
                        description='Test description',
                        application_info='test',
                        category_id=category.id,
                        company_id=company.id,
                        site_id=1,
                        user_id=owner.id,
                        city='Toronto',
                        state='Ontario',
                        email='*****@*****.**')
        self.job4.full_clean()
        self.job4.save()

        self.client.post('/login/', {
            'username': owner.username,
            'password': password
        })

    def test_index_view(self):
        response = self.client.get(reverse('jobs_index'))
        self.assertEqual(response.status_code, 200)

    def test_new_get_view(self):
        response = self.client.get(reverse('jobs_new'))
        self.assertEqual(response.status_code, 200)

    def test_new_post_view(self):
        job = {
            'title': 'DevOps Engineer',
            'description': 'testing',
            'application_info': 'testing',
            'email': '*****@*****.**',
            'category': 1,
            'company': 1,
            'country': 1,
            'state': 'Ontario',
            'city': 'Guelph',
        }
        response = self.client.post(reverse('jobs_new'), job)
        # NOTE: We assume a redirect here is success, the response.url could be
        #       anything so eventually we should find a way to ensure it
        #       redirects to /jobs/2/ (for example)
        self.assertRedirects(response, response.url)

    def test_mine_view(self):
        response = self.client.get(reverse('jobs_mine'))
        self.assertEqual(response.status_code, 200)

    def test_mine_view_only_shows_my_jobs(self):
        response = self.client.get(reverse('jobs_mine'))
        self.assertNotContains(response, self.job2.title)

    def test_show_view_on_own_paid_job(self):
        response = self.client.get(self.job1.get_absolute_url())
        self.assertEqual(response.status_code, 200)

    def test_show_view_on_own_unpaid_job(self):
        response = self.client.get(self.job4.get_absolute_url())
        self.assertEqual(response.status_code, 200)

    def test_show_view_on_own_unpaid_job_shows_unpaid_status(self):
        response = self.client.get(self.job4.get_absolute_url())
        self.assertContains(response,
                            '<span class="label label-warning">Unpaid</span>')

    def test_show_view_on_other_users_paid_job(self):
        response = self.client.get(self.job2.get_absolute_url())
        self.assertEqual(response.status_code, 200)

    def test_show_view_on_other_users_unpaid_job(self):
        response = self.client.get(self.job3.get_absolute_url())
        self.assertEqual(response.status_code, 404)

    def test_show_view_on_own_job_shows_job_admin(self):
        response = self.client.get(self.job1.get_absolute_url())
        self.assertContains(response, 'Job Admin')

    def test_show_view_on_own_job_does_not_show_posted_by(self):
        response = self.client.get(self.job1.get_absolute_url())
        posted_by = '<h4><mark>Posted By</mark></h4>'
        self.assertNotContains(response, posted_by)

    def test_show_view_on_own_job_shows_expire_button(self):
        response = self.client.get(self.job1.get_absolute_url())
        url = reverse('jobs_expire', args=(self.job1.id, ))
        expire = '<a href="%s" class="btn btn-default">Expire</a>' % url
        self.assertContains(response, expire)

    def test_show_view_on_own_job_does_not_show_admin_activate_button(self):
        response = self.client.get(self.job1.get_absolute_url())
        url = reverse('jobs_activate', args=(self.job1.id, ))
        activate = '<a href="%s" class="btn btn-default">Activate</a>' % url
        self.assertNotContains(response, activate)

    def test_show_view_on_own_job_shows_email_address(self):
        response = self.client.get(self.job1.get_absolute_url())
        self.assertContains(response, self.job1.email)

    def test_show_view_on_other_job_does_not_show_job_admin(self):
        response = self.client.get(self.job2.get_absolute_url())
        self.assertNotContains(response, 'Job Admin')

    def test_show_view_on_other_job_does_not_show_email_address(self):
        response = self.client.get(self.job2.get_absolute_url())
        self.assertNotContains(response, self.job2.email)

    def test_activate_view(self):
        response = self.client.get(
            reverse('jobs_activate', args=(self.job1.id, )))
        self.assertRedirects(response,
                             '/login/?next=/jobs/%s/activate' % self.job1.id)

    def test_expire_view(self):
        response = self.client.get(
            reverse('jobs_expire', args=(self.job1.id, )))
        self.assertRedirects(response, self.job1.get_absolute_url())

    def test_edit_get_view(self):
        response = self.client.get(reverse('jobs_edit', args=(self.job1.id, )))
        self.assertEqual(response.status_code, 200)

    def test_edit_post_view(self):
        job = {
            'title': 'Software Engineer',
            'description': 'testing',
            'application_info': 'testing',
            'email': '*****@*****.**',
            'category': 1,
            'company': 1,
            'country': 1,
            'state': 'Ontario',
            'city': 'Guelph'
        }
        response = self.client.post(
            reverse('jobs_edit', args=(self.job1.id, )), job)
        # Here we refresh the object otherwise it will show the old content
        # from before the update
        self.job1.refresh_from_db()
        self.assertRedirects(response, self.job1.get_absolute_url())
Esempio n. 4
0
class JobViewUnauthdTests(TestCase):
    def setUp(self):
        user = User(username='******')
        user.set_password('password')
        user.full_clean()
        user.save()
        company = Company(name='Tramcar',
                          url='http://www.tramcar.org',
                          site_id=1,
                          user_id=user.id)
        company.full_clean()
        company.save()
        category = Category(name='Software Development', site_id=1)
        category.full_clean()
        category.save()
        self.job = Job(title='Software Developer',
                       description='Test description',
                       application_info='test',
                       category_id=category.id,
                       company_id=company.id,
                       site_id=1,
                       user_id=user.id,
                       city='Toronto',
                       state='Ontario',
                       email='*****@*****.**')
        self.job.full_clean()
        self.job.save()
        self.job.activate()

    def test_index_view(self):
        response = self.client.get(reverse('jobs_index'))
        self.assertEqual(response.status_code, 200)

    def test_new_view(self):
        response = self.client.get(reverse('jobs_new'))
        self.assertRedirects(response, '/login/?next=/jobs/new/')

    def test_mine_view(self):
        response = self.client.get(reverse('jobs_mine'))
        self.assertRedirects(response, '/login/?next=/jobs/mine/')

    def test_show_view(self):
        response = self.client.get(self.job.get_absolute_url())
        self.assertEqual(response.status_code, 200)

    def test_show_view_without_slug_redirects_to_slug(self):
        response = self.client.get(reverse('jobs_show', args=(self.job.id, )))
        self.assertRedirects(response,
                             self.job.get_absolute_url(),
                             status_code=301)

    def test_show_view_does_not_show_job_admin(self):
        response = self.client.get(self.job.get_absolute_url())
        self.assertNotContains(response, 'Job Admin')

    def test_show_view_does_not_show_owner_email_address(self):
        response = self.client.get(self.job.get_absolute_url())
        self.assertNotContains(response, self.job.email)

    def test_activate_view(self):
        response = self.client.get(
            reverse('jobs_activate', args=(self.job.id, )))
        self.assertRedirects(response,
                             '/login/?next=/jobs/%s/activate' % self.job.id)

    def test_expire_view(self):
        response = self.client.get(reverse('jobs_expire',
                                           args=(self.job.id, )))
        self.assertRedirects(response,
                             '/login/?next=/jobs/%s/expire' % self.job.id)

    def test_edit_view(self):
        response = self.client.get(reverse('jobs_edit', args=(self.job.id, )))
        self.assertRedirects(response,
                             '/login/?next=/jobs/%s/edit' % self.job.id)
Esempio n. 5
0
class JobViewAuthdTests(TestCase):

    def setUp(self):
        password = '******'
        owner = User(username='******')
        owner.set_password(password)
        owner.full_clean()
        owner.save()

        other = User(username='******')
        other.set_password(password)
        other.full_clean()
        other.save()

        country = Country(name='Canada')
        country.full_clean()
        country.save()

        company = Company(name='Tramcar', site_id=1, user_id=owner.id,
                          url='http://www.tramcar.org')
        company.full_clean()
        company.save()

        category = Category(name='Software Development', site_id=1)
        category.full_clean()
        category.save()

        self.job1 = Job(title='Software Developer',
                        description='Test description',
                        application_info='test', category_id=category.id,
                        company_id=company.id, site_id=1, user_id=owner.id,
                        city='Toronto', state='Ontario',
                        email='*****@*****.**')
        self.job1.full_clean()
        self.job1.save()
        self.job1.activate()

        self.job2 = Job(title='QA Engineer',
                        description='Test description',
                        application_info='test', category_id=category.id,
                        company_id=company.id, site_id=1, user_id=other.id,
                        city='Toronto', state='Ontario',
                        email='*****@*****.**')
        self.job2.full_clean()
        self.job2.save()
        self.job2.activate()

        self.job3 = Job(title='DevOps Engineer',
                        description='Test description',
                        application_info='test', category_id=category.id,
                        company_id=company.id, site_id=1, user_id=other.id,
                        city='Toronto', state='Ontario',
                        email='*****@*****.**')
        self.job3.full_clean()
        self.job3.save()

        self.job4 = Job(title='Growth Hacker',
                        description='Test description',
                        application_info='test', category_id=category.id,
                        company_id=company.id, site_id=1, user_id=owner.id,
                        city='Toronto', state='Ontario',
                        email='*****@*****.**')
        self.job4.full_clean()
        self.job4.save()

        self.client.post(
          '/login/',
          {'username': owner.username, 'password': password}
        )

    def test_index_view(self):
        response = self.client.get(reverse('jobs_index'))
        self.assertEqual(response.status_code, 200)

    def test_new_get_view(self):
        response = self.client.get(reverse('jobs_new'))
        self.assertEqual(response.status_code, 200)

    def test_new_post_view(self):
        job = {
            'title': 'DevOps Engineer',
            'description': 'testing',
            'application_info': 'testing',
            'email': '*****@*****.**',
            'category': 1,
            'company': 1,
            'country': 1,
            'state': 'Ontario',
            'city': 'Guelph',
        }
        response = self.client.post(reverse('jobs_new'), job)
        # NOTE: We assume a redirect here is success, the response.url could be
        #       anything so eventually we should find a way to ensure it
        #       redirects to /jobs/2/ (for example)
        self.assertRedirects(response, response.url)

    def test_mine_view(self):
        response = self.client.get(reverse('jobs_mine'))
        self.assertEqual(response.status_code, 200)

    def test_mine_view_only_shows_my_jobs(self):
        response = self.client.get(reverse('jobs_mine'))
        self.assertNotContains(response, self.job2.title)

    def test_show_view_on_own_paid_job(self):
        response = self.client.get(self.job1.get_absolute_url())
        self.assertEqual(response.status_code, 200)

    def test_show_view_on_own_unpaid_job(self):
        response = self.client.get(self.job4.get_absolute_url())
        self.assertEqual(response.status_code, 200)

    def test_show_view_on_own_unpaid_job_shows_unpaid_status(self):
        response = self.client.get(self.job4.get_absolute_url())
        self.assertContains(
            response,
            '<span class="label label-warning">Unpaid</span>'
        )

    def test_show_view_on_other_users_paid_job(self):
        response = self.client.get(self.job2.get_absolute_url())
        self.assertEqual(response.status_code, 200)

    def test_show_view_on_other_users_unpaid_job(self):
        response = self.client.get(self.job3.get_absolute_url())
        self.assertEqual(response.status_code, 404)

    def test_show_view_on_own_job_shows_job_admin(self):
        response = self.client.get(self.job1.get_absolute_url())
        self.assertContains(response, 'Job Admin')

    def test_show_view_on_own_job_does_not_show_posted_by(self):
        response = self.client.get(self.job1.get_absolute_url())
        posted_by = '<h4><mark>Posted By</mark></h4>'
        self.assertNotContains(response, posted_by)

    def test_show_view_on_own_job_shows_expire_button(self):
        response = self.client.get(self.job1.get_absolute_url())
        url = reverse('jobs_expire', args=(self.job1.id,))
        expire = '<a href="%s" class="btn btn-default">Expire</a>' % url
        self.assertContains(response, expire)

    def test_show_view_on_own_job_does_not_show_admin_activate_button(self):
        response = self.client.get(self.job1.get_absolute_url())
        url = reverse('jobs_activate', args=(self.job1.id,))
        activate = '<a href="%s" class="btn btn-default">Activate</a>' % url
        self.assertNotContains(response, activate)

    def test_show_view_on_own_job_shows_email_address(self):
        response = self.client.get(self.job1.get_absolute_url())
        self.assertContains(response, self.job1.email)

    def test_show_view_on_other_job_does_not_show_job_admin(self):
        response = self.client.get(self.job2.get_absolute_url())
        self.assertNotContains(response, 'Job Admin')

    def test_show_view_on_other_job_does_not_show_email_address(self):
        response = self.client.get(self.job2.get_absolute_url())
        self.assertNotContains(response, self.job2.email)

    def test_activate_view(self):
        response = self.client.get(
                       reverse('jobs_activate', args=(self.job1.id,))
                   )
        self.assertRedirects(
            response, '/login/?next=/jobs/%s/activate' % self.job1.id
        )

    def test_expire_view(self):
        response = self.client.get(
                       reverse('jobs_expire', args=(self.job1.id,))
                   )
        self.assertRedirects(response, self.job1.get_absolute_url())

    def test_edit_get_view(self):
        response = self.client.get(reverse('jobs_edit', args=(self.job1.id,)))
        self.assertEqual(response.status_code, 200)

    def test_edit_post_view(self):
        job = {
            'title': 'Software Engineer',
            'description': 'testing',
            'application_info': 'testing',
            'email': '*****@*****.**',
            'category': 1,
            'company': 1,
            'country': 1,
            'state': 'Ontario',
            'city': 'Guelph'
        }
        response = self.client.post(
                       reverse('jobs_edit', args=(self.job1.id,)),
                       job
                   )
        # Here we refresh the object otherwise it will show the old content
        # from before the update
        self.job1.refresh_from_db()
        self.assertRedirects(response, self.job1.get_absolute_url())
Esempio n. 6
0
class JobViewUnauthdTests(TestCase):

    def setUp(self):
        user = User(username='******')
        user.set_password('password')
        user.full_clean()
        user.save()
        company = Company(name='Tramcar', url='http://www.tramcar.org',
                          site_id=1, user_id=user.id)
        company.full_clean()
        company.save()
        category = Category(name='Software Development', site_id=1)
        category.full_clean()
        category.save()
        self.job = Job(title='Software Developer',
                       description='Test description',
                       application_info='test', category_id=category.id,
                       company_id=company.id, site_id=1, user_id=user.id,
                       city='Toronto', state='Ontario',
                       email='*****@*****.**')
        self.job.full_clean()
        self.job.save()
        self.job.activate()

    def test_index_view(self):
        response = self.client.get(reverse('jobs_index'))
        self.assertEqual(response.status_code, 200)

    def test_new_view(self):
        response = self.client.get(reverse('jobs_new'))
        self.assertRedirects(response, '/login/?next=/jobs/new/')

    def test_mine_view(self):
        response = self.client.get(reverse('jobs_mine'))
        self.assertRedirects(response, '/login/?next=/jobs/mine/')

    def test_show_view(self):
        response = self.client.get(self.job.get_absolute_url())
        self.assertEqual(response.status_code, 200)

    def test_show_view_without_slug_redirects_to_slug(self):
        response = self.client.get(
                       reverse('jobs_show', args=(self.job.id,))
                   )
        self.assertRedirects(
            response, self.job.get_absolute_url(), status_code=301
        )

    def test_show_view_does_not_show_job_admin(self):
        response = self.client.get(self.job.get_absolute_url())
        self.assertNotContains(response, 'Job Admin')

    def test_show_view_does_not_show_owner_email_address(self):
        response = self.client.get(self.job.get_absolute_url())
        self.assertNotContains(response, self.job.email)

    def test_activate_view(self):
        response = self.client.get(
                       reverse('jobs_activate', args=(self.job.id,))
                   )
        self.assertRedirects(
            response, '/login/?next=/jobs/%s/activate' % self.job.id
        )

    def test_expire_view(self):
        response = self.client.get(reverse('jobs_expire', args=(self.job.id,)))
        self.assertRedirects(
            response, '/login/?next=/jobs/%s/expire' % self.job.id
        )

    def test_edit_view(self):
        response = self.client.get(reverse('jobs_edit', args=(self.job.id,)))
        self.assertRedirects(
            response, '/login/?next=/jobs/%s/edit' % self.job.id
        )