Ejemplo n.º 1
0
def _make_performance_config(
    domain, interval, hour=DEFAULT_HOUR, day_of_week=DEFAULT_WEEK_DAY, day_of_month=DEFAULT_MONTH_DAY
):
    config = PerformanceConfiguration(
        domain=domain,
        recipient_id=uuid.uuid4().hex,
        template="test",
        schedule=ScheduleConfiguration(
            interval=interval, hour=hour, day_of_week=day_of_week, day_of_month=day_of_month
        ),
    )
    config.save()
    return config
Ejemplo n.º 2
0
 def test_global_vars_validation(self):
     template = 'Hello {name} - you have completed {count} forms today!'
     # if 0 or 1 are defined it should fail
     with self.assertRaises(InvalidParameterException):
         PerformanceConfiguration(template=template).validate()
     with self.assertRaises(InvalidParameterException):
         PerformanceConfiguration(template=template, template_variables=[
             TemplateVariable(slug='name', type='form'),
         ]).validate()
     # if both are defined it should not succeed
     PerformanceConfiguration(template=template, template_variables=[
         TemplateVariable(slug='name', type='form'),
         TemplateVariable(slug='count', type='form'),
     ]).validate()
Ejemplo n.º 3
0
def _make_performance_config(domain, interval, hour=DEFAULT_HOUR, day_of_week=DEFAULT_WEEK_DAY,
                             day_of_month=DEFAULT_MONTH_DAY):
    config = PerformanceConfiguration(
        domain=domain,
        recipient_id=uuid.uuid4().hex,
        template='test',
        schedule=ScheduleConfiguration(
            interval=interval,
            hour=hour,
            day_of_week=day_of_week,
            day_of_month=day_of_month,
        )
    )
    config.save()
    return config
Ejemplo n.º 4
0
def _send_test_messages(request, domain, config_id, actually):
    performance_config = PerformanceConfiguration.get(config_id)
    assert performance_config.domain == domain
    sent_messages = send_messages_for_config(performance_config,
                                             actually_send=actually)
    heading = (_('The following messages have been sent')
               if actually else _('Would send the following messages'))
    if sent_messages:
        messages.success(request,
                         mark_safe(
                             _(u"{}: <br>{}").format(
                                 heading, '<br>'.join([
                                     u' - {} (to {} via {})'.format(
                                         result.message,
                                         result.user.raw_username,
                                         result.user.phone_number)
                                     for result in sent_messages
                                 ]))),
                         extra_tags='html')
    else:
        messages.info(
            request,
            _('Unfortunately, here were no valid recipients for this message.')
        )
    return HttpResponseRedirect(
        reverse(ListPerformanceConfigsView.urlname, args=[domain]))
Ejemplo n.º 5
0
def _send_test_messages(request, domain, config_id, actually):
    performance_config = PerformanceConfiguration.get(config_id)
    assert performance_config.domain == domain
    sent_messages = send_messages_for_config(performance_config, actually_send=actually)
    heading = (
        _('The following messages have been sent') if actually else
        _('Would send the following messages')
    )
    if sent_messages:
        messages.success(
            request,
            mark_safe(_(u"{}: <br>{}").format(
                heading,
                '<br>'.join([
                    u' - {} (to {} via {})'.format(
                        result.message, result.user.raw_username, result.user.phone_number
                    )
                    for result in sent_messages
                ])
            )),
            extra_tags='html'
        )
    else:
        messages.info(request, _('Unfortunately, here were no valid recipients for this message.'))
    return HttpResponseRedirect(reverse('performance_sms.list_performance_configs', args=[domain]))
Ejemplo n.º 6
0
def by_domain(domain):
    return list(PerformanceConfiguration.view(
        'performance_sms/by_domain',
        key=domain,
        reduce=False,
        include_docs=True
    ))
Ejemplo n.º 7
0
def by_interval(interval_keys):
    return list(PerformanceConfiguration.view(
        'performance_sms/by_schedule',
        key=interval_keys,
        reduce=False,
        include_docs=True,
    ))
Ejemplo n.º 8
0
def by_interval(interval_keys):
    return list(PerformanceConfiguration.view(
        'performance_sms/by_schedule',
        key=interval_keys,
        reduce=False,
        include_docs=True,
    ))
Ejemplo n.º 9
0
def delete_all_configs():
    assert settings.UNIT_TESTING
    db = PerformanceConfiguration.get_db()
    all_docs = [row['doc'] for row in db.view(
        'performance_sms/by_domain',
        reduce=False,
        include_docs=True
    )]
    db.bulk_delete(all_docs)
Ejemplo n.º 10
0
    def clean(self):
        cleaned_data = super(PerformanceFormMixin, self).clean()
        if self.errors:
            # don't bother processing if there are already errors
            return cleaned_data
        config = PerformanceConfiguration.wrap(self.config.to_json())
        self._apply_updates_to_config(config, cleaned_data)
        try:
            config.validate()
        except InvalidParameterException as e:
            raise forms.ValidationError(unicode(e))

        return cleaned_data
Ejemplo n.º 11
0
 def test_validate_bad_formats(self):
     invalid_test_cases = [
         None,
         '',
         'too.many.periods',
         'bad.namespace',
         ' prewhitespace',
         'postwhitespace ',
         'inner whitespace',
     ]
     for invalid in invalid_test_cases:
         with self.assertRaises(InvalidParameterException):
             parse_param(invalid)
         if invalid:
             with self.assertRaises(InvalidParameterException):
                 template = 'Hello {%s}' % invalid
                 PerformanceConfiguration(template=template).validate()
Ejemplo n.º 12
0
 def performance_config(self):
     return PerformanceConfiguration(domain=self.domain)
Ejemplo n.º 13
0
def _make_performance_config(domain):
    config = PerformanceConfiguration(domain=domain,
                                      recipient_id=uuid.uuid4().hex,
                                      template='test')
    config.save()
    return config
Ejemplo n.º 14
0
def _make_performance_config(domain):
    config = PerformanceConfiguration(domain=domain, recipient_id=uuid.uuid4().hex, template='test')
    config.save()
    return config
Ejemplo n.º 15
0
def delete_all_configs():
    delete_all_docs_by_doc_type(PerformanceConfiguration.get_db(), ('PerformanceConfiguration',))
Ejemplo n.º 16
0
def delete_all_configs():
    delete_all_docs_by_doc_type(PerformanceConfiguration.get_db(), ("PerformanceConfiguration",))