class NewsletterTest(TestCase): def setUp(self): self.user = User.objects.create_user( username="******", email="*****@*****.**", password="******", 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() def test_subscribe_to_newsletter(self): self.assertFalse(subscribe_user_to_chimp(self.profile)) @override_settings(MAILCHIMP_API_KEY="AAA", MAILCHIMP_USERNAME="******", MAILCHIMP_LIST_KEY="CCC") @patch("pyjobs.core.newsletter.MailChimp") def test_if_called(self, patched_mc): sub = subscribe_user_to_chimp(self.profile) patched_mc.assert_called_once_with("AAA", "BBB") patched_mc.return_value.lists.members.create.assert_called_once_with( "CCC", { "status": "subscribed", "email_address": "*****@*****.**" })
class ProfileTest(TestCase): def setUp(self): self.user = User.objects.create_user( username="******", email="*****@*****.**", password="******", 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() def test_create_profile_with_user(self): nome_real = "{} {}".format(self.user.first_name, self.user.last_name) self.assertTrue(str(self.profile), nome_real) def test_created(self): self.assertTrue(Profile.objects.exists()) def test_created_at(self): self.assertIsInstance(self.profile.created_at, datetime)
class NewsletterMailerliteTest(TestCase): @responses.activate def setUp(self): self.user = User.objects.create_user( username="******", email="*****@*****.**", password="******", 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() self.headers = { "content-type": "application/json", "x-mailerlite-apikey": "AAA", } @override_settings(MAILERLITE_API_KEY="AAA") @patch("pyjobs.marketing.newsletter.requests.post") @responses.activate def test_subscribe_user_to_mailer(self, _mocked_post): _mocked_post.return_value = Exception() _mocked_post.side_effect = Exception() out = subscribe_user_to_mailer(self.profile) self.assertFalse(out)
class ProfileTest(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="*****@*****.**", password="******", 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() def test_create_profile_with_user(self): nome_real = "{} {}".format(self.user.first_name, self.user.last_name) self.assertTrue(str(self.profile), nome_real) def test_created(self): self.assertTrue(Profile.objects.exists()) def test_created_at(self): self.assertIsInstance(self.profile.created_at, datetime)
class NewsletterTest(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="*****@*****.**", password="******", 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() def test_subscribe_to_newsletter(self): self.assertFalse(subscribe_user_to_chimp(self.profile)) @override_settings( MAILCHIMP_API_KEY="AAA", MAILCHIMP_USERNAME="******", MAILCHIMP_LIST_KEY="CCC" ) @patch("pyjobs.marketing.newsletter.MailChimp") def test_if_called(self, patched_mc): sub = subscribe_user_to_chimp(self.profile) patched_mc.assert_called_once_with("AAA", "BBB") patched_mc.return_value.lists.members.create.assert_called_once_with( "CCC", {"status": "subscribed", "email_address": "*****@*****.**"} ) @patch("pyjobs.marketing.newsletter.MailChimp") @override_settings( MAILCHIMP_API_KEY="AAA", MAILCHIMP_USERNAME="******", MAILCHIMP_LIST_KEY="CCC" ) def test_subscribe_failed(self, _mocked_mc): _mocked_mc.side_effect = Exception("Exception") out = subscribe_user_to_chimp(self.profile) self.assertFalse(out)
def save(self, commit=True): instance = super(RegisterForm, self).save(commit=False) if commit: instance.save() profile = Profile( user=instance, github=self.cleaned_data["github"], linkedin=self.cleaned_data["linkedin"], portfolio=self.cleaned_data["portfolio"], cellphone=self.cleaned_data["cellphone"], ) authenticate(username=instance.username, password=self.cleaned_data.get("password1")) profile.save() profile.skills = self.cleaned_data["skills_"] profile.save() return instance
class NewsletterTest(TestCase): def setUp(self): self.user = User.objects.create_user( username="******", email="*****@*****.**", password="******", 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() def test_subscribe_to_newsletter(self): self.assertFalse(subscribe_user_to_chimp(self.profile))