Exemplo n.º 1
0
    def test_update_priority(self):
        #Test default value of priority set to 1
        new_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
        )
        new_report.save()
        self.assertEquals(new_report.gravity, 0)
        self.assertEquals(new_report.probability, 0)
        self.assertEquals(new_report.get_priority(), 0)
        self.client.login(username='******', password='******')

        #Test update report priority
        self.client.get(
            reverse("report_update_priority", args=[new_report.id]),
            {
                'gravity': '2',
                'probability': '4'
            })
        updated_report = Report.objects.get(id=new_report.id)
        self.assertEquals(updated_report.gravity, 2)
        self.assertEquals(updated_report.probability, 4)
        self.assertEquals(updated_report.get_priority(), 8)
Exemplo n.º 2
0
 def test_entity_surface_raise_exception_when_outside(self):
     report = Report(
         point=dict_to_point({"x": '0', "y": '0'}),
         postalcode=1000,
         address='my address',
         address_number='6h',
         secondary_category=self.secondary_category,
         category=self.category,
     )
     with self.assertRaises(Exception):
         report.save()
Exemplo n.º 3
0
    def test_entity_surface_owner_is_responsible(self):
        report = Report(
            point=dict_to_point({"x": '149776', "y": '170005'}),
            postalcode=1000,
            address='my address',
            address_number='6h',
            secondary_category=self.secondary_category,
            category=self.category,
        )
        report.save()

        self.assertEqual(report.responsible_entity, self.commune)
Exemplo n.º 4
0
    def test_regional_road_is_detected_on_border(self):
        report = Report(
            # this point is outside the polygon of 1m
            point=dict_to_point({"x": '149776', "y": '170026'}),
            postalcode=1000,
            address='my address',
            address_number='1',
            secondary_category=self.secondary_category,
            category=self.category,
        )
        report.save()

        self.assertTrue(report.address_regional)
Exemplo n.º 5
0
def filter_map(request):  # pylint: disable=W0613
    reports = Report.objects.all().visible().public().transform(DEFAULT_SRID).values("id", "status", "point")

    features = []
    for report in reports:
        # report.point.transform(DEFAULT_SRID)
        features.append({
            "type": "Feature",
            "properties": {
                "id": report["id"],
                # "type": report.get_status_for_js_map(),
                "type": Report.static_get_status_for_js_map(report["status"]),
                # "address": {
                #     "street": report.address,
                #     "number": report.address_number,
                #     "postalCode": report.postalcode,
                #     "city": report.get_address_commune_name(),
                # },
                # "categories": report.get_category_path(),
                # "photo": report.thumbnail,
                # "icons": report.get_icons_for_js_map(),
                # "url": reverse("report_show", args=[report.get_slug(), report.id]),
            },
            "geometry": {
                "type": "Point",
                "coordinates": [report["point"].x, report["point"].y]
            }
        })

    geo = {
        "type": "FeatureCollection",
        "features": features
    }
    geo_json = json.dumps(geo)
    return HttpResponse(geo_json, mimetype="application/json")
Exemplo n.º 6
0
    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.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()
Exemplo n.º 7
0
    def test_list_agent_reports(self):
        new_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',
            citizen=self.citizen
        )
        new_report.save()

        reports = Report.objects.all()

        # Agent has no report
        self.assertFalse(reports.responsible(self.agent))
Exemplo n.º 8
0
    def test_list_contractor_reports(self):
        new_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',
            citizen=self.citizen
        )
        new_report.contractor = self.bxl
        new_report.save()

        reports = Report.objects.all()

        # Contractor has reports
        self.assertTrue(reports.entity_responsible(self.contractor))
Exemplo n.º 9
0
    def testReportResponsibleAssignment(self):
        '''Test the assignment of a responsible when creating a report'''
        new_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": '170105'}),
            address_number='6h',
            created_by=self.manager_etterbeek
        )
        new_report.save()
        # when created by pro report is under responsibility of etterbeek, not bxl
        self.assertEquals(new_report.responsible_entity, self.etterbeek)

        new_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": '170105'}),
            address_number='6h',
            citizen=self.citizen
        )
        new_report.save()
        # when created by citizen, postalcode used for resonsible
        self.assertEquals(new_report.responsible_entity, self.bxl)
