示例#1
0
    def test_find_your_match_with_remote(self, repos):
        class Repo:
            @classmethod
            def json(cls):
                return json.loads(GITHUB_REPO_RETURN)

        self.user = create_one_account()
        self.client.force_login(self.user)
        self.post = create_one_job(self.user.id, pay=True, type=2, repo_id=0)
        self.post2 = create_one_job(self.user.id,
                                    title='Backend Engineer',
                                    pay=True,
                                    repo_id=1)
        self.post3 = create_one_job(self.user.id,
                                    title='Data Scientist',
                                    pay=True,
                                    repo_id=2)
        self.post4 = create_one_job(self.user.id,
                                    title='Frontend Engineer',
                                    pay=True,
                                    repo_id=1)
        repos.return_value = Repo
        response = self.client.get('/match/?type=remote')
        self.assertContains(response, '<a class="job-title"')
        self.assertNotContains(response, 'Senior Software Engineer')
        self.assertContains(response, 'Backend Engineer')
        self.assertContains(response, '<i class="fa fa-building building"')
示例#2
0
 def test_browse_show_up_one_third_job(self):
     self.post = create_one_job(self.user.id, pay=True)
     self.post2 = create_one_job(self.user.id,
                                 title='Backend Engineer',
                                 pay=True)
     self.post3 = create_one_job(self.user.id,
                                 title='Data Scientist',
                                 pay=True)
     response = self.client.get(reverse('browse'))
     self.assertContains(response, '<a class="job-title"')
     self.assertContains(response, 'Backend Engineer')
     self.assertContains(
         response, '<i class="fa fa-building building" aria-hidden="true">')
示例#3
0
 def test_other_pages_not_login_redirect(self):
     # Before user login
     response = self.client.get(reverse('post_job'))
     self.assertEqual(response.status_code, 302)
     response = self.client.get(reverse('pay'))
     self.assertEqual(response.status_code, 302)
     response = self.client.get(reverse('repo_search'))
     self.assertEqual(response.status_code, 302)
     response = self.client.get(reverse('match'))
     self.assertEqual(response.status_code, 302)
     response = self.client.get(reverse('match'))
     self.assertEqual(response.status_code, 302)
     response = self.client.get(reverse('contributors'))
     self.assertEqual(response.status_code, 302)
     response = self.client.get(reverse('posted_jobs'))
     self.assertEqual(response.status_code, 302)
     # After user login
     user = create_one_account()
     self.client.force_login(user)
     self.post = create_one_job(user.id)
     response = self.client.get(reverse('contributors'))
     self.assertEqual(response.status_code, 200)
     self.assertContains(response, SEARCH)
     response = self.client.get(reverse('posted_jobs'))
     self.assertEqual(response.status_code, 200)
     response = self.client.get(reverse('post_job'))
     self.assertEqual(response.status_code, 200)
     self.assertContains(response, 'Job Details')
示例#4
0
    def test_expired_job(self):
        self.post = create_one_job(self.user.id)
        self.post.pay_time = timezone.now() - datetime.timedelta(days=40)
        self.post.save()
        self.post2 = create_one_job(self.user.id,
                                    title='Backend Engineer',
                                    pay=True)
        self.post2.pay_time = timezone.now() - datetime.timedelta(days=20)
        self.post2.save()

        def is_valid_post(post):
            return (post.pay and post.pay_time >
                    timezone.now() - datetime.timedelta(days=30))

        self.assertFalse(is_valid_post(self.post))
        self.assertTrue(is_valid_post(self.post2))
示例#5
0
    def test_pay(self, subscription, customer):
        # mock return value
        customer.return_value = json.loads(CUSTOMER_RETURN)
        subscription.return_value = json.loads(SUBSCRIPTION_RETURN)
        self.post = create_one_job(self.user.id)
        self.assertEqual(0, Customer.objects.count())
        data = self.get_data(self.post.id)
        response = self.client.post('/pay/',
                                    json.dumps(data),
                                    content_type='application/json')
        self.assertEqual(response.status_code, 200)
        # Wait for charge.successed callback
        cus = Customer.objects.get(stripe_email='*****@*****.**')
        self.assertEqual(cus.cus_id, 'cus_CGFa0zuiwqxHv1')
        self.assertEqual(cus.stripe_exp_year, 2022)
        self.assertEqual(1, Customer.objects.count())

        class Data:
            def __init__(self):
                self.body = (
                    b'{"data":'
                    b'{"object": {"customer": "cus_CGFa0zuiwqxHv1"}}}')

        request = Data()
        self.assertEqual(charge_su(request).status_code, 200)
        self.post.refresh_from_db()
        self.assertEqual(self.post.pay, True)
