Beispiel #1
0
class JobTest_03(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 3",
            workplace="Sao Paulo",
            company_name="XPTO",
            company_email="*****@*****.**",
            description="Job bem maneiro",
            premium=True,
            public=True,
        )
        self.job.save()
        self.job.premium_at = self.job.created_at
        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 #2
0
class HomeJobsViewsTest(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()
        self.home_page = resolve("/")
        self.request = HttpRequest()
        self.home_page_html = index(self.request).content.decode("utf-8")

    def test_job_is_in_websites_home(self):
        self.assertEqual(self.home_page.func, index)

    def test_job_in_home(self):
        job_title = str(self.job)
        self.assertTrue(job_title in self.home_page_html)

    def test_job_url_is_in_home(self):
        job_url = "/job/{}/".format(str(self.job.pk))
        self.assertTrue(job_url in self.home_page_html)
Beispiel #3
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.pk))
        self.assertEqual(response.status_code, 200)

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

    def test_return_feed_status_code(self):
        response = self.client.get("/feed/")
        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 #4
0
def jobs(request):
    publicly_available_jobs = Job.get_publicly_available_jobs()
    publicly_available_premium_jobs = Job.get_premium_jobs()

    user_filtered_query_set = JobFilter(request.GET,
                                        queryset=publicly_available_jobs)
    premium_filtered_query_set = JobFilter(
        request.GET, queryset=publicly_available_premium_jobs)

    paginator = Paginator(user_filtered_query_set.qs, 10)
    premium_paginator = Paginator(premium_filtered_query_set.qs, 10)

    try:
        page_number = int(request.GET.get("page", 1))
    except ValueError:
        return redirect("/")

    if page_number > paginator.num_pages:
        return redirect("/")

    public_jobs_to_display = paginator.page(page_number)
    premium_jobs_to_display = premium_paginator.page(1)

    context_dict = {
        "publicly_available_jobs": public_jobs_to_display,
        "premium_available_jobs": premium_jobs_to_display,
        "pages": paginator.page_range,
        "filter": user_filtered_query_set,
    }

    return render(request, template_name="jobs.html", context=context_dict)
Beispiel #5
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",
        )
        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)
Beispiel #6
0
class ThumbnailTestingViews(TestCase):
    def setUp(self):
        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.pk))
        self.assertEqual(response.status_code, 200)

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

    def test_return_jooble_feed_status_code(self):
        response = self.client.get("/jooble/")
        self.assertEqual(response.status_code, 200)

    def test_return_feed_status_code(self):
        response = self.client.get("/feed/")
        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 JobTest_01(TestCase):
    @patch("pyjobs.core.models.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 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), "Vaga 1")

    def test_job_application_link(self):
        self.assertEqual(str(self.job.get_application_link()),
                         "http://www.xpto.com.br/apply")
Beispiel #8
0
    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,
        )

        responses.add(
            responses.POST,
            "https://api.mailerlite.com/api/v2/subscribers",
            json={"status": "Success"},
            status=200,
        )

        self.user = User.objects.create_user(username="******",
                                             email="*****@*****.**",
                                             password="******")

        self.profile = Profile.objects.create(
            user=self.user,
            github="http://www.github.com/foobar",
            linkedin="http://www.linkedin.com/in/foobar",
            portfolio="http://www.foobar.com/",
            cellphone="11981435390",
        )

        self.job.save()