Exemplo n.º 10
0
 def test_dispatch_citizen(self):
     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',
         accepted_at=datetime.now()
     )
     self.report.save()
     self.assertEquals(self.report.responsible_entity, self.organisation)
     self.assertEquals(self.report.responsible_department, self.department)
Exemplo n.º 11
0
    def test_list_contractor_manager_reports(self):
        new_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',
            citizen=self.citizen
        )

        new_report.contractor = self.stib
        new_report.responsible_department = self.group
        new_report.save()

        new_report2 = 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.2'}),
            address_number='6',
            citizen=self.citizen
        )
        new_report2.responsible_department = self.group
        new_report2.save()

        reports = Report.objects.all()
        # Entity of contractor has 2 reports
        self.assertEquals(2, len(reports.entity_responsible(self.contractor_manager)))
        #contractor is responsible for 2 reports (1 as manager, 1 as contractor)
        self.assertEquals(2, len(reports.responsible(self.contractor_manager)))
Exemplo n.º 12
0
 def test_dispatch_pro(self):
     """
     when a report is created by a agent / manager / entity
     responsible entity is computed based on responsible entity from creator
     """
     self.client.login(username='******', password='******')
     self.report = Report(
         status=Report.CREATED,
         secondary_category=self.secondary_category,
         category=self.category,
         description='Just a test',
         postalcode=1090,
         address='my address',
         point=dict_to_point({"x": '149776', "y": '170005'}),
         address_number='6h',
         created_by=self.manager,
         accepted_at=datetime.now()
     )
     self.report.save()
     self.assertEquals(self.report.responsible_entity, self.organisation)
     self.assertEquals(self.report.responsible_department, self.department)
Exemplo n.º 13
0
    def test_list_entity_manager_reports(self):
        new_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',
            citizen=self.citizen
        )
        new_report.responsible_department = self.group
        new_report.save()

        reports = Report.objects.all()
        self.assertEquals(1, len(reports.entity_responsible(self.entity_manager)))
        self.assertEquals(1, len(reports.responsible(self.entity_manager)))

        new_report.responsible_department = self.group
        new_report.save()

        reports = Report.objects.all()
        self.assertEquals(1, len(reports.responsible(self.entity_manager)))
Exemplo n.º 14
0
    def test_regional_road_is_detected(self):
        report = Report(
            point=dict_to_point({"x": '149776', "y": '170005'}),
            postalcode=1000,
            address='my address',
            address_number='1',
            secondary_category=self.secondary_category,
            category=self.category,
        )
        report.save()

        self.assertTrue(report.address_regional)

        report = Report(
            point=dict_to_point({"x": '149776', "y": '170805'}),
            postalcode=1000,
            address='my address',
            address_number='1',
            secondary_category=self.secondary_category,
            category=self.category,
        )
        report.save()

        self.assertFalse(report.address_regional)
