Exemplo n.º 1
0
    def test_state_afgehandeld_text_required_invalid(self):
        new_status = Status(_signal=self.signal,
                            state=workflow.AFGEHANDELD,
                            text=None)

        with self.assertRaises(ValidationError) as error:
            new_status.full_clean()
        self.assertIn('text', error.exception.error_dict)
Exemplo n.º 2
0
    def test_state_te_verzenden_required_target_api_invalid_empty_choice(self):
        new_status = Status(_signal=self.signal,
                            state=workflow.TE_VERZENDEN,
                            target_api=None)

        with self.assertRaises(ValidationError) as error:
            new_status.full_clean()
        self.assertIn('target_api', error.exception.error_dict)
Exemplo n.º 3
0
    def test_state_transition_not_required_target_api(self):
        new_status = Status(_signal=self.signal,
                            state=workflow.ON_HOLD,
                            target_api=Status.TARGET_API_SIGMAX)

        with self.assertRaises(ValidationError) as error:
            new_status.full_clean()
        self.assertIn('target_api', error.exception.error_dict)
Exemplo n.º 4
0
    def test_state_te_verzenden_required_target_api_valid(self):
        new_status = Status(_signal=self.signal,
                            state=workflow.TE_VERZENDEN,
                            target_api=Status.TARGET_API_SIGMAX)
        new_status.full_clean()
        new_status.save()

        self.assertTrue(new_status.id)
Exemplo n.º 5
0
    def test_state_afgehandeld_text_required_valid(self):
        new_status = Status(_signal=self.signal, state=workflow.BEHANDELING, text='Working on it.')
        new_status.full_clean()
        new_status.save()

        self.signal.status = new_status
        self.signal.save()

        new_status = Status(_signal=self.signal, state=workflow.AFGEHANDELD, text='Done with it.')
        new_status.full_clean()
        new_status.save()

        self.assertTrue(new_status.id)
Exemplo n.º 6
0
def trigger_mail_action_for_email_preview(signal, status_data):
    """
    Helper function that will check which mail action will be triggered if a new status is requested.
    """
    from signals.apps.email_integrations.services import MailService

    # Create the "new" status we want to use to trigger the mail
    try:
        status = Status(_signal=signal, **status_data)
        status.full_clean()
        status.id = 0  # Fake id so that we still can trigger the action rule
    except ValidationError as e:
        raise convert_validation_error(e)

    subject = message = html_message = None
    for action in MailService._status_actions:
        # Execute the rule associated with the action
        if action.rule.validate(signal, status):
            # action found now render the subject, message and html_message and break the loop
            email_context = action.get_context(signal, dry_run=True)

            # overwrite the status context
            email_context.update({
                'status_text':
                status_data['text'],  # overwrite the status text
                'status_state':
                status_data['state'],  # overwrite the status state
                'afhandelings_text':
                status_data['text'],  # overwrite for the 'optional' action
                'reaction_request_answer':
                status_data[
                    'text'],  # overwrite for the 'reaction received' action
            })

            subject, message, html_message = action.render_mail_data(
                context=email_context)
            break

    if subject is None:
        raise NotFound(
            'No email preview available for given status transition')

    return subject, message, html_message
Exemplo n.º 7
0
    def test_state_transition_invalid(self):
        new_status = Status(_signal=self.signal, state=workflow.VERZONDEN)

        with self.assertRaises(ValidationError) as error:
            new_status.full_clean()
        self.assertIn('state', error.exception.error_dict)
Exemplo n.º 8
0
    def test_state_transition_valid(self):
        new_status = Status(_signal=self.signal, state=workflow.AFWACHTING)
        new_status.full_clean()
        new_status.save()

        self.assertTrue(new_status.id)