-
-
Notifications
You must be signed in to change notification settings - Fork 775
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Send email alert on low priced bounties
- Loading branch information
Dan Lipert
committed
Dec 11, 2018
1 parent
3628c64
commit 0ee3452
Showing
4 changed files
with
97 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Handle marketing mail related tests. | ||
Copyright (C) 2018 Gitcoin Core | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU Affero General Public License as published | ||
by the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU Affero General Public License for more details. | ||
You should have received a copy of the GNU Affero General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
""" | ||
from unittest.mock import patch | ||
|
||
from django.utils import timezone | ||
|
||
from bounty_requests.views import LOW_BOUNTY_THRESHOLD | ||
from dashboard.models import Profile | ||
from test_plus.test import APITestCase | ||
|
||
|
||
class BountyRequestTest(APITestCase): | ||
|
||
def setUp(self): | ||
self.email = '[email protected]' | ||
self.user = self.make_user() | ||
self.user.email = self.email | ||
self.user.profile = Profile.objects.create( | ||
user=self.user, | ||
handle='testuser', | ||
last_sync_date=timezone.now(), | ||
data={}, | ||
) | ||
self.user.save() | ||
|
||
@patch('marketing.mails.send_mail') | ||
def test_lowball_bounty(self, mock_send_mail): | ||
"""Test that an email alert is sent for low priced bounties.""" | ||
with self.login(username=self.user.username, password='password'): | ||
response = self.post('/requests/', | ||
data={'amount': LOW_BOUNTY_THRESHOLD - 1, | ||
'github_url': 'https://github.com/gitcoinco/test', | ||
'eth_address': '0x0', | ||
'comment': 'test'}, | ||
extra={'format': 'json'}) | ||
self.response_200(response) | ||
# In addition to the standard new bounty email, an alert email is sent | ||
assert mock_send_mail.call_count == 2 | ||
|
||
@patch('marketing.mails.send_mail') | ||
def test_normal_bounty(self, mock_send_mail): | ||
"""Test that no email alert is sent for resonably priced bounties.""" | ||
with self.login(username=self.user.username, password='password'): | ||
response = self.post('/requests/', | ||
data={'amount': LOW_BOUNTY_THRESHOLD, | ||
'github_url': 'https://github.com/gitcoinco/test', | ||
'eth_address': '0x0', | ||
'comment': 'test'}, | ||
extra={'format': 'json'}) | ||
self.response_200(response) | ||
assert mock_send_mail.call_count == 1 |
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 |
---|---|---|
|
@@ -896,6 +896,29 @@ def new_bounty_request(model): | |
translation.activate(cur_language) | ||
|
||
|
||
def low_bounty_request(bounty): | ||
to_email = '[email protected]' | ||
from_email = bounty.requested_by.email or settings.SERVER_EMAIL | ||
cur_language = translation.get_language() | ||
try: | ||
setup_lang(to_email) | ||
subject = _("Low Bounty Alert") | ||
body_str = _("A low bounty was set from") | ||
body = f"{body_str} {bounty.requested_by} ({bounty.requested_by.email}):"\ | ||
f"{settings.BASE_URL}_administrationbounty_requests/bountyrequest/{bounty.pk}/change\n\n"\ | ||
f"Github: {bounty.github_url}\n" | ||
send_mail( | ||
from_email, | ||
to_email, | ||
subject, | ||
body, | ||
from_name=_("No Reply from Gitcoin.co"), | ||
categories=['admin'], | ||
) | ||
finally: | ||
translation.activate(cur_language) | ||
|
||
|
||
def new_funding_limit_increase_request(profile, cleaned_data): | ||
to_email = '[email protected]' | ||
from_email = profile.email or settings.SERVER_EMAIL | ||
|
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