Exemplo n.º 15
0
class ExportPDFTest(SampleFilesTestCase):

    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.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()

    def test_pdf_attachment(self):
        response = self.client.get(reverse('report_pdf', args=[self.report.id]) + '?output=html', follow=True)
        self.assertEqual(response.status_code, 200)
        self.assertIn('comments', response.context)

        self.assertEqual(len(response.context['comments']), 1)
        self.assertEqual(response.context['comments'][0].text, 'test comment 2')
        self.assertEqual(response.context['privacy'], 'public')

    def test_attachment_private(self):
        self.assertTrue(self.client.login(username=self.manager_bxl.email, password='******'))

        response = self.client.get(reverse('report_pdf_pro', args=[self.report.id]) + '?output=html', follow=True)
        self.assertEqual(response.status_code, 200)
        self.assertTrue(hasattr(response.context['request'], 'fmsuser'))
        self.assertIn('comments', response.context)

        self.assertEqual(len(response.context['comments']), 2)
        self.assertEqual(response.context['comments'][0].text, 'test comment 1')
        self.assertEqual(response.context['comments'][1].text, 'test comment 2')
        self.assertEqual(response.context['privacy'], 'private')

    def test_show_attachment(self):
        response = self.client.get(reverse('report_show', kwargs={'report_id': self.report.id, 'slug': ''}), follow=True)
        self.assertEqual(response.status_code, 200)
        self.assertNotContains(response, 'test comment 1')
        self.assertContains(response, 'test comment 2')
        self.assertNotContains(response, 'test comment 3')

    def test_show_attachment_private(self):
        self.assertTrue(self.client.login(username=self.manager_bxl.email, password='******'))

        response = self.client.get(reverse('report_show_pro', kwargs={'report_id': self.report.id, 'slug': ''}), follow=True)
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, 'test comment 1')
        self.assertContains(response, 'test comment 2')
        self.assertNotContains(response, 'test comment 3')
