diff --git a/pyjobs/core/management/commands/run_routines.py b/pyjobs/core/management/commands/run_routines.py new file mode 100644 index 00000000..2300ee4e --- /dev/null +++ b/pyjobs/core/management/commands/run_routines.py @@ -0,0 +1,18 @@ +import os +from datetime import datetime + +from django.core.management.base import BaseCommand +from pyjobs.core.management.commands.send_weekly_mailing import ( + Command as weekly_mailing, +) +from pyjobs.core.management.commands.send_weekly_summary import ( + Command as weekly_summary, +) +from pyjobs.core.management.commands.send_test_reminder import Command as test_reminder + + +class Command(BaseCommand): + def handle(self, *args, **options): + weekly_mailing.handle() + weekly_summary.handle() + test_reminder.handle() diff --git a/pyjobs/core/management/commands/send_test_reminder.py b/pyjobs/core/management/commands/send_test_reminder.py new file mode 100644 index 00000000..85a47e89 --- /dev/null +++ b/pyjobs/core/management/commands/send_test_reminder.py @@ -0,0 +1,49 @@ +import os +from datetime import datetime + +from django.core.management.base import BaseCommand +from django.db import IntegrityError +from django.template.loader import get_template +from django.core.mail import EmailMultiAlternatives +from django.template import Context + +from pyjobs.core.models import Job, JobApplication +from pyjobs.core.email_utils import get_email_with_template +from django.conf import settings +from datetime import timedelta + + +class Command(BaseCommand): + def handle(self, *args, **options): + job_qs = Job.objects.filter(is_challenging=True) + for job in job_qs: + job_applications = JobApplication.objects.filter( + job=job, + challenge_response_at=None, + email_sent_at__gte=datetime.now() - timedelta(days=4), + email_sent_at__lte=datetime.now() + timedelta(days=3), + challenge_resent=False, + ) + + for job_app in job_applications: + print(job_app) + person_email_context = { + "vaga": job, + "pessoa": job_app.user.profile, + "mensagem": job_app, + } + template_person = "job_interest_challenge" + person_email_subject = "Reenviando: Teste Técnico da empresa: {}!".format( + job.company_name + ) + + job_app.challenge_resent = True + job_app.save() + + msg_email_person = get_email_with_template( + template_person, + person_email_context, + person_email_subject, + (job_app.user.email,), + ) + msg_email_person.send() diff --git a/pyjobs/core/migrations/0037_jobapplication_challenge_resent.py b/pyjobs/core/migrations/0037_jobapplication_challenge_resent.py new file mode 100644 index 00000000..7a501422 --- /dev/null +++ b/pyjobs/core/migrations/0037_jobapplication_challenge_resent.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.24 on 2019-09-28 16:09 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [("core", "0036_auto_20190917_1821")] + + operations = [ + migrations.AddField( + model_name="jobapplication", + name="challenge_resent", + field=models.BooleanField(default=False), + ) + ] diff --git a/pyjobs/core/models.py b/pyjobs/core/models.py index e2fe94e8..17ad55a9 100644 --- a/pyjobs/core/models.py +++ b/pyjobs/core/models.py @@ -283,6 +283,7 @@ class JobApplication(models.Model): "Link de resposta ao desafio", default="", blank=True, null=True ) challenge_response_at = models.DateTimeField(blank=True, null=True) + challenge_resent = models.BooleanField(default=False) class Meta: unique_together = ("user", "job") diff --git a/pyjobs/core/tests/test_job_challenge.py b/pyjobs/core/tests/test_job_challenge.py new file mode 100644 index 00000000..c1bfae14 --- /dev/null +++ b/pyjobs/core/tests/test_job_challenge.py @@ -0,0 +1,82 @@ +from unittest.mock import patch + +from django.contrib.auth.models import User +from django.http import HttpRequest +from django.test import Client, TestCase +from django.urls import resolve, reverse +from model_mommy import mommy +import responses +from pyjobs.core.models import Job, Profile, JobApplication +from pyjobs.core.views import index +import datetime + + +class TestingRestrictedViews(TestCase): + @responses.activate + @patch("pyjobs.core.models.post_telegram_channel") + def setUp(self, _mocked_post_telegram_channel): + self.job = mommy.make( + "core.Job", is_challenging=True, challenge="Ola mundo dos testes" + ) + + self.user = User.objects.create_user( + username="jacob", email="jacob@gmail.com", password="top_secret" + ) + + 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.client = Client() + + self.client.login(username="jacob", password="top_secret") + + def test_if_user_is_not_applied_to_job(self): + response = self.client.get("/job/{}".format(self.job.pk), follow=True) + self.assertEqual(200, response.status_code) + self.assertTrue(b"Candidate-se para esta vaga pelo" in response.content) + + def test_if_applied_user_can_get_job_challenge(self): + self.job_application = JobApplication.objects.create( + job=self.job, + user=self.user, + email_sent=True, + email_sent_at=datetime.datetime.now(), + ) + response = self.client.get("/job/{}".format(self.job.pk), follow=True) + self.assertEqual(200, response.status_code) + self.assertTrue(b"Clique aqui e preencha o desafio" in response.content) + + def test_if_applied_user_can_answer_job_challenge(self): + self.job_application = JobApplication.objects.create( + job=self.job, + user=self.user, + email_sent=True, + email_sent_at=datetime.datetime.now(), + ) + response = self.client.get( + "/job/{}/challenge_submit/".format(self.job.pk), follow=True + ) + + def test_if_applied_user_cant_answer_job_challenge(self): + self.job_application = JobApplication.objects.create( + job=self.job, + user=self.user, + email_sent=True, + email_sent_at=datetime.datetime.now(), + challenge_response_at=datetime.datetime.now(), + challenge_response_link="http://www.google.com", + ) + response = self.client.get( + "/job/{}/challenge_submit/".format(self.job.pk), follow=True + ) + + self.assertEqual(200, response.status_code) + self.assertTrue( + bytes("Recebemos seu teste, aguarde nosso retorno!", "utf8") + in response.content + ) diff --git a/pyjobs/core/views.py b/pyjobs/core/views.py index 1016c719..40aa06eb 100644 --- a/pyjobs/core/views.py +++ b/pyjobs/core/views.py @@ -321,13 +321,11 @@ def job_application_challenge_submission(request, pk): if request.method == "POST" and form.is_valid(): form.save() - if user_applied.challenge_response_link is not None and not "": + if user_applied.challenge_response_at is not None: context = { "message_first": "Seu teste já foi enviado!", "message_second": "Recebemos seu teste, aguarde nosso retorno!", - "message_explaining": "Recebemos seu teste na data: {}".format( - str(user_applied.challenge_response_at.date()) - ), + "message_explaining": "Recebemos seu teste e vamos avaliar!", } return render(request, template_name="generic.html", context=context)