forked from vmesel/PyJobs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
182 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
from django.test import TestCase | ||
from model_mommy import mommy | ||
from unittest.mock import patch | ||
from datetime import datetime | ||
from django.contrib.auth.models import User | ||
from pyjobs.core.models import Job | ||
from pyjobs.core.admin import * | ||
|
||
|
||
class TestUpdateCreatedAtFunc(TestCase): | ||
@patch("pyjobs.marketing.triggers.post_telegram_channel") | ||
def setUp(self, _mocked_post_telegram_channel): | ||
self.jobs = mommy.make(Job, _quantity=10 * 3, public=True) | ||
|
||
def test_update_created_at(self): | ||
qs = Job.objects.all() | ||
created_at_value = self.jobs[0].created_at | ||
update_created_at("a", "request_here", self.jobs[:1]) | ||
self.jobs[0].refresh_from_db() | ||
mod_created_at_value = self.jobs[0].created_at | ||
self.assertFalse(created_at_value == mod_created_at_value) | ||
|
||
@patch("pyjobs.core.admin.send_offer_email_template") | ||
def test_send_email_offer(self, _mocked_send_offer): | ||
send_email_offer("request", "request", self.jobs) | ||
_mocked_send_offer.assert_called() | ||
|
||
@patch("pyjobs.core.admin.send_feedback_collection_email") | ||
def test_send_feedback_collection_email( | ||
self, _mocked_send_feedback_collection_email | ||
): | ||
send_feedback_collection("request", "request", self.jobs) | ||
_mocked_send_feedback_collection_email.assert_called() | ||
|
||
@patch("pyjobs.core.admin.subscribe_user_to_mailer") | ||
def test_subscribe_user_to_mailer(self, _mocked_subscribe_user_to_mailer): | ||
add_subscriber("request", "request", self.jobs) | ||
_mocked_subscribe_user_to_mailer.assert_called() | ||
|
||
|
||
class TestSendingChallengesToOldApplicants(TestCase): | ||
@patch("pyjobs.marketing.triggers.post_telegram_channel") | ||
def setUp(self, _mocked_post_telegram_channel): | ||
self.job = Job.objects.create( | ||
title="Vaga 3", | ||
workplace="Sao Paulo", | ||
company_name="XPTO", | ||
company_email="[email protected]", | ||
description="Job bem maneiro", | ||
premium=True, | ||
public=True, | ||
) | ||
self.job.save() | ||
|
||
@patch("pyjobs.core.admin.get_email_with_template") | ||
def test_sending(self, _mocked_get_email_with_template): | ||
self.user = User.objects.create_user( | ||
username="jacob", email="[email protected]", 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.job_application = JobApplication.objects.create( | ||
user=self.user, job=self.job | ||
) | ||
|
||
self.job.is_challenging = True | ||
self.job.save() | ||
|
||
self.jobs = [self.job] | ||
|
||
send_challenge_to_old_applicants("modeladmin", "request", self.jobs) | ||
_mocked_get_email_with_template.assert_called() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -284,3 +284,27 @@ def test_if_str_rep_is_ok(self): | |
|
||
def test_if_repr_rep_is_ok(self): | ||
self.assertEqual(self.skill.__repr__(), self.skill.name) | ||
|
||
|
||
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="[email protected]", | ||
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,6 +46,27 @@ def test_return_register_new_job_status_code(self): | |
self.assertEqual(response.status_code, 302) | ||
|
||
|
||
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="[email protected]", | ||
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")) | ||
|
||
|
||
class TestingRestrictedViews(TestCase): | ||
@responses.activate | ||
@patch("pyjobs.marketing.triggers.post_telegram_channel") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
from unittest.mock import patch | ||
import responses | ||
from pyjobs.core.models import Job, Profile | ||
from pyjobs.marketing.newsletter import subscribe_user_to_chimp | ||
from pyjobs.marketing.newsletter import subscribe_user_to_chimp, subscribe_user_to_mailer | ||
from django.conf import settings | ||
|
||
|
||
|
@@ -46,3 +46,51 @@ def test_if_called(self, patched_mc): | |
patched_mc.return_value.lists.members.create.assert_called_once_with( | ||
"CCC", {"status": "subscribed", "email_address": "[email protected]"} | ||
) | ||
|
||
@patch('pyjobs.marketing.newsletter.MailChimp') | ||
def test_subscribe_failed(self, _mocked_post): | ||
_mocked_post.side_effect = Exception("Exception") | ||
out = subscribe_user_to_chimp(self.profile) | ||
self.assertFalse(out) | ||
|
||
class NewsletterMailerliteTest(TestCase): | ||
@responses.activate | ||
def setUp(self): | ||
responses.add( | ||
responses.POST, | ||
"https://api.mailerlite.com/api/v2/subscribers", | ||
json={"status": "Success"}, | ||
status=200, | ||
) | ||
self.user = User.objects.create_user( | ||
username="[email protected]", | ||
email="[email protected]", | ||
password="top_secret", | ||
first_name="Vinicius", | ||
last_name="Mesel", | ||
) | ||
self.profile = Profile( | ||
user=self.user, | ||
github="http://www.aaa.com.br", | ||
linkedin="http://www.aaa.com.br", | ||
portfolio="http://www.aaa.com.br", | ||
) | ||
self.profile.save() | ||
|
||
@override_settings( | ||
MAILERLITE_API_KEY="AAA" | ||
) | ||
@patch('pyjobs.marketing.newsletter.requests.post') | ||
def test_subscribe_user_to_mailer(self, _mocked_post): | ||
out = subscribe_user_to_mailer(self.profile) | ||
_mocked_post.assert_called_once() | ||
self.assertTrue(out) | ||
|
||
@patch('pyjobs.marketing.newsletter.requests.post') | ||
@patch('pyjobs.marketing.newsletter.json.dumps') | ||
def test_subscribe_user_to_mailer(self, _mocked_post, _mocked_json_dumps): | ||
_mocked_post.side_effect = Exception("Exception") | ||
out = subscribe_user_to_mailer(self.profile) | ||
_mocked_json_dumps.assert_called_once() | ||
# _mocked_post.assert_called_once() | ||
self.assertFalse(out) |