Example #1
0
 def post(self, request, *args, **kwargs):
     context = {'group_nums': [(x.id, x.calculate_cost) for x in RecipientGroup.objects.all()]}
     form = SendRecipientGroupForm(request.POST)
     if form.is_valid():
         form.cleaned_data['recipient_group'].send_message(
             content=form.cleaned_data['content'],
             eta=form.cleaned_data['scheduled_time'],
             sent_by=str(request.user)
         )
         if form.cleaned_data['scheduled_time'] is None:
             messages.info(
                 request,
                 "Sending '{0}' to '{1}'...\nPlease check the logs for verification...".format(
                     form.cleaned_data['content'],
                     form.cleaned_data['recipient_group']
                 )
             )
         else:
             messages.info(
                 request,
                 "'{0}' has been successfully queued.".format(
                     form.cleaned_data['content']
                 )
             )
         return redirect(reverse('send_group'))
     else:
         context['form'] = form
         return render(request, "apostello/send_group.html", context)
Example #2
0
 def test_correct_values(self, groups):
     form_data = {
         'content': 'This is a message',
         'recipient_group': groups['test_group'].pk,
     }
     form = SendRecipientGroupForm(data=form_data, user=UserMock())
     assert form.is_valid()
Example #3
0
 def post(self, request, *args, **kwargs):
     """Handle sending form submission."""
     context = {}
     context['group_nums'] = [(x.id, x.calculate_cost)
                              for x in RecipientGroup.objects.all()]
     form = SendRecipientGroupForm(request.POST)
     if form.is_valid():
         form.cleaned_data['recipient_group'].send_message(
             content=form.cleaned_data['content'],
             eta=form.cleaned_data['scheduled_time'],
             sent_by=str(request.user))
         if form.cleaned_data['scheduled_time'] is None:
             messages.info(
                 request,
                 "Sending '{0}' to '{1}'...\nPlease check the logs for verification..."
                 .format(form.cleaned_data['content'],
                         form.cleaned_data['recipient_group']))
         else:
             messages.info(
                 request, "'{0}' has been successfully queued.".format(
                     form.cleaned_data['content']))
         return redirect(reverse('send_group'))
     else:
         context['form'] = form
         return render(request, "apostello/send_group.html", context)
Example #4
0
    def post(self, request, format=None, **kwargs):
        form = SendRecipientGroupForm(request.data, user=request.user)
        if form.is_valid():
            form.cleaned_data['recipient_group'].send_message(
                content=form.cleaned_data['content'],
                eta=form.cleaned_data['scheduled_time'],
                sent_by=str(self.request.user))
            if form.cleaned_data['scheduled_time'] is None:
                msg_txt = "Sending '{0}' to '{1}'...\nPlease check the logs for verification...".format(
                    form.cleaned_data['content'],
                    form.cleaned_data['recipient_group'])
                msg = {
                    'type_': 'info',
                    'text': msg_txt,
                }
            else:
                msg = {
                    'type_':
                    'info',
                    'text':
                    "'{0}' has been successfully queued.".format(
                        form.cleaned_data['content']),
                }

            return Response({
                'messages': [msg],
                'errors': {}
            },
                            status=status.HTTP_201_CREATED)

        return Response({
            'messages': [],
            'errors': form.errors
        },
                        status=status.HTTP_400_BAD_REQUEST)
Example #5
0
    def post(self, request, format=None, **kwargs):
        form = SendRecipientGroupForm(request.data, user=request.user)
        if form.is_valid():
            form.cleaned_data["recipient_group"].send_message(
                content=form.cleaned_data["content"],
                eta=form.cleaned_data["scheduled_time"],
                sent_by=str(self.request.user),
            )
            if form.cleaned_data["scheduled_time"] is None:
                msg_txt = "Sending '{0}' to '{1}'...\nPlease check the logs for verification...".format(
                    form.cleaned_data["content"],
                    form.cleaned_data["recipient_group"])
                msg = {"type_": "info", "text": msg_txt}
            else:
                msg = {
                    "type_":
                    "info",
                    "text":
                    "'{0}' has been successfully queued.".format(
                        form.cleaned_data["content"]),
                }

            return Response({
                "messages": [msg],
                "errors": {}
            },
                            status=status.HTTP_201_CREATED)

        return Response({
            "messages": [],
            "errors": form.errors
        },
                        status=status.HTTP_400_BAD_REQUEST)
