Exemplo n.º 1
0
 def test_get_qos(self):
     a_type = ServiceType.objects.first()
     service = ServiceFactory(type=a_type)
     FeedbackFactory(service=service, delivered=True, quality=1)
     FeedbackFactory(service=service, delivered=True, quality=1)
     FeedbackFactory(service=service, delivered=True, quality=5)
     url = reverse('report-qos')
     rsp = self.get_with_token(url)
     self.assertEqual(OK, rsp.status_code)
     result = json.loads(rsp.content.decode('utf-8'))
     self.assertEqual(len(result), ServiceType.objects.all().count())
     for r in result:
         if r['number'] == a_type.number:
             # 1, 2, 3, 4, 5
             expected_totals = [
                 2,
                 0,
                 0,
                 0,
                 1,
             ]
         else:
             expected_totals = [
                 0,
                 0,
                 0,
                 0,
                 0,
             ]
         expected_labels = ['1', '2', '3', '4', '5']
         self.assertIn('totals', r)
         totals = r['totals']
         self.assertEqual([t['label_en'] for t in totals], expected_labels)
         self.assertEqual([t['total'] for t in totals], expected_totals)
Exemplo n.º 2
0
 def test_delivered_but_some_required_fields_missing(self):
     feedback = FeedbackFactory(delivered=True,
                                wait_time=None,
                                wait_time_satisfaction=None)
     with self.assertRaises(ValidationError) as e:
         feedback.full_clean()
     self.assertIn('wait_time', e.exception.message_dict)
     self.assertIn('wait_time_satisfaction', e.exception.message_dict)
Exemplo n.º 3
0
 def test_staff_sat_required_if_service_provided(self):
     example = FeedbackFactory(
         delivered=True,
         staff_satisfaction=None,
     )
     self.try_to_create_one_like(example, expected_status=BAD_REQUEST)
     example.staff_satisfaction = ''
     self.try_to_create_one_like(example, expected_status=BAD_REQUEST)
     example.staff_satisfaction = 3
     self.try_to_create_one_like(example, expected_status=CREATED)
Exemplo n.º 4
0
 def test_staff_sat_required_if_service_provided(self):
     example = FeedbackFactory(
         delivered=True,
         staff_satisfaction=None,
     )
     self.try_to_create_one_like(example, expected_status=BAD_REQUEST)
     example.staff_satisfaction = ''
     self.try_to_create_one_like(example, expected_status=BAD_REQUEST)
     example.staff_satisfaction = 3
     self.try_to_create_one_like(example, expected_status=CREATED)
Exemplo n.º 5
0
 def test_cannot_get_feedback(self):
     # Feedback is write-only
     feedback = FeedbackFactory()
     # `reverse` doesn't even work because there's no such URL defined anywhere
     # url = reverse('feedback-detail', args=[self.id])
     url = '/api/feedbacks/%d/' % feedback.pk
     rsp = self.client.get(url)
     self.assertEqual(NOT_FOUND, rsp.status_code, msg=rsp.content.decode('utf-8'))
Exemplo n.º 6
0
    def test_get_failure(self):
        a_type = ServiceType.objects.first()
        service = ServiceFactory(type=a_type)
        FeedbackFactory(service=service,
                        delivered=True,
                        non_delivery_explained='no')
        FeedbackFactory(service=service,
                        delivered=True,
                        non_delivery_explained='no')
        FeedbackFactory(service=service,
                        delivered=True,
                        non_delivery_explained='yes')
        url = reverse('report-failure')
        rsp = self.get_with_token(url)
        self.assertEqual(OK, rsp.status_code)
        result = json.loads(rsp.content.decode('utf-8'))
        self.assertEqual(len(result), ServiceType.objects.all().count())
        for r in result:
            if r['number'] == a_type.number:
                # 1, 2, 3, 4, 5
                expected_totals = [
                    2,
                    0,
                    0,
                    1,
                ]
            else:
                expected_totals = [
                    0,
                    0,
                    0,
                    0,
                ]
            field = Feedback._meta.get_field('non_delivery_explained')

            expected_labels = [str(label) for value, label in field.choices]
            self.assertIn('totals', r)
            totals = r['totals']
            self.assertEqual([t['label_en'] for t in totals], expected_labels)
            self.assertEqual([t['total'] for t in totals], expected_totals)
