Beispiel #1
0
class JobDetailsViewTest(TestCase):
    @patch("pyjobs.marketing.triggers.post_telegram_channel")
    def setUp(self, _mocked_post_telegram_channel):
        self.job = Job(
            title="Vaga 1",
            workplace="Sao Paulo",
            company_name="XPTO",
            application_link="http://www.xpto.com.br/apply",
            company_email="*****@*****.**",
            description="Job bem maneiro",
            requirements="Job bem maneiro",
            salary_range=10,
        )
        self.job.save()
        self.client = Client()
        self.job_view_html = self.client.get(
            f"/job/{self.job.pk}/").content.decode("utf-8")

    def test_job_title_in_view(self):
        self.assertTrue(self.job.title in self.job_view_html)

    def test_job_workplace_in_view(self):
        self.assertTrue(self.job.workplace in self.job_view_html)

    def test_job_company_in_view(self):
        self.assertTrue(self.job.company_name in self.job_view_html)

    def test_job_application_link_not_in_view(self):
        self.assertTrue(self.job.application_link not in self.job_view_html)

    def test_job_description_in_view(self):
        self.assertTrue(self.job.description in self.job_view_html)

    def test_job_requirements_in_view(self):
        self.assertTrue(self.job.requirements in self.job_view_html)

    def test_job_status_code_is_200(self):
        status_code = self.client.get(f"/job/{self.job.pk}/").status_code
        self.assertEqual(status_code, 200)
Beispiel #2
0
class JobTest_03(TestCase):
    @patch("pyjobs.core.models.post_telegram_channel")
    def setUp(self, _mocked_post_telegram_channel):
        self.job = Job(
            title="Vaga 3",
            workplace="Sao Paulo",
            company_name="XPTO",
            company_email="*****@*****.**",
            description="Job bem maneiro",
            premium=True,
            public=True,
        )
        self.job.save()

    def test_job_application_link(self):
        self.assertEqual(False, self.job.get_application_link())

    def test_premium_available(self):
        self.assertTrue((self.job in Job.get_premium_jobs()))

    def test_publicly_available(self):
        self.assertTrue((self.job not in Job.get_publicly_available_jobs()))
Beispiel #3
0
class JobManagerTest(TestCase):
    @patch("pyjobs.marketing.triggers.post_telegram_channel")
    def setUp(self, _mocked_post_telegram_channel):
        self.job = Job(
            title="Vaga 1",
            workplace="Sao Paulo",
            company_name="XPTO",
            application_link="http://www.xpto.com.br/apply",
            company_email="*****@*****.**",
            description="Job bem maneiro",
            premium=True,
        )
        self.job.created_at = datetime.now() - timedelta(14)
        self.job.premium_at = datetime.now() - timedelta(14)
        self.job.save()

    def test_if_job_in_premium_manager(self):
        qs = Job.objects.premium().created_in_the_last(30, premium=True)
        qs_term = Job.objects.search(term="Vaga 1")

        self.assertIn(self.job, qs)
        self.assertIn(self.job, qs_term)
Beispiel #4
0
class SitemapTestingView(TestCase):
    @patch("pyjobs.marketing.triggers.send_group_notification")
    @patch("pyjobs.marketing.triggers.send_job_to_github_issues")
    @patch("pyjobs.marketing.triggers.post_telegram_channel")
    def setUp(
        self, _mocked_send_group_push, _mock_github, _mocked_post_telegram_channel
    ):
        self.job = Job(
            title="Vaga 1",
            workplace="Sao Paulo",
            company_name="XPTO",
            application_link="http://www.xpto.com.br/apply",
            company_email="*****@*****.**",
            description="Job bem maneiro",
            requirements="Job bem maneiro",
        )
        self.job.save()
        self.client = Client()

    def test_if_status_code_is_two_hundred_on(self):
        response = self.client.get("/sitemap.xml")
        self.assertEqual(200, response.status_code)
        self.assertIn("lastmod", response.content.decode("utf-8"))