Example #6
0
 def test_missing_group(self, groups):
     """Test missing group"""
     form_data = {
         'content': 'This is a message',
     }
     form = SendRecipientGroupForm(data=form_data)
     assert form.is_valid() is False
Example #7
0
 def test_missing_content(self, groups):
     """Test missing content"""
     form_data = {
         'recipient_group': '1',
     }
     form = SendRecipientGroupForm(data=form_data)
     assert form.is_valid() is False
Example #8
0
 def test_correct_values(self, groups):
     form_data = {
         'content': 'This is a message',
         'recipient_group': '1',
     }
     form = SendRecipientGroupForm(data=form_data)
     assert form.is_valid()
Example #9
0
    def post(self, request, format=None, **kwargs):
        form = SendRecipientGroupForm(request.data, user=request.user)
        if form.is_valid():
            form.cleaned_data['recipient_group'].send_message(
                content=form.cleaned_data['content'],
                eta=form.cleaned_data['scheduled_time'],
                sent_by=str(self.request.user)
            )
            if form.cleaned_data['scheduled_time'] is None:
                msg_txt = "Sending '{0}' to '{1}'...\nPlease check the logs for verification...".format(
                    form.cleaned_data['content'], form.cleaned_data['recipient_group']
                )
                msg = {
                    'type_': 'info',
                    'text': msg_txt,
                }
            else:
                msg = {
                    'type_': 'info',
                    'text': "'{0}' has been successfully queued.".format(form.cleaned_data['content']),
                }

            return Response({'messages': [msg], 'errors': {}}, status=status.HTTP_201_CREATED)

        return Response({'messages': [], 'errors': form.errors}, status=status.HTTP_400_BAD_REQUEST)
Example #10
0
 def test_missing_group(self, groups):
     """Test missing group"""
     form_data = {
         'content': 'This is a message',
     }
     form = SendRecipientGroupForm(data=form_data)
     assert form.is_valid() is False
Example #11
0
 def test_correct_values(self, groups):
     form_data = {
         'content': 'This is a message',
         'recipient_group': groups['test_group'].pk,
     }
     form = SendRecipientGroupForm(data=form_data, user=UserMock())
     assert form.is_valid()
Example #12
0
 def test_disabled_user_limit(self, groups):
     """Tests the SMS cost limit check is disabled."""
     form_data = {"content": "This is a message", "recipient_group": groups["test_group"].pk}
     user = UserMock()
     user.profile.message_cost_limit = 0
     form = SendRecipientGroupForm(data=form_data, user=UserMock())
     assert form.is_valid()
Example #13
0
 def test_missing_content(self, groups):
     """Test missing content"""
     form_data = {
         'recipient_group': '1',
     }
     form = SendRecipientGroupForm(data=form_data, user=UserMock())
     assert form.is_valid() is False
Example #14
0
 def test_fails_user_limit(self, groups):
     """Tests the SMS cost limit check."""
     form_data = {"content": "This is a message", "recipient_group": groups["test_group"].pk}
     user = UserMock()
     user.profile.message_cost_limit = 0.01
     form = SendRecipientGroupForm(data=form_data, user=UserMock())
     assert not form.is_valid()
     assert "cost no more than ${0}".format(user.profile.message_cost_limit) in "\n".join(form.errors["__all__"])
Example #15
0
 def test_empty_content(self, groups):
     """Test empty content"""
     form_data = {
         'content': '',
         'recipient_group': '1',
     }
     form = SendRecipientGroupForm(data=form_data)
     assert form.is_valid() is False
Example #16
0
 def test_max_length(self, groups):
     """Test message far too long"""
     form_data = {
         'content': 50 * "test",
         'recipient': ['1'],
     }
     form = SendRecipientGroupForm(data=form_data)
     assert form.is_valid() is False
Example #17
0
 def test_empty_group(self):
     """Test empty group"""
     form_data = {
         'content': 'Hi!',
         'recipient_group': '',
     }
     form = SendRecipientGroupForm(data=form_data)
     assert form.is_valid() is False
Example #18
0
 def test_empty_group(self):
     """Test empty group"""
     form_data = {
         'content': 'Hi!',
         'recipient_group': '',
     }
     form = SendRecipientGroupForm(data=form_data)
     assert form.is_valid() is False
Example #19
0
 def test_archived(self, groups):
     """Test archived group"""
     form_data = {
         'content': 'This is a message',
         'recipient_group': '2',
     }
     form = SendRecipientGroupForm(data=form_data)
     assert form.is_valid() is False