Exemplo n.º 7
0
 def test_get_wait_times(self):
     a_type = ServiceType.objects.first()
     service = ServiceFactory(type=a_type)
     FeedbackFactory(service=service, delivered=True, wait_time='lesshour')
     FeedbackFactory(service=service, delivered=True, wait_time='lesshour')
     FeedbackFactory(service=service, delivered=True, wait_time='more')
     url = reverse('report-wait-times')
     rsp = self.get_with_token(url)
     self.assertEqual(OK, rsp.status_code)
     result = json.loads(rsp.content.decode('utf-8'))
     self.assertEqual(len(result), ServiceType.objects.all().count())
     for r in result:
         if r['number'] == a_type.number:
             # less than hour, 1-2 days, 3-7 days, 1-2 weeks, more than 2 weeks
             expected_totals = [
                 2,
                 0,
                 0,
                 0,
                 1,
             ]
         else:
             expected_totals = [
                 0,
                 0,
                 0,
                 0,
                 0,
             ]
         expected_labels = [
             'Less than 1 hour', 'Up to 2 days', '3-7 days', '1-2 weeks',
             'More than 2 weeks'
         ]
         self.assertIn('totals', r)
         totals = r['totals']
         self.assertEqual([t['label_en'] for t in totals], expected_labels)
         self.assertEqual([t['total'] for t in totals], expected_totals)
Exemplo n.º 8
0
 def test_creating_feedback_sends_data_to_jira(self, mock_JIRA):
     for delivered in [False, True]:
         mock_JIRA.reset_mock()
         feedback = FeedbackFactory(
             service=self.test_service,
             delivered=delivered,
             difficulty_contacting='didntknow',
             extra_comments='I have a little dog',
         )
         jira_record = feedback.jira_records.get()
         self.assertEqual(jira_record.feedback, feedback)
         self.assertEqual('', jira_record.jira_issue_key)
         self.setup_issue_key(mock_JIRA)
         jira_project = 'XYZ'
         with override_settings(JIRA_FEEDBACK_PROJECT_KEY=jira_project):
             jira_record.do_jira_work()
         mock_JIRA.return_value.create_issue.assert_called_with(
             issuetype={'name': 'Task'},
             summary='Feedback about %s' % feedback.service.name_en,
             project={'key': jira_project},
             description=mock.ANY,
             duedate=mock.ANY,
         )
         description = mock_JIRA.return_value.create_issue.call_args[1]['description']
         self.assertIn(feedback.name, description)
         self.assertIn(feedback.nationality.name_en, description)
         self.assertIn(feedback.phone_number, description)
         self.assertIn(feedback.service.name_en, description)
         if delivered:
             self.assertIn('Quality', description)
             self.assertIn(feedback.get_wait_time_display(), description)
         else:
             self.assertNotIn('Quality', description)
             self.assertIn(feedback.get_non_delivery_explained_display(), description)
         self.assertIn('Did not know how to contact them', description)
         self.assertIn('I have a little dog', description)
Exemplo n.º 9
0
 def test_good_validation(self):
     # Factory ought to create a valid instance
     feedback = FeedbackFactory()
     feedback.full_clean()
Exemplo n.º 10
0
 def test_non_delivery_explanation(self):
     feedback = FeedbackFactory(delivered=False, non_delivery_explained=None)
     with self.assertRaises(ValidationError) as e:
         feedback.full_clean()
     self.assertIn('non_delivery_explained', e.exception.message_dict)
Exemplo n.º 11
0
 def test_other_difficulties(self):
     feedback = FeedbackFactory(difficulty_contacting='other', other_difficulties='')
     with self.assertRaises(ValidationError) as e:
         feedback.full_clean()
     self.assertIn('other_difficulties', e.exception.message_dict)
Exemplo n.º 12
0
 def test_delivered_but_some_required_fields_missing(self):
     feedback = FeedbackFactory(delivered=True, wait_time=None, wait_time_satisfaction=None)
     with self.assertRaises(ValidationError) as e:
         feedback.full_clean()
     self.assertIn('wait_time', e.exception.message_dict)
     self.assertIn('wait_time_satisfaction', e.exception.message_dict)
Exemplo n.º 13
0
 def test_good_validation(self):
     # Factory ought to create a valid instance
     feedback = FeedbackFactory()
     feedback.full_clean()
Exemplo n.º 14
0
 def test_create_undelivered_feedback(self):
     example = FeedbackFactory(delivered=False)
     self.try_to_create_one_like(example)
Exemplo n.º 15
0
 def test_other_difficulties(self):
     feedback = FeedbackFactory(difficulty_contacting='other',
                                other_difficulties='')
     with self.assertRaises(ValidationError) as e:
         feedback.full_clean()
     self.assertIn('other_difficulties', e.exception.message_dict)
Exemplo n.º 16
0
 def test_non_delivery_explanation(self):
     feedback = FeedbackFactory(delivered=False,
                                non_delivery_explained=None)
     with self.assertRaises(ValidationError) as e:
         feedback.full_clean()
     self.assertIn('non_delivery_explained', e.exception.message_dict)
Exemplo n.º 17
0
 def test_staff_sat_not_required_if_service_not_provided(self):
     example = FeedbackFactory(
         delivered=False,
         staff_satisfaction=None,
     )
     self.try_to_create_one_like(example)