def test_reopen_report(self): # New report response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post_citizen, follow=True) report = response.context['report'] comment = ReportComment(report_id=report.id, text='test', type=3) comment.save() # Set status to REFUSED report.status = Report.REFUSED report.save() # Login to access the pro page self.client.login(username='******', password='******') # Reopen reports url = reverse('report_reopen_pro', args=[report.id]) response = self.client.get(url) # Fetch activities activities = report.activities.all() # Assert self.assertEqual(activities.count(), 3) self.assertEquals(ReportEventLog.REOPEN, activities[2].event_type)
def test_reopen_report(self): # New report response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post, follow=True) report = response.context['report'] comment = ReportComment(report_id=report.id, text='test', type=3) comment.save() # Set status to REFUSED report.status = Report.REFUSED report.save() # Login to access the pro page self.client.login(username='******', password='******') # Clear mail outbox mail.outbox = [] # Reopen reports url = reverse('report_reopen_pro', args=[report.id]) response = self.client.get(url, follow=True) report = response.context['report'] # Assert self.assertEquals(Report.MANAGER_ASSIGNED, report.status) # No mail sent in real-time self.assertEquals(len(mail.outbox), 0)
def test_reopen_report_refused(self): url = "%s?x=148360&y=171177" % reverse('report_new') response = self.client.post(url, self.sample_post, follow=True) self.assertEqual(response.status_code, 200) report = response.context['report'] comment = ReportComment(report_id=report.id, text='test', type=3) comment.save() report.status = Report.REFUSED report.save() self.client.login(username='******', password='******') url = reverse('report_reopen_pro', args=[report.id]) response = self.client.get(url, follow=True) self.assertEqual(response.status_code, 200) report_reopen = response.context['report'] self.assertEqual(Report.MANAGER_ASSIGNED, report_reopen.status) self.assertNotEqual(report.status , report_reopen.status) self.assertEqual(report.created , report_reopen.created) self.assertEqual(report.close_date , report_reopen.close_date) # accepted_at need to be initialized self.assertFalse(report.accepted_at) self.assertTrue(report_reopen.accepted_at) self.assertEqual(report.subscriptions.all().count(), report_reopen.subscriptions.all().count()) self.assertEqual(report.responsible_entity , report_reopen.responsible_entity) self.assertEqual(report.responsible_department , report_reopen.responsible_department)
def testReopenRequestOnlyForProcessed(self): # New report response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post, follow=True) report = response.context['report'] comment = ReportComment(report_id=report.id, text='test', type=3) comment.save() # Set status to REFUSED (we want a status different that report.status = Report.REFUSED report.close_date = datetime.now() report.save() # Request reopen report response = self.client.post(reverse('report_reopen_request', args=["hello", report.id]), self.sample_post_reopen_request, follow=True) url = reverse('report_show', args=[report.get_slug(), report.id]) self.assertRedirects(response, url, status_code=302, target_status_code=200) error_msg = str(list(response.context["messages"])[0]) self.assertEqual(error_msg, gettext(ERROR_MSG_REOPEN_REQUEST_ONLY_CLOSED)) # Fetch activities activities = report.activities.all() # Assert self.assertEqual(activities.count(), 2) self.assertEquals(ReportEventLog.REFUSE, activities[1].event_type) #this can't be ReportEventLog.REOPEN_REQUEST
def _add_comment(self, context): context["action_msg"] = context["action_msg"].format(third_party=self._third_party.name) formatted_comment = render_to_string("webhooks/report_comment.txt", context) fms_user = FMSUser.objects.get(pk=self._user.id) comment = ReportComment( report=self._report, text=formatted_comment, type=ReportAttachment.DOCUMENTATION, created_by=fms_user ) comment.save()
def saveComments(cls, session, report): if 'comments' in session: commentsData = session['comments'] for comment in commentsData: c = ReportComment(text=comment['text'], report=report) c.created_by = report.created_by c.save() del session['comments']
def handle_request(request, report_id, action): try: if not request.method == "POST": payload = {"message": "{0} error. Bad request method".format(action)} return HttpResponseBadRequest(json.dumps(payload), mimetype="application/json") # if not fms_proxy_signature_is_valid(request): # payload = {"message": "{0} error. Invalid signature"} # return HttpResponseForbidden(json.dumps(payload), mimetype="application/json") report = get_object_or_404(Report, id=report_id) data = json.loads(request.body) application = data.get("application") comment_text = data.get("comment") reference_id = data.get("reference_id") org_entity = report.get_organisation_entity_with_fms_proxy() if not (report.waiting_for_organisation_entity() and org_entity.fmsproxy.slug.lower() == application.lower()): payload = {"message": "{0} error. Cannot {0} report with id : ".format(action) + report_id} return HttpResponseForbidden(json.dumps(payload), mimetype="application/json") params = { "action_msg": get_action_msg(action), "contractor_name": org_entity.name, "fms_proxy_id": org_entity.fmsproxy.id, "reference_id": reference_id, "comment": comment_text, } formatted_comment = render_to_string("formatted_comment.txt", params) comment = ReportComment(report_id=report.id, text=formatted_comment, type=ReportAttachment.DOCUMENTATION) comment.save() if action == ACTION_REJECT and not report.contractor: report.responsible_department = ( ReportEventLog.objects.filter( report=report_id, organisation=report.responsible_entity, event_type=ReportEventLog.MANAGER_ASSIGNED ) .latest("event_at") .related_old ) report.responsible_entity = report.responsible_department.dependency report.status = Report.MANAGER_ASSIGNED report.save() elif action == ACTION_CLOSE and not report.contractor: report.close() payload = {"message": "{0} ok".format(action)} return HttpResponse(json.dumps(payload), mimetype="application/json") except: payload = {"message": "{0} error. Internal server error".format(action)} return HttpResponse(json.dumps(payload), mimetype="application/json", status=500)