Example #20
0
 def test_illegal_chars(self, groups):
     """Test illegal (non-GSM) characters"""
     form_data = {
         'content': u"This should not pass…",
         'recipient': ['1'],
     }
     form = SendRecipientGroupForm(data=form_data)
     assert form.is_valid() is False
Example #21
0
 def test_illegal_chars(self, groups):
     """Test illegal (non-GSM) characters"""
     form_data = {
         'content': u"This should not pass…",
         'recipient': ['1'],
     }
     form = SendRecipientGroupForm(data=form_data)
     assert form.is_valid() is False
Example #22
0
 def test_max_length(self, groups):
     """Test message far too long"""
     form_data = {
         'content': 50 * "test",
         'recipient': ['1'],
     }
     form = SendRecipientGroupForm(data=form_data)
     assert form.is_valid() is False
Example #23
0
 def test_archived(self, groups):
     """Test archived group"""
     form_data = {
         'content': 'This is a message',
         'recipient_group': '2',
     }
     form = SendRecipientGroupForm(data=form_data)
     assert form.is_valid() is False
Example #24
0
 def test_empty_content(self, groups):
     """Test empty content"""
     form_data = {
         'content': '',
         'recipient_group': '1',
     }
     form = SendRecipientGroupForm(data=form_data, user=UserMock())
     assert form.is_valid() is False
Example #25
0
 def test_disabled_user_limit(self, groups):
     """Tests the SMS cost limit check is disabled."""
     form_data = {
         'content': 'This is a message',
         'recipient_group': groups['test_group'].pk,
     }
     user = UserMock()
     user.profile.message_cost_limit = 0
     form = SendRecipientGroupForm(data=form_data, user=UserMock())
     assert form.is_valid()
Example #26
0
 def test_disabled_user_limit(self, groups):
     """Tests the SMS cost limit check is disabled."""
     form_data = {
         'content': 'This is a message',
         'recipient_group': groups['test_group'].pk,
     }
     user = UserMock()
     user.profile.message_cost_limit = 0
     form = SendRecipientGroupForm(data=form_data, user=UserMock())
     assert form.is_valid()
Example #27
0
 def test_fails_user_limit(self, groups):
     """Tests the SMS cost limit check."""
     form_data = {
         'content': 'This is a message',
         'recipient_group': groups['test_group'].pk,
     }
     user = UserMock()
     user.profile.message_cost_limit = 0.01
     form = SendRecipientGroupForm(data=form_data, user=UserMock())
     assert not form.is_valid()
     assert 'cost no more than ${0}'.format(user.profile.message_cost_limit) in '\n'.join(form.errors['__all__'])
Example #28
0
 def test_fails_user_limit(self, groups):
     """Tests the SMS cost limit check."""
     form_data = {
         'content': 'This is a message',
         'recipient_group': groups['test_group'].pk,
     }
     user = UserMock()
     user.profile.message_cost_limit = 0.01
     form = SendRecipientGroupForm(data=form_data, user=UserMock())
     assert not form.is_valid()
     assert 'cost no more than ${0}'.format(
         user.profile.message_cost_limit
     ) in '\n'.join(form.errors['__all__'])
Example #29
0
 def test_archived(self, groups):
     """Test archived group"""
     form_data = {"content": "This is a message", "recipient_group": "2"}
     form = SendRecipientGroupForm(data=form_data)
     assert form.is_valid() is False
 def test_correct_values(self, groups):
     form_data = {'content': 'This is a message', 'recipient_group': '1', }
     form = SendRecipientGroupForm(data=form_data)
     assert form.is_valid()
Example #31
0
 def test_max_length(self, groups):
     """Test message far too long"""
     form_data = {"content": 50 * "test", "recipient": ["1"]}
     form = SendRecipientGroupForm(data=form_data)
     assert form.is_valid() is False
Example #32
0
 def test_empty_group(self):
     """Test empty group"""
     form_data = {"content": "Hi!", "recipient_group": ""}
     form = SendRecipientGroupForm(data=form_data)
     assert form.is_valid() is False
Example #33
0
 def test_empty_content(self, groups):
     """Test empty content"""
     form_data = {"content": "", "recipient_group": "1"}
     form = SendRecipientGroupForm(data=form_data, user=UserMock())
     assert form.is_valid() is False
Example #34
0
 def test_correct_values(self, groups):
     form_data = {"content": "This is a message", "recipient_group": groups["test_group"].pk}
     form = SendRecipientGroupForm(data=form_data, user=UserMock())
     assert form.is_valid()