示例#6
0
 def test_get_valid_post(self):
     self.user = create_one_account()
     self.client.force_login(self.user)
     self.post = create_one_job(self.user.id, pay=True)
     self.post2 = create_one_job(self.user.id,
                                 title='Backend Engineer',
                                 pay=True,
                                 repo_id=1,
                                 type=1)
     self.post3 = create_one_job(self.user.id,
                                 title='Data Scientist',
                                 pay=True,
                                 repo_id=2,
                                 type=2)
     post = views._get_valid_post()
     self.assertEqual(post.count(), 3)
     remote_post = views._get_valid_post(type='remote')
     self.assertEqual(remote_post.count(), 2)
示例#7
0
 def test_pay_post(self):
     self.user = create_one_account()
     self.client.force_login(self.user)
     self.post = create_one_job(self.user.id)
     response = views._pay_post(999)
     self.assertEqual(response.status_code, 400)
     self.assertEqual(self.post.pay, False)
     response = views._pay_post(self.post.id)
     self.post.refresh_from_db()
     self.assertEqual(self.post.pay, True)
示例#8
0
 def test_create_job_with_pay_show_up(self):
     self.post = create_one_job(self.user.id, pay=True)
     response = self.client.get(reverse('job', kwargs={'id': self.post.id}))
     self.assertNotContains(response, 'To pay with your credit card')
     self.assertContains(response, 'Senior Software Engineer')
     self.assertContains(response, 'django')
     self.assertContains(response, 'No Visa Support')
     self.assertContains(response, 'Onsite And Remote')
     self.assertNotContains(response, 'Pay $69.3/first month')
     self.client.logout()
     response = self.client.get(reverse('job', kwargs={'id': self.post.id}))
     self.assertContains(response, 'Senior Software Engineer')
示例#9
0
    def test_repo_search_valid_post_user(self, repos):
        class Repo:
            @classmethod
            def json(cls):
                return json.loads(GITHUB_REPO_RETURN)

        repos.return_value = Repo
        user = create_one_account()
        self.client.force_login(user)
        create_one_job(user.id, pay=True)
        response = self.client.get(reverse('match'))
        response = self.client.get("%s?repo_id=4164482" %
                                   (reverse('repo_search')))
        user_response = {
            'length':
            1,
            'data': [{
                'username':
                '******',
                'avatar_url':
                'https://avatars2.githubusercontent.com/u/14333046?v=4'
            }]
        }
        self.assertEqual(response.json(), user_response)
示例#10
0
 def test_create_job_without_pay(self):
     self.post = create_one_job(self.user.id)
     # Posted jobs list on navbar
     response = self.client.get(reverse('front_page'))
     self.assertContains(response, 'Jobs Posted')
     # Access job detail
     response = self.client.get(reverse('job', kwargs={'id': self.post.id}))
     self.assertEqual(response.status_code, 200)
     self.assertContains(response, 'To pay with your credit card')
     self.assertContains(response, 'Senior Software Engineer')
     self.assertContains(response, 'Pay $69.3/first month')
     self.client.logout()
     response = self.client.get(reverse('job', kwargs={'id': self.post.id}))
     self.assertEqual(response.status_code, 404)
     self.assertTemplateUsed('404.html')
示例#11
0
 def test_posted_jobs_show_up_after_created(self):
     response = self.client.get(reverse('front_page'))
     self.assertNotContains(response, 'Jobs Created')
     self.post = create_one_job(self.user.id, pay=True)
     response = self.client.get(reverse('front_page'))
     self.assertContains(response, 'Jobs Posted')