Beispiel #9
0
class JobManagerTest(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",
            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 #10
0
class RedirectTest(TestCase):
    @patch("pyjobs.marketing.triggers.post_telegram_channel")
    @patch("pyjobs.marketing.triggers.send_group_notification")
    @patch("pyjobs.marketing.triggers.send_job_to_github_issues")
    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.client = Client()

        self.job_old_url = reverse("job_view",
                                   kwargs={"unique_slug": self.job.pk})
        self.job_new_url = reverse(
            "job_view", kwargs={"unique_slug": self.job.unique_slug})

    def test_if_redirect_exists(self):
        response = self.client.get(self.job_old_url, follow=True)
        self.assertEquals(response.redirect_chain[0][0], self.job_new_url)
        self.assertEquals(response.redirect_chain[0][1], 301)
Beispiel #11
0
 def setUp(self, _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()
Beispiel #12
0
 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()
Beispiel #13
0
 def setUp(self):
     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()
Beispiel #14
0
 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()
     self.home_page = resolve("/")
     self.request = HttpRequest()
     self.home_page_html = index(self.request).content.decode("utf-8")
Beispiel #15
0
 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()
Beispiel #16
0
 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()
Beispiel #17
0
    def handle(self, *args, **options):
        if not check_today_is_the_right_day():
            print("Today is not the right day!")
            return

        emails_mailing_lists = [
            mailing.email for mailing in MailingList.objects.all()
        ]

        if len(emails_mailing_lists) == 0:
            print("There are no mailing lists!")
            return

        emails_mailing_replies = [
            format_owner_email(email) for email in emails_mailing_lists
        ]

        to_emails = emails_mailing_replies
        from_emails = emails_mailing_lists

        jobs = list(Job.get_premium_jobs())

        missing_jobs = 10 - len(jobs)

        jobs += list(Job.get_feed_jobs())[:missing_jobs]

        if len(jobs) == 0:
            print("There are no jobs on the platform!")
            return

        plain_text = get_template("emails/weekly_summary.txt")

        subject = "[Vagas][PyJobs] Vagas Python da semana passada"

        context = {
            "dono_do_site": settings.WEBSITE_OWNER_NAME,
            "nome_do_site": settings.WEBSITE_NAME,
            "url_do_site": settings.WEBSITE_HOME_URL,
            "jobs": jobs,
        }

        text_content = plain_text.render(context)

        for email_tup in zip(to_emails, from_emails):
            msg = EmailMultiAlternatives(subject, text_content, email_tup[0],
                                         [email_tup[1]])

            msg.send()

        print("Message sent!")
Beispiel #18
0
 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",
     )
     self.job.save()
     self.client = Client()
     self.job_view_html = self.client.get(
         f"/job/{self.job.pk}/").content.decode("utf-8")
Beispiel #19
0
 def setUp(self, _mocked_send_group_push, _mock_github,
           _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()
     self.job.premium_at = self.job.created_at
     self.job.save()
Beispiel #20
0
class ThumbnailCreationTest(TestCase):
    def setUp(self):
        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_if_generated_object_is_valid(self):
        generated_thumbnail = generate_thumbnail(self.job)
        self.assertIsInstance(generated_thumbnail, Image.Image)
Beispiel #21
0
    def handle(self, *args, **options):
        if not check_today_is_the_right_day():
            return "False"

        jobs = list(Job.get_premium_jobs())

        missing_jobs = 10 - len(jobs)

        jobs += list(Job.get_feed_jobs())[:missing_jobs]

        formated_jobs = [format_job(job) for job in jobs]

        post_telegram_channel(format_message_text(formated_jobs))

        return "True"
Beispiel #22
0
    def handle(self, *args, **options):
        jobs = Job.get_jobs_to_get_feedback()

        for job in jobs:
            send_feedback_collection_email(job)

        print("Message sent!")
Beispiel #23
0
class ThumbnailCreationTest(TestCase):
    @patch("pyjobs.marketing.triggers.post_telegram_channel")
    def setUp(self, _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_if_generated_object_is_valid(self):
        generated_thumbnail = generate_thumbnail(self.job)
        self.assertIsInstance(generated_thumbnail, Image.Image)
Beispiel #24
0
    def handle(self, *args, **options):
        jobs = Job().get_jobs_to_get_feedback()

        for job in jobs:
            send_feedback_collection_email(job)

        return "True"
    def handle(self, *args, **options):
        if not check_today_is_the_right_day():
            print("Today is not the right day!")
            return

        jobs = list(Job.get_premium_jobs())

        missing_jobs = 10 - len(jobs)

        jobs += list(Job.get_feed_jobs())[:missing_jobs]

        formated_jobs = [format_job(job) for job in jobs]

        post_telegram_channel(format_message_text(formated_jobs))

        print("Message sent!")
Beispiel #26
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)
Beispiel #27
0
    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.client = Client()

        self.job_old_url = reverse("job_view",
                                   kwargs={"unique_slug": self.job.pk})
        self.job_new_url = reverse(
            "job_view", kwargs={"unique_slug": self.job.unique_slug})
Beispiel #28
0
class SitemapTestingView(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",
        )
        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 #29
0
class JobDetailsViewTest(TestCase):
    @patch("pyjobs.marketing.triggers.post_telegram_channel")
    @patch("pyjobs.marketing.triggers.send_group_notification")
    @patch("pyjobs.marketing.triggers.send_job_to_github_issues")
    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",
            salary_range=10,
        )
        self.job.save()
        self.client = Client()
        self.job_view_html = self.client.get(
            f"/job/{self.job.unique_slug}/").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.unique_slug}/").status_code
        self.assertEqual(status_code, 200)
Beispiel #30
0
def job_skill_view(request, unique_slug):
    """
    This view will return jobs related to a certain skill,
    i.e., Django Jobs or Flask Jobs.
    """
    skill = Skill.objects.filter(unique_slug=unique_slug).first()

    if not skill:
        return redirect("/")

    publicly_available_jobs = Job.get_publicly_available_jobs().filter(
        skills=skill)
    publicly_available_premium_jobs = Job.get_premium_jobs().filter(
        skills=skill)

    paginator = Paginator(publicly_available_jobs, 10)
    premium_paginator = Paginator(publicly_available_premium_jobs, 10)

    try:
        page_number = int(request.GET.get("page", 1))
    except ValueError:
        return redirect("/")

    if page_number > paginator.num_pages:
        return redirect("/")

    public_jobs_to_display = paginator.page(page_number)
    premium_jobs_to_display = premium_paginator.page(1)

    context_dict = {
        "publicly_available_jobs": public_jobs_to_display,
        "premium_available_jobs": premium_jobs_to_display,
        "pages": paginator.page_range,
        "skill": skill,
        "webpush": WEBPUSH_CONTEXT,
    }

    return render(
        request,
        template_name="jobs_by_skill.html",
        context=context_dict,
    )