Exemplo n.º 1
0
class PyJobsJobCloseView(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",
        )
        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 = {
            "unique_slug": self.job.unique_slug,
            "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.unique_slug[:-2]
        kwargs = {"unique_slug": 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 = {
            "unique_slug": self.job.unique_slug,
            "close_hash": wrong_hash
        }
        self._assert_close_link(kwargs, closed=False)
Exemplo n.º 2
0
class JobTest_01(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",
        )
        self.job.save()
        self.email, *_ = mail.outbox

    def test_job_created(self):
        self.assertTrue(Job.objects.exists())

    def test_job_created_at(self):
        self.assertIsInstance(self.job.created_at, datetime)

    def test_job_str(self):
        self.assertEqual(
            str(self.job),
            f"{self.job.title} - {self.job.company_name} - {self.job.pk}")

    def test_job_application_link(self):
        self.assertEqual(str(self.job.get_application_link()),
                         "http://www.xpto.com.br/apply")

    def test_job_url_is_sent_in_the_email(self):
        self.assertIn("/job/{}/".format(self.job.pk), self.email.body)

    def test_close_hash(self):
        value = "::".join(
            ("close", "Foo Bar", str(self.job.pk), str(self.job.created_at)))
        hash_obj = sha512(value.encode("utf-8"))
        self.assertEqual(self.job.close_hash("Foo Bar"), hash_obj.hexdigest())

    def test_close_url(self):
        self.assertEqual(
            f"/job/close/{self.job.pk}/{self.job.close_hash()}/",
            self.job.get_close_url(),
        )

    def test_close_url_is_sent_in_the_email(self):
        self.assertIn(self.job.get_close_url(), self.email.body)