Exemplo n.º 16
0
class UpdatesTest(FMSTestCase):

    def setUp(self):
        self.client = Client()

        self.secondary_category = ReportCategory.objects.all()[0]
        self.category = self.secondary_category.category_class

        self.organisation = OrganisationEntity.objects.get(pk=14)
        self.organisation2 = OrganisationEntity.objects.get(pk=15)

        self.group = OrganisationEntity(
            type="D",
            name_nl="Werken",
            name_fr="Travaux",
            phone="090987",
            dependency=self.organisation,
            email="*****@*****.**"
            )
        self.group.save()

        self.group_mail_config       = GroupMailConfig()
        self.group_mail_config.group = self.group
        self.group_mail_config.save()

        self.group2 = OrganisationEntity(
            type="D",
            name_nl="Werken2",
            name_fr="Travaux2",
            phone="090987",
            dependency=self.organisation2,
            email="*****@*****.**"
            )
        self.group2.save()

        self.group_mail_config2       = GroupMailConfig()
        self.group_mail_config2.group = self.group2
        self.group_mail_config2.save()

        self.manager = FMSUser(
            is_active=True,
            telephone="0123456789",
            last_used_language="fr",
            password='******',
            first_name="manager",
            last_name="manager",
            email="*****@*****.**",
            manager=True
        )
        self.manager.set_password('test')
        self.manager.organisation = self.organisation
        self.manager.save()

        self.manager2 = FMSUser(
            is_active=True,
            telephone="0123456789",
            last_used_language="fr",
            password='******',
            first_name="manager2",
            last_name="manager2",
            email="*****@*****.**",
            manager=True
        )
        self.manager2.set_password('test')
        self.manager2.organisation = self.organisation
        self.manager2.save()

        self.usergroupmembership = UserOrganisationMembership(user_id=self.manager.id, organisation_id=self.group.id, contact_user=True)
        self.usergroupmembership.save()

        self.usergroupmembership = UserOrganisationMembership(user_id=self.manager2.id, organisation_id=self.group2.id, contact_user=True)
        self.usergroupmembership.save()

        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,
            accepted_at=datetime.now()
        )
        self.report.save()

    def test_change_manager(self):
        """Tests manager change assigned to a report and test the view of it."""

        report = self.report
        report.responsible_department = self.group
        report.save()

        self.client.login(username='******', password='******')

        """Change manager department"""
        url = reverse('report_change_manager_pro', args=[report.id])
        response = self.client.get("{0}?manId=department_{1}".format(url, self.group2.id), follow=True)
        self.assertEqual(response.status_code, 200)

        self.assertIsNotNone(report.responsible_department)

        """Change manager entity"""
        url = reverse('report_change_manager_pro', args=[report.id])
        response = self.client.get(url+'?manId=entity_14', follow=True)
        self.assertEqual(response.status_code, 200)

        self.assertIsNotNone(report.responsible_department)

    def test_update_planned(self):
        self.client.login(username='******', password='******')

        date_planned = (datetime.now() + timedelta(days=1)).strftime("%m/%Y")
        url = '%s?date_planned=%s' % (reverse('report_planned_pro', args=[self.report.id]), date_planned)

        # Set as planned
        self.client.login(username='******', password='******')
        response = self.client.get(url, follow=True)
        report = response.context['report']

        self.assertTrue(report.is_planned())
        self.assertTrue(report.date_planned)

    def test_update_planned_max_date(self):
        self.client.login(username='******', password='******')

        max_date_planned = self.report.accepted_at + timedelta(days=450)
        url = '%s?date_planned=%s' % (reverse('report_planned_pro', args=[self.report.id]), max_date_planned.strftime("%m/%Y"))

        # Set as planned
        self.client.login(username='******', password='******')
        response = self.client.get(url, follow=True)
        report = response.context['report']

        self.assertFalse(report.is_planned())
        self.assertFalse(report.date_planned)

    def test_update_planned_min_date(self):
        self.client.login(username='******', password='******')

        min_date_planned = self.report.accepted_at - timedelta(days=366)
        url = '%s?date_planned=%s' % (reverse('report_planned_pro', args=[self.report.id]), min_date_planned.strftime("%m/%Y"))

        # Set as planned
        self.client.login(username='******', password='******')
        response = self.client.get(url, follow=True)
        report = response.context['report']

        self.assertFalse(report.is_planned())
        self.assertFalse(report.date_planned)

    def test_update_planned_not_accepted(self):
        self.client.login(username='******', password='******')

        self.report.accepted_at = None
        self.report.save()

        date_planned = (datetime.now() + timedelta(days=1)).strftime("%m/%Y")
        url = '%s?date_planned=%s' % (reverse('report_planned_pro', args=[self.report.id]), date_planned)

        # Set as planned
        self.client.login(username='******', password='******')
        response = self.client.get(url, follow=True)
        report = response.context['report']

        self.assertFalse(report.is_planned())
        self.assertFalse(report.date_planned)

    def test_update_planned_no_date_planned(self):
        self.client.login(username='******', password='******')

        self.report.accepted_at = None
        self.report.save()

        url = reverse('report_planned_pro', args=[self.report.id])

        # Set as planned
        self.client.login(username='******', password='******')
        response = self.client.get(url, follow=True)
        report = response.context['report']

        self.assertFalse(report.is_planned())
        self.assertFalse(report.date_planned)

    def test_update_planned_change(self):
        self.client.login(username='******', password='******')

        first_date_planned = datetime.now()

        self.report.date_planned = first_date_planned
        self.report.save()

        date_planned = datetime.now() + timedelta(days=1)
        url = '%s?date_planned=%s' % (reverse('report_planned_pro', args=[self.report.id]), date_planned.strftime("%m/%Y"))

        # Set as planned
        self.client.login(username='******', password='******')
        response = self.client.get(url, follow=True)
        report = response.context['report']

        self.assertTrue(report.is_planned())
        self.assertEqual(date_planned.strftime("%m/%Y"), report.date_planned.strftime("%m/%Y"))
        self.assertNotEqual(first_date_planned, report.date_planned)

    def test_update_planned_unauth(self):
        url = reverse('report_planned_pro', args=[self.report.id])

        # Set as planned without auth raise an error by accessing report in context
        response = self.client.get(url, follow=True)
        self.assertRaises(KeyError, lambda: response.context['report'])

    def test_update_priority(self):
        #Test default value of priority set to 1
        new_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
        )
        new_report.save()
        self.assertEquals(new_report.gravity, 0)
        self.assertEquals(new_report.probability, 0)
        self.assertEquals(new_report.get_priority(), 0)
        self.client.login(username='******', password='******')

        #Test update report priority
        self.client.get(
            reverse("report_update_priority", args=[new_report.id]),
            {
                'gravity': '2',
                'probability': '4'
            })
        updated_report = Report.objects.get(id=new_report.id)
        self.assertEquals(updated_report.gravity, 2)
        self.assertEquals(updated_report.probability, 4)
        self.assertEquals(updated_report.get_priority(), 8)

    @skip("no more available")
    def test_previous_reports(self):
        self.client.login(username='******', password='******')
        manager2 = FMSUser(
            telephone="0123456789",
            last_used_language="fr",
            password='******',
            first_name="manager2",
            last_name="manager2",
            email="*****@*****.**",
            manager=True
        )
        manager2.set_password('test')
        manager2.organisation = self.organisation
        manager2.save()
        managerId = "manager_%s" % (manager2.id)
        self.client.post(reverse("report_change_manager_pro", args=[self.report.id])+"?manId="+managerId)
        self.assertEquals(len(self.manager.previous_reports.all()), 1)
        self.assertEquals(self.manager.previous_reports.all()[0].id, self.report.id)
        self.assertEquals(len(self.manager.reports_in_charge.all()), 0)

    def test_update_visibility(self):
        #Test switch to public and back
        self.client.login(username='******', password='******')
        self.client.get(
            reverse("report_change_switch_privacy", args=[self.report.id]),
            {"privacy": "true"})
        self.assertTrue(Report.objects.get(id=self.report.id).private)
        self.client.get(
            reverse("report_change_switch_privacy", args=[self.report.id]),
            {"privacy": "false"})
        self.assertFalse(self.report.private)

        #Test constraint: cannot turn report public if category is private

        #Turn report private
        self.client.get(reverse("report_change_switch_privacy", args=[self.report.id])+"?privacy=true")

        #Change category to private one
        report = Report.objects.get(id=self.report.id)
        report.secondary_category = ReportCategory.objects.get(id=4)
        report.save()
        #Try to set report to public
        self.client.get(reverse("report_change_switch_privacy", args=[self.report.id])+"?privacy=false")
        #Report not set to public because private category
        self.assertTrue(Report.objects.get(id=self.report.id).private)

    def test_false_address(self):
        self.client.login(username='******', password='******')

        url = reverse("report_false_address", args=[self.report.id])
        post_data = {'false_address': 'This is a false address'}
        response = self.client.post(url, post_data, follow=True)
        report = Report.objects.get(id=self.report.id)

        self.assertEquals(response.status_code, 200)
        self.assertEqual(report.false_address, post_data['false_address'])

        post_data = {'false_address': 'Another false address'}
        response = self.client.post(url, post_data, follow=True)

        report = Report.objects.get(id=self.report.id)
        self.assertEquals(response.status_code, 200)
        self.assertEqual(report.false_address, post_data['false_address'])
