def test_raises_error_if_activated_monitor_exists_for_phone_number(self): event = factories.create_event() factories.create_monitor_for_event( event=event, phone_number=factories.VALID_PHONE_NUMBER, status=MONITOR_STATUS_ACTIVATED) with self.assertRaises(ValueError): monitor_service.create_monitor_for_event( event=event, phone_number=factories.VALID_PHONE_NUMBER, amount=Decimal('70'))
def test_sends_monitor_confirmation_message(self, send_sms_message_mock): event = factories.create_event() monitor_service.create_monitor_for_event( event=event, phone_number=factories.VALID_PHONE_NUMBER, amount=Decimal('70')) expected_message = OUTGOING_MESSAGE_MONITOR_CONFIRMATION.format( event_title=event.title) send_sms_message_mock.assert_called_once_with( to_phone_number=factories.VALID_PHONE_NUMBER, message=expected_message)
def save(form): cleaned_data = form.cleaned_data return monitor_service.create_monitor_for_event( event=cleaned_data['event'], phone_number=cleaned_data['phone_number'], amount=cleaned_data['amount'] )
def test_raises_error_if_status_is_invalid(self): event = factories.create_event() monitor = monitor_service.create_monitor_for_event( event=event, phone_number=factories.VALID_PHONE_NUMBER, amount=Decimal('70')) with self.assertRaises(ValueError): monitor_service.set_status_of_monitor(monitor, 'invalid_status')
def test_does_not_raise_error_if_deactivated_monitor_exists_for_phone_number( self): event = factories.create_event() monitor = monitor_service.create_monitor_for_event( event=event, phone_number=factories.VALID_PHONE_NUMBER, amount=Decimal('70')) monitor_service.set_status_of_monitor(monitor, MONITOR_STATUS_DEACTIVATED) try: monitor_service.create_monitor_for_event( event=event, phone_number=factories.VALID_PHONE_NUMBER, amount=Decimal('80')) except ValueError: self.fail( 'create_monitor_for_event should not raise if existing monitors are deactivated' )
def test_sets_created_status_for_monitor(self): event = factories.create_event() monitor = monitor_service.create_monitor_for_event( event=event, phone_number=factories.VALID_PHONE_NUMBER, amount=Decimal('70')) self.assertEqual(1, monitor.statuses.count()) self.assertEqual(MONITOR_STATUS_CREATED, monitor.current_status.status)
def test_creates_new_monitor_status(self): event = factories.create_event() monitor = monitor_service.create_monitor_for_event( event=event, phone_number=factories.VALID_PHONE_NUMBER, amount=Decimal('70')) monitor_service.set_status_of_monitor(monitor, MONITOR_STATUS_ACTIVATED) self.assertEqual(2, monitor.statuses.count()) self.assertEqual(MONITOR_STATUS_ACTIVATED, monitor.current_status.status)
def create_monitor_for_event(event, amount=None, phone_number=None, status=None): amount = amount or Decimal('65.01') phone_number = phone_number or VALID_PHONE_NUMBER monitor = monitor_service.create_monitor_for_event( event=event, phone_number=phone_number, amount=amount) if status: monitor_service.set_status_of_monitor(monitor, status) return monitor
def test_creates_new_monitor(self): event = factories.create_event() monitor = monitor_service.create_monitor_for_event( event=event, phone_number=factories.VALID_PHONE_NUMBER, amount=Decimal('70')) self.assertTrue(Monitor.objects.filter(id=monitor.id).exists()) self.assertEqual(Decimal('70'), monitor.amount) self.assertEqual(factories.VALID_PHONE_NUMBER, monitor.phone_number.as_e164) self.assertEqual(event.id, monitor.event_id) self.assertRegexpMatches(monitor.external_id, '^[a-z]{5,10}$')