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, str(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 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 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 _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=self._comment_type, created_by=fms_user ) comment.save()
def set_description(self, report, row): description = "{} - {}: {}".format(self._get_pave_id(row), row[self.PAVE_CATEGORY_IDX], row[self.PAVE_SOLUTION_IDX]) comment = ReportComment(text=description, security_level=ReportComment.PRIVATE, report=report, created_by=self._get_pave_user()) comment.bypassNotification = True comment.save()
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), content_type="application/json") # if not fms_proxy_signature_is_valid(request): # payload = {"message": "{0} error. Invalid signature"} # return HttpResponseForbidden(json.dumps(payload), content_type="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), content_type="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), content_type="application/json") except: payload = {"message": "{0} error. Internal server error".format(action)} return HttpResponse(json.dumps(payload), content_type="application/json", status=500)
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=self._comment_type, created_by=fms_user) comment.save()
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 IN_PROGRESS (we want a status different that report.status = Report.IN_PROGRESS 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_show2', args=[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, str(gettext(ERROR_MSG_REOPEN_REQUEST_ONLY_CLOSED))) # Fetch activities activities = report.activities.all() # Assert self.assertEqual(activities.count(), 2) self.assertEquals(ReportEventLog.VALID, activities[1].event_type ) #this can't be ReportEventLog.REOPEN_REQUEST
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 setUp(self): self.bxl = OrganisationEntity.objects.get(id=4) self.manager_bxl = FMSUser(is_active=True, email="*****@*****.**", telephone="0123456789", last_used_language="fr", manager=True, organisation=self.bxl) self.manager_bxl.set_password('test') self.manager_bxl.save() self.group = OrganisationEntity(type="D", name_nl="Werken", name_fr="Travaux", phone="090987", dependency=self.bxl, email="*****@*****.**") self.group.save() self.group_mail_config = GroupMailConfig() self.group_mail_config.group = self.group self.group_mail_config.save() self.usergroupmembership = UserOrganisationMembership( user_id=self.manager_bxl.id, organisation_id=self.group.id, contact_user=True) self.usergroupmembership.save() self.citizen = FMSUser(email="*****@*****.**", telephone="0123456789", last_used_language="fr") self.citizen.save() self.secondary_category = ReportCategory.objects.all()[0] self.category = self.secondary_category.category_class self.client.login(username=self.manager_bxl.email, password='******') self.report = Report(status=Report.CREATED, secondary_category=self.secondary_category, category=self.category, description='Just a test', postalcode=1000, address='my address', point=dict_to_point({ "x": '149776', "y": '170005' }), address_number='6h', created_by=self.manager_bxl) self.report.save() self.report.attachments.add( ReportComment(text='test comment 1', security_level=ReportComment.PRIVATE)) self.client.logout() self.report.attachments.add( ReportComment(text='test comment 2', security_level=ReportComment.PUBLIC)) self.report.attachments.add( ReportComment(text='test comment 3', logical_deleted=True, security_level=ReportComment.PUBLIC)) self.client = Client()