Exemplo n.º 17
0
class DispatchingTest(FMSTestCase):

    def setUp(self):
        self.client = Client()

        self.secondary_category = ReportCategory.objects.all()[0]
        self.category = self.secondary_category.category_class

        self.organisation = OrganisationEntity.objects.get(pk=4)
        self.department = OrganisationEntity(
            type="D",
            name_nl="Werken",
            name_fr="Travaux",
            phone="090987",
            dependency=self.organisation,
            email="*****@*****.**"
        )
        self.department.save()

        self.group_mail_config       = GroupMailConfig()
        self.group_mail_config.group = self.department
        self.group_mail_config.save()

        p1 = (148776, 171005)
        p2 = (150776, 171005)
        p3 = (150776, 169005)
        p4 = (148776, 169005)

        surface = OrganisationEntitySurface(
            geom=Polygon([p1, p2, p3, p4, p1]),
            owner=self.organisation,
        )
        surface.save()

        self.manager = FMSUser(
            is_active=True,
            telephone="0123456789",
            last_used_language="fr",
            password='******',
            first_name="manager",
            last_name="manager",
            email="*****@*****.**",
            manager=True
        )
        self.manager.set_password('test')
        self.manager.organisation = self.organisation
        self.manager.save()
        self.department.dispatch_categories.add(self.secondary_category)

        self.usergroupmembership = UserOrganisationMembership(user=self.manager, organisation=self.department, contact_user=True)
        self.usergroupmembership.save()

        self.applicant_group = OrganisationEntity(
            type="A",
            name_nl="Belgacom",
            name_fr="Belgacom",
            phone="090987",
            email="*****@*****.**"
        )
        self.applicant_group.save()

        self.applicant = FMSUser(
            is_active=True,
            telephone="0123456789",
            last_used_language="fr",
            password='******',
            first_name="manager",
            last_name="manager",
            email="*****@*****.**",
            manager=True
        )
        self.applicant.set_password('test')
        self.applicant.save()

        self.applicantmembership = UserOrganisationMembership(user=self.applicant, organisation=self.applicant_group, contact_user=True)
        self.applicantmembership.save()

    def test_dispatch_pro(self):
        """
        when a report is created by a agent / manager / entity
        responsible entity is computed based on responsible entity from creator
        """
        self.client.login(username='******', password='******')
        self.report = Report(
            status=Report.CREATED,
            secondary_category=self.secondary_category,
            category=self.category,
            description='Just a test',
            postalcode=1090,
            address='my address',
            point=dict_to_point({"x": '149776', "y": '170005'}),
            address_number='6h',
            created_by=self.manager,
            accepted_at=datetime.now()
        )
        self.report.save()
        self.assertEquals(self.report.responsible_entity, self.organisation)
        self.assertEquals(self.report.responsible_department, self.department)

    def test_dispatch_applicant(self):
        """
        when a report is created by a applicant / contractor
        responsible entity is computed based on geography
        """
        self.client.login(username='******', 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.applicant,
            accepted_at=datetime.now()
        )
        self.report.save()
        self.assertEquals(self.report.responsible_entity, self.organisation)
        self.assertEquals(self.report.responsible_department, self.department)

    def test_dispatch_citizen(self):
        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',
            accepted_at=datetime.now()
        )
        self.report.save()
        self.assertEquals(self.report.responsible_entity, self.organisation)
        self.assertEquals(self.report.responsible_department, self.department)
