def setUp(self): self.signal = SignalFactoryValidLocation() self.feedback = FeedbackFactory( _signal=self.signal, is_satisfied=None, ) self.feedback_endpoint = '/signals/v1/public/feedback/forms/{token}' self.history_endpoint = '/signals/v1/private/signals/{id}/history'
def setUp(self): self.signal = SignalFactory.create() self.feedback_submitted = FeedbackFactory.create( _signal=self.signal, created_at=datetime(2019, 4, 9, 12, 0, tzinfo=pytz.UTC), submitted_at=datetime(2019, 4, 9, 18, 0, 0, tzinfo=pytz.UTC), text='Tevreden want mooi weer', text_extra='Waarom? Daarom!') self.feedback_requested = FeedbackFactory.create( _signal=self.signal, created_at=datetime(2019, 4, 9, 12, 0, 0), ) self.csv_tmp_dir = tempfile.mkdtemp()
def test_send_system_email_with_context(self): """ Check if the email with context is send to the user """ action = MailService._system_actions.get('feedback_received')() signal = SignalFactory.create(status__state=workflow.GEMELD, reporter__email='*****@*****.**') text = 'my text _1234567' text_extra = 'my extra text _extra_987654321' feedback = FeedbackFactory.create(_signal=signal, text=text, text_extra=text_extra, token=uuid.uuid4()) result = action(signal=signal, dry_run=False, feedback=feedback) self.assertTrue(result) self.assertEqual(len(mail.outbox), 1) self.assertEqual(mail.outbox[0].to, [ signal.reporter.email, ]) self.assertEqual(mail.outbox[0].from_email, settings.DEFAULT_FROM_EMAIL) self.assertIn(text, mail.outbox[0].body) self.assertIn(text_extra, mail.outbox[0].body) self.assertEqual(Note.objects.count(), 1)
def test_only_send_feedback_negative_contact_mail(self): """ Test to see if when a status is changed from VERZOEK_TOT_AFHANDELING to AFGEHANDELD and has allows_contact on the feedback to only send one email """ self.assertEqual(len(mail.outbox), 0) signal = SignalFactory.create( status__state=workflow.VERZOEK_TOT_AFHANDELING, reporter__email='*****@*****.**') status = StatusFactory.create(_signal=signal, state=workflow.AFGEHANDELD) feedback = FeedbackFactory.create( allows_contact=True, _signal=signal, ) feedback.save() signal.status = status # change to new status AFGEHANDELD signal.save() self.assertTrue(MailService.status_mail(signal)) self.assertEqual(len(mail.outbox), 1) self.assertEqual(mail.outbox[0].subject, f'Meer over uw melding {signal.get_id_display()}') self.assertEqual(mail.outbox[0].to, [ signal.reporter.email, ]) self.assertEqual(mail.outbox[0].from_email, settings.DEFAULT_FROM_EMAIL) self.assertEqual(Note.objects.count(), 1)
def test_send_system_mail_feedback_received(self): """ Test the sending of the sending mail from the mail services """ EmailTemplate.objects.create( key=EmailTemplate.SIGNAL_FEEDBACK_RECEIVED, title='Uw Feedback is ontvangen', body='test text {{ feedback_text }} {{ feedback_text_extra }}') signal = SignalFactory.create(status__state=workflow.GEMELD, reporter__email='*****@*****.**') text = 'my text _1234567' text_extra = 'my extra text _extra_987654321' feedback = FeedbackFactory.create( _signal=signal, text=text, text_extra=text_extra, ) result = MailService.system_mail(signal=signal, action_name='feedback_received', feedback=feedback) self.assertTrue(result) self.assertEqual(len(mail.outbox), 1) self.assertEqual(mail.outbox[0].to, [ signal.reporter.email, ]) self.assertEqual(mail.outbox[0].from_email, settings.DEFAULT_FROM_EMAIL) self.assertIn(text, mail.outbox[0].body) self.assertIn(text_extra, mail.outbox[0].body) self.assertEqual(Note.objects.count(), 1)
def test_apply_for_parent_signals(self): status_text = FuzzyText(length=400) parent_signal = SignalFactory.create( status__state=self.prev_state, status__text=status_text, status__send_email=self.send_email, reporter__email='*****@*****.**') SignalFactory.create(status__state=self.state, status__text=status_text, reporter__email='*****@*****.**', parent=parent_signal) # create the new current state status = StatusFactory.create(_signal=parent_signal, state=self.state) parent_signal.status = status parent_signal.save() feedback = FeedbackFactory.create( allows_contact=True, _signal=parent_signal, ) feedback.save() self.assertTrue(self.rule(parent_signal))
def test_filter_feedback_not_received(self): feedback = FeedbackFactory.create(_signal=self.signals[0]) params = {'feedback': 'not_received'} result_ids = self._request_filter_signals(params) self.assertEqual(1, len(result_ids)) self.assertEqual(feedback._signal_id, result_ids[0])
def test_allows_contact_False_unsummited(self): """ Unsubmitedd Feedback with Allows Contact False """ signal = factories.SignalFactory.create() feedback = FeedbackFactory.create(_signal=signal, allows_contact=False) feedback.save() self.assertTrue(signal.allows_contact)
def setUp(self): # Times for various actions (assumes a 14 day window for feedback). self.t_now = '2019-04-01 12:00:00' self.t_creation = '2019-03-01 12:00:00' self.t_expired = '2019-03-02 12:00:00' self.t_received = '2019-03-29 12:00:00' # Setup our test signal and feedback instances with freeze_time(self.t_creation): self.reporter = ReporterFactory() self.signal = SignalFactoryValidLocation( reporter=self.reporter, status__state=workflow.AFGEHANDELD, ) with freeze_time(self.t_now): self.feedback = FeedbackFactory( submitted_at=None, _signal=self.signal, ) with freeze_time(self.t_expired): self.feedback_expired = FeedbackFactory( submitted_at=None, _signal=self.signal, ) with freeze_time(self.t_received): self.feedback_received = FeedbackFactory( submitted_at=timezone.now() - timedelta(days=5), _signal=self.signal, ) # Setup a standard answer that triggers a request to reopen. self.sa_reopens = StandardAnswerFactory.create( text='Ik ben niet blij met de afhandeling, duurde te lang.', is_satisfied=False, reopens_when_unhappy=True, ) self.sa_no_sideeffect = StandardAnswerFactory.create( text='Ik ben niet blij. Blah, blah.', is_satisfied=False, reopens_when_unhappy=False, )
def test_filter_feedback_negative_feedback(self): feedback = FeedbackFactory.create(_signal=self.signals[0], is_satisfied=False, submitted_at=timezone.now()) params = {'feedback': 'not_satisfied'} result_ids = self._request_filter_signals(params) self.assertEqual(1, len(result_ids)) self.assertEqual(feedback._signal_id, result_ids[0])
def test_allows_contact_True(self): """ Submitted feedback with allows_contantact True """ signal = factories.SignalFactory.create() feedback = FeedbackFactory.create(_signal=signal, submitted_at='2022-01-01', allows_contact=True) feedback.save() self.assertTrue(signal.allows_contact)
def test_allows_contact_False(self): feedback = FeedbackFactory.create( _signal=self.signal, submitted_at='2022-01-01', allows_contact=False ) feedback.save() data = self.serializer().to_representation(self.reporter) self.assertFalse(data['allows_contact'])
def test_filter_feedback_multiple_negative(self): now = timezone.now() FeedbackFactory.create(_signal=self.signals[0], is_satisfied=True, submitted_at=now - timedelta(days=1)) feedback_negative = FeedbackFactory.create(_signal=self.signals[0], is_satisfied=False, submitted_at=now) params = {'feedback': 'satisfied'} result_ids = self._request_filter_signals(params) self.assertEqual(0, len(result_ids)) params = {'feedback': 'not_satisfied'} result_ids = self._request_filter_signals(params) self.assertEqual(1, len(result_ids)) self.assertEqual(feedback_negative._signal_id, result_ids[0])
def test_allowed_contact_disabled_flag(self): """ When the flag is set to false the feature should always return true even if allows_contact is set to false """ signal = factories.SignalFactory.create() feedback = FeedbackFactory.create(_signal=signal, allows_contact=False, submitted_at='2022-01-01') feedback.save() self.assertTrue(signal.allows_contact)
def test__get_description_of_receive_feedback_no_satisfied(self): feedback = FeedbackFactory.create( is_satisfied=False, text="My Text", text_list=None, text_extra=None, allows_contact=False, ) response = _get_description_of_receive_feedback(feedback.token) validate_text = "Nee, de melder is ontevreden\nWaarom: My Text\n" \ "Toestemming contact opnemen: Nee" self.assertEqual(response, validate_text)
def test__get_description_of_receive_feedback(self): feedback = FeedbackFactory.create( is_satisfied=True, text=None, text_list=['my', 'test', 'list'], text_extra='extra_text', allows_contact=True, ) response = _get_description_of_receive_feedback(feedback.token) validate_text = "Ja, de melder is tevreden\nWaarom: my,test,list\nToelichting: extra_text\n" \ "Toestemming contact opnemen: Ja" self.assertEqual(response, validate_text)
def test_allowed_contact_disable_flag(self): """ When the flag is set to false the feature should always return true and still mail the users """ status_text = FuzzyText(length=400) signal = SignalFactory.create(status__state=self.state, status__text=status_text, status__send_email=self.send_email, reporter__email='*****@*****.**') feedback = FeedbackFactory.create(_signal=signal, allows_contact=False, submitted_at='2022-01-01') feedback.save() signal.save() self.assertTrue(self.action(signal, dry_run=False)) self.assertTrue(len(mail.outbox) > 0)
def test_allowed_contact_false(self): """ Disable all emails when a signal has a feedback object with allows_contact False """ status_text = FuzzyText(length=400) signal = SignalFactory.create(status__state=self.state, status__text=status_text, status__send_email=self.send_email, reporter__email='*****@*****.**') feedback = FeedbackFactory.create(_signal=signal, allows_contact=False, submitted_at='2022-01-01') feedback.save() signal.save() self.assertFalse(self.action(signal, dry_run=False)) self.assertEqual(len(mail.outbox), 0)
def setUp(self): status_text = FuzzyText(length=400) self.signal = SignalFactory.create(status__state=self.prev_state, status__text=status_text, status__send_email=self.send_email, reporter__email='*****@*****.**') # create the new current state status = StatusFactory.create(_signal=self.signal, state=self.state) self.signal.status = status self.signal.save() self.feedback = FeedbackFactory.create(_signal=self.signal, allows_contact=True, is_satisfied=False) self.feedback.save() super().setUp()
def test_feedback_received_action_disabled(self): """ FeedbackReceivedAction is disabled in settings """ action = MailService._system_actions.get('feedback_received')() signal = SignalFactory.create(status__state=workflow.GEMELD, reporter__email='*****@*****.**') text = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.' text_extra = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.' feedback = FeedbackFactory.create(_signal=signal, text=text, text_extra=text_extra, token=uuid.uuid4()) result = action(signal=signal, dry_run=False, feedback=feedback) self.assertFalse(result) self.assertEqual(len(mail.outbox), 0)
def test_happy_flow(self): status_text = FuzzyText(length=400) # create signal in prev status signal = SignalFactory.create(status__state=self.prev_state, status__text=status_text, status__send_email=self.send_email, reporter__email='*****@*****.**') # create the new current state status = StatusFactory.create(_signal=signal, state=self.state) signal.status = status signal.save() feedback = FeedbackFactory.create( allows_contact=True, _signal=signal, ) feedback.save() self.assertTrue(self.rule(signal))
def test_feedback_received_action_context(self): text = 'my text' text_extra = 'my extra text' signal = SignalFactory() feedback = FeedbackFactory.create(text=text, text_extra=text_extra, allows_contact=True, is_satisfied=False, token=uuid.uuid4(), _signal=signal) action = MailService._system_actions.get('feedback_received')() action(signal=signal, feedback=feedback) result = action.get_additional_context(signal) self.assertIn('feedback_text', result) self.assertIn('feedback_text_extra', result) self.assertIn('feedback_allows_contact', result) self.assertIn('feedback_is_satisfied', result) self.assertEqual(result['feedback_text'], text) self.assertEqual(result['feedback_text_extra'], text_extra) self.assertTrue(result['feedback_allows_contact']) self.assertFalse(result['feedback_is_satisfied'])
def setUp(self): self.feedback = FeedbackFactory.create()
def setUp(self): self.feedback = FeedbackFactory()
class TestFeedbackFlow(SignalsBaseApiTestCase): def setUp(self): # Times for various actions (assumes a 14 day window for feedback). self.t_now = '2019-04-01 12:00:00' self.t_creation = '2019-03-01 12:00:00' self.t_expired = '2019-03-02 12:00:00' self.t_received = '2019-03-29 12:00:00' # Setup our test signal and feedback instances with freeze_time(self.t_creation): self.reporter = ReporterFactory() self.signal = SignalFactoryValidLocation( reporter=self.reporter, status__state=workflow.AFGEHANDELD, ) with freeze_time(self.t_now): self.feedback = FeedbackFactory( submitted_at=None, _signal=self.signal, ) with freeze_time(self.t_expired): self.feedback_expired = FeedbackFactory( submitted_at=None, _signal=self.signal, ) with freeze_time(self.t_received): self.feedback_received = FeedbackFactory( submitted_at=timezone.now() - timedelta(days=5), _signal=self.signal, ) # Setup a standard answer that triggers a request to reopen. self.sa_reopens = StandardAnswerFactory.create( text='Ik ben niet blij met de afhandeling, duurde te lang.', is_satisfied=False, reopens_when_unhappy=True, ) self.sa_no_sideeffect = StandardAnswerFactory.create( text='Ik ben niet blij. Blah, blah.', is_satisfied=False, reopens_when_unhappy=False, ) def test_setup(self): self.assertEqual(Feedback.objects.count(), 3) def test_404_if_no_feedback_requested(self): response = self.client.get('/forms/DIT_IS_GEEN_token/') self.assertEqual(response.status_code, 404) def test_410_gone_too_late(self): token = self.feedback_expired.token with freeze_time(self.t_now): response = self.client.get('/forms/{}/'.format(token)) self.assertEqual(response.status_code, 410) # faalt! self.assertEqual(response.json()['detail'], 'too late') response = self.client.put('/forms/{}/'.format(token), data={}) self.assertEqual(response.status_code, 410) self.assertEqual(response.json()['detail'], 'too late') def test_410_gone_filled_out(self): """Test that we receive correct HTTP 410 reply when form filled out already""" token = self.feedback_received.token with freeze_time(self.t_now): response = self.client.get('/forms/{}/'.format(token)) self.assertEqual(response.status_code, 410) self.assertEqual(response.json()['detail'], 'filled out') response = self.client.put('/forms/{}/'.format(token), data={}) self.assertEqual(response.status_code, 410) self.assertEqual(response.json()['detail'], 'filled out') def test_200_if_feedback_requested(self): """Test that we receive an empty JSON object HTTP 200 reply.""" token = self.feedback.token with freeze_time(self.t_now): response = self.client.get('/forms/{}/'.format(token)) self.assertEqual(response.status_code, 200) self.assertEqual(response.json(), {}) def test_200_on_submit_feedback(self): """Test that the feedback can be PUT once.""" token = self.feedback.token reason = 'testen is leuk' explanation = 'ook voor de lunch' data = { 'is_satisfied': True, 'allows_contact': True, 'text': reason, 'text_area': explanation, } with freeze_time(self.t_now): response = self.client.put( '/forms/{}/'.format(token), data=data, format='json', ) self.assertEqual(response.status_code, 200) self.feedback.refresh_from_db() self.assertEqual(self.feedback.is_satisfied, True) self.assertEqual(self.feedback.allows_contact, True) self.assertEqual(self.feedback.text, reason) def test_400_on_submit_feedback_without_is_satisfied(self): """Test that the feedback can be PUT once.""" token = self.feedback.token reason = 'testen is leuk' explanation = 'ook voor de lunch' data = { 'allows_contact': True, 'text': reason, 'text_area': explanation, } with freeze_time(self.t_now): response = self.client.put( '/forms/{}/'.format(token), data=data, format='json', ) self.assertEqual(response.status_code, 400) def test_reopen_requested_on_unsatisfied_standard_answer(self): """Certain standard answers (in feedback) lead to "reopen requested" state.""" token = self.feedback.token data = { 'allows_contact': False, 'text': self.sa_reopens.text, 'is_satisfied': False, } with freeze_time(self.t_now): response = self.client.put( '/forms/{}/'.format(token), data=data, format='json', ) self.assertEqual(response.status_code, 200) self.signal.refresh_from_db() self.assertEqual(self.signal.status.state, workflow.VERZOEK_TOT_HEROPENEN) def test_reopen_requested_on_unsatisfied_custom_answer(self): """All custom unsatisfied answers (in feedback) lead to "reopen requested" state.""" token = self.feedback.token data = { 'allows_contact': False, 'text': 'MEH, probleem niet opgelost.', 'is_satisfied': False, } with freeze_time(self.t_now): response = self.client.put( '/forms/{}/'.format(token), data=data, format='json', ) self.assertEqual(response.status_code, 200) self.signal.refresh_from_db() self.assertEqual(self.signal.status.state, workflow.VERZOEK_TOT_HEROPENEN) def test_no_reopen_requested_on_unsatisfied_and_known_feedback(self): """Some negative feedback is explicitly marked not to trigger reopen requested.""" token = self.feedback.token data = { 'allows_contact': False, 'text': self.sa_no_sideeffect.text, 'is_satisfied': False, } with freeze_time(self.t_now): response = self.client.put( '/forms/{}/'.format(token), data=data, format='json', ) self.assertEqual(response.status_code, 200) self.signal.refresh_from_db() self.assertEqual(self.signal.status.state, workflow.AFGEHANDELD) def test_no_reopen_requested_when_not_in_state_afgehandeld(self): """Only request reopen from AFGEHANDELD state.""" with freeze_time(self.t_now): # Reopen the test signal (so it is no longer in AFGEHANDELD). payload = { 'text': 'De melder is niet tevreden blijkt uit feedback. Zo nodig heropenen.', 'state': workflow.HEROPEND, } Signal.actions.update_status(payload, self.signal) # Send feedback that potentially reopens a signal (should not happen in this test). token = self.feedback.token data = { 'allows_contact': False, 'text': self.sa_reopens.text, 'is_satisfied': False, } response = self.client.put( '/forms/{}/'.format(token), data=data, format='json', ) self.assertEqual(response.status_code, 200) # Assert that nothing happened. self.signal.refresh_from_db() self.assertEqual(self.signal.status.state, workflow.HEROPEND) def test_no_reopen_requested_on_positive_feedback(self): """Positive feedback should never request a reopen""" # Create a positive feedback StandardAnswer that could possibly lead to # the status reopen requested. sa_positive = StandardAnswerFactory.create( text='Ik ben blij met de afhandeling.', is_satisfied=True, reopens_when_unhappy=True, ) status_id_before = self.signal.status.id with freeze_time(self.t_now): # Send feedback that potentially reopens a signal (should not happen in this test). token = self.feedback.token data = { 'allows_contact': False, 'text': sa_positive.text, 'is_satisfied': True, # should not be able to override, refactor into separate test } response = self.client.put( '/forms/{}/'.format(token), data=data, format='json', ) self.assertEqual(response.status_code, 200) # Assert that nothing happened. self.signal.refresh_from_db() self.assertEqual(self.signal.status.state, workflow.AFGEHANDELD) self.assertEqual(status_id_before, self.signal.status.id)
def setUp(self): now = timezone.now() self.reporter_1_email = '*****@*****.**' self.reporter_2_email = '*****@*****.**' self.test_category = CategoryFactory.create() stadhuis_point = Point(STADHUIS['lon'], STADHUIS['lat']) arena_point = Point(ARENA['lon'], ARENA['lat']) filmhuis_eye_point = Point(FILMMUSEUM_EYE['lon'], FILMMUSEUM_EYE['lat']) blauwe_theehuis_point = Point(BLAUWE_THEEHUIS['lon'], BLAUWE_THEEHUIS['lat']) with freeze_time(now - timedelta(days=5)): signal = SignalFactory.create(reporter__email=self.reporter_1_email, status__state=workflow.BEHANDELING, location__geometrie=stadhuis_point, location__buurt_code=STADHUIS['buurt_code'], category_assignment__category=self.test_category) FeedbackFactory.create(_signal=signal, submitted_at=now, is_satisfied=False) # Child signals ("deelmeldingen") should not show up in the reporter context, as they are used internally. self.child_signals = SignalFactory.create_batch(size=2, reporter__email=self.reporter_1_email, parent=signal, location__geometrie=stadhuis_point, location__buurt_code=ARENA['buurt_code'], category_assignment__category=self.test_category) with freeze_time(now - timedelta(days=4)): SignalFactory.create(reporter__email=self.reporter_1_email, status__state=workflow.BEHANDELING, location__geometrie=stadhuis_point, location__buurt_code=STADHUIS['buurt_code'], category_assignment__category=self.test_category) with freeze_time(now - timedelta(days=3)): signal = SignalFactory.create(reporter__email=self.reporter_1_email, status__state=workflow.AFGEHANDELD, location__geometrie=arena_point, location__area_code='arena', location__buurt_code=ARENA['buurt_code'], category_assignment__category=self.test_category) FeedbackFactory.create(_signal=signal, submitted_at=now, is_satisfied=False) SignalFactory.create(reporter__email=self.reporter_1_email, status__state=workflow.AFGEHANDELD, location__geometrie=filmhuis_eye_point, location__buurt_code=FILMMUSEUM_EYE['buurt_code'], category_assignment__category=self.test_category) signal = SignalFactory.create(reporter__email=self.reporter_1_email, status__state=workflow.AFGEHANDELD, location__geometrie=blauwe_theehuis_point, location__buurt_code=BLAUWE_THEEHUIS['buurt_code'], category_assignment__category=self.test_category) FeedbackFactory.create(_signal=signal, submitted_at=now, is_satisfied=True) self.reporter_1_signals = Signal.objects.filter( (Q(parent__isnull=True) & Q(children__isnull=True)) | Q(children__isnull=False), reporter__email=self.reporter_1_email ) self.anonymous_signals = [ SignalFactory.create(reporter__email=None, status__state=workflow.BEHANDELING, location__geometrie=filmhuis_eye_point, location__buurt_code=FILMMUSEUM_EYE['buurt_code'], category_assignment__category=self.test_category), SignalFactory.create(reporter__email='', status__state=workflow.BEHANDELING, location__geometrie=blauwe_theehuis_point, location__buurt_code=BLAUWE_THEEHUIS['buurt_code'], category_assignment__category=self.test_category) ] self.reporter_2_signals = SignalFactory.create_batch(size=5, reporter__email=self.reporter_2_email, location__geometrie=filmhuis_eye_point, location__buurt_code=FILMMUSEUM_EYE['buurt_code'], category_assignment__category=self.test_category)
def test_send_system_email_dry_run(self): action = MailService._system_actions.get('feedback_received')() signal = SignalFactory() feedback = FeedbackFactory.create(token=uuid.uuid4(), _signal=signal) self.assertTrue(action(signal=signal, dry_run=True, feedback=feedback))
class TestHistoryForFeedback(SignalsBaseApiTestCase, SIAReadUserMixin): def setUp(self): self.signal = SignalFactoryValidLocation() self.feedback = FeedbackFactory( _signal=self.signal, is_satisfied=None, ) self.feedback_endpoint = '/signals/v1/public/feedback/forms/{token}' self.history_endpoint = '/signals/v1/private/signals/{id}/history' def test_setup(self): self.assertEqual(Signal.objects.count(), 1) self.assertEqual(Feedback.objects.count(), 1) self.assertEqual(Feedback.objects.count(), 1) self.assertEqual(self.feedback.is_satisfied, None) self.assertEqual(self.feedback.submitted_at, None) def test_submit_feedback_check_history(self): # get a user privileged to read from API read_user = self.sia_read_user read_user.user_permissions.add( Permission.objects.get(codename='sia_can_view_all_categories')) self.client.force_authenticate(user=read_user) history_url = self.history_endpoint.format(id=self.signal.id) # check history before submitting feedback response = self.client.get(history_url) self.assertEqual(response.status_code, 200) response_data = response.json() self.assertEqual(len(response_data), 6) # Note the unhappy flow regarding feedback is tested in the feedback # app. Here we only check that it shows up in the history. url = self.feedback_endpoint.format(token=self.feedback.token) payload = { 'is_satisfied': True, 'allows_contact': False, 'text': 'De zon schijnt.', 'text_extra': 'maar niet heus', } response = self.client.put(url, data=payload, format='json') self.assertEqual(response.status_code, 200) # check that feedback object in db is updated self.feedback.refresh_from_db() self.assertEqual(self.feedback.is_satisfied, True) self.assertNotEqual(self.feedback.submitted_at, None) # check have an entry in the history for the feedback response = self.client.get(history_url) self.assertEqual(response.status_code, 200) response_data = response.json() self.assertEqual(len(response_data), 7) # check that filtering by RECEIVE_FEEDBACK works response = self.client.get(history_url + '?what=RECEIVE_FEEDBACK') self.assertEqual(response.status_code, 200) response_data = response.json() self.assertEqual(len(response_data), 1) def test_history_entry_description_property(self): # equivalent to submitting feedback: text = 'TEXT' text_extra = 'TEXT_EXTRA' self.feedback.is_satisfied = True self.feedback.allows_contact = False self.feedback.text = text self.feedback.text_extra = text_extra self.feedback.submitted_at = self.feedback.created_at + timedelta( days=1) self.feedback.save() # check the rendering read_user = self.sia_read_user read_user.user_permissions.add( Permission.objects.get(codename='sia_can_view_all_categories')) self.client.force_authenticate(user=read_user) history_url = self.history_endpoint.format(id=self.signal.id) response = self.client.get(history_url + '?what=RECEIVE_FEEDBACK') self.assertEqual(response.status_code, 200) response_data = response.json() self.assertEqual(len(response_data), 1) history_entry = response_data[0] self.assertIn('Ja, de melder is tevreden', history_entry['description']) self.assertIn(f'Waarom: {text}', history_entry['description']) self.assertIn(f'Toelichting: {text_extra}', history_entry['description']) self.assertIn('Toestemming contact opnemen: Nee', history_entry['description']) def test_history_no_permissions(self): """ The sia_read_user does not have a link with any department and also is not configured with the permission "sia_can_view_all_categories". Therefore it should not be able to see a Signal and it's history. """ self.client.force_authenticate(user=self.sia_read_user) response = self.client.get( self.history_endpoint.format(id=self.signal.id) + '?what=RECEIVE_FEEDBACK') self.assertEqual(response.status_code, 403)