Beispiel #5
0
class PyJobsJobCloseView(TestCase):
    @patch("pyjobs.marketing.triggers.post_telegram_channel")
    def setUp(self, _mocked_post_telegram_channel):
        self.job = Job(
            title="Vaga 1",
            workplace="Sao Paulo",
            company_name="XPTO",
            application_link="http://www.xpto.com.br/apply",
            company_email="*****@*****.**",
            description="Job bem maneiro",
        )
        self.job.save()

    def _assert_close_link(self, kwargs, closed):
        url = reverse("close_job", kwargs=kwargs)
        response = self.client.get(url)
        if closed:
            self.assertEqual(200, response.status_code)
            self.assertEqual(0, Job.objects.filter(is_open=True).count())
        else:
            self.assertEqual(302, response.status_code)
            self.assertEqual(1, Job.objects.filter(is_open=True).count())

    def test_valid_close_view(self):
        kwargs = {"pk": self.job.pk, "close_hash": self.job.close_hash()}
        self._assert_close_link(kwargs, closed=True)

    def test_close_view_for_non_existent_job(self):
        wrong_pk = self.job.pk + 1
        kwargs = {"pk": wrong_pk, "close_hash": self.job.close_hash()}
        self._assert_close_link(kwargs, closed=False)

    def test_close_view_with_wrong_hash(self):
        right_hash = self.job.close_hash()
        wrong_hash = right_hash[64:] + right_hash[:64]
        kwargs = {"pk": self.job.pk, "close_hash": wrong_hash}
        self._assert_close_link(kwargs, closed=False)
Beispiel #6
0
class ThumbnailTestingViews(TestCase):
    @patch("pyjobs.marketing.triggers.send_group_notification")
    @patch("pyjobs.marketing.triggers.send_job_to_github_issues")
    @patch("pyjobs.marketing.triggers.post_telegram_channel")
    def setUp(
        self, _mocked_send_group_push, _mock_github, _mocked_post_telegram_channel
    ):
        self.job = Job(
            title="Vaga 1",
            workplace="Sao Paulo",
            company_name="XPTO",
            application_link="http://www.xpto.com.br/apply",
            company_email="*****@*****.**",
            description="Job bem maneiro",
            requirements="Job bem maneiro",
        )
        self.job.save()
        self.client = Client()

    def test_return_thumbnail_endpoint_status_code(self):
        response = self.client.get(
            "/thumb/{}/".format(self.job.unique_slug), follow=True
        )
        self.assertEqual(response.status_code, 200)

    def test_return_signup_page_status_code(self):
        response = self.client.get("/user/signup/", follow=True)
        self.assertEqual(response.status_code, 200)

    def test_return_feed_status_code(self):
        response = self.client.get("/feed/", follow=True)
        self.assertEqual(response.status_code, 200)

    def test_return_register_new_job_status_code(self):
        response = self.client.get("/register/new/job/")
        self.assertEqual(response.status_code, 302)
Beispiel #7
0
class ApiRequestTest(TestCase):
    @patch("pyjobs.marketing.triggers.send_group_notification")
    @patch("pyjobs.marketing.triggers.send_job_to_github_issues")
    @patch("pyjobs.marketing.triggers.post_telegram_channel")
    def setUp(self, _mocked_send_group_push, _mock_github,
              _mocked_post_telegram_channel):
        self.client = Client()
        self.job = Job(
            title="Vaga 1",
            workplace="Sao Paulo",
            company_name="XPTO",
            application_link="http://www.xpto.com.br/apply",
            company_email="*****@*****.**",
            description="Job bem maneiro",
        )
        self.job.save()

    def test_if_api_endpoint_is_available(self):
        response = self.client.get("/api/jobs/")
        self.assertEqual(response.status_code, 200)

    def test_if_api_returns_details_from_only_job(self):
        response = self.client.get("/api/jobs/{}/".format(self.job.pk))
        self.assertEqual(response.status_code, 200)
Beispiel #8
0
class JobTest_02(TestCase):
    @patch("pyjobs.marketing.triggers.send_group_notification")
    @patch("pyjobs.marketing.triggers.send_job_to_github_issues")
    @patch("pyjobs.marketing.triggers.post_telegram_channel")
    def setUp(self, _mocked_send_group_push, _mock_github,
              _mocked_post_telegram_channel):
        self.job = Job(
            title="Vaga 2",
            workplace="Sao Paulo",
            company_name="XPTO",
            company_email="*****@*****.**",
            description="Job bem maneiro",
            public=True,
        )
        self.job.save()

    def test_job_application_link(self):
        self.assertEqual(False, self.job.get_application_link())

    def test_publicly_available(self):
        self.assertTrue((self.job in Job.get_publicly_available_jobs()))

    def test_premium_available(self):
        self.assertTrue((self.job not in Job.get_premium_jobs()))