Exemplo n.º 18
0
    def setUp(self):
        self.client = Client()

        self.secondary_category = ReportCategory.objects.all()[0]
        self.category = self.secondary_category.category_class

        self.organisation = OrganisationEntity.objects.get(pk=14)
        self.organisation2 = OrganisationEntity.objects.get(pk=15)

        self.group = OrganisationEntity(
            type="D",
            name_nl="Werken",
            name_fr="Travaux",
            phone="090987",
            dependency=self.organisation,
            email="*****@*****.**"
            )
        self.group.save()

        self.group_mail_config       = GroupMailConfig()
        self.group_mail_config.group = self.group
        self.group_mail_config.save()

        self.group2 = OrganisationEntity(
            type="D",
            name_nl="Werken2",
            name_fr="Travaux2",
            phone="090987",
            dependency=self.organisation2,
            email="*****@*****.**"
            )
        self.group2.save()

        self.group_mail_config2       = GroupMailConfig()
        self.group_mail_config2.group = self.group2
        self.group_mail_config2.save()

        self.manager = FMSUser(
            is_active=True,
            telephone="0123456789",
            last_used_language="fr",
            password='******',
            first_name="manager",
            last_name="manager",
            email="*****@*****.**",
            manager=True
        )
        self.manager.set_password('test')
        self.manager.organisation = self.organisation
        self.manager.save()

        self.manager2 = FMSUser(
            is_active=True,
            telephone="0123456789",
            last_used_language="fr",
            password='******',
            first_name="manager2",
            last_name="manager2",
            email="*****@*****.**",
            manager=True
        )
        self.manager2.set_password('test')
        self.manager2.organisation = self.organisation
        self.manager2.save()

        self.usergroupmembership = UserOrganisationMembership(user_id=self.manager.id, organisation_id=self.group.id, contact_user=True)
        self.usergroupmembership.save()

        self.usergroupmembership = UserOrganisationMembership(user_id=self.manager2.id, organisation_id=self.group2.id, contact_user=True)
        self.usergroupmembership.save()

        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,
            accepted_at=datetime.now()
        )
        self.report.save()