diff --git a/opentech/apply/activity/messaging.py b/opentech/apply/activity/messaging.py index 2a80763a3d6c68d22c5c356669ad9f8baa4a9256..38115ea0b71822ccd7a275ecd382b421422b38d7 100644 --- a/opentech/apply/activity/messaging.py +++ b/opentech/apply/activity/messaging.py @@ -61,10 +61,9 @@ class AdapterBase: if not message: return - recipients = self.recipients(message_type, **kwargs) kwargs.update(self.extra_kwargs(message_type, **kwargs)) - for recipient in recipients: + for recipient in self.recipients(message_type, **kwargs): if settings.SEND_MESSAGES or self.always_send: self.send_message(message, recipient=recipient, **kwargs) @@ -142,7 +141,7 @@ class SlackAdapter(AdapterBase): link = link_to(submission, request) return {'link': link} - def recipients(self, message_type, message, **kwargs): + def recipients(self, message_type, submission, **kwargs): return [self.slack_id(submission.lead)] def notify_reviewers(self, submission, **kwargs): diff --git a/opentech/apply/activity/tests/test_messaging.py b/opentech/apply/activity/tests/test_messaging.py index 41ba22622c67aa158f018c5b9a534ea3a05f521a..77c1452b4171e949b89b4bf4f2b3b270f30f3b06 100644 --- a/opentech/apply/activity/tests/test_messaging.py +++ b/opentech/apply/activity/tests/test_messaging.py @@ -203,6 +203,20 @@ class TestSlackAdapter(TestCase): } ) + @responses.activate + def test_gets_lead_if_slack_set(self): + adapter = SlackAdapter() + submission = ApplicationSubmissionFactory() + recipients = adapter.recipients(MESSAGES.COMMENT, submission) + self.assertTrue(submission.lead.slack in recipients[0]) + + @responses.activate + def test_gets_black_if_slack_not_set(self): + adapter = SlackAdapter() + submission = ApplicationSubmissionFactory(lead__slack='') + recipients = adapter.recipients(MESSAGES.COMMENT, submission) + self.assertTrue(submission.lead.slack in recipients[0]) + @override_settings(SEND_MESSAGES=True) class TestEmailAdapter(TestCase): diff --git a/opentech/apply/determinations/forms.py b/opentech/apply/determinations/forms.py index b8d24a711c06ad1b33dbba5f5bb3caecbd03aaba..14a8773936458ea485e7a3bb6c66bfbe93ada37c 100644 --- a/opentech/apply/determinations/forms.py +++ b/opentech/apply/determinations/forms.py @@ -1,13 +1,9 @@ from django import forms from django.core.exceptions import NON_FIELD_ERRORS -from opentech.apply.funds.workflow import DETERMINATION_OUTCOMES from .models import ( Determination, DETERMINATION_CHOICES, - NEEDS_MORE_INFO, - REJECTED, - ACCEPTED, TRANSITION_DETERMINATION, ) @@ -101,7 +97,6 @@ class BaseDeterminationForm(forms.ModelForm): return available_choices - @classmethod def get_detailed_response(cls, saved_data): data = {} diff --git a/opentech/apply/determinations/tests/test_views.py b/opentech/apply/determinations/tests/test_views.py index b0d064f8cc97a2e07b1767717ed1147b67784762..5f3f0c00523e6d466094e84bd86924ac5d4e2af2 100644 --- a/opentech/apply/determinations/tests/test_views.py +++ b/opentech/apply/determinations/tests/test_views.py @@ -113,7 +113,7 @@ class DeterminationFormTestCase(BaseTestCase): submission = ApplicationSubmissionFactory(status='in_discussion', lead=self.user) determination = DeterminationFactory(submission=submission, author=self.user) determination_message = 'This is the message' - response = self.post_page( + self.post_page( submission, {'data': 'value', 'outcome': determination.outcome, 'message': determination_message}, 'form', diff --git a/opentech/apply/determinations/views.py b/opentech/apply/determinations/views.py index 7d15370c023a2296f173898f8a8fb5588edc6c34..d39cfac32069faa2d15653d4ee0e839efac86b6e 100644 --- a/opentech/apply/determinations/views.py +++ b/opentech/apply/determinations/views.py @@ -1,5 +1,5 @@ from django.contrib.auth.decorators import login_required -from django.core.exceptions import PermissionDenied, ObjectDoesNotExist +from django.core.exceptions import PermissionDenied from django.http import HttpResponseRedirect from django.shortcuts import get_object_or_404 from django.urls import reverse_lazy diff --git a/opentech/apply/funds/models.py b/opentech/apply/funds/models.py index b74f734fac308a46ecd45eaeefc9e3f22abc218e..cb4024d9457c5bd253db9f8f2b1bead53b592e8e 100644 --- a/opentech/apply/funds/models.py +++ b/opentech/apply/funds/models.py @@ -12,7 +12,6 @@ from django.db.models import Q from django.db.models.expressions import RawSQL, OrderBy from django.dispatch import receiver from django.http import Http404 -from django.template.loader import render_to_string from django.urls import reverse from django.utils.text import mark_safe, slugify from django.utils.translation import ugettext_lazy as _ diff --git a/opentech/apply/users/tests/factories.py b/opentech/apply/users/tests/factories.py index bbeead33536945666cad7f8c4a5955d8f35c99f4..1ee80d85f419553a609ff2f9c2e24da280a17e61 100644 --- a/opentech/apply/users/tests/factories.py +++ b/opentech/apply/users/tests/factories.py @@ -42,6 +42,14 @@ class AdminFactory(UserFactory): class StaffFactory(UserFactory): + class Meta: + exclude = ('slack_temp', ) + + # Required to generate the fake data add pass to LazyAttribute + slack_temp = factory.Faker('word') + + slack = factory.LazyAttribute(lambda p: '@{}'.format(p.slack_temp)) + @factory.post_generation def groups(self, create, extracted, **kwargs): if create: