Пример #1
0
def create_group(request,):
    can_edit = request.fmsuser.leader

    if request.method == "POST" and can_edit:
        group_form = GroupForm(request.POST)

        if group_form.is_valid():
            group = group_form.save(commit=False)
            group.dependency = request.fmsuser.organisation
            group.save()
            config = GroupMailConfig(group=group)
            config.save()

            messages.add_message(request, messages.SUCCESS, _("Group has been created successfully"))
            return HttpResponseRedirect(reverse('list_groups'))

    else:
        group_form = GroupForm()


    return render_to_response("pro/auth/group_create.html", {
        "group_form": group_form,
        "can_edit":  can_edit,
    }, context_instance=RequestContext(request))
Пример #2
0
class GeographicDispatchingTest(FMSTestCase):

    def setUp(self):
        '''
        Create organisations and surfaces
        '''

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

        self.region = OrganisationEntity(
            type=OrganisationEntity.REGION,
            name_nl="Region",
            name_fr="Region"
        )
        self.region.save()
        self.region_group = OrganisationEntity(
            type=OrganisationEntity.DEPARTMENT,
            name_nl="Werken",
            name_fr="Travaux",
            phone="090987",
            dependency=self.region,
            email="*****@*****.**"
        )
        self.region_group.save()

        self.region_group_mail_config       = GroupMailConfig()
        self.region_group_mail_config.group = self.region_group
        self.region_group_mail_config.save()

        self.commune = OrganisationEntity(
            name_nl="Commune",
            name_fr="Commune",
        )
        self.commune.save()
        self.commune_group = OrganisationEntity(
            type=OrganisationEntity.DEPARTMENT,
            name_nl="Werken",
            name_fr="Travaux",
            phone="090987",
            dependency=self.commune,
            email="*****@*****.**"
        )
        self.commune_group.save()
        self.commune_group.dispatch_categories.add(self.secondary_category)

        self.commune_group_mail_config       = GroupMailConfig()
        self.commune_group_mail_config.group = self.commune_group
        self.commune_group_mail_config.save()

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

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

        p1 = (149756, 169985)
        p2 = (149796, 169985)
        p3 = (149796, 170025)
        p4 = (149756, 170025)

        self.street_surface = StreetSurface(
            geom=Polygon([p1, p2, p3, p4, p1]),
            administrator=StreetSurface.REGION,
        )
        self.street_surface.save()

    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)

    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)


    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)


    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()
Пример #3
0
class GroupsTest(FMSTestCase):

    def setUp(self):
        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 = OrganisationEntity.objects.get(pk=14)
        self.manager.save()

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

        self.group1 = OrganisationEntity(
            name_fr="groupe1",
            name_nl="groep1",
            phone="00000000",
            email="*****@*****.**",
            type='D',
            dependency=OrganisationEntity.objects.get(pk=14)
        )
        self.group1.save()

        self.group_mail_config1       = GroupMailConfig()
        self.group_mail_config1.group = self.group1
        self.group_mail_config1.save()

        self.group2 = OrganisationEntity(
            name_fr="groupe2",
            name_nl="groep2",
            phone="00000000",
            email="*****@*****.**",
            type='D',
            dependency=OrganisationEntity.objects.get(pk=11)
        )
        self.group2.save()

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

        self.creategroup_post = {
            'name_fr': 'groupe3',
            'name_nl': 'groep3',
            'phone': '0000000000',
            'email': '*****@*****.**',
            'type': 'D',
            'notify_group': True
        }

        self.creategroup_post2 = {
            'name_fr': 'groupe4',
            'name_nl': 'groep4',
            'phone': '0000000000',
            'email': '*****@*****.**',
            'type': 'S',
            'notify_group': True
        }

        self.editgroup_post = {
            'name_fr': 'groupe1nouveau',
            'name_nl': 'groep1nieuw',
            'phone': '111111',
            'email': '*****@*****.**',
            'type': 'D',

            ### Mail Config ###
            'groupmailconfig-TOTAL_FORMS'   : u'1',
            'groupmailconfig-INITIAL_FORMS' : u'1',
            'groupmailconfig-MAX_NUM_FORMS' : u'1',

            'groupmailconfig-0-notify_group'      : True,
            'groupmailconfig-0-notify_members'    : True,
            'groupmailconfig-0-digest_created'    : True,
            'groupmailconfig-0-digest_inprogress' : True,
            'groupmailconfig-0-digest_closed'     : True,
            'groupmailconfig-0-digest_other'      : True,
        }
        self.editgroup_post2 = {
            'name_fr': 'groupe2nouveau',
            'name_nl': 'groep2nieuw',
            'phone': '2222222',
            'email': '*****@*****.**',
            'type': 'S',
        }

    def testListGroups(self):
        self.client.login(username='******', password='******')
        response = self.client.post(reverse('list_groups'), follow=True)
        self.assertEquals(response.status_code, 200)
        self.assertTrue('groups' in response.context)
        self.assertTrue('can_create' in response.context)
        can_create = response.context['can_create']
        #This user should not be able to create
        groups = response.context['groups']
        self.assertFalse(can_create)
        #now check that all groups are groups of organisation should only be group1 as the other is assigned to other entity

        #check to see only your groups is back enabled
        self.assertEquals(groups.count(), 1)
        self.assertEquals(self.group1, groups[0])
        #now do same test with leader user the result should be the same only can_create has to be true
        self.client.logout()
        self.client.login(username='******', password='******')
        response = self.client.post(reverse('list_groups'), follow=True)
        self.assertEquals(response.status_code, 200)
        self.assertTrue('groups' in response.context)
        self.assertTrue('can_create' in response.context)
        can_create = response.context['can_create']
        #This user should not be able to create
        groups = response.context['groups']
        self.assertTrue(can_create)
        #now check that all groups are groups of organisation should only be group1 as the other is assigned to other entity
        #test if the security to show only groups of your organisation is enabled
        self.assertEquals(groups.count(), 1)
        self.assertEquals(self.group1, groups[0])

    def testCreateGroups(self):
        self.client.login(username='******', password='******')
        response = self.client.post(reverse('create_group'), self.creategroup_post)
        self.assertEquals(response.status_code, 302)
        response = self.client.post(reverse('list_groups'), follow=True)

        #now check if we have 2 groups and that the 2nd is group3
        self.assertEquals(response.status_code, 200)
        self.assertTrue('groups' in response.context)
        self.assertTrue('can_create' in response.context)
        groups = response.context['groups']
        can_create = response.context['can_create']
        self.assertTrue(can_create)

        #check to see only your organisation's groups is enabled again also update the number of the element we get from the array
        self.assertEquals(groups.count(), 2)

        if groups[0].name_fr == 'groupe3':
            group = groups[0]
        else:
            group = groups[1]

        self.assertEquals(group.name_fr, 'groupe3')
        self.assertEquals(group.name_nl, 'groep3')
        self.assertEquals(group.phone, '0000000000')
        self.assertEquals(group.email, '*****@*****.**')
        self.assertEquals(group.type, 'D')
        self.assertEquals(group.dependency, self.leader.organisation)

        #now test create with user who is not leader
        self.client.logout()
        self.client.login(username='******', password='******')
        response = self.client.post(reverse('create_group'), self.creategroup_post2)
        self.assertEquals(response.status_code, 200)
        response = self.client.post(reverse('list_groups'), follow=True)

        #now check if we have 2 groups and that the 2nd is group3
        self.assertEquals(response.status_code, 200)
        self.assertTrue('groups' in response.context)
        self.assertTrue('can_create' in response.context)
        can_create = response.context['can_create']
        self.assertFalse(can_create)
        groups = response.context['groups']

        self.assertEquals(groups.count(), 2)

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

        self.editgroup_post['groupmailconfig-0-group'] = self.group1.id
        self.editgroup_post['groupmailconfig-0-id']    = self.group_mail_config1.id

        response = self.client.post(reverse('edit_group', args=[self.group1.id]), self.editgroup_post)
        self.assertEquals(response.status_code, 302)
        response = self.client.post(reverse('list_groups'), follow=True)

        #now check if we have 2 groups and that the 2nd is group3
        self.assertEquals(response.status_code, 200)
        self.assertTrue('groups' in response.context)
        self.assertTrue('can_create' in response.context)

        groups = response.context['groups']
        can_create = response.context['can_create']

        self.assertTrue(can_create)
        self.assertEquals(groups.count(), 1)
        self.assertEquals(groups[0].name_fr, 'groupe1nouveau')
        self.assertEquals(groups[0].name_nl, 'groep1nieuw')
        self.assertEquals(groups[0].phone, '111111')
        self.assertEquals(groups[0].email, '*****@*****.**')
        self.assertEquals(groups[0].type, 'D')
        self.assertEquals(groups[0].dependency, self.leader.organisation)

        #now do the test with a non leader
        self.client.logout()
        self.client.login(username='******', password='******')

        response = self.client.post(reverse('edit_group', args=[self.group1.id]), self.editgroup_post2)
        self.assertEquals(response.status_code, 200)
        response = self.client.post(reverse('list_groups'), follow=True)

        #now check if we have 1 group that depends of my organisation
        self.assertEquals(response.status_code, 200)
        self.assertTrue('groups' in response.context)
        self.assertTrue('can_create' in response.context)
        groups = response.context['groups']
        can_create = response.context['can_create']
        self.assertFalse(can_create)
        self.assertEquals(groups.count(), 1)

        #should still be the same as this user does not have the rights to update groups
        self.assertEquals(groups[0].name_fr, 'groupe1nouveau')
        self.assertEquals(groups[0].name_nl, 'groep1nieuw')
        self.assertEquals(groups[0].phone, '111111')
        self.assertEquals(groups[0].email, '*****@*****.**')
        self.assertEquals(groups[0].type, 'D')
        self.assertEquals(groups[0].dependency, self.leader.organisation)

    def testDeleteGroups(self):
        #first try to delete with user who has no permissions
        self.client.login(username='******', password='******')
        response = self.client.get(reverse('delete_group', args=[self.group1.id]), follow=True)
        self.assertEquals(response.status_code, 200)
        response = self.client.post(reverse('list_groups'), follow=True)

        #now check if we have 1 group that depends of my organisation
        self.assertEquals(response.status_code, 200)
        self.assertTrue('groups' in response.context)
        self.assertTrue('can_create' in response.context)
        groups = response.context['groups']
        can_create = response.context['can_create']
        self.assertFalse(can_create)
        self.assertEquals(groups.count(), 1)
        self.assertIn(self.group1, groups)

        self.client.logout()

        #now try to delete with user who can
        self.client.login(username='******', password='******')
        response = self.client.get(reverse('delete_group', args=[self.group1.id]), follow=True)
        self.assertEquals(response.status_code, 200)
        response = self.client.post(reverse('list_groups'), follow=True)

        #now check if we have 2 groups and that the 2nd is group3
        self.assertEquals(response.status_code, 200)
        self.assertTrue('groups' in response.context)
        self.assertTrue('can_create' in response.context)
        groups = response.context['groups']
        can_create = response.context['can_create']
        self.assertTrue(can_create)
        self.assertEquals(groups.count(), 1)  # not deleted, linked to categories
        self.assertGreater(groups[0].dispatch_categories.count(), 0)
        self.assertIn(self.group1, groups)

        group2 = OrganisationEntity(
            name_fr="group2",
            name_nl="group2",
            phone="00000000",
            email="*****@*****.**",
            type='D',
            dependency=OrganisationEntity.objects.get(pk=14)
        )
        group2.save()

        response = self.client.post(reverse('list_groups'), follow=True)
        self.assertEquals(response.status_code, 200)
        self.assertTrue('groups' in response.context)
        groups = response.context['groups']
        self.assertEquals(groups.count(), 2)
        self.assertEquals(group2.dispatch_categories.count(), 0)

        response = self.client.get(reverse('delete_group', args=[group2.id]), follow=True)
        self.assertEquals(response.status_code, 200)
        response = self.client.post(reverse('list_groups'), follow=True)

        #now check if we have 2 groups and that the 2nd is group3
        self.assertEquals(response.status_code, 200)
        self.assertTrue('groups' in response.context)
        groups = response.context['groups']
        self.assertEquals(groups.count(), 1)
        self.assertNotIn(group2, groups)

    def testAssignMemberToGroup(self):
        #first try to add with user who has not enough rights
        self.client.login(username='******', password='******')
        response = self.client.get(reverse('add_membership', args=[self.group1.id, self.manager.id]), follow=True)
        self.assertEquals(response.status_code, 200)
        returnobject = json.loads(str(response.content))
        self.assertTrue('status' in returnobject)
        self.assertFalse('membership_id' in returnobject)
        status = returnobject['status']
        self.assertEquals('Permission Denied', status)

        self.client.logout()
        self.client.login(username='******', password='******')
        response = self.client.get(reverse('add_membership', args=[self.group1.id, self.manager.id]), follow=True)
        self.assertEquals(response.status_code, 200)
        returnobject = json.loads(str(response.content))
        self.assertTrue('status' in returnobject)
        self.assertTrue('membership_id' in returnobject)
        status = returnobject['status']
        membership_id = returnobject['membership_id']
        self.assertEquals('OK', status)
        organisationMemberShip = UserOrganisationMembership.objects.get(id=membership_id)
        self.assertEquals(self.manager, organisationMemberShip.user)
        self.assertEquals(self.group1, organisationMemberShip.organisation)

    def testRemoveMemberFromGroup(self):
        #first assign a member to a group
        self.client.login(username='******', password='******')
        response = self.client.get(reverse('add_membership', args=[self.group1.id, self.manager.id]), follow=True)
        self.assertEquals(response.status_code, 200)
        returnobject = json.loads(str(response.content))
        self.assertTrue('status' in returnobject)
        self.assertTrue('membership_id' in returnobject)
        status = returnobject['status']
        membership1_id = returnobject['membership_id']
        self.assertEquals('OK', status)

        response = self.client.get(reverse('add_membership', args=[self.group1.id, self.leader.id]), follow=True)
        self.assertEquals(response.status_code, 200)
        returnobject = json.loads(str(response.content))
        self.assertTrue('status' in returnobject)
        self.assertTrue('membership_id' in returnobject)
        membership2_id = returnobject['membership_id']

        self.assertTrue(UserOrganisationMembership.objects.get(id=membership1_id).contact_user)
        self.assertFalse(UserOrganisationMembership.objects.get(id=membership2_id).contact_user)

        #try with user who has no rights to remove it
        self.client.logout()
        self.client.login(username='******', password='******')

        response = self.client.get(reverse('remove_membership', args=[membership1_id]), follow=True)
        self.assertEquals(response.status_code, 200)
        self.assertIn('Permission Denied', response.content)

        #now try with user who has rights to remove
        self.client.logout()
        self.client.login(username='******', password='******')

        response = self.client.get(reverse('remove_membership', args=[membership1_id]), follow=True)
        self.assertEquals(response.status_code, 200)
        self.assertNotIn('OK', response.content)  # can not remove contact membership

        response = self.client.get(reverse('remove_membership', args=[membership2_id]), follow=True)
        self.assertEquals(response.status_code, 200)
        self.assertIn('OK', response.content)

        self.assertTrue(UserOrganisationMembership.objects.filter(id=membership1_id).exists())
        self.assertFalse(UserOrganisationMembership.objects.filter(id=membership2_id).exists())
Пример #4
0
class MailTest(FMSTestCase):
    def setUp(self):
        self.citizen = FMSUser(telephone="0123456789",
                               last_used_language="fr",
                               first_name="citizen",
                               last_name="citizen",
                               email="*****@*****.**")
        self.citizen.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 = OrganisationEntity.objects.get(pk=14)
        self.manager.save()

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

        self.group = OrganisationEntity(
            type="D",
            name_nl="Werken",
            name_fr="Travaux",
            phone="090987",
            dependency=OrganisationEntity.objects.get(pk=14),
            email="*****@*****.**")
        self.group.save()
        self.group.dispatch_categories.add(ReportCategory.objects.get(pk=1))

        # Mail config: notify group and members in real time
        self.group_mail_config = GroupMailConfig()
        self.group_mail_config.group = self.group
        self.group_mail_config.notify_group = True
        self.group_mail_config.notify_members = True
        self.group_mail_config.save()

        self.manager.memberships.create(organisation=self.group,
                                        contact_user=True)
        self.manager4.memberships.create(organisation=self.group,
                                         contact_user=True)

        self.client = Client()

        self.manager2 = FMSUser(is_active=True,
                                telephone="9876543210",
                                last_used_language="nl",
                                password='******',
                                first_name="manager2",
                                last_name="manager2",
                                email="*****@*****.**",
                                manager=True)
        self.manager2.set_password('test2')
        self.manager2.organisation = OrganisationEntity.objects.get(pk=14)
        self.manager2.save()

        self.group2 = OrganisationEntity(
            type="D",
            name_nl="Werken",
            name_fr="Travaux",
            phone="090987",
            dependency=OrganisationEntity.objects.get(pk=21),
            email="*****@*****.**")
        self.group2.save()
        self.group2.dispatch_categories.add(ReportCategory.objects.get(pk=2))
        self.group2.dispatch_categories.add(ReportCategory.objects.get(pk=1))

        # Mail config: notify group and members in real time
        self.group_mail_config2 = GroupMailConfig()
        self.group_mail_config2.group = self.group2
        self.group_mail_config2.notify_group = True
        self.group_mail_config2.notify_members = True
        self.group_mail_config2.save()

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

        surface = OrganisationEntitySurface(
            geom=Polygon([p1, p2, p3, p4, p1]),
            owner=OrganisationEntity.objects.get(pk=14),
        )
        surface.save()

        self.manager2.memberships.create(organisation=self.group2)

        self.manager3 = FMSUser(is_active=True,
                                telephone="000000000",
                                last_used_language="nl",
                                password='******',
                                first_name="manager3",
                                last_name="manager3",
                                email="*****@*****.**",
                                manager=True)
        self.manager3.set_password('test3')
        self.manager3.organisation = OrganisationEntity.objects.get(pk=21)
        self.manager3.save()

        self.manager3.memberships.create(organisation=self.group2)

        self.impetrant = OrganisationEntity(name_nl="MIVB",
                                            name_fr="STIB",
                                            email="*****@*****.**")

        self.impetrant.save()

        self.contractor = OrganisationEntity(name_nl="Fabricom GDF",
                                             name_fr="Fabricom GDF",
                                             email="*****@*****.**")
        self.contractor.save()

        self.sample_post = {
            'report-x': '150056.538',
            'report-y': '170907.56',
            'report-address_fr': 'Avenue des Arts, 3',
            'report-address_nl': 'Kunstlaan, 3',
            'report-address_number': '3',
            'report-postalcode': '1210',
            'report-category': '1',
            'report-secondary_category': '1',
            'report-subscription': 'on',
            'citizen-quality': '1',
            'comment-text': 'test',
            'files-TOTAL_FORMS': 0,
            'files-INITIAL_FORMS': 0,
            'files-MAX_NUM_FORMS': 0,
            'citizen-email': self.citizen.email,
            'citizen-firstname': self.citizen.first_name,
            'citizen-lastname': self.citizen.last_name,
            'report-terms_of_use_validated': True
        }

        self.sample_post_pro = {
            'report-x': '150056.538',
            'report-y': '170907.56',
            'report-address_fr': 'Avenue des Arts, 3',
            'report-address_nl': 'Kunstlaan, 3',
            'report-address_number': '3',
            'report-postalcode': '1210',
            'report-category': '1',
            'report-secondary_category': '1',
            'report-subscription': 'on',
            'comment-text': 'test',
            'files-TOTAL_FORMS': 0,
            'files-INITIAL_FORMS': 0,
            'files-MAX_NUM_FORMS': 0,
            'report-terms_of_use_validated': True
        }

        self.sample_post_mail_pdf_pro = {
            'comments': 'test comment',
            'visibility': 'private',
            'to': '[email protected],[email protected];[email protected]'
        }

        self.sample_post_mail_pdf_citzen = {
            'comments': 'test comment',
            'visibility': 'public',
            'to': '[email protected],[email protected];[email protected]'
        }

    def test_create_report_mail(self):
        # Send a post request filling in the form to create a report
        response = self.client.post(reverse('report_new') +
                                    '?x=150056.538&y=170907.56',
                                    self.sample_post,
                                    follow=True)

        # Mails are sent to responsibles according to mail config of the group: 1 for group + members
        expected_recipients = self.group_mail_config.get_manager_recipients()

        # 1 more mail is sent to creator in real time
        expected_recipients.append(self.citizen.email)

        self.assertTrue(mail.outbox)
        self.assertEquals(len(mail.outbox), len(expected_recipients))

        for email in mail.outbox:
            self.assertIn(email.to[0], expected_recipients)

    def test_close_report_mail(self):
        # Send a post request filling in the form to create a report
        response = self.client.post(reverse('report_new') +
                                    '?x=150056.538&y=170907.56',
                                    self.sample_post,
                                    follow=True)
        report = response.context['report']

        report = response.context['report']
        report.accepted_at = datetime.now()
        report.save()

        # Reset outbox
        mail.outbox = []

        # Close the report
        self.client.login(username='******', password='******')
        response = self.client.get(reverse('report_close_pro',
                                           args=[report.id]),
                                   follow=True)

        report = Report.objects.get(id=report.id)

        self.assertEquals(report.status, Report.PROCESSED)

        # One mail is sent in real time to the creator if citizen. All others are digest to subscribers.
        self.assertEquals(len(mail.outbox), 1)
        self.assertIn(self.citizen.email, mail.outbox[0].to)

    def test_refuse_report_mail(self):
        # Send a post request filling in the form to create a report
        response = self.client.post(reverse('report_new') +
                                    '?x=150056.538&y=170907.56',
                                    self.sample_post,
                                    follow=True)
        report = response.context['report']

        # Reset outbox
        mail.outbox = []

        # Login to access the pro page to create a user
        self.client.login(username='******', password='******')

        # Refuse the created report
        refused_url = reverse('report_refuse_pro', args=[report.id])
        refused_params = {'text': 'more info'}
        response = self.client.post(refused_url, refused_params, follow=True)

        report = Report.objects.get(id=report.id)

        # The status of the report must now be REFUSED
        self.assertEquals(report.status, Report.REFUSED)

        # All mail are sent as digest to subscribers
        self.assertEquals(len(mail.outbox), 1)

    def test_subscription_for_citizen_mail(self):
        # Send a post request filling in the form to create a report
        response = self.client.post(reverse('report_new') +
                                    '?x=150056.538&y=170907.56',
                                    self.sample_post,
                                    follow=True)
        report = response.context['report']

        # Reset outobox
        mail.outbox = []

        # Send a post request subscribing a citizen to the just created report
        subscribe_url = reverse('subscribe', args=[report.id])
        subscribe_email = '*****@*****.**'
        subscribe_params = {'citizen_email': subscribe_email}
        response = self.client.post(subscribe_url,
                                    subscribe_params,
                                    follow=True)

        # 1 mail sent in real-time to subscriber
        self.assertEquals(len(mail.outbox), 1)
        self.assertTrue(subscribe_email in mail.outbox[0].to)

    def test_mark_report_as_done_mail(self):
        # Send a post request filling in the form to create a report
        response = self.client.post(reverse('report_new') +
                                    '?x=150056.538&y=170907.56',
                                    self.sample_post,
                                    follow=True)
        report = response.context['report']

        # Login to access the pro page
        self.client.login(username='******', password='******')

        # Publish the created report
        response = self.client.post(reverse('report_accept_pro',
                                            args=[report.id]),
                                    follow=True)

        # Reset outbox
        mail.outbox = []

        # Send a post request to mark the report as done
        update_url = reverse('report_fix_pro', args=[report.id])
        update_params = {'text': 'My comment'}
        response = self.client.post(update_url, update_params)

        # Mails are sent to responsibles according to mail config of the group: 1 for group + members without the author
        expected_recipients = self.group_mail_config.get_manager_recipients(
            self.manager)

        self.assertTrue(mail.outbox)
        self.assertEquals(len(mail.outbox), len(expected_recipients))

        for email in mail.outbox:
            self.assertIn(email.to[0], expected_recipients)

    def test_accept_report_mail(self):
        # Send a post request filling in the form to create a report
        response = self.client.post(reverse('report_new') +
                                    '?x=150056.538&y=170907.56',
                                    self.sample_post,
                                    follow=True)
        report = response.context['report']

        # Reset outbox
        mail.outbox = []

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

        url = reverse('report_accept_pro', args=[report.id])
        response = self.client.get(url, follow=True)

        # All mails are sent to subscribers as digest
        self.assertEquals(len(mail.outbox), 0)

    def test_planned_report_mail(self):
        # Send a post request filling in the form to create a report
        response = self.client.post(reverse('report_new') +
                                    '?x=150056.538&y=170907.56',
                                    self.sample_post,
                                    follow=True)

        report = response.context['report']
        report.accepted_at = datetime.now()
        report.save()

        # Reset outbox
        mail.outbox = []

        # Set as planned
        date_planned = (datetime.now() + timedelta(days=1)).strftime("%m/%Y")
        url = '%s?date_planned=%s' % (reverse('report_planned_pro',
                                              args=[report.id]), date_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, report.date_planned.strftime("%m/%Y"))

        # Only digest are sent to subscribers
        self.assertEquals(len(mail.outbox), 0)

        # Planned another date
        date_planned = (datetime.now() + timedelta(days=40)).strftime("%m/%Y")
        url = '%s?date_planned=%s' % (reverse('report_planned_pro',
                                              args=[report.id]), date_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, report.date_planned.strftime("%m/%Y"))

        # Only digest are sent to subscribers
        self.assertEquals(len(mail.outbox), 0)

    def test_create_report_as_pro_mail(self):
        # Create a report
        self.client.login(username='******', password='******')
        response = self.client.post(reverse('report_new_pro') +
                                    '?x=150056.538&y=170907.56',
                                    self.sample_post_pro,
                                    follow=True)

        # Mails are sent to responsibles according to mail config of the group: 1 for group + members without the author
        expected_recipients = self.group_mail_config.get_manager_recipients(
            self.manager)

        self.assertTrue(mail.outbox)
        self.assertEquals(len(mail.outbox), len(expected_recipients))

        for email in mail.outbox:
            self.assertIn(email.to[0], expected_recipients)

    def test_report_resolved_as_pro_mail(self):
        response = self.client.post(reverse('report_new') +
                                    '?x=150056.538&y=170907.56',
                                    self.sample_post,
                                    follow=True)
        report_id = response.context['report'].id

        # Login to access the pro page
        self.client.login(username='******', password='******')

        # Publish the created report
        response = self.client.post(reverse('report_accept_pro',
                                            args=[report_id]),
                                    follow=True)
        self.assertEquals(response.status_code, 200)

        # Clear outbox
        mail.outbox = []

        params = {'text': 'Ceci est un commentaire'}
        response = self.client.post(reverse('report_fix_pro',
                                            args=[report_id]),
                                    params,
                                    follow=True)

        self.assertEquals(response.status_code, 200)
        self.assertEquals(
            Report.objects.get(id=report_id).status, Report.SOLVED)

        # Mails are sent to responsibles according to mail config of the group: 1 for group + members without the author
        expected_recipients = self.group_mail_config.get_manager_recipients(
            self.manager)

        self.assertTrue(mail.outbox)
        self.assertEquals(len(mail.outbox), len(expected_recipients))

        for email in mail.outbox:
            self.assertIn(email.to[0], expected_recipients)

    def test_assign_to_other_member_of_same_entity_mail(self):
        response = self.client.post(reverse('report_new') +
                                    '?x=150056.538&y=170907.56',
                                    self.sample_post,
                                    follow=True)
        report = response.context['report']

        # Login to access the pro page
        self.client.login(username='******', password='******')

        # Publish the created report
        response = self.client.post(reverse('report_accept_pro',
                                            args=[report.id]),
                                    follow=True)

        # Restet outbox
        mail.outbox = []

        # Change manager in the same entity
        response = self.client.post(
            reverse('report_change_manager_pro', args=[report.id]), {
                'man_id': 'department_' + str(self.group2.id),
                'transfer': 0
            },
            follow=True)

        # Mails are sent to responsibles according to mail config of the group: 1 for group + members
        expected_recipients = self.group_mail_config2.get_manager_recipients()

        self.assertTrue(mail.outbox)
        self.assertEquals(len(mail.outbox), len(expected_recipients))

        for email in mail.outbox:
            self.assertIn(email.to[0], expected_recipients)

    def test_assign_to_another_entity_mail(self):
        response = self.client.post(reverse('report_new') +
                                    '?x=150056.538&y=170907.56',
                                    self.sample_post,
                                    follow=True)
        report = response.context['report']

        # Login to access the pro page
        self.client.login(username='******', password='******')

        # Publish the created report
        response = self.client.post(reverse('report_accept_pro',
                                            args=[report.id]),
                                    follow=True)

        # Restet outbox
        mail.outbox = []

        # Change to another entity
        response = self.client.post(reverse('report_change_manager_pro',
                                            args=[report.id]), {
                                                "man_id": "entity_21",
                                                "transfer": 0
                                            },
                                    follow=True)

        # Mails are sent to responsibles according to mail config of the group: 1 for group + members
        expected_recipients = self.group_mail_config2.get_manager_recipients()

        self.assertTrue(mail.outbox)
        self.assertEquals(len(mail.outbox), len(expected_recipients))

        for email in mail.outbox:
            self.assertIn(email.to[0], expected_recipients)

    def test_assign_to_impetrant_mail(self):
        response = self.client.post(reverse('report_new') +
                                    '?x=150056.538&y=170907.56',
                                    self.sample_post,
                                    follow=True)
        report = response.context['report']

        # Add a worker for this entity
        worker = FMSUser(email="*****@*****.**", telephone="0123456789")
        worker.save()
        worker.memberships.create(organisation=self.impetrant)

        # Login to access the pro page
        self.client.login(username='******', password='******')

        # Publish the created report
        response = self.client.post(reverse('report_accept_pro',
                                            args=[report.id]),
                                    follow=True)

        # Reset outbox
        mail.outbox = []

        # Assign to another impetrant
        response = self.client.get(
            reverse('report_change_contractor_pro', args=[report.id]) +
            '?contractorId=' + str(self.impetrant.id), {},
            follow=True)

        # 1 mail sent in real time to impetrant
        self.assertEquals(len(mail.outbox), 1)
        self.assertIn(self.impetrant.email, mail.outbox[0].to)

    def test_assign_to_contractor_mail(self):
        response = self.client.post(reverse('report_new') +
                                    '?x=150056.538&y=170907.56',
                                    self.sample_post,
                                    follow=True)

        report = response.context['report']
        report.accepted_at = datetime.now()
        report.save()

        # Add a worker for this entity
        worker = FMSUser(email="*****@*****.**", telephone="0123456789")
        worker.save()
        worker.memberships.create(organisation=self.contractor)

        # Reset outbox
        mail.outbox = []

        self.client.login(username='******', password='******')
        response = self.client.get(
            reverse('report_change_contractor_pro', args=[report.id]) +
            '?contractorId=' + str(self.contractor.id), {},
            follow=True)

        # 1 mail sent in real time to contractor
        self.assertEquals(len(mail.outbox), 1)
        self.assertIn(self.contractor.email, mail.outbox[0].to)

    def test_citizen_updates_report_mail(self):
        response = self.client.post(reverse('report_new') +
                                    '?x=150056.538&y=170907.56',
                                    self.sample_post,
                                    follow=True)

        report = response.context['report']
        report.accepted_at = datetime.now()
        report.save()

        # Reset outbox
        mail.outbox = []

        # A citizen documents a report
        response = self.client.post(reverse('report_document',
                                            kwargs={
                                                'report_id': report.id,
                                                'slug': 'hello'
                                            }),
                                    {
                                        'comment-text': 'new created comment',
                                        'citizen-email': self.citizen.email,
                                        'citizen-quality': 1,
                                        'files-TOTAL_FORMS': 0,
                                        'files-INITIAL_FORMS': 0,
                                        'files-MAX_NUM_FORMS': 0
                                    },
                                    follow=True)

        report = response.context['report']

        # Mails are sent to responsibles according to mail config of the group: 1 for group + members
        expected_recipients = self.group_mail_config.get_manager_recipients()

        self.assertTrue(mail.outbox)
        self.assertEquals(len(mail.outbox), len(expected_recipients))

        for email in mail.outbox:
            self.assertIn(email.to[0], expected_recipients)

    def test_pro_updates_report_mail(self):
        response = self.client.post(reverse('report_new') +
                                    '?x=150056.538&y=170907.56',
                                    self.sample_post,
                                    follow=True)

        report = response.context['report']

        # Login to access the pro page
        self.client.login(username='******', password='******')

        # Publish the created report
        response = self.client.post(reverse('report_accept_pro',
                                            args=[report.id]),
                                    follow=True)

        # Reset outbox
        mail.outbox = []

        # Document report as pro
        response = self.client.post(reverse('report_show_pro',
                                            kwargs={
                                                'report_id': report.id,
                                                'slug': 'hello'
                                            }),
                                    {
                                        'comment-text': 'new created comment',
                                        'files-TOTAL_FORMS': 0,
                                        'files-INITIAL_FORMS': 0,
                                        'files-MAX_NUM_FORMS': 0
                                    },
                                    follow=True)

        # Mails are sent to responsibles according to mail config of the group: 1 for group + members without the author
        expected_recipients = self.group_mail_config.get_manager_recipients(
            self.manager)

        self.assertTrue(mail.outbox)
        self.assertEquals(len(mail.outbox), len(expected_recipients))

        for email in mail.outbox:
            self.assertIn(email.to[0], expected_recipients)

    def test_publish_comment_mail(self):
        response = self.client.post(reverse('report_new') +
                                    '?x=150056.538&y=170907.56',
                                    self.sample_post,
                                    follow=True)
        report = response.context['report']

        # Login to access the pro page
        self.client.login(username='******', password='******')

        # Accept and publish the created report
        report.private = False
        report.accepted_at = datetime.now()
        report.save()

        # Assure that comment is private
        self.assertEqual(ReportAttachment.PRIVATE,
                         report.comments()[0].security_level)

        # Reset outbox
        mail.outbox = []

        # Now make the comment public
        response = self.client.get(reverse('report_update_attachment',
                                           args=[report.id]),
                                   {
                                       'updateType': 1,
                                       'attachmentId': report.comments()[0].id
                                   },
                                   follow=True)

        self.assertEqual(ReportAttachment.PUBLIC,
                         report.comments()[0].security_level)

        # All notifications are sent to subscribers as digest
        self.assertEquals(len(mail.outbox), 0)

    def test_subscription_for_pro_mail(self):
        response = self.client.post(reverse('report_new') +
                                    '?x=150056.538&y=170907.56',
                                    self.sample_post,
                                    follow=True)
        report = response.context['report']

        # Login to access the pro page
        self.client.login(username='******', password='******')

        # Publish the created report
        response = self.client.post(reverse('report_accept_pro',
                                            args=[report.id]),
                                    follow=True)
        self.client.logout()

        # Reset outbox
        mail.outbox = []

        self.client.login(username='******', password='******')
        response = self.client.get(reverse('subscribe_pro', args=[report.id]),
                                   {},
                                   follow=True)

        # 1 mail sent in real-time to subscriber
        self.assertEquals(len(mail.outbox), 1)
        self.assertTrue(self.manager2.email in mail.outbox[0].to)

    def test_make_report_switch_visibility(self):
        response = self.client.post(reverse('report_new') +
                                    '?x=150056.538&y=170907.56',
                                    self.sample_post,
                                    follow=True)

        # Assure that report is public
        report = response.context['report']
        self.assertFalse(report.private)

        # Login to access the pro page
        self.client.login(username='******', password='******')

        # Publish the created report
        response = self.client.post(reverse('report_accept_pro',
                                            args=[report.id]),
                                    follow=True)

        # Reset outbox
        mail.outbox = []

        # 1/ Now make the report private
        response = self.client.get(
            reverse('report_change_switch_visibility', args=[report.id]) +
            '?visibility=true',
            follow=True)

        report = Report.objects.get(id=report.id)
        self.assertTrue(report.private)

        # Mails are sent in real time
        self.assertEquals(len(mail.outbox), 1)

        # Reset outbox
        mail.outbox = []

        # 2/ Now make the report public
        response = self.client.get(
            reverse('report_change_switch_visibility', args=[report.id]) +
            '?visibility=false',
            follow=True)

        report = Report.objects.get(id=report.id)
        self.assertFalse(report.private)

        # Mails are sent in real time
        self.assertEquals(len(mail.outbox), 1)

    #def testMergeReportMail(self):
    #    #Login to access the pro page
    #    self.client.login(username='******', password='******')
    #    #Send a post request filling in the form to create a report
    #    response = self.client.post(reverse('report_new_pro') + '?x=150056.538&y=170907.56', self.sample_post, follow=True)
    #    self.assertEquals(response.status_code, 200)
    #    self.assertIn('report', response.context)

    #    report_id = response.context['report'].id

    #    self.assertEquals(len(mail.outbox),  1)  # one for creator subscription, one for manager

    #    self.client.logout()
    #    response = self.client.post(
    #        reverse('report_new') + '?x=150056.538&y=170907.56',
    #        self.sample_post,
    #        follow=True)
    #    self.assertEquals(response.status_code, 200)
    # Should send mail only to responsible
    #    self.assertEquals(len(mail.outbox), 3)

    #    report2_id = response.context['report'].id

    #    self.client.login(username='******', password='******')
    # Publish the created report
    #    response3 = self.client.post(reverse('report_accept_pro', args=[report2_id]), follow=True)
    #    self.assertEquals(response3.status_code, 200)
    #    self.assertEquals(len(mail.outbox), 4)

    # Merge reports
    #    url2 = reverse('report_do_merge_pro', args=[report_id])
    #    self.client.post(url2, {"mergeId": report2_id})

    #    self.assertTrue(Report.objects.all().visible().filter(id=report_id).exists())
    #    self.assertFalse(Report.objects.all().visible().filter(id=report2_id).exists())

    #Reference from merged to kept report
    #    self.assertEqual(report_id, Report.objects.get(id=report2_id).merged_with.id)
    #A mail has been sent to the creator of the first report to notify him that his report has been merged
    #    self.assertEquals(len(mail.outbox), 5)

    def test_send_PDF_to_pro_mail(self):
        response = self.client.post(reverse('report_new') +
                                    '?x=150056.538&y=170907.56',
                                    self.sample_post,
                                    follow=True)
        report = response.context['report']

        # Login to access the pro page
        self.client.login(username='******', password='******')

        # Publish the created report
        response = self.client.post(reverse('report_accept_pro',
                                            args=[report.id]),
                                    follow=True)

        # Reset outbox
        mail.outbox = []

        # Send Pro PDF
        response = self.client.post(reverse('send_pdf', args=[report.id]),
                                    self.sample_post_mail_pdf_pro)

        # 3 mails should be sent
        self.assertEquals(len(mail.outbox), 3)

    def test_send_PDF_to_citizen_mail(self):
        response = self.client.post(reverse('report_new') +
                                    '?x=150056.538&y=170907.56',
                                    self.sample_post,
                                    follow=True)

        report = response.context['report']
        report.accepted_at = datetime.now()
        report.save()

        # Reset outbox
        mail.outbox = []

        # Login to access the pro page
        self.client.login(username='******', password='******')

        # Now send Pro PDF
        response = self.client.post(reverse('send_pdf', args=[report.id]),
                                    self.sample_post_mail_pdf_citzen)

        # 3 mails should be sent to citizens
        self.assertEquals(len(mail.outbox), 3)

    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_recipient_for_everyone(self):
        """
        recipients must contains everyone (group, manager and manager4)
        """
        recipients = self.group_mail_config.get_manager_recipients()
        self.assertEquals(len(recipients), 3)
        self.assertIn(self.group.email, recipients)
        self.assertIn(self.manager.email, recipients)
        self.assertIn(self.manager4.email, recipients)

    def test_recipient_exclude_author(self):
        """
        recipients must contains everyone (group, manager and manager4)
        """
        recipients = self.group_mail_config.get_manager_recipients(
            self.manager)
        self.assertEquals(len(recipients), 2)
        self.assertIn(self.group.email, recipients)
        self.assertIn(self.manager4.email, recipients)

    def test_recipient_for_manager_as_group(self):
        """
        if email group is same as manager then recipients
        must contains ony once this email (distinct values)
        (group email and manager4)
        """
        self.group.email = self.manager.email
        self.group.save()
        self.group_mail_config.notify_group = False
        self.group_mail_config.save()

        recipients = self.group_mail_config.get_manager_recipients()
        self.assertEquals(len(recipients), 2)
        self.assertIn(self.manager.email, recipients)
        self.assertIn(self.manager4.email, recipients)

    def test_recipient_for_manager_as_group_author(self):
        """
        if email group is same as manager then recipients and also is the author
        this email must be excluded
        """
        self.group.email = self.manager.email
        recipients = self.group_mail_config.get_manager_recipients(
            self.manager)
        self.assertEquals(len(recipients), 2)
        self.assertIn(self.manager4.email, recipients)
        self.assertIn(self.group.email, recipients)
Пример #5
0
class ApiTest(FMSTestCase):

    def setUp(self):

        try:
            organisation = OrganisationEntity.objects.get(id=1)
        except ObjectDoesNotExist:
            organisation = OrganisationEntity(id=1, name="Test organisation")
            organisation.save()

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

        surface = OrganisationEntitySurface(
            geom=Polygon([p1, p2, p3, p4, p1]),
            owner=OrganisationEntity.objects.get(pk=14)
        )
        surface.save()

        #user_auth = User.objects.create_user(username='******', email='*****@*****.**', password='******')
        #user_auth.save()
        user = FMSUser(
            is_active=True,
            password="******",
            email="*****@*****.**",
            first_name="zaza",
            telephone="00000000",
            last_used_language="fr",
            organisation=organisation,
            username='******')
        user.save()

        #~ main_category = ReportMainCategoryClass(id=2,name_en='test main en',name_nl='test main nl',name_fr='test main fr')
        #~ main_category.save()
        #~
        #~ secondary_category = ReportSecondaryCategoryClass(id=2,name_en='test second en',name_nl='test second nl',name_fr='test second fr')
        #~ secondary_category.save()
        #~
        #~ category = ReportCategory(id=2,name_en='test parent en',name_nl='test parent nl',name_fr='test parent fr', public=True, category_class=main_category, secondary_category_class=secondary_category)
        #~ category.save()
        self.citizen = FMSUser(
            telephone="0123456789",
            last_used_language="fr",
            first_name="citizen",
            last_name="citizen",
            email="*****@*****.**"
        )
        self.citizen.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 = OrganisationEntity.objects.get(pk=14)
        self.manager.save()

        self.group = OrganisationEntity(
            type="D",
            name_nl="Werken",
            name_fr="Travaux",
            phone="090987",
            dependency=OrganisationEntity.objects.get(pk=14),
            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.id, organisation_id=self.group.id, contact_user=True)
        self.usergroupmembership.save()

        self.sample_post = {
            'report-x': '150056.538',
            'report-y': '170907.56',
            'report-address_fr': 'Avenue des Arts, 3',
            'report-address_nl': 'Kunstlaan, 3',
            'report-address_number': '3',
            'report-postalcode': '1210',
            'report-category': '1',
            'report-secondary_category': '1',
            'report-subscription': 'on',
            'report-terms_of_use_validated': True,

            'comment-text': 'test',

            'files-TOTAL_FORMS': 0,
            'files-INITIAL_FORMS': 0,
            'files-MAX_NUM_FORMS': 1000,

            'citizen-quality': '1',
            'citizen-email': self.citizen.email,
            'citizen-firstname': self.citizen.first_name,
            'citizen-lastname': self.citizen.last_name
        }

    def testCreateReportCitizen(self):
        #Create a client to launch requests
        client = Client()

        #Get the request response
        response = client.post(reverse('create_report_citizen'), self.sample_post, follow=True)

        #Test the http response code (200 = OK)
        self.assertEqual(response.status_code, 200)

        #Test if the response if JSON structured.
        self.assertEqual(response['Content-Type'], 'application/json; charset=utf-8')

        self.assertEqual(1, len(Report.objects.all()))

        #Load the response data as JSON object
        result = json.loads(response.content)

        # Get in the DB the created report
        report = Report.objects.get(id=result['id'])

        # Check that source is correct
        self.assertEqual(Report.SOURCES['MOBILE'], report.source)

    def testCreateReportDoubleCitizen(self):
        #Parameters to save the report in database.

        #Create a client to launch requests
        client = Client()

        #Get the request response
        response = client.post(reverse('create_report_citizen'), self.sample_post, follow=True)
        response = client.post(reverse('create_report_citizen'), self.sample_post, follow=True)
        response = client.post(reverse('create_report_citizen'), self.sample_post, follow=True)
        response = client.post(reverse('create_report_citizen'), self.sample_post, follow=True)

        self.assertEqual(1, len(Report.objects.all()))

        #Load the response data as JSON object
        result = json.loads(response.content)

    def testCreateReportPro(self):
        self.sample_post['username'] = self.manager.username
        self.sample_post['password'] = '******'

        #Create a client to launch requests
        client = Client()
        #Get the request response

        response = client.post('/fr/api/login/', {
            'username': self.manager.username,
            'password': '******'
        }, follow=True)
        self.assertEqual(response.status_code, 200)
        #Load the response data as JSON object
        result = json.loads(response.content)
        self.assertIn('email', result)

        response = client.post(reverse('create_report_citizen'), self.sample_post, follow=True)
        #Test the http response code (200 = OK)
        self.assertEqual(response.status_code, 200)

        #Test if the response if JSON structured.
        self.assertEqual(response['Content-Type'], 'application/json; charset=utf-8')

        #Load the response data as JSON object
        result = json.loads(response.content)

        #Verify if the report_id is returned by the webservice
        self.assertTrue(result['id'])

        #Get in the DB the created report
        report = Report.objects.get(id=result['id'])

        #Verify the persisted data for the new created report
        self.assertEquals(report.address, self.sample_post['report-address_fr'])
        self.assertTrue(report.is_pro())

        # Check that source is correct
        self.assertEqual(Report.SOURCES['MOBILE'], report.source)

    def testCreateReportDoublePro(self):
        self.sample_post['username'] = self.manager.username
        self.sample_post['password'] = '******'

        #Create a client to launch requests
        client = Client()

        #Get the request response
        client.post(reverse('create_report_citizen'), self.sample_post, follow=True)
        client.post(reverse('create_report_citizen'), self.sample_post, follow=True)
        client.post(reverse('create_report_citizen'), self.sample_post, follow=True)
        client.post(reverse('create_report_citizen'), self.sample_post, follow=True)

        self.assertEqual(1, len(Report.objects.all()))

    def testLoadCategories(self):
        #Parameters to save the report in database.
        params = {
            "user_name": "superuser"
        }
        #Create a client to launch requests
        client = Client()
        #Get the request response
        response = client.get(reverse('load_categories'), params, follow=True)
        #Test the http response code (200 = OK)
        self.assertEqual(response.status_code, 200)
        #Test if the response if JSON structured.
        self.assertEqual(response['Content-Type'], 'application/json')
        #Load the response data as JSON object
        result = json.loads(response.content)

    def test_login_user(self):
        params = {
            'username': self.manager.email,
            'password': '******'
        }
        response = self.client.post(reverse('login_user'), params)

        self.assertEqual(response.status_code, 200)

        result = json.loads(response.content)
        self.assertEqual(result['id'], self.manager.id)
        self.assertEqual(result['first_name'], self.manager.first_name)

    def test_login_user_fail(self):
        params = {
            'username': self.manager.email,
            'password': '******'
        }
        response = self.client.post(reverse('login_user'), params)

        self.assertEqual(response.status_code, 403)

        result = json.loads(response.content)
        self.assertEqual("ERROR_LOGIN_INVALID_PARAMETERS", result["error_key"])

    def test_login_user_fail_empty_field(self):
        params = {
            'username': self.manager.email
        }
        response = self.client.post(reverse('login_user'), params)

        self.assertEqual(response.status_code, 400)

        result = json.loads(response.content)
        self.assertEqual("ERROR_LOGIN_INVALID_PARAMETERS", result["error_key"])

    def test_login_user_bad_username(self):
        params = {
            'username': "******",
            'password': "******"
        }
        response = self.client.post(reverse('login_user'), params)

        self.assertEqual(response.status_code, 403)

        result = json.loads(response.content)
        self.assertEqual("ERROR_LOGIN_INVALID_PARAMETERS", result["error_key"])

    def test_logout_user(self):
        response = self.client.post(reverse('logout_user'))
        self.assertEqual(response.status_code, 200)

        self.assertEqual('', response.content)
Пример #6
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()
Пример #7
0
class ListTest(FMSTestCase):
    def setUp(self):
        self.secondary_category = ReportCategory.objects.all()[0]
        self.category = self.secondary_category.category_class

        self.bxl = OrganisationEntity.objects.get(id=4)  # postal code = 1000 Bxl
        self.bxl.save()

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

        surface = OrganisationEntitySurface(geom=Polygon([p1, p2, p3, p4, p1]), owner=self.bxl)
        surface.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.agent = FMSUser(
            is_active=True,
            email="*****@*****.**",
            telephone="0123456789",
            last_used_language="fr",
            agent=True,
            organisation=self.bxl,
        )
        self.agent.save()

        self.stib = OrganisationEntity.objects.get(id=21)
        self.stib.dependency = self.bxl
        self.stib.save()

        self.contractor = FMSUser(
            is_active=True,
            email="*****@*****.**",
            telephone="0123456789",
            last_used_language="fr",
            contractor=True,
            organisation=self.bxl,
        )
        self.contractor.save()

        self.contractor_manager = FMSUser(
            is_active=True,
            email="*****@*****.**",
            telephone="90870870",
            last_used_language="fr",
            contractor=True,
            organisation=self.bxl,
            manager=True,
        )
        self.contractor_manager.save()
        uom = UserOrganisationMembership(user=self.contractor_manager, organisation=self.group)
        uom.save()

        self.entity_manager = FMSUser(
            is_active=True,
            email="*****@*****.**",
            telephone="90870870",
            last_used_language="fr",
            leader=True,
            organisation=self.bxl,
            manager=True,
        )
        self.entity_manager.save()
        self.usergroupmembership = UserOrganisationMembership(
            user_id=self.entity_manager.id, organisation_id=self.group.id
        )
        self.usergroupmembership.save()

        self.manager = FMSUser(
            is_active=True,
            email="*****@*****.**",
            telephone="0123456789",
            last_used_language="fr",
            manager=True,
            organisation=self.bxl,
        )
        self.manager.save()
        self.usergroupmembership2 = UserOrganisationMembership(
            user_id=self.manager.id, organisation_id=self.group.id, contact_user=True
        )
        self.usergroupmembership2.save()

        self.citizen = FMSUser(email="*****@*****.**", telephone="0123456789", last_used_language="fr")
        self.citizen.save()

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

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

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

    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)))
Пример #8
0
class ReportViewsTest(FMSTestCase):

    def setUp(self):

        self.user = FMSUser(username='******', email='*****@*****.**', password='******')
        self.user.save()

        self.client = Client()

        self.citizen = FMSUser(
            telephone="0123456789",
            last_used_language="fr",
            first_name="citizen",
            last_name="citizen",
            email="*****@*****.**"
        )
        self.citizen.save()

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

        self.group_mail_config       = GroupMailConfig()
        self.group_mail_config.group = self.group
        self.group_mail_config.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 = OrganisationEntity.objects.get(pk=14)
        self.manager.save()
        self.group.dispatch_categories.add(ReportCategory.objects.get(pk=1))

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

        surface = OrganisationEntitySurface(
            geom=Polygon([p1, p2, p3, p4, p1]),
            owner=OrganisationEntity.objects.get(pk=14),
        )
        surface.save()

        self.manager.memberships.create(organisation=self.group, contact_user=True)

        self.sample_post = {
            'report-x': '150056.538',
            'report-y': '170907.56',
            'report-address_fr': 'Avenue des Arts, 3',
            'report-address_nl': 'Kunstlaan, 3',
            'report-address_number': '3',
            'report-postalcode': '1210',
            'report-category': '1',
            'report-secondary_category': '1',
            'report-subscription': 'on',
            'comment-text': 'test',
            'files-TOTAL_FORMS': 0,
            'files-INITIAL_FORMS': 0,
            'files-MAX_NUM_FORMS': 0,
            'citizen-email': self.citizen.email,
            'citizen-firstname': self.citizen.first_name,
            'citizen-lastname': self.citizen.last_name,
            'citizen-quality': '1',
            'report-terms_of_use_validated': True
        }
        self.sample_post_2 = {
            'report-x': '150056',
            'report-y': '170907.56',
            'report-address_fr': 'Avenue des Arts, 3',
            'report-address_nl': 'Kunstlaan, 3',
            'report-address_number': '5',
            'report-postalcode': '1210',
            'report-category': '1',
            'report-secondary_category': '1',
            'report-subscription': 'on',
            'comment-text': 'test2',
            'files-TOTAL_FORMS': 0,
            'files-INITIAL_FORMS': 0,
            'files-MAX_NUM_FORMS': 0,
            'citizen-email': self.citizen.email,
            'citizen-firstname': self.citizen.first_name,
            'citizen-lastname': self.citizen.last_name,
            'citizen-quality': '1',
            'report-terms_of_use_validated': True
        }

    def test_home(self):
        """Tests the new report view."""
        response = self.client.get(reverse('home'), follow=True)
        self.assertEqual(response.status_code, 200)
        self.assertTrue('report_counts' in response.context)
        self.assertTrue('zipcodes' in response.context)
        #Are the zipcodes well loaded from DB??
        self.assertTrue(len(response.context['zipcodes']) > 0)

    @skip('replaced by database pages')
    def test_about(self):
        """Tests the about view."""
        response = self.client.get(reverse('about'), follow=True)
        self.assertEqual(response.status_code, 200)

    @skip('replaced by database pages')
    def test_term_of_use(self):
        """Tests the term of use view."""
        response = self.client.get(reverse('terms_of_use'), follow=True)
        self.assertEqual(response.status_code, 200)

    def test_new_report(self):
        """Tests the new report page."""
        url = reverse('report_new')
        response = self.client.get(url, {'x': '148360', 'y': '171177'}, follow=True)
        self.assertEqual(response.status_code, 200)

    def test_verify_report(self):
        """Tests the new report page get verify existings."""
        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)

        url = reverse('report_verify')
        response = self.client.get(url, {'x': '150056', 'y': '170907'}, follow=True)
        self.assertEqual(response.status_code, 200)

        self.assertIn('reports_nearby', response.context)
        # Assert that the list view displays minimal information about reports
        last_dist = 0
        for report in response.context['reports_nearby']:
            self.assertContains(response, report.get_absolute_url())
            self.assertTrue(report.distance.m <= 20)  # limit to 1km around
            self.assertTrue(report.distance.m >= last_dist)  # ordered by distance
            last_dist = report.distance.m

    def test_create_report(self):
        """Tests the creation of a report and test the view of it."""

        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)

        self.assertIn('report', response.context)

        report = response.context['report']

        self.assertContains(response, report.postalcode)
        self.assertContains(response, report.status)

        self.assertEqual(1, len(Report.objects.all()))

        # Get in the DB the created report
        report = Report.objects.all()[0]

        # Check that source is correct
        self.assertEqual(Report.SOURCES['WEB'], report.source)

    def test_create_report_double(self):
        """Tests the creation of a double report and test the view of it."""

        url = "%s?x=148360&y=171177" % reverse('report_new')

        self.client.post(url, self.sample_post, follow=True)
        self.client.post(url, self.sample_post, follow=True)
        self.client.post(url, self.sample_post, follow=True)
        self.client.post(url, self.sample_post, follow=True)

        self.assertEqual(1, len(Report.objects.all()))

    def test_accept_report(self):
        """Tests acceptation a report and test the view of it."""

        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']

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

        url = reverse('report_accept_pro', args=[report.id])
        response = self.client.get(url, follow=True)
        self.assertEqual(response.status_code, 200)

        report = response.context['report']

        self.assertTrue(report.accepted_at is not None)

    def test_refuse_report(self):
        """Tests refuse a report and test the view of it."""

        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']

        # Be sure it's private
        report.private = True
        report.save()

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

        url = reverse('report_refuse_pro', args=[report.id])
        response = self.client.post(url, {'text': "Message de refus"}, follow=True)
        self.assertEqual(response.status_code, 200)

        report = response.context['report']

        self.assertTrue(report.accepted_at is None)
        self.assertEqual(report.status, Report.REFUSED)

        comment = ReportComment.objects.get(report_id=report.id, type=ReportAttachment.REFUSED)
        self.assertEqual(comment.security_level, ReportComment.PRIVATE)

    def test_refuse_report_comment_visible_for_citizen(self):
        """Tests refuse a report and test the view of it."""

        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']

        # Be sure it's public
        report.private = False
        report.save()

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

        url = reverse('report_refuse_pro', args=[report.id])
        response = self.client.post(url, {'text': "Message de refus"}, follow=True)
        self.assertEqual(response.status_code, 200)

        report = response.context['report']

        self.assertTrue(report.accepted_at is None)
        self.assertEqual(report.status, Report.REFUSED)

        comment = ReportComment.objects.get(report_id=report.id, type=ReportAttachment.REFUSED)
        self.assertEqual(comment.security_level, ReportComment.PUBLIC)

    def test_add_comment(self):
        """Tests the update of a report."""
        url = "%s?x=148360&y=171177" % reverse('report_new')
        response = self.client.post(url, self.sample_post, follow=True)
        report = response.context['report']

        self.assertEqual(report.comments().count(), 1)
        self.assertEqual(report.comments()[0].created_by, self.citizen)
        report.save()

        response = self.client.post(reverse('report_document', kwargs={'report_id': report.id, 'slug': 'hello'}), {
            'comment-text': 'new created comment',
            'citizen-email': self.user.email,
            'citizen-quality': 1,
            'files-TOTAL_FORMS': 0,
            'files-INITIAL_FORMS': 0,
            'files-MAX_NUM_FORMS': 0
        }, follow=True)
        self.assertEqual(response.status_code, 200)
        url = reverse('report_show2', args=[report.id])
        self.assertRedirects(response, url)

        self.assertEqual(report.comments().count(), 2)
        self.assertEqual(report.comments()[1].created_by, self.user)

    def test_add_comment_as_pro(self):
        """Tests the update of a report as a pro."""
        self.client.login(username='******', password='******')

        url = "%s?x=148360&y=171177" % reverse('report_new_pro')
        response = self.client.post(url, self.sample_post, follow=True)
        report = response.context['report']

        self.assertEqual(report.comments().count(), 1)
        self.assertEqual(report.comments()[0].created_by, self.manager)
        report.save()

        response = self.client.post(reverse('report_show_pro', kwargs={'report_id': report.id, 'slug': 'hello'}), {
            'comment-text': 'new created comment',
            'files-TOTAL_FORMS': 0,
            'files-INITIAL_FORMS': 0,
            'files-MAX_NUM_FORMS': 0
        }, follow=True)
        self.assertEqual(response.status_code, 200)
        self.assertRedirects(response, report.get_absolute_url_pro())

        self.assertEqual(report.comments().count(), 2)
        self.assertEqual(report.comments()[1].created_by, self.manager)

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

        url = "%s?x=148360&y=171177" % reverse('report_new')
        response = self.client.post(url, self.sample_post, follow=True)
        report = response.context['report']

        self.assertEqual(Report.objects.get(id=report.id).category.id, 1)
        self.assertEqual(Report.objects.get(id=report.id).secondary_category.id, 1)

        # Setting a private sec_cat to a public report is not allowed
        self.client.post(reverse('update_category_for_report', args=[report.id]), {"main_category": "2", "secondary_category": "32"})

        # So, cat not changed
        self.assertEqual(Report.objects.get(id=report.id).category.id, 1)
        self.assertEqual(Report.objects.get(id=report.id).secondary_category.id, 1)

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

        url = "%s?x=148360&y=171177" % reverse('report_new')
        response = self.client.post(url, self.sample_post, follow=True)
        report = response.context['report']

        self.assertEqual(Report.objects.get(id=report.id).category.id, 1)
        self.assertEqual(Report.objects.get(id=report.id).secondary_category.id, 1)

        self.client.post(reverse('update_category_for_report', args=[report.id]), {"main_category": "2", "secondary_category": "2"})

        self.assertEqual(Report.objects.get(id=report.id).category.id, 2)
        self.assertEqual(Report.objects.get(id=report.id).secondary_category.id, 2)

    def test_subscription(self):
        """Tests the subscription of a report."""

        url = "%s?x=148360&y=171177" % reverse('report_new')
        response = self.client.post(url, self.sample_post, follow=True)
        report = response.context['report']

        # responsible manager is NOT subscribed by default
        self.assertFalse(report.subscriptions.filter(subscriber=self.manager).exists())

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

        # subscribe to the report
        response = self.client.get(reverse('subscribe_pro', args=[report.id]), {}, follow=True)
        self.assertRedirects(response, report.get_absolute_url_pro())
        self.assertEqual(response.status_code, 200)

        #current user is subscribed
        self.assertTrue(report.subscriptions.filter(subscriber=self.manager).exists())

    def test_subscription_citizen(self):
        """Tests the subscription of a report."""

        url = "%s?x=148360&y=171177" % reverse('report_new')
        response = self.client.post(url, self.sample_post, follow=True)
        report = response.context['report']

        # current user is not subscribed yet
        self.assertTrue(report.subscriptions.filter(subscriber=self.citizen).exists())

        #unsubscribe to the report
        response = self.client.get(reverse('unsubscribe', args=[report.id]) + '?citizen_email=' + self.citizen.email, {}, follow=True)
        url = reverse('report_show2', args=[report.id])
        self.assertRedirects(response, url)
        self.assertEqual(response.status_code, 200)

        #current user is no more subscribed
        self.assertFalse(report.subscriptions.filter(subscriber=self.citizen).exists())

    def test_do_merge_reports(self):
        """Test do merge reports. """

        #Add first report
        url = "%s?x=148360&y=171177" % reverse('report_new')
        response = self.client.post(url, self.sample_post, follow=True)
        report = response.context['report']

        #Add second report
        response2 = self.client.post(url, self.sample_post_2, follow=True)
        report2 = response2.context['report']

        #Login user
        params = {
            'username': self.manager.email,
            'password': '******'
        }
        self.client.post(reverse('login'), params)

        #Merge reports
        url2 = reverse('report_do_merge_pro', args=[report.id])
        self.client.post(url2, {"mergeId": report2.id})

        #Reference from merged to kept report
        self.assertEqual(report.id, Report.objects.get(id=report2.id).merged_with.id)

        #The first one (oldest one) is kept
        self.assertEqual(Report.objects.all().visible()[0].id, report.id)

        #The comment of the second one is added to the first one
        self.assertEqual(Report.objects.get(id=report.id).comments().count(), 2)

    def test_merge_reports(self):
        """Test merge reports. """

        # Add first report
        url = "%s?x=148360&y=171177" % reverse('report_new')
        response = self.client.post(url, self.sample_post, follow=True)
        report = response.context['report']

        # Add second report
        response2      = self.client.post(url, self.sample_post_2, follow=True)
        report2        = response2.context['report']
        report2.status = Report.IN_PROGRESS
        report2.save()

        # Login user
        params = {
            'username': self.manager.email,
            'password': '******'
        }
        self.client.post(reverse('login'), params)

        # Display mergeable reports list
        url = reverse('report_merge_pro', args=[report.get_slug(), report.id])
        response = self.client.get(url)

        self.assertEqual(report, response.context['report'])
        self.assertEqual(1, len(response.context['reports_nearby']))

    def test_merge_reports_search_ticket(self):
        """Test merge reports with search of ticket number """

        # Add first report
        url = "%s?x=148360&y=171177" % reverse('report_new')
        response = self.client.post(url, self.sample_post, follow=True)
        report = response.context['report']

        # Add second report
        response2 = self.client.post(url, self.sample_post_2, follow=True)
        report2 = response2.context['report']
        report2.status = Report.IN_PROGRESS #necessary otherwise both report will be with "CREATED" status
                                            # and you can't merge 2 reports with 2 "CREATED" status
        report2.save()

        # Login user
        params = {
            'username': self.manager.email,
            'password': '******'
        }
        self.client.post(reverse('login'), params)

        # Display mergeable report according to ticket number
        url2 = reverse('report_merge_pro', args=[report.get_slug(), report.id])
        response = self.client.get("%s?ticketNumber=%s" % (url2, report2.id))

        self.assertEqual(report, response.context['report'])
        self.assertEqual(1, len(response.context['reports_nearby']))
        self.assertEqual(report2.id, response.context['reports_nearby'][0].id)

    def test_mark_done_as_user(self):
        """Tests marking report as done."""

        url = "%s?x=148360&y=171177" % reverse('report_new')
        response = self.client.post(url, self.sample_post, follow=True)
        report = response.context['report']

        self.client.login(username='******', password='******')
        url      = reverse('report_accept_pro', args=[report.id])
        response = self.client.get(url, follow=True)

        # Mark as done as citizen
        self.client.logout()
        response = self.client.post(reverse('report_update', args=[report.id]), {'is_fixed': 'True'}, follow=True)
        self.assertEqual(response.status_code, 200)

        report = response.context['report']
        self.assertTrue(report.fixed_at)
        self.assertEqual(report.status, Report.SOLVED)
        self.assertFalse(ReportComment.objects.filter(type=ReportAttachment.MARK_AS_DONE, report=report).exists())

    def test_mark_done_as_pro(self):
        """Tests marking report as done."""

        url      = "%s?x=148360&y=171177" % reverse('report_new')
        response = self.client.post(url, self.sample_post, follow=True)
        report   = response.context['report']

        self.client.login(username='******', password='******')
        url = reverse('report_accept_pro', args=[report.id])
        response = self.client.get(url, follow=True)
        self.assertEqual(response.status_code, 200)

        # Mark as done as pro
        response = self.client.post(reverse('report_fix_pro', args=[report.id]), {'text': 'commentaire'}, follow=True)
        self.assertEquals(response.status_code, 200)

        report = response.context['report']

        self.assertTrue(report.fixed_at)
        self.assertTrue(ReportComment.objects.filter(type=ReportAttachment.MARK_AS_DONE, report=report).exists())
        self.assertEquals(report.status, Report.SOLVED)
    def test_mark_done_as_user_denied(self):
        """Tests marking report not done if denied."""

        url = "%s?x=148360&y=171177" % reverse('report_new')
        response = self.client.post(url, self.sample_post, follow=True)
        report = response.context['report']

        self.client.login(username='******', password='******')
        url      = reverse('report_accept_pro', args=[report.id])
        response = self.client.get(url, follow=True)

        # Change status to refused
        report.status = report.REFUSED
        report.save()

        # Try to mark as done as citizen
        self.client.logout()
        response = self.client.post(reverse('report_update', args=[report.id]), {'is_fixed': 'True'}, follow=True)
        self.assertEqual(response.status_code, 200)

        report = response.context['report']

        self.assertFalse(report.fixed_at)
        self.assertEqual(report.status, Report.REFUSED)
        self.assertFalse(ReportComment.objects.filter(type=ReportAttachment.MARK_AS_DONE, report=report).exists())

    def test_mark_done_as_pro_denied(self):
        """Tests marking report as done."""

        url      = "%s?x=148360&y=171177" % reverse('report_new')
        response = self.client.post(url, self.sample_post, follow=True)
        report   = response.context['report']

        self.client.login(username='******', password='******')
        url = reverse('report_accept_pro', args=[report.id])
        response = self.client.get(url, follow=True)
        self.assertEqual(response.status_code, 200)

        # Change status to refused
        report.status = report.REFUSED
        report.save()

        # Try to mark as done as pro
        response = self.client.post(reverse('report_fix_pro', args=[report.id]), {'text': 'commentaire'}, follow=True)
        self.assertEquals(response.status_code, 200)

        report = response.context['report']

        self.assertFalse(report.fixed_at)
        self.assertFalse(ReportComment.objects.filter(type=ReportAttachment.MARK_AS_DONE, report=report).exists())
        self.assertEquals(report.status, Report.REFUSED)

    def test_mark_done_as_user_denied(self):
        """Tests marking report not done if denied."""

        url = "%s?x=148360&y=171177" % reverse('report_new')
        response = self.client.post(url, self.sample_post, follow=True)
        report = response.context['report']

        self.client.login(username='******', password='******')
        url      = reverse('report_accept_pro', args=[report.id])
        response = self.client.get(url, follow=True)

        # Change status to refused
        report.status = report.REFUSED
        report.save()

        # Try to mark as done as citizen
        self.client.logout()
        response = self.client.post(reverse('report_update', args=[report.id]), {'is_fixed': 'True'}, follow=True)
        self.assertEqual(response.status_code, 200)

        report = response.context['report']

        self.assertFalse(report.fixed_at)
        self.assertEqual(report.status, Report.REFUSED)
        self.assertFalse(ReportComment.objects.filter(type=ReportAttachment.MARK_AS_DONE, report=report).exists())

    def test_mark_done_as_pro_denied(self):
        """Tests marking report as done."""

        url      = "%s?x=148360&y=171177" % reverse('report_new')
        response = self.client.post(url, self.sample_post, follow=True)
        report   = response.context['report']

        self.client.login(username='******', password='******')
        url = reverse('report_accept_pro', args=[report.id])
        response = self.client.get(url, follow=True)
        self.assertEqual(response.status_code, 200)

        # Change status to refused
        report.status = report.REFUSED
        report.save()

        # Try to mark as done as pro
        response = self.client.post(reverse('report_fix_pro', args=[report.id]), {'text': 'commentaire'}, follow=True)
        self.assertEquals(response.status_code, 200)

        report = response.context['report']

        self.assertFalse(report.fixed_at)
        self.assertFalse(ReportComment.objects.filter(type=ReportAttachment.MARK_AS_DONE, report=report).exists())
        self.assertEquals(report.status, Report.REFUSED)

    def test_search_ticket(self):
        """Tests searching ticket."""
        url = "%s?x=148360&y=171177" % reverse('report_new')
        response = self.client.post(url, self.sample_post, follow=True)
        report = response.context['report']

        url = '%s?report_id=%s' % (reverse('search_ticket'), report.id)
        response = self.client.get(url, follow=True)

        self.assertEqual(response.status_code, 200)
        report_result = response.context['report']

        self.assertEqual(report, report_result)

    def test_login_user(self):
        params = {
            'username': self.manager.email,
            'password': '******'
        }
        response = self.client.post(reverse('login'), params)

        self.assertEqual(response.status_code, 302)

    def test_login_user_with_redirect(self):
        params = {
            'username': self.manager.email,
            'password': '******'
        }

        url = '%s?next=/fr/pro/reports/' % reverse('login')
        response = self.client.post(url, params)

        self.assertEqual(response.status_code, 302)

    def test_login_user_fail(self):
        params = {
            'username': self.manager.email,
            'password': '******'
        }
        response = self.client.post(reverse('login'), params)

        self.assertEqual(response.status_code, 200)

        escaped = escape(ugettext('Please enter a correct username and password. Note that both fields are case-sensitive.'))
        self.assertContains(response, escaped)

    def test_logout_user(self):
        params = {
            'username': self.manager.email,
            'password': '******'
        }
        self.client.post(reverse('login'), params)

        response = self.client.post(reverse('logout'))
        self.assertEqual(response.status_code, 302)

    def test_marker_detail_citizen(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)

        self.assertIn('report', response.context)

        report = response.context['report']
        jsonResult = report.full_marker_detail_JSON()
        #Now test on all mandatory fields
        self.assertIn('id', jsonResult)
        self.assertIn('point', jsonResult)
        self.assertIn('category', jsonResult)
        self.assertIn('address', jsonResult)
        self.assertIn('address_number', jsonResult)
        self.assertIn('postalcode', jsonResult)
        self.assertIn('address_commune_name', jsonResult)
        self.assertIn('address_regional', jsonResult)
        self.assertIn('thumb', jsonResult)
        self.assertIn('contractor', jsonResult)
        self.assertIn('date_planned', jsonResult)
        self.assertNotIn('is_closed', jsonResult)
        self.assertNotIn('citizen', jsonResult)
        self.assertNotIn('priority', jsonResult)

    def test_marker_detail_pro(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)

        self.assertIn('report', response.context)

        report = response.context['report']
        jsonResult = report.full_marker_detail_pro_JSON()
        #Now test on all mandatory fields
        self.assertIn('id', jsonResult)
        self.assertIn('point', jsonResult)
        self.assertIn('category', jsonResult)
        self.assertIn('address', jsonResult)
        self.assertIn('address_number', jsonResult)
        self.assertIn('postalcode', jsonResult)
        self.assertIn('address_commune_name', jsonResult)
        self.assertIn('address_regional', jsonResult)
        self.assertIn('thumb', jsonResult)
        self.assertIn('contractor', jsonResult)
        self.assertIn('date_planned', jsonResult)
        self.assertIn('is_closed', jsonResult)
        self.assertIn('citizen', jsonResult)
        self.assertIn('priority', jsonResult)

    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 test_reopen_report_processed(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']
        report.status = Report.PROCESSED
        report.accepted_at = datetime.now()
        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.accepted_at, report_reopen.accepted_at)
        self.assertEqual(report.close_date , report_reopen.close_date)

        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 test_reopen_report_badstatus(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']
        report.accepted_at = datetime.now()
        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_not_reopen = response.context['report']

        self.assertNotEqual(Report.MANAGER_ASSIGNED, report_not_reopen.status)
        self.assertEqual(report.status        , report_not_reopen.status)
        self.assertEqual(report.created       , report_not_reopen.created)
        self.assertEqual(report.modified      , report_not_reopen.modified)
        self.assertEqual(report.accepted_at   , report_not_reopen.accepted_at)
        self.assertEqual(report.close_date    , report_not_reopen.close_date)

        self.assertEqual(report.subscriptions.all().count(), report_not_reopen.subscriptions.all().count())
        self.assertEqual(report.responsible_entity         , report_not_reopen.responsible_entity)
        self.assertEqual(report.responsible_department     , report_not_reopen.responsible_department)

    def test_auto_assign(self):
        # Associate a category to an organisation for auto-dispatching
        entity            = OrganisationEntity()
        entity.name_fr    = "My entity"
        entity.type       = OrganisationEntity.COMMUNE
        entity.email      = "*****@*****.**"
        entity.save()

        # Associate a category to an organisation for auto-dispatching
        department            = OrganisationEntity()
        department.name_fr    = "My group"
        department.type       = OrganisationEntity.DEPARTMENT
        department.dependency = entity
        department.email      = "*****@*****.**"
        department.save()

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

        category                       = ReportCategory.objects.get(id=self.sample_post['report-category'])
        category.organisation_communal = entity
        category.save()

        department.dispatch_categories.add(category)

        # Create new report
        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']

        # Auto-dispatching working for commune
        self.assertFalse(report.is_regional())
        self.assertEqual(report.responsible_department, department)
        self.assertEqual(report.responsible_entity, entity)

    def test_not_auto_assign_if_report_already_exists(self):
        # Create new report
        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']

        # Associate a category to an organisation for auto-dispatching
        entity            = OrganisationEntity()
        entity.name_fr    = "My entity"
        entity.type       = OrganisationEntity.COMMUNE
        entity.email      = "*****@*****.**"
        entity.save()

        # Associate a category to an organisation for auto-dispatching
        department            = OrganisationEntity()
        department.name_fr    = "My group"
        department.type       = OrganisationEntity.DEPARTMENT
        department.dependency = entity
        department.email      = "*****@*****.**"
        department.save()

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

        category                       = ReportCategory.objects.get(id=self.sample_post['report-category'])
        category.organisation_communal = entity
        category.save()

        department.dispatch_categories.add(category)

        # Assign report to another entity
        report.responsible_entity = self.group.dependency
        report.responsible_department = None
        report.save()

        # Check it's not auto-dispatching
        report = Report.objects.get(id=report.id)

        self.assertFalse(report.is_regional())
        self.assertNotEqual(report.responsible_department, department)
        self.assertNotEqual(report.responsible_entity, entity)

        self.assertEqual(report.responsible_entity, self.group.dependency)
        self.assertEqual(report.responsible_department, self.group)
Пример #9
0
class NotificationTest(FMSTestCase):
    def setUp(self):
        self.secondary_category = ReportCategory.objects.all()[0]
        self.category = self.secondary_category.category_class
        # Create a FMSUser
        self.etterbeek = OrganisationEntity.objects.get(id=5)  # postal code = 1040 Etterbeek
        self.etterbeek.save()
        self.bxl = OrganisationEntity.objects.get(id=4)  # postal code = 1000 Bxl
        self.bxl.save()

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

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

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

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

        self.manager_etterbeek = FMSUser(
            is_active=True,
            email="*****@*****.**",
            telephone="0123456789",
            last_used_language="fr",
            manager=True,
            organisation=self.etterbeek,
        )
        self.manager_etterbeek.save()
        self.manager_bxl = FMSUser(
            is_active=True,
            email="*****@*****.**",
            telephone="0123456789",
            last_used_language="fr",
            manager=True,
            organisation=self.bxl,
        )
        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.group2 = OrganisationEntity(
            type="D",
            name_nl="Werken",
            name_fr="Travaux",
            phone="090987",
            dependency=self.etterbeek,
            email="*****@*****.**",
        )
        self.group2.save()

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

        self.usergroupmembership2 = UserOrganisationMembership(
            user_id=self.manager_etterbeek.id, organisation_id=self.group2.id, contact_user=True
        )
        self.usergroupmembership2.save()
        self.citizen = FMSUser(email="*****@*****.**", telephone="0123456789", last_used_language="fr")
        self.citizen.save()

    def testReportFileType(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": "170105"}),
            address_number="6h",
            created_by=self.manager_etterbeek,
        )
        new_report.save()

        reportFile = ReportFile(file_type=ReportFile.PDF, report=new_report)
        self.assertTrue(reportFile.is_pdf())
        self.assertFalse(reportFile.is_word())
        self.assertFalse(reportFile.is_excel())
        self.assertFalse(reportFile.is_image())
        self.assertTrue(reportFile.is_document())

        reportFile = ReportFile(file_type=ReportFile.WORD, report=new_report)
        self.assertFalse(reportFile.is_pdf())
        self.assertTrue(reportFile.is_word())
        self.assertFalse(reportFile.is_excel())
        self.assertFalse(reportFile.is_image())
        self.assertTrue(reportFile.is_document())

        reportFile = ReportFile(file_type=ReportFile.EXCEL, report=new_report)
        self.assertFalse(reportFile.is_pdf())
        self.assertFalse(reportFile.is_word())
        self.assertTrue(reportFile.is_excel())
        self.assertFalse(reportFile.is_image())
        self.assertTrue(reportFile.is_document())

        reportFile = ReportFile(file_type=ReportFile.IMAGE, report=new_report)
        self.assertFalse(reportFile.is_pdf())
        self.assertFalse(reportFile.is_word())
        self.assertFalse(reportFile.is_excel())
        self.assertTrue(reportFile.is_image())
        self.assertFalse(reportFile.is_document())

    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)
Пример #10
0
    def setUp(self):

        try:
            organisation = OrganisationEntity.objects.get(id=1)
        except ObjectDoesNotExist:
            organisation = OrganisationEntity(id=1, name="Test organisation")
            organisation.save()

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

        surface = OrganisationEntitySurface(
            geom=Polygon([p1, p2, p3, p4, p1]),
            owner=OrganisationEntity.objects.get(pk=14))
        surface.save()

        #user_auth = User.objects.create_user(username='******', email='*****@*****.**', password='******')
        #user_auth.save()
        user = FMSUser(is_active=True,
                       password="******",
                       email="*****@*****.**",
                       first_name="zaza",
                       telephone="00000000",
                       last_used_language="fr",
                       organisation=organisation,
                       username='******')
        user.save()

        #~ main_category = ReportMainCategoryClass(id=2,name_en='test main en',name_nl='test main nl',name_fr='test main fr')
        #~ main_category.save()
        #~
        #~ secondary_category = ReportSecondaryCategoryClass(id=2,name_en='test second en',name_nl='test second nl',name_fr='test second fr')
        #~ secondary_category.save()
        #~
        #~ category = ReportCategory(id=2,name_en='test parent en',name_nl='test parent nl',name_fr='test parent fr', public=True, category_class=main_category, secondary_category_class=secondary_category)
        #~ category.save()
        self.citizen = FMSUser(telephone="0123456789",
                               last_used_language="fr",
                               first_name="citizen",
                               last_name="citizen",
                               email="*****@*****.**")
        self.citizen.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 = OrganisationEntity.objects.get(pk=14)
        self.manager.save()

        self.group = OrganisationEntity(
            type="D",
            name_nl="Werken",
            name_fr="Travaux",
            phone="090987",
            dependency=OrganisationEntity.objects.get(pk=14),
            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.id,
            organisation_id=self.group.id,
            contact_user=True)
        self.usergroupmembership.save()

        self.sample_post = {
            'report-x': '150056.538',
            'report-y': '170907.56',
            'report-address_fr': 'Avenue des Arts, 3',
            'report-address_nl': 'Kunstlaan, 3',
            'report-address_number': '3',
            'report-postalcode': '1210',
            'report-category': '1',
            'report-secondary_category': '1',
            'report-subscription': 'on',
            'report-terms_of_use_validated': True,
            'comment-text': 'test',
            'files-TOTAL_FORMS': 0,
            'files-INITIAL_FORMS': 0,
            'files-MAX_NUM_FORMS': 1000,
            'citizen-quality': '1',
            'citizen-email': self.citizen.email,
            'citizen-firstname': self.citizen.first_name,
            'citizen-lastname': self.citizen.last_name
        }
Пример #11
0
class ApiTest(FMSTestCase):
    def setUp(self):

        try:
            organisation = OrganisationEntity.objects.get(id=1)
        except ObjectDoesNotExist:
            organisation = OrganisationEntity(id=1, name="Test organisation")
            organisation.save()

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

        surface = OrganisationEntitySurface(
            geom=Polygon([p1, p2, p3, p4, p1]),
            owner=OrganisationEntity.objects.get(pk=14))
        surface.save()

        #user_auth = User.objects.create_user(username='******', email='*****@*****.**', password='******')
        #user_auth.save()
        user = FMSUser(is_active=True,
                       password="******",
                       email="*****@*****.**",
                       first_name="zaza",
                       telephone="00000000",
                       last_used_language="fr",
                       organisation=organisation,
                       username='******')
        user.save()

        #~ main_category = ReportMainCategoryClass(id=2,name_en='test main en',name_nl='test main nl',name_fr='test main fr')
        #~ main_category.save()
        #~
        #~ secondary_category = ReportSecondaryCategoryClass(id=2,name_en='test second en',name_nl='test second nl',name_fr='test second fr')
        #~ secondary_category.save()
        #~
        #~ category = ReportCategory(id=2,name_en='test parent en',name_nl='test parent nl',name_fr='test parent fr', public=True, category_class=main_category, secondary_category_class=secondary_category)
        #~ category.save()
        self.citizen = FMSUser(telephone="0123456789",
                               last_used_language="fr",
                               first_name="citizen",
                               last_name="citizen",
                               email="*****@*****.**")
        self.citizen.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 = OrganisationEntity.objects.get(pk=14)
        self.manager.save()

        self.group = OrganisationEntity(
            type="D",
            name_nl="Werken",
            name_fr="Travaux",
            phone="090987",
            dependency=OrganisationEntity.objects.get(pk=14),
            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.id,
            organisation_id=self.group.id,
            contact_user=True)
        self.usergroupmembership.save()

        self.sample_post = {
            'report-x': '150056.538',
            'report-y': '170907.56',
            'report-address_fr': 'Avenue des Arts, 3',
            'report-address_nl': 'Kunstlaan, 3',
            'report-address_number': '3',
            'report-postalcode': '1210',
            'report-category': '1',
            'report-secondary_category': '1',
            'report-subscription': 'on',
            'report-terms_of_use_validated': True,
            'comment-text': 'test',
            'files-TOTAL_FORMS': 0,
            'files-INITIAL_FORMS': 0,
            'files-MAX_NUM_FORMS': 1000,
            'citizen-quality': '1',
            'citizen-email': self.citizen.email,
            'citizen-firstname': self.citizen.first_name,
            'citizen-lastname': self.citizen.last_name
        }

    def testCreateReportCitizen(self):
        #Create a client to launch requests
        client = Client()

        #Get the request response
        response = client.post(reverse('create_report_citizen'),
                               self.sample_post,
                               follow=True)

        #Test the http response code (200 = OK)
        self.assertEqual(response.status_code, 200)

        #Test if the response if JSON structured.
        self.assertEqual(response['Content-Type'],
                         'application/json; charset=utf-8')

        self.assertEqual(1, len(Report.objects.all()))

        #Load the response data as JSON object
        result = json.loads(response.content)

        # Get in the DB the created report
        report = Report.objects.get(id=result['id'])

        # Check that source is correct
        self.assertEqual(Report.SOURCES['MOBILE'], report.source)

    def testCreateReportDoubleCitizen(self):
        #Parameters to save the report in database.

        #Create a client to launch requests
        client = Client()

        #Get the request response
        response = client.post(reverse('create_report_citizen'),
                               self.sample_post,
                               follow=True)
        response = client.post(reverse('create_report_citizen'),
                               self.sample_post,
                               follow=True)
        response = client.post(reverse('create_report_citizen'),
                               self.sample_post,
                               follow=True)
        response = client.post(reverse('create_report_citizen'),
                               self.sample_post,
                               follow=True)

        self.assertEqual(1, len(Report.objects.all()))

        #Load the response data as JSON object
        result = json.loads(response.content)

    def testCreateReportPro(self):
        self.sample_post['username'] = self.manager.username
        self.sample_post['password'] = '******'

        #Create a client to launch requests
        client = Client()
        #Get the request response

        response = client.post('/fr/api/login/', {
            'username': self.manager.username,
            'password': '******'
        },
                               follow=True)
        self.assertEqual(response.status_code, 200)
        #Load the response data as JSON object
        result = json.loads(response.content)
        self.assertIn('email', result)

        response = client.post(reverse('create_report_citizen'),
                               self.sample_post,
                               follow=True)
        #Test the http response code (200 = OK)
        self.assertEqual(response.status_code, 200)

        #Test if the response if JSON structured.
        self.assertEqual(response['Content-Type'],
                         'application/json; charset=utf-8')

        #Load the response data as JSON object
        result = json.loads(response.content)

        #Verify if the report_id is returned by the webservice
        self.assertTrue(result['id'])

        #Get in the DB the created report
        report = Report.objects.get(id=result['id'])

        #Verify the persisted data for the new created report
        self.assertEquals(report.address,
                          self.sample_post['report-address_fr'])
        self.assertTrue(report.is_pro())

        # Check that source is correct
        self.assertEqual(Report.SOURCES['MOBILE'], report.source)

    def testCreateReportDoublePro(self):
        self.sample_post['username'] = self.manager.username
        self.sample_post['password'] = '******'

        #Create a client to launch requests
        client = Client()

        #Get the request response
        client.post(reverse('create_report_citizen'),
                    self.sample_post,
                    follow=True)
        client.post(reverse('create_report_citizen'),
                    self.sample_post,
                    follow=True)
        client.post(reverse('create_report_citizen'),
                    self.sample_post,
                    follow=True)
        client.post(reverse('create_report_citizen'),
                    self.sample_post,
                    follow=True)

        self.assertEqual(1, len(Report.objects.all()))

    def testLoadCategories(self):
        #Parameters to save the report in database.
        params = {"user_name": "superuser"}
        #Create a client to launch requests
        client = Client()
        #Get the request response
        response = client.get(reverse('load_categories'), params, follow=True)
        #Test the http response code (200 = OK)
        self.assertEqual(response.status_code, 200)
        #Test if the response if JSON structured.
        self.assertEqual(response['Content-Type'], 'application/json')
        #Load the response data as JSON object
        result = json.loads(response.content)

    def test_login_user(self):
        params = {'username': self.manager.email, 'password': '******'}
        response = self.client.post(reverse('login_user'), params)

        self.assertEqual(response.status_code, 200)

        result = json.loads(response.content)
        self.assertEqual(result['id'], self.manager.id)
        self.assertEqual(result['first_name'], self.manager.first_name)

    def test_login_user_fail(self):
        params = {'username': self.manager.email, 'password': '******'}
        response = self.client.post(reverse('login_user'), params)

        self.assertEqual(response.status_code, 403)

        result = json.loads(response.content)
        self.assertEqual("ERROR_LOGIN_INVALID_PARAMETERS", result["error_key"])

    def test_login_user_fail_empty_field(self):
        params = {'username': self.manager.email}
        response = self.client.post(reverse('login_user'), params)

        self.assertEqual(response.status_code, 400)

        result = json.loads(response.content)
        self.assertEqual("ERROR_LOGIN_INVALID_PARAMETERS", result["error_key"])

    def test_login_user_bad_username(self):
        params = {'username': "******", 'password': "******"}
        response = self.client.post(reverse('login_user'), params)

        self.assertEqual(response.status_code, 403)

        result = json.loads(response.content)
        self.assertEqual("ERROR_LOGIN_INVALID_PARAMETERS", result["error_key"])

    def test_logout_user(self):
        response = self.client.post(reverse('logout_user'))
        self.assertEqual(response.status_code, 200)

        self.assertEqual('', response.content)
Пример #12
0
class ExportPDFTest(FMSTestCase):

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

    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['visibility'], '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['visibility'], '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')
Пример #13
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.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()
Пример #14
0
    def setUp(self):
        self.secondary_category = ReportCategory.objects.all()[0]
        self.category = self.secondary_category.category_class
        #Create a FMSUser
        self.etterbeek = OrganisationEntity.objects.get(id=5)  # postal code = 1040 Etterbeek
        self.etterbeek.save()
        self.bxl = OrganisationEntity.objects.get(id=4)  # postal code = 1000 Bxl
        self.bxl.save()

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

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

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

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

        self.manager_etterbeek = FMSUser(
            is_active=True,
            email="*****@*****.**",
            telephone="0123456789",
            last_used_language="fr",
            manager=True,
            organisation=self.etterbeek)
        self.manager_etterbeek.save()
        self.manager_bxl = FMSUser(
            is_active=True,
            email="*****@*****.**",
            telephone="0123456789",
            last_used_language="fr",
            manager=True,
            organisation=self.bxl)
        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.group2 = OrganisationEntity(
            type="D",
            name_nl="Werken",
            name_fr="Travaux",
            phone="090987",
            dependency=self.etterbeek,
            email="*****@*****.**"
            )
        self.group2.save()

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

        self.usergroupmembership2 = UserOrganisationMembership(user_id=self.manager_etterbeek.id, organisation_id=self.group2.id, contact_user=True)
        self.usergroupmembership2.save()
        self.citizen = FMSUser(
            email="*****@*****.**",
            telephone="0123456789",
            last_used_language="fr")
        self.citizen.save()
Пример #15
0
class NotificationTest(FMSTestCase):

    def setUp(self):
        self.secondary_category = ReportCategory.objects.all()[0]
        self.category = self.secondary_category.category_class
        #Create a FMSUser
        self.etterbeek = OrganisationEntity.objects.get(id=5)  # postal code = 1040 Etterbeek
        self.etterbeek.save()
        self.bxl = OrganisationEntity.objects.get(id=4)  # postal code = 1000 Bxl
        self.bxl.save()

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

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

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

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

        self.manager_etterbeek = FMSUser(
            is_active=True,
            email="*****@*****.**",
            telephone="0123456789",
            last_used_language="fr",
            manager=True,
            organisation=self.etterbeek)
        self.manager_etterbeek.save()
        self.manager_bxl = FMSUser(
            is_active=True,
            email="*****@*****.**",
            telephone="0123456789",
            last_used_language="fr",
            manager=True,
            organisation=self.bxl)
        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.group2 = OrganisationEntity(
            type="D",
            name_nl="Werken",
            name_fr="Travaux",
            phone="090987",
            dependency=self.etterbeek,
            email="*****@*****.**"
            )
        self.group2.save()

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

        self.usergroupmembership2 = UserOrganisationMembership(user_id=self.manager_etterbeek.id, organisation_id=self.group2.id, contact_user=True)
        self.usergroupmembership2.save()
        self.citizen = FMSUser(
            email="*****@*****.**",
            telephone="0123456789",
            last_used_language="fr")
        self.citizen.save()

    def testReportFileType(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": '170105'}),
            address_number='6h',
            created_by=self.manager_etterbeek
        )
        new_report.save()

        reportFile = ReportFile(file_type=ReportFile.PDF, report=new_report)
        self.assertTrue(reportFile.is_pdf())
        self.assertFalse(reportFile.is_word())
        self.assertFalse(reportFile.is_excel())
        self.assertFalse(reportFile.is_image())
        self.assertTrue(reportFile.is_document())

        reportFile = ReportFile(file_type=ReportFile.WORD, report=new_report)
        self.assertFalse(reportFile.is_pdf())
        self.assertTrue(reportFile.is_word())
        self.assertFalse(reportFile.is_excel())
        self.assertFalse(reportFile.is_image())
        self.assertTrue(reportFile.is_document())

        reportFile = ReportFile(file_type=ReportFile.EXCEL, report=new_report)
        self.assertFalse(reportFile.is_pdf())
        self.assertFalse(reportFile.is_word())
        self.assertTrue(reportFile.is_excel())
        self.assertFalse(reportFile.is_image())
        self.assertTrue(reportFile.is_document())

        reportFile = ReportFile(file_type=ReportFile.IMAGE, report=new_report)
        self.assertFalse(reportFile.is_pdf())
        self.assertFalse(reportFile.is_word())
        self.assertFalse(reportFile.is_excel())
        self.assertTrue(reportFile.is_image())
        self.assertFalse(reportFile.is_document())

    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)
class ReopenRequestTest(FMSTestCase):
    def setUp(self):
        self.citizen = FMSUser(telephone="0123456789",
                               last_used_language="fr",
                               first_name="citizen",
                               last_name="citizen",
                               email="*****@*****.**")
        self.citizen.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 = OrganisationEntity.objects.get(pk=14)
        self.manager.save()

        self.group = OrganisationEntity(
            type="D",
            name_nl="Werken",
            name_fr="Travaux",
            phone="090987",
            dependency=OrganisationEntity.objects.get(pk=14),
            email="*****@*****.**")
        self.group.save()
        self.group.dispatch_categories.add(ReportCategory.objects.get(pk=1))

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

        self.manager.memberships.create(organisation=self.group,
                                        contact_user=True)

        self.client = Client()

        self.manager2 = FMSUser(is_active=True,
                                telephone="9876543210",
                                last_used_language="nl",
                                password='******',
                                first_name="manager2",
                                last_name="manager2",
                                email="*****@*****.**",
                                manager=True)
        self.manager2.set_password('test2')
        self.manager2.organisation = OrganisationEntity.objects.get(pk=14)
        self.manager2.save()

        self.group2 = OrganisationEntity(
            type="D",
            name_nl="Werken",
            name_fr="Travaux",
            phone="090987",
            dependency=OrganisationEntity.objects.get(pk=21),
            email="*****@*****.**")
        self.group2.save()
        self.group2.dispatch_categories.add(ReportCategory.objects.get(pk=2))
        self.group2.dispatch_categories.add(ReportCategory.objects.get(pk=1))

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

        surface = OrganisationEntitySurface(
            geom=Polygon([p1, p2, p3, p4, p1]),
            owner=OrganisationEntity.objects.get(pk=14),
        )
        surface.save()

        self.manager2.memberships.create(organisation=self.group2)

        self.manager3 = FMSUser(is_active=True,
                                telephone="000000000",
                                last_used_language="nl",
                                password='******',
                                first_name="manager3",
                                last_name="manager3",
                                email="*****@*****.**",
                                manager=True)
        self.manager3.set_password('test3')
        self.manager3.organisation = OrganisationEntity.objects.get(pk=21)
        self.manager3.save()

        self.manager3.memberships.create(organisation=self.group2)

        self.impetrant = OrganisationEntity(name_nl="MIVB",
                                            name_fr="STIB",
                                            email="*****@*****.**")

        self.impetrant.save()

        self.contractor = OrganisationEntity(name_nl="Fabricom GDF",
                                             name_fr="Fabricom GDF",
                                             email="*****@*****.**")
        self.contractor.save()

        self.sample_post = {
            'report-x': '150056.538',
            'report-y': '170907.56',
            'report-address_fr': 'Avenue des Arts, 3',
            'report-address_nl': 'Kunstlaan, 3',
            'report-address_number': '3',
            'report-postalcode': '1210',
            'report-category': '1',
            'report-secondary_category': '1',
            'report-subscription': 'on',
            'citizen-quality': '1',
            'comment-text': 'test',
            'files-TOTAL_FORMS': 0,
            'files-INITIAL_FORMS': 0,
            'files-MAX_NUM_FORMS': 0,
            'citizen-email': self.citizen.email,
            'citizen-firstname': self.citizen.first_name,
            'citizen-lastname': self.citizen.last_name,
            'report-terms_of_use_validated': True
        }

        ##### Following data was created specifically for the reopen_request tests #######

        self.citizen_reopen_request = FMSUser(
            telephone="987654321",
            last_used_language="fr",
            first_name="citizen_reopen_request",
            last_name="citizen_reopen_request",
            email="*****@*****.**")
        self.citizen_reopen_request.save()

        self.sample_post_reopen_request_pro = {
            'reopen-text': 'this is the reopen request comment',
            'reopen-reason': 1
        }

        self.sample_post_reopen_request = {
            'reopen-text': 'this is the reopen request comment',
            'reopen-reason': 1,
            'citizen-quality': 2,
            'citizen-email': self.citizen_reopen_request.email,
            'citizen-telephone': self.citizen_reopen_request.telephone,
            'citizen-last_name': self.citizen_reopen_request.last_name,
        }

    def testReopenRequestMailByPro(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']

        # Set status to Processed
        report.status = Report.PROCESSED
        report.close_date = datetime.now()
        report.save()

        # Login to access the pro page
        self.client.login(username='******', password='******')

        # Request reopen report
        response = self.client.post(reverse('report_reopen_request_pro',
                                            args=["hello", report.id]),
                                    self.sample_post_reopen_request_pro,
                                    follow=True)

        #check redirect
        url_redirect = reverse('report_show_pro',
                               args=[report.get_slug(), report.id])
        self.assertRedirects(response,
                             url_redirect,
                             status_code=302,
                             target_status_code=200)

        #test there is a message
        success_msg = str(list(response.context["messages"])[0])
        self.assertEqual(success_msg,
                         str(gettext(SUCCESS_MSG_REOPEN_REQUEST_CONFIRM)))

        # Fetch activities
        activities = report.activities.all()

        # Assert
        self.assertEqual(activities.count(), 3)
        self.assertEquals(ReportEventLog.REOPEN_REQUEST,
                          activities[2].event_type)

    def testReopenRequestMailByCitizen(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']

        # Set status to Processed
        report.status = Report.PROCESSED
        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)

        #test there is a message
        success_msg = str(list(response.context["messages"])[0])
        self.assertEqual(success_msg,
                         str(gettext(SUCCESS_MSG_REOPEN_REQUEST_CONFIRM)))

        # Fetch activities
        activities = report.activities.all()

        # Assert
        self.assertEqual(activities.count(), 3)
        self.assertEquals(ReportEventLog.REOPEN_REQUEST,
                          activities[2].event_type)

    #Test that you cannot access the page if you don't have status closed. (Should be tested with all status
    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 testReopenRequestNotAfter90Days(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']

        #limit date is 90 days. let's check a report closed 91 days ago
        report.status = Report.PROCESSED
        limit_date_plus_one = datetime.now() - timedelta(days=91)
        report.close_date = limit_date_plus_one
        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_90_DAYS)))

        # Fetch activities
        activities = report.activities.all()

        # Assert
        self.assertEqual(activities.count(), 2)
        self.assertEquals(ReportEventLog.CLOSE, activities[1].event_type)
Пример #17
0
class ReopenRequestTest(FMSTestCase):

    def setUp(self):
        self.citizen = FMSUser(
            telephone="0123456789",
            last_used_language="fr",
            first_name="citizen",
            last_name="citizen",
            email="*****@*****.**"
        )
        self.citizen.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 = OrganisationEntity.objects.get(pk=14)
        self.manager.save()

        self.group = OrganisationEntity(
            type="D",
            name_nl="Werken",
            name_fr="Travaux",
            phone="090987",
            dependency=OrganisationEntity.objects.get(pk=14),
            email="*****@*****.**"
            )
        self.group.save()
        self.group.dispatch_categories.add(ReportCategory.objects.get(pk=1))

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

        self.manager.memberships.create(organisation=self.group, contact_user=True)

        self.client = Client()

        self.manager2 = FMSUser(
            is_active=True,
            telephone="9876543210",
            last_used_language="nl",
            password='******',
            first_name="manager2",
            last_name="manager2",
            email="*****@*****.**",
            manager=True
        )
        self.manager2.set_password('test2')
        self.manager2.organisation = OrganisationEntity.objects.get(pk=14)
        self.manager2.save()

        self.group2 = OrganisationEntity(
            type="D",
            name_nl="Werken",
            name_fr="Travaux",
            phone="090987",
            dependency=OrganisationEntity.objects.get(pk=21),
            email="*****@*****.**"
        )
        self.group2.save()
        self.group2.dispatch_categories.add(ReportCategory.objects.get(pk=2))
        self.group2.dispatch_categories.add(ReportCategory.objects.get(pk=1))

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

        surface = OrganisationEntitySurface(
            geom=Polygon([p1, p2, p3, p4, p1]),
            owner=OrganisationEntity.objects.get(pk=14),
        )
        surface.save()

        self.manager2.memberships.create(organisation=self.group2)

        self.manager3 = FMSUser(
            is_active=True,
            telephone="000000000",
            last_used_language="nl",
            password='******',
            first_name="manager3",
            last_name="manager3",
            email="*****@*****.**",
            manager=True
        )
        self.manager3.set_password('test3')
        self.manager3.organisation = OrganisationEntity.objects.get(pk=21)
        self.manager3.save()

        self.manager3.memberships.create(organisation=self.group2)

        self.impetrant = OrganisationEntity(
            name_nl="MIVB",
            name_fr="STIB",
            email="*****@*****.**")

        self.impetrant.save()

        self.contractor = OrganisationEntity(
            name_nl="Fabricom GDF",
            name_fr="Fabricom GDF",
            email="*****@*****.**")
        self.contractor.save()

        self.sample_post = {
            'report-x': '150056.538',
            'report-y': '170907.56',
            'report-address_fr': 'Avenue des Arts, 3',
            'report-address_nl': 'Kunstlaan, 3',
            'report-address_number': '3',
            'report-postalcode': '1210',
            'report-category': '1',
            'report-secondary_category': '1',
            'report-subscription': 'on',
            'citizen-quality': '1',
            'comment-text': 'test',
            'files-TOTAL_FORMS': 0,
            'files-INITIAL_FORMS': 0,
            'files-MAX_NUM_FORMS': 0,
            'citizen-email': self.citizen.email,
            'citizen-firstname': self.citizen.first_name,
            'citizen-lastname': self.citizen.last_name,
            'report-terms_of_use_validated': True
        }

        ##### Following data was created specifically for the reopen_request tests #######

        self.citizen_reopen_request = FMSUser(
            telephone="987654321",
            last_used_language="fr",
            first_name="citizen_reopen_request",
            last_name="citizen_reopen_request",
            email="*****@*****.**"
        )
        self.citizen_reopen_request.save()

        self.sample_post_reopen_request_pro = {
            'reopen-text': 'this is the reopen request comment',
            'reopen-reason': 1
        }

        self.sample_post_reopen_request = {
            'reopen-text': 'this is the reopen request comment',
            'reopen-reason': 1,
            'citizen-quality': 2,
            'citizen-email': self.citizen_reopen_request.email,
            'citizen-telephone': self.citizen_reopen_request.telephone,
            'citizen-last_name': self.citizen_reopen_request.last_name,
        }

    def testReopenRequestMailByPro(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']

        # Set status to Processed
        report.status = Report.PROCESSED
        report.close_date = datetime.now()
        report.save()

        # Login to access the pro page
        self.client.login(username='******', password='******')

        # Request reopen report
        response = self.client.post(reverse('report_reopen_request_pro', args=["hello", report.id]), self.sample_post_reopen_request_pro, follow=True)

        #check redirect
        url_redirect = reverse('report_show_pro', args=[report.get_slug(), report.id])
        self.assertRedirects(response, url_redirect, status_code=302, target_status_code=200)

        #test there is a message
        success_msg = str(list(response.context["messages"])[0])
        self.assertEqual(success_msg, str(gettext(SUCCESS_MSG_REOPEN_REQUEST_CONFIRM)))

        # Fetch activities
        activities = report.activities.all()

        # Assert
        self.assertEqual(activities.count(), 3)
        self.assertEquals(ReportEventLog.REOPEN_REQUEST, activities[2].event_type)


    def testReopenRequestMailByCitizen(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']

        # Set status to Processed
        report.status = Report.PROCESSED
        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)

        #test there is a message
        success_msg = str(list(response.context["messages"])[0])
        self.assertEqual(success_msg, str(gettext(SUCCESS_MSG_REOPEN_REQUEST_CONFIRM)))

        # Fetch activities
        activities = report.activities.all()

        # Assert
        self.assertEqual(activities.count(), 3)
        self.assertEquals(ReportEventLog.REOPEN_REQUEST, activities[2].event_type)


    #Test that you cannot access the page if you don't have status closed. (Should be tested with all status
    #except PROCESSED but let's test it with REFUSED)
    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 testReopenRequestNotAfter90Days(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']

        #limit date is 90 days. let's check a report closed 91 days ago
        report.status = Report.PROCESSED
        limit_date_plus_one = datetime.now() - timedelta(days=91)
        report.close_date = limit_date_plus_one
        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_90_DAYS)))

        # Fetch activities
        activities = report.activities.all()

        # Assert
        self.assertEqual(activities.count(), 2)
        self.assertEquals(ReportEventLog.CLOSE, activities[1].event_type)
Пример #18
0
    def setUp(self):
        self.secondary_category = ReportCategory.objects.all()[0]
        self.category = self.secondary_category.category_class
        # Create a FMSUser
        self.etterbeek = OrganisationEntity.objects.get(id=5)  # postal code = 1040 Etterbeek
        self.etterbeek.save()
        self.bxl = OrganisationEntity.objects.get(id=4)  # postal code = 1000 Bxl
        self.bxl.save()

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

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

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

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

        self.manager_etterbeek = FMSUser(
            is_active=True,
            email="*****@*****.**",
            telephone="0123456789",
            last_used_language="fr",
            manager=True,
            organisation=self.etterbeek,
        )
        self.manager_etterbeek.save()
        self.manager_bxl = FMSUser(
            is_active=True,
            email="*****@*****.**",
            telephone="0123456789",
            last_used_language="fr",
            manager=True,
            organisation=self.bxl,
        )
        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.group2 = OrganisationEntity(
            type="D",
            name_nl="Werken",
            name_fr="Travaux",
            phone="090987",
            dependency=self.etterbeek,
            email="*****@*****.**",
        )
        self.group2.save()

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

        self.usergroupmembership2 = UserOrganisationMembership(
            user_id=self.manager_etterbeek.id, organisation_id=self.group2.id, contact_user=True
        )
        self.usergroupmembership2.save()
        self.citizen = FMSUser(email="*****@*****.**", telephone="0123456789", last_used_language="fr")
        self.citizen.save()
Пример #19
0
class MailTest(FMSTestCase):

    def setUp(self):
        self.citizen = FMSUser(
            telephone="0123456789",
            last_used_language="fr",
            first_name="citizen",
            last_name="citizen",
            email="*****@*****.**"
        )
        self.citizen.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 = OrganisationEntity.objects.get(pk=14)
        self.manager.save()

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

        self.group = OrganisationEntity(
            type="D",
            name_nl="Werken",
            name_fr="Travaux",
            phone="090987",
            dependency=OrganisationEntity.objects.get(pk=14),
            email="*****@*****.**"
            )
        self.group.save()
        self.group.dispatch_categories.add(ReportCategory.objects.get(pk=1))

        # Mail config: notify group and members in real time
        self.group_mail_config                = GroupMailConfig()
        self.group_mail_config.group          = self.group
        self.group_mail_config.notify_group   = True
        self.group_mail_config.notify_members = True
        self.group_mail_config.save()

        self.manager.memberships.create(organisation=self.group, contact_user=True)
        self.manager4.memberships.create(organisation=self.group, contact_user=True)

        self.client = Client()

        self.manager2 = FMSUser(
            is_active=True,
            telephone="9876543210",
            last_used_language="nl",
            password='******',
            first_name="manager2",
            last_name="manager2",
            email="*****@*****.**",
            manager=True
        )
        self.manager2.set_password('test2')
        self.manager2.organisation = OrganisationEntity.objects.get(pk=14)
        self.manager2.save()

        self.group2 = OrganisationEntity(
            type="D",
            name_nl="Werken",
            name_fr="Travaux",
            phone="090987",
            dependency=OrganisationEntity.objects.get(pk=21),
            email="*****@*****.**"
        )
        self.group2.save()
        self.group2.dispatch_categories.add(ReportCategory.objects.get(pk=2))
        self.group2.dispatch_categories.add(ReportCategory.objects.get(pk=1))

        # Mail config: notify group and members in real time
        self.group_mail_config2                = GroupMailConfig()
        self.group_mail_config2.group          = self.group2
        self.group_mail_config2.notify_group   = True
        self.group_mail_config2.notify_members = True
        self.group_mail_config2.save()

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

        surface = OrganisationEntitySurface(
            geom=Polygon([p1, p2, p3, p4, p1]),
            owner=OrganisationEntity.objects.get(pk=14),
        )
        surface.save()

        self.manager2.memberships.create(organisation=self.group2)

        self.manager3 = FMSUser(
            is_active=True,
            telephone="000000000",
            last_used_language="nl",
            password='******',
            first_name="manager3",
            last_name="manager3",
            email="*****@*****.**",
            manager=True
        )
        self.manager3.set_password('test3')
        self.manager3.organisation = OrganisationEntity.objects.get(pk=21)
        self.manager3.save()

        self.manager3.memberships.create(organisation=self.group2)

        self.impetrant = OrganisationEntity(
            name_nl="MIVB",
            name_fr="STIB",
            email="*****@*****.**")

        self.impetrant.save()

        self.contractor = OrganisationEntity(
            name_nl="Fabricom GDF",
            name_fr="Fabricom GDF",
            email="*****@*****.**")
        self.contractor.save()

        self.sample_post = {
            'report-x': '150056.538',
            'report-y': '170907.56',
            'report-address_fr': 'Avenue des Arts, 3',
            'report-address_nl': 'Kunstlaan, 3',
            'report-address_number': '3',
            'report-postalcode': '1210',
            'report-category': '1',
            'report-secondary_category': '1',
            'report-subscription': 'on',
            'citizen-quality': '1',
            'comment-text': 'test',
            'files-TOTAL_FORMS': 0,
            'files-INITIAL_FORMS': 0,
            'files-MAX_NUM_FORMS': 0,
            'citizen-email': self.citizen.email,
            'citizen-firstname': self.citizen.first_name,
            'citizen-lastname': self.citizen.last_name,
            'report-terms_of_use_validated': True
        }

        self.sample_post_pro = {
            'report-x': '150056.538',
            'report-y': '170907.56',
            'report-address_fr': 'Avenue des Arts, 3',
            'report-address_nl': 'Kunstlaan, 3',
            'report-address_number': '3',
            'report-postalcode': '1210',
            'report-category': '1',
            'report-secondary_category': '1',
            'report-subscription': 'on',
            'comment-text': 'test',
            'files-TOTAL_FORMS': 0,
            'files-INITIAL_FORMS': 0,
            'files-MAX_NUM_FORMS': 0,
            'report-terms_of_use_validated': True
        }

        self.sample_post_mail_pdf_pro = {
            'comments': 'test comment',
            'visibility': 'private',
            'to': '[email protected],[email protected];[email protected]'
        }

        self.sample_post_mail_pdf_citzen = {
            'comments': 'test comment',
            'visibility': 'public',
            'to': '[email protected],[email protected];[email protected]'
        }

    def test_create_report_mail(self):
        # Send a post request filling in the form to create a report
        response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post, follow=True)

        # Mails are sent to responsibles according to mail config of the group: 1 for group + members
        expected_recipients = self.group_mail_config.get_manager_recipients()

        # 1 more mail is sent to creator in real time
        expected_recipients.append(self.citizen.email)

        self.assertTrue(mail.outbox)
        self.assertEquals(len(mail.outbox), len(expected_recipients))

        for email in mail.outbox:
            self.assertIn(email.to[0], expected_recipients)

    def test_close_report_mail(self):
        # Send a post request filling in the form to create a report
        response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post, follow=True)
        report = response.context['report']

        report             = response.context['report']
        report.accepted_at = datetime.now()
        report.save()

        # Reset outbox
        mail.outbox = []

        # Close the report
        self.client.login(username='******', password='******')
        response = self.client.get(reverse('report_close_pro', args=[report.id]), follow=True)

        report = Report.objects.get(id=report.id)

        self.assertEquals(report.status, Report.PROCESSED)

        # One mail is sent in real time to the creator if citizen. All others are digest to subscribers.
        self.assertEquals(len(mail.outbox), 1)
        self.assertIn(self.citizen.email, mail.outbox[0].to)

    def test_refuse_report_mail(self):
        # Send a post request filling in the form to create a report
        response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post, follow=True)
        report   = response.context['report']

        # Reset outbox
        mail.outbox = []

        # Login to access the pro page to create a user
        self.client.login(username='******', password='******')

        # Refuse the created report
        refused_url    = reverse('report_refuse_pro', args=[report.id])
        refused_params = {'text': 'more info'}
        response       = self.client.post(refused_url, refused_params, follow=True)

        report = Report.objects.get(id=report.id)

        # The status of the report must now be REFUSED
        self.assertEquals(report.status, Report.REFUSED)

        # All mail are sent as digest to subscribers
        self.assertEquals(len(mail.outbox), 0)

    def test_subscription_for_citizen_mail(self):
        # Send a post request filling in the form to create a report
        response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post, follow=True)
        report   = response.context['report']

        # Reset outobox
        mail.outbox = []

        # Send a post request subscribing a citizen to the just created report
        subscribe_url    = reverse('subscribe', args=[report.id])
        subscribe_email  = '*****@*****.**'
        subscribe_params = {'citizen_email': subscribe_email}
        response         = self.client.post(subscribe_url, subscribe_params, follow=True)

        # 1 mail sent in real-time to subscriber
        self.assertEquals(len(mail.outbox), 1)
        self.assertTrue(subscribe_email in mail.outbox[0].to)

    def test_mark_report_as_done_mail(self):
        # Send a post request filling in the form to create a report
        response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post, follow=True)
        report   = response.context['report']

        # Login to access the pro page
        self.client.login(username='******', password='******')

        # Publish the created report
        response = self.client.post(reverse('report_accept_pro', args=[report.id]), follow=True)

        # Reset outbox
        mail.outbox = []

        # Send a post request to mark the report as done
        update_url    = reverse('report_fix_pro', args=[report.id])
        update_params = {'text':'My comment'}
        response      = self.client.post(update_url, update_params)

        # Mails are sent to responsibles according to mail config of the group: 1 for group + members without the author
        expected_recipients = self.group_mail_config.get_manager_recipients(self.manager)

        self.assertTrue(mail.outbox)
        self.assertEquals(len(mail.outbox), len(expected_recipients))

        for email in mail.outbox:
            self.assertIn(email.to[0], expected_recipients)

    def test_accept_report_mail(self):
        # Send a post request filling in the form to create a report
        response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post, follow=True)
        report   = response.context['report']

        # Reset outbox
        mail.outbox = []

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

        url      = reverse('report_accept_pro', args=[report.id])
        response = self.client.get(url, follow=True)

        # All mails are sent to subscribers as digest
        self.assertEquals(len(mail.outbox), 0)

    def test_planned_report_mail(self):
        # Send a post request filling in the form to create a report
        response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post, follow=True)

        report             = response.context['report']
        report.accepted_at = datetime.now()
        report.save()

        # Reset outbox
        mail.outbox = []

        # Set as planned
        date_planned = (datetime.now() + timedelta(days=1)).strftime("%m/%Y")
        url = '%s?date_planned=%s' % (reverse('report_planned_pro', args=[report.id]), date_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, report.date_planned.strftime("%m/%Y"))

        # Only digest are sent to subscribers
        self.assertEquals(len(mail.outbox), 0)

        # Planned another date
        date_planned = (datetime.now() + timedelta(days=40)).strftime("%m/%Y")
        url = '%s?date_planned=%s' % (reverse('report_planned_pro', args=[report.id]), date_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, report.date_planned.strftime("%m/%Y"))

        # Only digest are sent to subscribers
        self.assertEquals(len(mail.outbox), 0)

    def test_create_report_as_pro_mail(self):
        # Create a report
        self.client.login(username='******', password='******')
        response = self.client.post(reverse('report_new_pro') + '?x=150056.538&y=170907.56', self.sample_post_pro, follow=True)

        # Mails are sent to responsibles according to mail config of the group: 1 for group + members without the author
        expected_recipients = self.group_mail_config.get_manager_recipients(self.manager)

        self.assertTrue(mail.outbox)
        self.assertEquals(len(mail.outbox), len(expected_recipients))

        for email in mail.outbox:
            self.assertIn(email.to[0], expected_recipients)

    def test_report_resolved_as_pro_mail(self):
        response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post, follow=True)
        report_id = response.context['report'].id

        # Login to access the pro page
        self.client.login(username='******', password='******')

        # Publish the created report
        response = self.client.post(reverse('report_accept_pro', args=[report_id]), follow=True)
        self.assertEquals(response.status_code, 200)

        # Clear outbox
        mail.outbox = []

        params = {
            'text' : 'Ceci est un commentaire'
        }
        response = self.client.post(reverse('report_fix_pro', args=[report_id]), params, follow=True)

        self.assertEquals(response.status_code, 200)
        self.assertEquals(Report.objects.get(id=report_id).status, Report.SOLVED)

        # Mails are sent to responsibles according to mail config of the group: 1 for group + members without the author
        expected_recipients = self.group_mail_config.get_manager_recipients(self.manager)

        self.assertTrue(mail.outbox)
        self.assertEquals(len(mail.outbox), len(expected_recipients))

        for email in mail.outbox:
            self.assertIn(email.to[0], expected_recipients)

    def test_assign_to_other_member_of_same_entity_mail(self):
        response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post, follow=True)
        report   = response.context['report']

        # Login to access the pro page
        self.client.login(username='******', password='******')

        # Publish the created report
        response = self.client.post(reverse('report_accept_pro', args=[report.id]), follow=True)

        # Restet outbox
        mail.outbox = []

        # Change manager in the same entity
        response = self.client.post(reverse('report_change_manager_pro', args=[report.id]), {'man_id' : 'department_' + str(self.group2.id), 'transfer':0}, follow=True)

        # Mails are sent to responsibles according to mail config of the group: 1 for group + members
        expected_recipients = self.group_mail_config2.get_manager_recipients()

        self.assertTrue(mail.outbox)
        self.assertEquals(len(mail.outbox), len(expected_recipients))

        for email in mail.outbox:
            self.assertIn(email.to[0], expected_recipients)

    def test_assign_to_another_entity_mail(self):
        response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post, follow=True)
        report   = response.context['report']

        # Login to access the pro page
        self.client.login(username='******', password='******')

        # Publish the created report
        response = self.client.post(reverse('report_accept_pro', args=[report.id]), follow=True)

        # Restet outbox
        mail.outbox = []

        # Change to another entity
        response = self.client.post(reverse('report_change_manager_pro', args=[report.id]), {"man_id": "entity_21", "transfer": 0}, follow=True)

        # Mails are sent to responsibles according to mail config of the group: 1 for group + members
        expected_recipients = self.group_mail_config2.get_manager_recipients()

        self.assertTrue(mail.outbox)
        self.assertEquals(len(mail.outbox), len(expected_recipients))

        for email in mail.outbox:
            self.assertIn(email.to[0], expected_recipients)

    def test_assign_to_impetrant_mail(self):
        response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post, follow=True)
        report   = response.context['report']

        # Add a worker for this entity
        worker = FMSUser(email="*****@*****.**", telephone="0123456789")
        worker.save()
        worker.memberships.create(organisation=self.impetrant)

        # Login to access the pro page
        self.client.login(username='******', password='******')

        # Publish the created report
        response = self.client.post(reverse('report_accept_pro', args=[report.id]), follow=True)

        # Reset outbox
        mail.outbox = []

        # Assign to another impetrant
        response = self.client.get(reverse('report_change_contractor_pro', args=[report.id]) + '?contractorId=' + str(self.impetrant.id), {}, follow=True)

        # 1 mail sent in real time to impetrant
        self.assertEquals(len(mail.outbox), 1)
        self.assertIn(self.impetrant.email, mail.outbox[0].to)

    def test_assign_to_contractor_mail(self):
        response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post, follow=True)

        report             = response.context['report']
        report.accepted_at = datetime.now()
        report.save()

        # Add a worker for this entity
        worker = FMSUser(email="*****@*****.**", telephone="0123456789")
        worker.save()
        worker.memberships.create(organisation=self.contractor)

        # Reset outbox
        mail.outbox = []

        self.client.login(username='******', password='******')
        response = self.client.get(reverse('report_change_contractor_pro', args=[report.id]) + '?contractorId=' + str(self.contractor.id), {}, follow=True)

        # 1 mail sent in real time to contractor
        self.assertEquals(len(mail.outbox), 1)
        self.assertIn(self.contractor.email, mail.outbox[0].to)

    def test_citizen_updates_report_mail(self):
        response = self.client.post(
            reverse('report_new') + '?x=150056.538&y=170907.56',
            self.sample_post,
            follow=True)

        report             = response.context['report']
        report.accepted_at = datetime.now()
        report.save()

        # Reset outbox
        mail.outbox = []

        # A citizen documents a report
        response = self.client.post(reverse('report_document', kwargs={'report_id': report.id, 'slug': 'hello'}), {
            'comment-text': 'new created comment',
            'citizen-email': self.citizen.email,
            'citizen-quality': 1,
            'files-TOTAL_FORMS': 0,
            'files-INITIAL_FORMS': 0,
            'files-MAX_NUM_FORMS': 0
        }, follow=True)

        report = response.context['report']

        # Mails are sent to responsibles according to mail config of the group: 1 for group + members
        expected_recipients = self.group_mail_config.get_manager_recipients()

        self.assertTrue(mail.outbox)
        self.assertEquals(len(mail.outbox), len(expected_recipients))

        for email in mail.outbox:
            self.assertIn(email.to[0], expected_recipients)

    def test_pro_updates_report_mail(self):
        response = self.client.post(
            reverse('report_new') + '?x=150056.538&y=170907.56',
            self.sample_post,
            follow=True)

        report = response.context['report']

        # Login to access the pro page
        self.client.login(username='******', password='******')

        # Publish the created report
        response = self.client.post(reverse('report_accept_pro', args=[report.id]), follow=True)

        # Reset outbox
        mail.outbox = []

        # Document report as pro
        response = self.client.post(reverse('report_show_pro', kwargs={'report_id': report.id, 'slug': 'hello'}), {
            'comment-text': 'new created comment',
            'files-TOTAL_FORMS': 0,
            'files-INITIAL_FORMS': 0,
            'files-MAX_NUM_FORMS': 0
        }, follow=True)

        # Mails are sent to responsibles according to mail config of the group: 1 for group + members without the author
        expected_recipients = self.group_mail_config.get_manager_recipients(self.manager)

        self.assertTrue(mail.outbox)
        self.assertEquals(len(mail.outbox), len(expected_recipients))

        for email in mail.outbox:
            self.assertIn(email.to[0], expected_recipients)

    def test_publish_comment_mail(self):
        response  = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post, follow=True)
        report = response.context['report']

        # Login to access the pro page
        self.client.login(username='******', password='******')

        # Accept and publish the created report
        report.private     = False
        report.accepted_at = datetime.now()
        report.save()

        # Assure that comment is private
        self.assertEqual(ReportAttachment.PRIVATE, report.comments()[0].security_level)

        # Reset outbox
        mail.outbox = []

        # Now make the comment public
        response = self.client.get(
            reverse('report_update_attachment', args=[report.id]),
            {
                'updateType': 1,
                'attachmentId': report.comments()[0].id
            },
        follow=True)

        self.assertEqual(ReportAttachment.PUBLIC, report.comments()[0].security_level)

        # All notifications are sent to subscribers as digest
        self.assertEquals(len(mail.outbox), 0)

    def test_subscription_for_pro_mail(self):
        response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post, follow=True)
        report = response.context['report']

        # Login to access the pro page
        self.client.login(username='******', password='******')

        # Publish the created report
        response = self.client.post(reverse('report_accept_pro', args=[report.id]), follow=True)
        self.client.logout()

        # Reset outbox
        mail.outbox = []

        self.client.login(username='******', password='******')
        response = self.client.get(reverse('subscribe_pro', args=[report.id]), {}, follow=True)

        # 1 mail sent in real-time to subscriber
        self.assertEquals(len(mail.outbox), 1)
        self.assertTrue(self.manager2.email in mail.outbox[0].to)

    def test_make_report_switch_visibility(self):
        response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post, follow=True)

        # Assure that report is public
        report = response.context['report']
        self.assertFalse(report.private)

        # Login to access the pro page
        self.client.login(username='******', password='******')

        # Publish the created report
        response = self.client.post(reverse('report_accept_pro', args=[report.id]), follow=True)

        # Reset outbox
        mail.outbox = []

        # 1/ Now make the report private
        response = self.client.get(reverse('report_change_switch_visibility', args=[report.id]) + '?visibility=true', follow=True)

        report = Report.objects.get(id=report.id)
        self.assertTrue(report.private)

        # Mails are sent in real time
        self.assertEquals(len(mail.outbox), 1)

        # Reset outbox
        mail.outbox = []

        # 2/ Now make the report public
        response = self.client.get(reverse('report_change_switch_visibility', args=[report.id]) + '?visibility=false', follow=True)

        report = Report.objects.get(id=report.id)
        self.assertFalse(report.private)

        # Mails are sent in real time
        self.assertEquals(len(mail.outbox), 1)

    #def testMergeReportMail(self):
    #    #Login to access the pro page
    #    self.client.login(username='******', password='******')
    #    #Send a post request filling in the form to create a report
    #    response = self.client.post(reverse('report_new_pro') + '?x=150056.538&y=170907.56', self.sample_post, follow=True)
    #    self.assertEquals(response.status_code, 200)
    #    self.assertIn('report', response.context)

    #    report_id = response.context['report'].id

    #    self.assertEquals(len(mail.outbox),  1)  # one for creator subscription, one for manager

    #    self.client.logout()
    #    response = self.client.post(
    #        reverse('report_new') + '?x=150056.538&y=170907.56',
    #        self.sample_post,
    #        follow=True)
    #    self.assertEquals(response.status_code, 200)
        # Should send mail only to responsible
    #    self.assertEquals(len(mail.outbox), 3)

    #    report2_id = response.context['report'].id

    #    self.client.login(username='******', password='******')
        # Publish the created report
    #    response3 = self.client.post(reverse('report_accept_pro', args=[report2_id]), follow=True)
    #    self.assertEquals(response3.status_code, 200)
    #    self.assertEquals(len(mail.outbox), 4)

        # Merge reports
    #    url2 = reverse('report_do_merge_pro', args=[report_id])
    #    self.client.post(url2, {"mergeId": report2_id})

    #    self.assertTrue(Report.objects.all().visible().filter(id=report_id).exists())
    #    self.assertFalse(Report.objects.all().visible().filter(id=report2_id).exists())

        #Reference from merged to kept report
    #    self.assertEqual(report_id, Report.objects.get(id=report2_id).merged_with.id)
        #A mail has been sent to the creator of the first report to notify him that his report has been merged
    #    self.assertEquals(len(mail.outbox), 5)

    def test_send_PDF_to_pro_mail(self):
        response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post, follow=True)
        report   = response.context['report']

        # Login to access the pro page
        self.client.login(username='******', password='******')

        # Publish the created report
        response = self.client.post(reverse('report_accept_pro', args=[report.id]), follow=True)

        # Reset outbox
        mail.outbox = []

        # Send Pro PDF
        response = self.client.post(reverse('send_pdf', args=[report.id]), self.sample_post_mail_pdf_pro)

        # 3 mails should be sent
        self.assertEquals(len(mail.outbox), 3)

    def test_send_PDF_to_citizen_mail(self):
        response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post, follow=True)

        report             = response.context['report']
        report.accepted_at = datetime.now()
        report.save()

        # Reset outbox
        mail.outbox = []

        # Login to access the pro page
        self.client.login(username='******', password='******')

        # Now send Pro PDF
        response = self.client.post(reverse('send_pdf', args=[report.id]), self.sample_post_mail_pdf_citzen)

        # 3 mails should be sent to citizens
        self.assertEquals(len(mail.outbox), 3)

    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_recipient_for_everyone(self):
        """
        recipients must contains everyone (group, manager and manager4)
        """
        recipients = self.group_mail_config.get_manager_recipients()
        self.assertEquals(len(recipients), 3)
        self.assertIn(self.group.email, recipients)
        self.assertIn(self.manager.email, recipients)
        self.assertIn(self.manager4.email, recipients)

    def test_recipient_exclude_author(self):
        """
        recipients must contains everyone (group, manager and manager4)
        """
        recipients = self.group_mail_config.get_manager_recipients(self.manager)
        self.assertEquals(len(recipients), 2)
        self.assertIn(self.group.email, recipients)
        self.assertIn(self.manager4.email, recipients)

    def test_recipient_for_manager_as_group(self):
        """
        if email group is same as manager then recipients
        must contains ony once this email (distinct values)
        (group email and manager4)
        """
        self.group.email = self.manager.email
        self.group.save()
        self.group_mail_config.notify_group = False
        self.group_mail_config.save()

        recipients = self.group_mail_config.get_manager_recipients()
        self.assertEquals(len(recipients), 2)
        self.assertIn(self.manager.email, recipients)
        self.assertIn(self.manager4.email, recipients)

    def test_recipient_for_manager_as_group_author(self):
        """
        if email group is same as manager then recipients and also is the author
        this email must be excluded
        """
        self.group.email = self.manager.email
        recipients = self.group_mail_config.get_manager_recipients(self.manager)
        self.assertEquals(len(recipients), 2)
        self.assertIn(self.manager4.email, recipients)
        self.assertIn(self.group.email, recipients)
Пример #20
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_visibility", args=[self.report.id]),
            {"visibility": "true"})
        self.assertTrue(Report.objects.get(id=self.report.id).private)
        self.client.get(
            reverse("report_change_switch_visibility", args=[self.report.id]),
            {"visibility": "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_visibility", args=[self.report.id])+"?visibility=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_visibility", args=[self.report.id])+"?visibility=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'])
Пример #21
0
class ReportViewsTest(FMSTestCase):
    def setUp(self):

        self.user = FMSUser(username='******',
                            email='*****@*****.**',
                            password='******')
        self.user.save()

        self.client = Client()

        self.citizen = FMSUser(telephone="0123456789",
                               last_used_language="fr",
                               first_name="citizen",
                               last_name="citizen",
                               email="*****@*****.**")
        self.citizen.save()

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

        self.group_mail_config = GroupMailConfig()
        self.group_mail_config.group = self.group
        self.group_mail_config.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 = OrganisationEntity.objects.get(pk=14)
        self.manager.save()
        self.group.dispatch_categories.add(ReportCategory.objects.get(pk=1))

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

        surface = OrganisationEntitySurface(
            geom=Polygon([p1, p2, p3, p4, p1]),
            owner=OrganisationEntity.objects.get(pk=14),
        )
        surface.save()

        self.manager.memberships.create(organisation=self.group,
                                        contact_user=True)

        self.sample_post = {
            'report-x': '150056.538',
            'report-y': '170907.56',
            'report-address_fr': 'Avenue des Arts, 3',
            'report-address_nl': 'Kunstlaan, 3',
            'report-address_number': '3',
            'report-postalcode': '1210',
            'report-category': '1',
            'report-secondary_category': '1',
            'report-subscription': 'on',
            'comment-text': 'test',
            'files-TOTAL_FORMS': 0,
            'files-INITIAL_FORMS': 0,
            'files-MAX_NUM_FORMS': 0,
            'citizen-email': self.citizen.email,
            'citizen-firstname': self.citizen.first_name,
            'citizen-lastname': self.citizen.last_name,
            'citizen-quality': '1',
            'report-terms_of_use_validated': True
        }
        self.sample_post_2 = {
            'report-x': '150056',
            'report-y': '170907.56',
            'report-address_fr': 'Avenue des Arts, 3',
            'report-address_nl': 'Kunstlaan, 3',
            'report-address_number': '5',
            'report-postalcode': '1210',
            'report-category': '1',
            'report-secondary_category': '1',
            'report-subscription': 'on',
            'comment-text': 'test2',
            'files-TOTAL_FORMS': 0,
            'files-INITIAL_FORMS': 0,
            'files-MAX_NUM_FORMS': 0,
            'citizen-email': self.citizen.email,
            'citizen-firstname': self.citizen.first_name,
            'citizen-lastname': self.citizen.last_name,
            'citizen-quality': '1',
            'report-terms_of_use_validated': True
        }

    def test_home(self):
        """Tests the new report view."""
        response = self.client.get(reverse('home'), follow=True)
        self.assertEqual(response.status_code, 200)
        self.assertTrue('report_counts' in response.context)
        self.assertTrue('zipcodes' in response.context)
        #Are the zipcodes well loaded from DB??
        self.assertTrue(len(response.context['zipcodes']) > 0)

    @skip('replaced by database pages')
    def test_about(self):
        """Tests the about view."""
        response = self.client.get(reverse('about'), follow=True)
        self.assertEqual(response.status_code, 200)

    @skip('replaced by database pages')
    def test_term_of_use(self):
        """Tests the term of use view."""
        response = self.client.get(reverse('terms_of_use'), follow=True)
        self.assertEqual(response.status_code, 200)

    def test_new_report(self):
        """Tests the new report page."""
        url = reverse('report_new')
        response = self.client.get(url, {
            'x': '148360',
            'y': '171177'
        },
                                   follow=True)
        self.assertEqual(response.status_code, 200)

    def test_verify_report(self):
        """Tests the new report page get verify existings."""
        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)

        url = reverse('report_verify')
        response = self.client.get(url, {
            'x': '150056',
            'y': '170907'
        },
                                   follow=True)
        self.assertEqual(response.status_code, 200)

        self.assertIn('reports_nearby', response.context)
        # Assert that the list view displays minimal information about reports
        last_dist = 0
        for report in response.context['reports_nearby']:
            self.assertContains(response, report.get_absolute_url())
            self.assertTrue(report.distance.m <= 20)  # limit to 1km around
            self.assertTrue(
                report.distance.m >= last_dist)  # ordered by distance
            last_dist = report.distance.m

    def test_create_report(self):
        """Tests the creation of a report and test the view of it."""

        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)

        self.assertIn('report', response.context)

        report = response.context['report']

        self.assertContains(response, report.postalcode)
        self.assertContains(response, report.status)

        self.assertEqual(1, len(Report.objects.all()))

        # Get in the DB the created report
        report = Report.objects.all()[0]

        # Check that source is correct
        self.assertEqual(Report.SOURCES['WEB'], report.source)

    def test_create_report_double(self):
        """Tests the creation of a double report and test the view of it."""

        url = "%s?x=148360&y=171177" % reverse('report_new')

        self.client.post(url, self.sample_post, follow=True)
        self.client.post(url, self.sample_post, follow=True)
        self.client.post(url, self.sample_post, follow=True)
        self.client.post(url, self.sample_post, follow=True)

        self.assertEqual(1, len(Report.objects.all()))

    def test_accept_report(self):
        """Tests acceptation a report and test the view of it."""

        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']

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

        url = reverse('report_accept_pro', args=[report.id])
        response = self.client.get(url, follow=True)
        self.assertEqual(response.status_code, 200)

        report = response.context['report']

        self.assertTrue(report.accepted_at is not None)

    def test_refuse_report(self):
        """Tests refuse a report and test the view of it."""

        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']

        # Be sure it's private
        report.private = True
        report.save()

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

        url = reverse('report_refuse_pro', args=[report.id])
        response = self.client.post(url, {'text': "Message de refus"},
                                    follow=True)
        self.assertEqual(response.status_code, 200)

        report = response.context['report']

        self.assertTrue(report.accepted_at is None)
        self.assertEqual(report.status, Report.REFUSED)

        comment = ReportComment.objects.get(report_id=report.id,
                                            type=ReportAttachment.REFUSED)
        self.assertEqual(comment.security_level, ReportComment.PRIVATE)

    def test_refuse_report_comment_visible_for_citizen(self):
        """Tests refuse a report and test the view of it."""

        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']

        # Be sure it's public
        report.private = False
        report.save()

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

        url = reverse('report_refuse_pro', args=[report.id])
        response = self.client.post(url, {'text': "Message de refus"},
                                    follow=True)
        self.assertEqual(response.status_code, 200)

        report = response.context['report']

        self.assertTrue(report.accepted_at is None)
        self.assertEqual(report.status, Report.REFUSED)

        comment = ReportComment.objects.get(report_id=report.id,
                                            type=ReportAttachment.REFUSED)
        self.assertEqual(comment.security_level, ReportComment.PUBLIC)

    def test_add_comment(self):
        """Tests the update of a report."""
        url = "%s?x=148360&y=171177" % reverse('report_new')
        response = self.client.post(url, self.sample_post, follow=True)
        report = response.context['report']

        self.assertEqual(report.comments().count(), 1)
        self.assertEqual(report.comments()[0].created_by, self.citizen)
        report.save()

        response = self.client.post(reverse('report_document',
                                            kwargs={
                                                'report_id': report.id,
                                                'slug': 'hello'
                                            }),
                                    {
                                        'comment-text': 'new created comment',
                                        'citizen-email': self.user.email,
                                        'citizen-quality': 1,
                                        'files-TOTAL_FORMS': 0,
                                        'files-INITIAL_FORMS': 0,
                                        'files-MAX_NUM_FORMS': 0
                                    },
                                    follow=True)
        self.assertEqual(response.status_code, 200)
        url = reverse('report_show2', args=[report.id])
        self.assertRedirects(response, url)

        self.assertEqual(report.comments().count(), 2)
        self.assertEqual(report.comments()[1].created_by, self.user)

    def test_add_comment_as_pro(self):
        """Tests the update of a report as a pro."""
        self.client.login(username='******', password='******')

        url = "%s?x=148360&y=171177" % reverse('report_new_pro')
        response = self.client.post(url, self.sample_post, follow=True)
        report = response.context['report']

        self.assertEqual(report.comments().count(), 1)
        self.assertEqual(report.comments()[0].created_by, self.manager)
        report.save()

        response = self.client.post(reverse('report_show_pro',
                                            kwargs={
                                                'report_id': report.id,
                                                'slug': 'hello'
                                            }),
                                    {
                                        'comment-text': 'new created comment',
                                        'files-TOTAL_FORMS': 0,
                                        'files-INITIAL_FORMS': 0,
                                        'files-MAX_NUM_FORMS': 0
                                    },
                                    follow=True)
        self.assertEqual(response.status_code, 200)
        self.assertRedirects(response, report.get_absolute_url_pro())

        self.assertEqual(report.comments().count(), 2)
        self.assertEqual(report.comments()[1].created_by, self.manager)

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

        url = "%s?x=148360&y=171177" % reverse('report_new')
        response = self.client.post(url, self.sample_post, follow=True)
        report = response.context['report']

        self.assertEqual(Report.objects.get(id=report.id).category.id, 1)
        self.assertEqual(
            Report.objects.get(id=report.id).secondary_category.id, 1)

        # Setting a private sec_cat to a public report is not allowed
        self.client.post(
            reverse('update_category_for_report', args=[report.id]), {
                "main_category": "2",
                "secondary_category": "32"
            })

        # So, cat not changed
        self.assertEqual(Report.objects.get(id=report.id).category.id, 1)
        self.assertEqual(
            Report.objects.get(id=report.id).secondary_category.id, 1)

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

        url = "%s?x=148360&y=171177" % reverse('report_new')
        response = self.client.post(url, self.sample_post, follow=True)
        report = response.context['report']

        self.assertEqual(Report.objects.get(id=report.id).category.id, 1)
        self.assertEqual(
            Report.objects.get(id=report.id).secondary_category.id, 1)

        self.client.post(
            reverse('update_category_for_report', args=[report.id]), {
                "main_category": "2",
                "secondary_category": "2"
            })

        self.assertEqual(Report.objects.get(id=report.id).category.id, 2)
        self.assertEqual(
            Report.objects.get(id=report.id).secondary_category.id, 2)

    def test_subscription(self):
        """Tests the subscription of a report."""

        url = "%s?x=148360&y=171177" % reverse('report_new')
        response = self.client.post(url, self.sample_post, follow=True)
        report = response.context['report']

        # responsible manager is NOT subscribed by default
        self.assertFalse(
            report.subscriptions.filter(subscriber=self.manager).exists())

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

        # subscribe to the report
        response = self.client.get(reverse('subscribe_pro', args=[report.id]),
                                   {},
                                   follow=True)
        self.assertRedirects(response, report.get_absolute_url_pro())
        self.assertEqual(response.status_code, 200)

        #current user is subscribed
        self.assertTrue(
            report.subscriptions.filter(subscriber=self.manager).exists())

    def test_subscription_citizen(self):
        """Tests the subscription of a report."""

        url = "%s?x=148360&y=171177" % reverse('report_new')
        response = self.client.post(url, self.sample_post, follow=True)
        report = response.context['report']

        # current user is not subscribed yet
        self.assertTrue(
            report.subscriptions.filter(subscriber=self.citizen).exists())

        #unsubscribe to the report
        response = self.client.get(reverse('unsubscribe', args=[report.id]) +
                                   '?citizen_email=' + self.citizen.email, {},
                                   follow=True)
        url = reverse('report_show2', args=[report.id])
        self.assertRedirects(response, url)
        self.assertEqual(response.status_code, 200)

        #current user is no more subscribed
        self.assertFalse(
            report.subscriptions.filter(subscriber=self.citizen).exists())

    def test_do_merge_reports(self):
        """Test do merge reports. """

        #Add first report
        url = "%s?x=148360&y=171177" % reverse('report_new')
        response = self.client.post(url, self.sample_post, follow=True)
        report = response.context['report']

        #Add second report
        response2 = self.client.post(url, self.sample_post_2, follow=True)
        report2 = response2.context['report']

        #Login user
        params = {'username': self.manager.email, 'password': '******'}
        self.client.post(reverse('login'), params)

        #Merge reports
        url2 = reverse('report_do_merge_pro', args=[report.id])
        self.client.post(url2, {"mergeId": report2.id})

        #Reference from merged to kept report
        self.assertEqual(report.id,
                         Report.objects.get(id=report2.id).merged_with.id)

        #The first one (oldest one) is kept
        self.assertEqual(Report.objects.all().visible()[0].id, report.id)

        #The comment of the second one is added to the first one
        self.assertEqual(
            Report.objects.get(id=report.id).comments().count(), 2)

    def test_merge_reports(self):
        """Test merge reports. """

        # Add first report
        url = "%s?x=148360&y=171177" % reverse('report_new')
        response = self.client.post(url, self.sample_post, follow=True)
        report = response.context['report']

        # Add second report
        response2 = self.client.post(url, self.sample_post_2, follow=True)
        report2 = response2.context['report']
        report2.status = Report.IN_PROGRESS
        report2.save()

        # Login user
        params = {'username': self.manager.email, 'password': '******'}
        self.client.post(reverse('login'), params)

        # Display mergeable reports list
        url = reverse('report_merge_pro', args=[report.get_slug(), report.id])
        response = self.client.get(url)

        self.assertEqual(report, response.context['report'])
        self.assertEqual(1, len(response.context['reports_nearby']))

    def test_merge_reports_search_ticket(self):
        """Test merge reports with search of ticket number """

        # Add first report
        url = "%s?x=148360&y=171177" % reverse('report_new')
        response = self.client.post(url, self.sample_post, follow=True)
        report = response.context['report']

        # Add second report
        response2 = self.client.post(url, self.sample_post_2, follow=True)
        report2 = response2.context['report']
        report2.status = Report.IN_PROGRESS  #necessary otherwise both report will be with "CREATED" status
        # and you can't merge 2 reports with 2 "CREATED" status
        report2.save()

        # Login user
        params = {'username': self.manager.email, 'password': '******'}
        self.client.post(reverse('login'), params)

        # Display mergeable report according to ticket number
        url2 = reverse('report_merge_pro', args=[report.get_slug(), report.id])
        response = self.client.get("%s?ticketNumber=%s" % (url2, report2.id))

        self.assertEqual(report, response.context['report'])
        self.assertEqual(1, len(response.context['reports_nearby']))
        self.assertEqual(report2.id, response.context['reports_nearby'][0].id)

    def test_mark_done_as_user(self):
        """Tests marking report as done."""

        url = "%s?x=148360&y=171177" % reverse('report_new')
        response = self.client.post(url, self.sample_post, follow=True)
        report = response.context['report']

        self.client.login(username='******', password='******')
        url = reverse('report_accept_pro', args=[report.id])
        response = self.client.get(url, follow=True)

        # Mark as done as citizen
        self.client.logout()
        response = self.client.post(reverse('report_update', args=[report.id]),
                                    {'is_fixed': 'True'},
                                    follow=True)
        self.assertEqual(response.status_code, 200)

        report = response.context['report']
        self.assertTrue(report.fixed_at)
        self.assertEqual(report.status, Report.SOLVED)
        self.assertFalse(
            ReportComment.objects.filter(type=ReportAttachment.MARK_AS_DONE,
                                         report=report).exists())

    def test_mark_done_as_pro(self):
        """Tests marking report as done."""

        url = "%s?x=148360&y=171177" % reverse('report_new')
        response = self.client.post(url, self.sample_post, follow=True)
        report = response.context['report']

        self.client.login(username='******', password='******')
        url = reverse('report_accept_pro', args=[report.id])
        response = self.client.get(url, follow=True)
        self.assertEqual(response.status_code, 200)

        # Mark as done as pro
        response = self.client.post(reverse('report_fix_pro',
                                            args=[report.id]),
                                    {'text': 'commentaire'},
                                    follow=True)
        self.assertEquals(response.status_code, 200)

        report = response.context['report']

        self.assertTrue(report.fixed_at)
        self.assertTrue(
            ReportComment.objects.filter(type=ReportAttachment.MARK_AS_DONE,
                                         report=report).exists())
        self.assertEquals(report.status, Report.SOLVED)

    def test_mark_done_as_user_denied(self):
        """Tests marking report not done if denied."""

        url = "%s?x=148360&y=171177" % reverse('report_new')
        response = self.client.post(url, self.sample_post, follow=True)
        report = response.context['report']

        self.client.login(username='******', password='******')
        url = reverse('report_accept_pro', args=[report.id])
        response = self.client.get(url, follow=True)

        # Change status to refused
        report.status = report.REFUSED
        report.save()

        # Try to mark as done as citizen
        self.client.logout()
        response = self.client.post(reverse('report_update', args=[report.id]),
                                    {'is_fixed': 'True'},
                                    follow=True)
        self.assertEqual(response.status_code, 200)

        report = response.context['report']

        self.assertFalse(report.fixed_at)
        self.assertEqual(report.status, Report.REFUSED)
        self.assertFalse(
            ReportComment.objects.filter(type=ReportAttachment.MARK_AS_DONE,
                                         report=report).exists())

    def test_mark_done_as_pro_denied(self):
        """Tests marking report as done."""

        url = "%s?x=148360&y=171177" % reverse('report_new')
        response = self.client.post(url, self.sample_post, follow=True)
        report = response.context['report']

        self.client.login(username='******', password='******')
        url = reverse('report_accept_pro', args=[report.id])
        response = self.client.get(url, follow=True)
        self.assertEqual(response.status_code, 200)

        # Change status to refused
        report.status = report.REFUSED
        report.save()

        # Try to mark as done as pro
        response = self.client.post(reverse('report_fix_pro',
                                            args=[report.id]),
                                    {'text': 'commentaire'},
                                    follow=True)
        self.assertEquals(response.status_code, 200)

        report = response.context['report']

        self.assertFalse(report.fixed_at)
        self.assertFalse(
            ReportComment.objects.filter(type=ReportAttachment.MARK_AS_DONE,
                                         report=report).exists())
        self.assertEquals(report.status, Report.REFUSED)

    def test_mark_done_as_user_denied(self):
        """Tests marking report not done if denied."""

        url = "%s?x=148360&y=171177" % reverse('report_new')
        response = self.client.post(url, self.sample_post, follow=True)
        report = response.context['report']

        self.client.login(username='******', password='******')
        url = reverse('report_accept_pro', args=[report.id])
        response = self.client.get(url, follow=True)

        # Change status to refused
        report.status = report.REFUSED
        report.save()

        # Try to mark as done as citizen
        self.client.logout()
        response = self.client.post(reverse('report_update', args=[report.id]),
                                    {'is_fixed': 'True'},
                                    follow=True)
        self.assertEqual(response.status_code, 200)

        report = response.context['report']

        self.assertFalse(report.fixed_at)
        self.assertEqual(report.status, Report.REFUSED)
        self.assertFalse(
            ReportComment.objects.filter(type=ReportAttachment.MARK_AS_DONE,
                                         report=report).exists())

    def test_mark_done_as_pro_denied(self):
        """Tests marking report as done."""

        url = "%s?x=148360&y=171177" % reverse('report_new')
        response = self.client.post(url, self.sample_post, follow=True)
        report = response.context['report']

        self.client.login(username='******', password='******')
        url = reverse('report_accept_pro', args=[report.id])
        response = self.client.get(url, follow=True)
        self.assertEqual(response.status_code, 200)

        # Change status to refused
        report.status = report.REFUSED
        report.save()

        # Try to mark as done as pro
        response = self.client.post(reverse('report_fix_pro',
                                            args=[report.id]),
                                    {'text': 'commentaire'},
                                    follow=True)
        self.assertEquals(response.status_code, 200)

        report = response.context['report']

        self.assertFalse(report.fixed_at)
        self.assertFalse(
            ReportComment.objects.filter(type=ReportAttachment.MARK_AS_DONE,
                                         report=report).exists())
        self.assertEquals(report.status, Report.REFUSED)

    def test_search_ticket(self):
        """Tests searching ticket."""
        url = "%s?x=148360&y=171177" % reverse('report_new')
        response = self.client.post(url, self.sample_post, follow=True)
        report = response.context['report']

        url = '%s?report_id=%s' % (reverse('search_ticket'), report.id)
        response = self.client.get(url, follow=True)

        self.assertEqual(response.status_code, 200)
        report_result = response.context['report']

        self.assertEqual(report, report_result)

    def test_login_user(self):
        params = {'username': self.manager.email, 'password': '******'}
        response = self.client.post(reverse('login'), params)

        self.assertEqual(response.status_code, 302)

    def test_login_user_with_redirect(self):
        params = {'username': self.manager.email, 'password': '******'}

        url = '%s?next=/fr/pro/reports/' % reverse('login')
        response = self.client.post(url, params)

        self.assertEqual(response.status_code, 302)

    def test_login_user_fail(self):
        params = {'username': self.manager.email, 'password': '******'}
        response = self.client.post(reverse('login'), params)

        self.assertEqual(response.status_code, 200)

        escaped = escape(
            ugettext(
                'Please enter a correct username and password. Note that both fields are case-sensitive.'
            ))
        self.assertContains(response, escaped)

    def test_logout_user(self):
        params = {'username': self.manager.email, 'password': '******'}
        self.client.post(reverse('login'), params)

        response = self.client.post(reverse('logout'))
        self.assertEqual(response.status_code, 302)

    def test_marker_detail_citizen(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)

        self.assertIn('report', response.context)

        report = response.context['report']
        jsonResult = report.full_marker_detail_JSON()
        #Now test on all mandatory fields
        self.assertIn('id', jsonResult)
        self.assertIn('point', jsonResult)
        self.assertIn('category', jsonResult)
        self.assertIn('address', jsonResult)
        self.assertIn('address_number', jsonResult)
        self.assertIn('postalcode', jsonResult)
        self.assertIn('address_commune_name', jsonResult)
        self.assertIn('address_regional', jsonResult)
        self.assertIn('thumb', jsonResult)
        self.assertIn('contractor', jsonResult)
        self.assertIn('date_planned', jsonResult)
        self.assertNotIn('is_closed', jsonResult)
        self.assertNotIn('citizen', jsonResult)
        self.assertNotIn('priority', jsonResult)

    def test_marker_detail_pro(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)

        self.assertIn('report', response.context)

        report = response.context['report']
        jsonResult = report.full_marker_detail_pro_JSON()
        #Now test on all mandatory fields
        self.assertIn('id', jsonResult)
        self.assertIn('point', jsonResult)
        self.assertIn('category', jsonResult)
        self.assertIn('address', jsonResult)
        self.assertIn('address_number', jsonResult)
        self.assertIn('postalcode', jsonResult)
        self.assertIn('address_commune_name', jsonResult)
        self.assertIn('address_regional', jsonResult)
        self.assertIn('thumb', jsonResult)
        self.assertIn('contractor', jsonResult)
        self.assertIn('date_planned', jsonResult)
        self.assertIn('is_closed', jsonResult)
        self.assertIn('citizen', jsonResult)
        self.assertIn('priority', jsonResult)

    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 test_reopen_report_processed(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']
        report.status = Report.PROCESSED
        report.accepted_at = datetime.now()
        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.accepted_at, report_reopen.accepted_at)
        self.assertEqual(report.close_date, report_reopen.close_date)

        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 test_reopen_report_badstatus(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']
        report.accepted_at = datetime.now()
        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_not_reopen = response.context['report']

        self.assertNotEqual(Report.MANAGER_ASSIGNED, report_not_reopen.status)
        self.assertEqual(report.status, report_not_reopen.status)
        self.assertEqual(report.created, report_not_reopen.created)
        self.assertEqual(report.modified, report_not_reopen.modified)
        self.assertEqual(report.accepted_at, report_not_reopen.accepted_at)
        self.assertEqual(report.close_date, report_not_reopen.close_date)

        self.assertEqual(report.subscriptions.all().count(),
                         report_not_reopen.subscriptions.all().count())
        self.assertEqual(report.responsible_entity,
                         report_not_reopen.responsible_entity)
        self.assertEqual(report.responsible_department,
                         report_not_reopen.responsible_department)

    def test_auto_assign(self):
        # Associate a category to an organisation for auto-dispatching
        entity = OrganisationEntity()
        entity.name_fr = "My entity"
        entity.type = OrganisationEntity.COMMUNE
        entity.email = "*****@*****.**"
        entity.save()

        # Associate a category to an organisation for auto-dispatching
        department = OrganisationEntity()
        department.name_fr = "My group"
        department.type = OrganisationEntity.DEPARTMENT
        department.dependency = entity
        department.email = "*****@*****.**"
        department.save()

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

        category = ReportCategory.objects.get(
            id=self.sample_post['report-category'])
        category.organisation_communal = entity
        category.save()

        department.dispatch_categories.add(category)

        # Create new report
        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']

        # Auto-dispatching working for commune
        self.assertFalse(report.is_regional())
        self.assertEqual(report.responsible_department, department)
        self.assertEqual(report.responsible_entity, entity)

    def test_not_auto_assign_if_report_already_exists(self):
        # Create new report
        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']

        # Associate a category to an organisation for auto-dispatching
        entity = OrganisationEntity()
        entity.name_fr = "My entity"
        entity.type = OrganisationEntity.COMMUNE
        entity.email = "*****@*****.**"
        entity.save()

        # Associate a category to an organisation for auto-dispatching
        department = OrganisationEntity()
        department.name_fr = "My group"
        department.type = OrganisationEntity.DEPARTMENT
        department.dependency = entity
        department.email = "*****@*****.**"
        department.save()

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

        category = ReportCategory.objects.get(
            id=self.sample_post['report-category'])
        category.organisation_communal = entity
        category.save()

        department.dispatch_categories.add(category)

        # Assign report to another entity
        report.responsible_entity = self.group.dependency
        report.responsible_department = None
        report.save()

        # Check it's not auto-dispatching
        report = Report.objects.get(id=report.id)

        self.assertFalse(report.is_regional())
        self.assertNotEqual(report.responsible_department, department)
        self.assertNotEqual(report.responsible_entity, entity)

        self.assertEqual(report.responsible_entity, self.group.dependency)
        self.assertEqual(report.responsible_department, self.group)
Пример #22
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()
Пример #23
0
    def setUp(self):
        self.secondary_category = ReportCategory.objects.all()[0]
        self.category = self.secondary_category.category_class

        self.bxl = OrganisationEntity.objects.get(
            id=4)  # postal code = 1000 Bxl
        self.bxl.save()

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

        surface = OrganisationEntitySurface(
            geom=Polygon([p1, p2, p3, p4, p1]),
            owner=self.bxl,
        )
        surface.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.agent = FMSUser(is_active=True,
                             email="*****@*****.**",
                             telephone="0123456789",
                             last_used_language="fr",
                             agent=True,
                             organisation=self.bxl)
        self.agent.save()

        self.stib = OrganisationEntity.objects.get(id=21)
        self.stib.dependency = self.bxl
        self.stib.save()

        self.contractor = FMSUser(is_active=True,
                                  email="*****@*****.**",
                                  telephone="0123456789",
                                  last_used_language="fr",
                                  contractor=True,
                                  organisation=self.bxl)
        self.contractor.save()

        self.contractor_manager = FMSUser(is_active=True,
                                          email="*****@*****.**",
                                          telephone="90870870",
                                          last_used_language="fr",
                                          contractor=True,
                                          organisation=self.bxl,
                                          manager=True)
        self.contractor_manager.save()
        uom = UserOrganisationMembership(user=self.contractor_manager,
                                         organisation=self.group)
        uom.save()

        self.entity_manager = FMSUser(is_active=True,
                                      email="*****@*****.**",
                                      telephone="90870870",
                                      last_used_language="fr",
                                      leader=True,
                                      organisation=self.bxl,
                                      manager=True)
        self.entity_manager.save()
        self.usergroupmembership = UserOrganisationMembership(
            user_id=self.entity_manager.id, organisation_id=self.group.id)
        self.usergroupmembership.save()

        self.manager = FMSUser(is_active=True,
                               email="*****@*****.**",
                               telephone="0123456789",
                               last_used_language="fr",
                               manager=True,
                               organisation=self.bxl)
        self.manager.save()
        self.usergroupmembership2 = UserOrganisationMembership(
            user_id=self.manager.id,
            organisation_id=self.group.id,
            contact_user=True)
        self.usergroupmembership2.save()

        self.citizen = FMSUser(email="*****@*****.**",
                               telephone="0123456789",
                               last_used_language="fr")
        self.citizen.save()
Пример #24
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)
Пример #25
0
    def setUp(self):

        try:
            organisation = OrganisationEntity.objects.get(id=1)
        except ObjectDoesNotExist:
            organisation = OrganisationEntity(id=1, name="Test organisation")
            organisation.save()

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

        surface = OrganisationEntitySurface(
            geom=Polygon([p1, p2, p3, p4, p1]),
            owner=OrganisationEntity.objects.get(pk=14)
        )
        surface.save()

        #user_auth = User.objects.create_user(username='******', email='*****@*****.**', password='******')
        #user_auth.save()
        user = FMSUser(
            is_active=True,
            password="******",
            email="*****@*****.**",
            first_name="zaza",
            telephone="00000000",
            last_used_language="fr",
            organisation=organisation,
            username='******')
        user.save()

        #~ main_category = ReportMainCategoryClass(id=2,name_en='test main en',name_nl='test main nl',name_fr='test main fr')
        #~ main_category.save()
        #~
        #~ secondary_category = ReportSecondaryCategoryClass(id=2,name_en='test second en',name_nl='test second nl',name_fr='test second fr')
        #~ secondary_category.save()
        #~
        #~ category = ReportCategory(id=2,name_en='test parent en',name_nl='test parent nl',name_fr='test parent fr', public=True, category_class=main_category, secondary_category_class=secondary_category)
        #~ category.save()
        self.citizen = FMSUser(
            telephone="0123456789",
            last_used_language="fr",
            first_name="citizen",
            last_name="citizen",
            email="*****@*****.**"
        )
        self.citizen.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 = OrganisationEntity.objects.get(pk=14)
        self.manager.save()

        self.group = OrganisationEntity(
            type="D",
            name_nl="Werken",
            name_fr="Travaux",
            phone="090987",
            dependency=OrganisationEntity.objects.get(pk=14),
            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.id, organisation_id=self.group.id, contact_user=True)
        self.usergroupmembership.save()

        self.sample_post = {
            'report-x': '150056.538',
            'report-y': '170907.56',
            'report-address_fr': 'Avenue des Arts, 3',
            'report-address_nl': 'Kunstlaan, 3',
            'report-address_number': '3',
            'report-postalcode': '1210',
            'report-category': '1',
            'report-secondary_category': '1',
            'report-subscription': 'on',
            'report-terms_of_use_validated': True,

            'comment-text': 'test',

            'files-TOTAL_FORMS': 0,
            'files-INITIAL_FORMS': 0,
            'files-MAX_NUM_FORMS': 1000,

            'citizen-quality': '1',
            'citizen-email': self.citizen.email,
            'citizen-firstname': self.citizen.first_name,
            'citizen-lastname': self.citizen.last_name
        }
Пример #26
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=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 setUp(self):
        self.citizen = FMSUser(
            telephone="0123456789",
            last_used_language="fr",
            first_name="citizen",
            last_name="citizen",
            email="*****@*****.**",
        )
        self.citizen.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 = OrganisationEntity.objects.get(pk=14)
        self.manager.save()

        self.group = OrganisationEntity(
            type="D",
            name_nl="Werken",
            name_fr="Travaux",
            phone="090987",
            dependency=OrganisationEntity.objects.get(pk=14),
            email="*****@*****.**",
        )
        self.group.save()
        self.group.dispatch_categories.add(ReportCategory.objects.get(pk=1))

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

        self.manager.memberships.create(organisation=self.group, contact_user=True)

        self.client = Client()

        self.manager2 = FMSUser(
            is_active=True,
            telephone="9876543210",
            last_used_language="nl",
            password="******",
            first_name="manager2",
            last_name="manager2",
            email="*****@*****.**",
            manager=True,
        )
        self.manager2.set_password("test2")
        self.manager2.organisation = OrganisationEntity.objects.get(pk=14)
        self.manager2.save()

        self.group2 = OrganisationEntity(
            type="D",
            name_nl="Werken",
            name_fr="Travaux",
            phone="090987",
            dependency=OrganisationEntity.objects.get(pk=21),
            email="*****@*****.**",
        )
        self.group2.save()
        self.group2.dispatch_categories.add(ReportCategory.objects.get(pk=2))
        self.group2.dispatch_categories.add(ReportCategory.objects.get(pk=1))

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

        surface = OrganisationEntitySurface(
            geom=Polygon([p1, p2, p3, p4, p1]), owner=OrganisationEntity.objects.get(pk=14)
        )
        surface.save()

        self.manager2.memberships.create(organisation=self.group2)

        self.manager3 = FMSUser(
            is_active=True,
            telephone="000000000",
            last_used_language="nl",
            password="******",
            first_name="manager3",
            last_name="manager3",
            email="*****@*****.**",
            manager=True,
        )
        self.manager3.set_password("test3")
        self.manager3.organisation = OrganisationEntity.objects.get(pk=21)
        self.manager3.save()

        self.manager3.memberships.create(organisation=self.group2)

        self.impetrant = OrganisationEntity(name_nl="MIVB", name_fr="STIB", email="*****@*****.**")

        self.impetrant.save()

        self.contractor = OrganisationEntity(
            name_nl="Fabricom GDF", name_fr="Fabricom GDF", email="*****@*****.**"
        )
        self.contractor.save()

        self.sample_post = {
            "report-x": "150056.538",
            "report-y": "170907.56",
            "report-address_fr": "Avenue des Arts, 3",
            "report-address_nl": "Kunstlaan, 3",
            "report-address_number": "3",
            "report-postalcode": "1210",
            "report-category": "1",
            "report-secondary_category": "1",
            "report-subscription": "on",
            "citizen-quality": "1",
            "comment-text": "test",
            "files-TOTAL_FORMS": 0,
            "files-INITIAL_FORMS": 0,
            "files-MAX_NUM_FORMS": 0,
            "citizen-email": self.citizen.email,
            "citizen-firstname": self.citizen.first_name,
            "citizen-lastname": self.citizen.last_name,
            "report-terms_of_use_validated": True,
        }

        ##### Following data was created specifically for the reopen_request tests #######

        self.citizen_reopen_request = FMSUser(
            telephone="987654321",
            last_used_language="fr",
            first_name="citizen_reopen_request",
            last_name="citizen_reopen_request",
            email="*****@*****.**",
        )
        self.citizen_reopen_request.save()

        self.sample_post_reopen_request_pro = {"reopen-text": "this is the reopen request comment", "reopen-reason": 1}

        self.sample_post_reopen_request = {
            "reopen-text": "this is the reopen request comment",
            "reopen-reason": 1,
            "citizen-quality": 2,
            "citizen-email": self.citizen_reopen_request.email,
            "citizen-telephone": self.citizen_reopen_request.telephone,
            "citizen-last_name": self.citizen_reopen_request.last_name,
        }
Пример #28
0
class HistoryTest(FMSTestCase):

    def setUp(self):
        self.citizen = FMSUser(
            telephone="0123456789",
            last_used_language="fr",
            first_name="Fake first name",
            last_name="Fake last name",
            email="*****@*****.**"
        )
        self.citizen.save()
        self.citizen2 = FMSUser(
            telephone="9876543210",
            last_used_language="nl",
            first_name="Fake first name2",
            last_name="Fake last name2",
            email="*****@*****.**"
        )
        self.citizen2.save()
        self.citizen3 = FMSUser(
            telephone="5649783210",
            last_used_language="nl",
            first_name="Fake first name3",
            last_name="Fake last name3",
            email="*****@*****.**"
        )
        self.citizen3.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 = OrganisationEntity.objects.get(pk=14)
        self.manager.save()

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

        surface = OrganisationEntitySurface(
            geom=Polygon([p1, p2, p3, p4, p1]),
            owner=OrganisationEntity.objects.get(pk=14),
        )
        surface.save()

        self.group = OrganisationEntity(
            type="D",
            name_nl="Werken",
            name_fr="Travaux",
            phone="090987",
            dependency=OrganisationEntity.objects.get(pk=14),
            email="*****@*****.**"
            )
        self.group.save()
        self.group.dispatch_categories.add(ReportCategory.objects.get(pk=1))
        self.group.dispatch_categories.add(ReportCategory.objects.get(pk=2))

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

        self.manager.memberships.create(organisation=self.group, contact_user=True)

        self.manager2 = FMSUser(
            is_active=True,
            telephone="9876543210",
            last_used_language="nl",
            password='******',
            first_name="manager2",
            last_name="manager2",
            email="*****@*****.**",
            manager=True
        )
        self.manager2.set_password('test2')
        self.manager2.organisation = OrganisationEntity.objects.get(pk=14)
        self.manager2.save()

        self.manager2.memberships.create(organisation=self.group)

        self.manager3 = FMSUser(
            is_active=True,
            telephone="000000000",
            last_used_language="nl",
            password='******',
            first_name="manager3",
            last_name="manager3",
            email="*****@*****.**",
            manager=True
        )
        self.manager3.set_password('test3')
        self.manager3.organisation = OrganisationEntity.objects.get(pk=21)
        self.manager3.save()

        self.group2 = OrganisationEntity(
            type="D",
            name_nl="Werken",
            name_fr="Travaux",
            phone="090987",
            dependency=OrganisationEntity.objects.get(pk=21),
            email="*****@*****.**"
            )
        self.group2.save()
        self.group2.dispatch_categories.add(ReportCategory.objects.get(pk=1))

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

        self.manager3.memberships.create(organisation=self.group2)

        self.impetrant = OrganisationEntity(
            name_nl="MIVB",
            name_fr="STIB",
            type=OrganisationEntity.APPLICANT)
        self.impetrant.save()

        self.contractor = OrganisationEntity(
            name_nl="Fabricom GDF",
            name_fr="Fabricom GDF",
            type=OrganisationEntity.SUBCONTRACTOR)
        self.contractor.save()

        self.client = Client()

        self.sample_post_citizen = {
            'report-x': '150056.538',
            'report-y': '170907.56',
            'report-address_fr': 'Avenue des Arts, 3',
            'report-address_nl': 'Kunstlaan, 3',
            'report-address_number': '3',
            'report-postalcode': '1210',
            'report-category': '1',
            'report-secondary_category': '1',
            'report-subscription': 'on',
            'citizen-quality': '1',
            'comment-text': 'test',
            'files-TOTAL_FORMS': 0,
            'files-INITIAL_FORMS': 0,
            'files-MAX_NUM_FORMS': 0,
            'citizen-email': self.citizen.email,
            'citizen-firstname': self.citizen.first_name,
            'citizen-lastname': self.citizen.last_name,
            'report-terms_of_use_validated': True
        }

        self.sample_post_pro = {
            'report-x': '150056.538',
            'report-y': '170907.56',
            'report-address_fr': 'Avenue des Arts, 3',
            'report-address_nl': 'Kunstlaan, 3',
            'report-address_number': '3',
            'report-postalcode': '1210',
            'report-category': '1',
            'report-secondary_category': '1',
            'report-subscription': 'on',
            'comment-text': 'test',
            'files-TOTAL_FORMS': 0,
            'files-INITIAL_FORMS': 0,
            'files-MAX_NUM_FORMS': 0,
            'report-terms_of_use_validated': True
        }

        self.sample_post_comment = {
            'text' : 'Ceci est un commentaire'
        }

    def testCreateReportHistoryCitizen(self):
        #Send a post request filling in the form to create a report
        response = self.client.post(
            reverse('report_new') + '?x=150056.538&y=170907.56',
            self.sample_post_citizen,
            follow=True)
        self.assertEquals(response.status_code, 200)
        # self.assertIn(
        #    '/en/report/trou-en-revetements-en-trottoir-en-saint-josse-ten-noode/1',
        #    response['Location'])
        # check the history if it contains 1 line and that the content is correct
        report_id = response.context['report'].id
        report = Report.objects.get(id=report_id)
        activities = report.activities.all()
        self.assertEquals(activities.all().count(), 1)

        url = '%s?report_id=%s' % (reverse('search_ticket'), report.id)
        response = self.client.get(url, follow=True)
        self.assertEquals(response.status_code, 200)
        self.assertContains(response, self.calculatePrint(activities[0]))
        self.assertNotContains(response, self.calculatePrintPro(activities[0]))

        #Now redo the test with a manager user
        self.client.login(username='******', password='******')
        url = '%s?report_id=%s' % (reverse('search_ticket_pro'), report.id)
        response = self.client.get(url, follow=True)
        report = Report.objects.get(id=report_id)
        activities = report.activities.all()
        self.assertEquals(activities.all().count(), 1)
        #check if the page contains the exact string as it should be generated
        self.assertEquals(response.status_code, 200)
        self.assertContains(response, self.calculatePrintPro(activities[0]))

    def testCreateReportHistoryPro(self):
        self.client.login(username='******', password='******')
        response = self.client.post(
            reverse('report_new_pro') + '?x=150056.538&y=170907.56',
            self.sample_post_pro,
            follow=True)
        self.assertEquals(response.status_code, 200)
        report_id = response.context['report'].id
        report = Report.objects.get(id=report_id)
        activities = report.activities.all()
        self.assertEquals(activities.all().count(), 1)

        url = reverse('report_change_switch_visibility', args=[report_id])
        response = self.client.get(url, {
            'visibility': 'false'
        }, follow=True)
        self.assertEqual(response.status_code, 200)
        report = response.context['report']
        self.assertFalse(report.private)

        url = '%s?report_id=%s' % (reverse('search_ticket_pro'), report.id)
        self.client.login(username='******', password='******')
        response = self.client.get(url, follow=True)
        self.assertEquals(response.status_code, 200)
        self.assertContains(response, self.calculatePrintPro(activities[0]))
        self.client.logout()
        #now test as citizen
        url = '%s?report_id=%s' % (reverse('search_ticket'), report.id)
        response = self.client.get(url, follow=True)
        self.assertEquals(response.status_code, 200)

        self.assertContains(response, self.calculatePrint(activities[0]))
        self.assertNotContains(response, self.calculatePrintPro(activities[0]))

    def testValidateReport(self):
        response = self.client.post(
            reverse('report_new') + '?x=150056.538&y=170907.56',
            self.sample_post_citizen,
            follow=True)
        report = response.context['report']

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

        url      = reverse('report_accept_pro', args=[report.id])
        response = self.client.get(url, follow=True)

        report     = response.context['report']
        activities = report.activities.all()

        self.assertEqual(response.status_code, 200)
        self.assertIsNotNone(report.accepted_at)
        self.assertEquals(activities.all().count(), 2)

        # now check status as pro
        self.client.login(username='******', password='******')
        url = '%s?report_id=%s' % (reverse('search_ticket_pro'), report.id)
        response = self.client.get(url, follow=True)

        self.assertContains(response, self.calculatePrintPro(activities[1]))

        # check if the status as citizen
        self.client.logout()

        url      = '%s?report_id=%s' % (reverse('search_ticket'), report.id)
        response = self.client.get(url, follow=True)

        report   = Report.objects.get(id=report.id)
        activities = report.activities.all()

        self.assertEquals(activities.all().count(), 2)
        self.assertContains(response, self.calculatePrint(activities[1]))
        self.assertNotContains(response, self.calculatePrintPro(activities[1]))

    def testInvalidateReport(self):
        response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post_citizen, follow=True)
        self.assertEquals(response.status_code, 200)
        report_id = response.context['report'].id

        self.client.login(username='******', password='******')
        url = reverse('report_refuse_pro', args=[report_id])
        response = self.client.post(url, self.sample_post_comment, follow=True)
        self.assertEqual(response.status_code, 200)
        self.client.logout()

        #check if the status is updated
        url = '%s?report_id=%s' % (reverse('search_ticket'), report_id)
        response = self.client.get(url, follow=True)
        report = Report.objects.get(id=report_id)
        activities = report.activities.all()

        self.assertEquals(response.status_code, 200)
        self.assertEquals(activities.all().count(), 2)
        self.assertContains(response, self.calculatePrint(activities[1]))
        self.assertNotContains(response, self.calculatePrintPro(activities[1]))

        #now check status as pro
        self.client.login(username='******', password='******')
        url = '%s?report_id=%s' % (reverse('search_ticket_pro'), report_id)
        response = self.client.get(url, follow=True)
        self.assertEquals(response.status_code, 200)
        report = Report.objects.get(id=report_id)
        activities = report.activities.all()
        self.assertEquals(activities.all().count(), 2)
        self.assertContains(response, self.calculatePrintPro(activities[1]))

    def testClosureReport(self):
        response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post_citizen, follow=True)
        self.assertEquals(response.status_code, 200)
        report_id = response.context['report'].id
        self.client.login(username='******', password='******')
        url = reverse('report_close_pro', args=[report_id])
        response = self.client.get(url, follow=True)
        self.assertEqual(response.status_code, 200)
        report = response.context['report']
        self.assertTrue(report.close_date is not None)
        self.client.logout()

        #check if the status is updated
        url = '%s?report_id=%s' % (reverse('search_ticket'), report_id)
        response = self.client.get(url, follow=True)
        self.assertEquals(response.status_code, 200)
        report = Report.objects.get(id=report_id)
        activities = report.activities.all()
        self.assertEquals(activities.all().count(), 2)
        self.assertContains(response, self.calculatePrint(activities[1]))
        self.assertNotContains(response, self.calculatePrintPro(activities[1]))

        #now check status as pro
        self.client.login(username='******', password='******')
        url = '%s?report_id=%s' % (reverse('search_ticket_pro'), report_id)
        response = self.client.get(url, follow=True)
        self.assertEquals(response.status_code, 200)
        report = Report.objects.get(id=report_id)
        activities = report.activities.all()
        self.assertEquals(activities.all().count(), 2)
        self.assertContains(response, self.calculatePrintPro(activities[1]))

    @skip("mark as done is actually disabled for citizen")
    def testResolvedByCitizenReport(self):
        response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post_citizen, follow=True)
        self.assertEquals(response.status_code, 200)
        report_id = response.context['report'].id

        #first accept the report before citizen can update
        self.client.login(username='******', password='******')
        url = reverse('report_accept_pro', args=[report_id])
        response = self.client.get(url, follow=True)
        self.assertEqual(response.status_code, 200)
        report = response.context['report']
        self.assertTrue(report.accepted_at is not None)

        self.client.logout()

        response = self.client.post(reverse('report_update', args=[report_id]), {'is_fixed': 'True'}, follow=True)
        self.assertEqual(response.status_code, 200)

        #check that activity is not visible to citizen
        url = '%s?report_id=%s' % (reverse('search_ticket'), report_id)
        response = self.client.get(url, follow=True)
        self.assertEquals(response.status_code, 200)
        report = Report.objects.get(id=report_id)
        activities = report.activities.all()
        self.assertEquals(activities.all().count(), 3)
        self.assertNotContains(response, self.calculatePrint(activities[2]))
        self.assertNotContains(response, self.calculatePrintPro(activities[2]))

        #check that activity is visible to pro
        self.client.login(username='******', password='******')
        url = '%s?report_id=%s' % (reverse('search_ticket_pro'), report_id)
        response = self.client.get(url, follow=True)
        self.assertEquals(response.status_code, 200)
        report = Report.objects.get(id=report_id)
        activities = report.activities.all()
        self.assertEquals(activities.all().count(), 3)
        self.assertContains(response, self.calculatePrintPro(activities[2]))

    def testResolvedByProReport(self):
        response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post_citizen, follow=True)
        self.assertEquals(response.status_code, 200)
        report_id = response.context['report'].id

        #first accept the report before citizen can update
        self.client.login(username='******', password='******')
        url = reverse('report_accept_pro', args=[report_id])
        response = self.client.get(url, follow=True)
        self.assertEqual(response.status_code, 200)
        report = response.context['report']
        self.assertTrue(report.accepted_at is not None)

        response = self.client.post(reverse('report_fix_pro', args=[report_id]), self.sample_post_comment, follow=True)
        self.assertEqual(response.status_code, 200)

        #first check that pro has right status
        url = '%s?report_id=%s' % (reverse('search_ticket_pro'), report_id)
        response = self.client.get(url, follow=True)
        self.assertEquals(response.status_code, 200)
        report = Report.objects.get(id=report_id)
        activities = report.activities.all()
        self.assertEquals(activities.all().count(), 3)
        self.assertContains(response, self.calculatePrintPro(activities[2]))
        self.client.logout()

        #Now check for citizen
        url = '%s?report_id=%s' % (reverse('search_ticket'), report_id)
        response = self.client.get(url, follow=True)
        self.assertEquals(response.status_code, 200)
        report = Report.objects.get(id=report_id)
        activities = report.activities.all()
        self.assertEquals(activities.all().count(), 3)
        self.assertNotContains(response, self.calculatePrint(activities[2]))
        self.assertNotContains(response, self.calculatePrintPro(activities[2]))

    def testCitizenUpdatesReport(self):
        response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post_citizen, follow=True)
        self.assertEquals(response.status_code, 200)
        report_id = response.context['report'].id

        #first accept the report before citizen can update
        self.client.login(username='******', password='******')
        url = reverse('report_accept_pro', args=[report_id])
        response = self.client.get(url, follow=True)
        self.assertEqual(response.status_code, 200)
        report = response.context['report']
        self.assertTrue(report.accepted_at is not None)

        self.client.logout()
        response = self.client.post(reverse('report_document', kwargs={'report_id': report_id, 'slug': 'hello'}), {
            'comment-text': 'new created comment',
            'citizen-email': self.citizen.email,
            'citizen-quality': 1,
            'files-TOTAL_FORMS': 0,
            'files-INITIAL_FORMS': 0,
            'files-MAX_NUM_FORMS': 0
        }, follow=True)
        self.assertEqual(response.status_code, 200)
        report = Report.objects.get(id=report_id)
        activities = report.activities.all()
        self.assertEqual(report.comments().count(), 2)
         #check that there is no message
        url = '%s?report_id=%s' % (reverse('search_ticket'), report_id)
        response = self.client.get(url, follow=True)
        self.assertEquals(response.status_code, 200)
        self.assertEqual(activities.all().count(), 3)
        self.assertNotContains(response, self.calculatePrint(activities[2]))
        self.assertNotContains(response, self.calculatePrintPro(activities[2]))

        #Now check the message for pro users
        self.client.login(username='******', password='******')
        url = '%s?report_id=%s' % (reverse('search_ticket_pro'), report_id)
        response = self.client.get(url, follow=True)
        self.assertEquals(response.status_code, 200)
        report = Report.objects.get(id=report_id)
        activities = report.activities.all()
        self.assertEquals(activities.all().count(), 3)
        self.assertContains(response, self.calculatePrintPro(activities[2]))
        self.client.logout()

    def testProUpdatesReport(self):
        response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post_citizen, follow=True)
        self.assertEquals(response.status_code, 200)
        report_id = response.context['report'].id
        report = Report.objects.get(id=report_id)
        activities = report.activities
        self.assertEquals(activities.count(), 1)
        self.assertEquals(activities.all()[0].event_type, ReportEventLog.CREATED)

        #first accept the report before citizen can update
        self.client.login(username='******', password='******')
        url = reverse('report_accept_pro', args=[report_id])
        response = self.client.get(url, follow=True)
        self.assertEquals(response.status_code, 200)
        report = response.context['report']
        self.assertIsNotNone(report.accepted_at)

        self.assertEquals(activities.count(), 2)
        self.assertEquals(activities.all()[1].event_type, ReportEventLog.VALID)

        response = self.client.post(reverse('report_show_pro', kwargs={'report_id': report_id, 'slug': 'hello'}), {
            'comment-text': 'new created comment',
            'files-TOTAL_FORMS': 0,
            'files-INITIAL_FORMS': 0,
            'files-MAX_NUM_FORMS': 0
        }, follow=True)
        self.assertEqual(response.status_code, 200)
        report = Report.objects.get(id=report_id)
        self.assertEqual(report.comments().count(), 2)

        #Check for pro user first
        url = '%s?report_id=%s' % (reverse('search_ticket_pro'), report_id)
        response = self.client.get(url, follow=True)
        self.assertEquals(response.status_code, 200)
        report = Report.objects.get(id=report_id)

        self.assertEquals(activities.count(), 3)
        self.assertEquals(activities.all()[2].event_type, ReportEventLog.UPDATED)

        self.assertContains(response, self.calculatePrintPro(activities.all()[2]))

        self.client.logout()
        #Check for citizen user
        url = '%s?report_id=%s' % (reverse('search_ticket'), report_id)
        response = self.client.get(url, follow=True)
        self.assertEquals(response.status_code, 200)
        self.assertEqual(activities.all().count(), 3)
        self.assertNotContains(response, self.calculatePrint(activities.all()[2]))
        self.assertNotContains(response, self.calculatePrintPro(activities.all()[2]))

    def test_assign_to_other_member_of_same_entity(self):
        response = self.client.post(
            reverse('report_new') + '?x=150056.538&y=170907.56',
            self.sample_post_citizen,
            follow=True)

        report             = response.context['report']
        report.accepted_at = datetime.now()
        report.status      = Report.MANAGER_ASSIGNED
        report.save()

        # Reset events
        report.activities.all().delete()

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

        response = self.client.post(
            reverse('report_change_manager_pro', args=[report.id]), {
                'man_id': 'department_' + str(self.group2.id),
                'transfer': 0
            }, follow=True)

        report     = Report.objects.get(id=report.id)
        activities = report.activities.all()

        self.assertEquals(response.status_code, 200)

        # 1 activity for changing manager group
        self.assertEquals(activities.count(), 1)
        self.assertEqual(activities[0].event_type, ReportEventLog.MANAGER_ASSIGNED)

        # History for pro
        url      = '%s?report_id=%s' % (reverse('search_ticket_pro'), report.id)
        response = self.client.get(url, follow=True)

        self.assertContains(response, self.calculatePrintPro(activities[0]))

        # History for citizen
        self.client.logout()

        url      = '%s?report_id=%s' % (reverse('search_ticket'), report.id)
        response = self.client.get(url, follow=True)

        self.assertNotContains(response, self.calculatePrint(activities[0]))
        self.assertNotContains(response, self.calculatePrintPro(activities[0]))

    def test_assign_to_other_entity(self):
        response = self.client.post(
            reverse('report_new') + '?x=150056.538&y=170907.56',
            self.sample_post_citizen,
            follow=True)

        report             = response.context['report']
        report.accepted_at = datetime.now()
        report.status      = Report.MANAGER_ASSIGNED
        report.save()

        # Reset events
        report.activities.all().delete()

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

        response = self.client.post(
            reverse('report_change_manager_pro', args=[report.id]), {
                'man_id'  : 'entity_21',
                'transfer': 0
            },
            follow=True)

        report     = Report.objects.get(id=report.id)
        activities = report.activities.all()

        self.assertEquals(response.status_code, 200)

        # 1 activity for changing manager and 1 for entity change
        self.assertEqual(activities.count(), 2)
        self.assertEqual(activities[0].event_type, ReportEventLog.MANAGER_ASSIGNED)
        self.assertEqual(activities[1].event_type, ReportEventLog.ENTITY_ASSIGNED)

        # Test history of pro
        url      = '%s?report_id=%s' % (reverse('search_ticket_pro'), report.id)
        response = self.client.get(url, follow=True)

        self.assertEquals(response.status_code, 200)

        self.assertContains(response, self.calculatePrintPro(activities[0]))

        # Test history of citizen
        self.client.logout()

        url      = '%s?report_id=%s' % (reverse('search_ticket'), report.id)
        response = self.client.get(url, follow=True)

        self.assertEquals(response.status_code, 200)

        self.assertNotContains(response, self.calculatePrint(activities[0]))
        self.assertNotContains(response, self.calculatePrintPro(activities[0]))

        self.assertContains(response, self.calculatePrint(activities[1]))

    def testMergeReports(self):
        #Send a post request filling in the form to create a report
        response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post_citizen, follow=True)
        self.assertEquals(response.status_code, 200)
        self.assertIn('report', response.context)

        report_id = response.context['report'].id

        #Login to access the pro page
        self.client.login(username='******', password='******')

        response = self.client.post(reverse('report_new_pro') + '?x=150056.538&y=170907.56', self.sample_post_pro, follow=True)
        self.assertEquals(response.status_code, 200)
        #Should send mail only to responsible

        report2_id = response.context['report'].id

        #Publish the created report
        response = self.client.post(reverse('report_accept_pro', args=[report2_id]), follow=True)
        self.assertEquals(response.status_code, 200)

        #Merge reports
        url2 = reverse('report_do_merge_pro', args=[report_id])
        response = self.client.post(url2, {"mergeId": report2_id}, follow=True)
        self.assertEquals(response.status_code, 200)

        # keep older, remove newer
        self.assertTrue(Report.objects.all().visible().filter(id=report_id).exists())
        self.assertFalse(Report.objects.all().visible().filter(id=report2_id).exists())
        # Reference from merged to kept report
        self.assertEqual(report_id, Report.objects.get(id=report2_id).merged_with.id)

        report = Report.objects.get(id=report_id)
        activities = report.activities.all()
        #2 activities are present: 1 for creation and 1 for merge
        self.assertEquals(activities.all().count(), 2)
        #Type of the second activity = merge (18)
        self.assertEqual(18, activities[1].event_type)

        report2 = Report.objects.get(id=report2_id)
        activities2 = report2.activities.all()
        #3 activities are present: 1 for creation, 1 for acception and 1 for merge
        self.assertEquals(activities2.all().count(), 3)
        #Type of the third activity = merge (18)
        self.assertEquals(18, activities2[2].event_type)

    def testAssignToContractor(self):
        response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post_citizen, follow=True)
        self.assertEquals(response.status_code, 200)
        report_id = response.context['report'].id
        report = Report.objects.get(id=report_id)

        activities = report.activities.all()
        self.assertEquals(activities.all().count(), 1)

         #first accept the report before citizen can update
        self.client.login(username='******', password='******')
        url = reverse('report_accept_pro', args=[report_id])
        response = self.client.get(url, follow=True)
        self.assertEqual(response.status_code, 200)
        self.assertEquals(activities.all().count(), 2)

        report = response.context['report']
        self.assertTrue(report.accepted_at is not None)
        self.client.login(username='******', password='******')
        response = self.client.get(
            reverse('report_change_contractor_pro', args=[report_id]), {
                'contractorId': self.contractor.id
            }, follow=True)
        self.assertEquals(response.status_code, 200)
        self.assertEquals(activities.all().count(), 3)
        url = '%s?report_id=%s' % (reverse('search_ticket_pro'), report_id)
        response = self.client.get(url, follow=True)
        self.assertEquals(response.status_code, 200)
        self.assertContains(response, escape(self.calculatePrintPro(activities[2])))

        #Now see if the information for the citizen is ok
        self.client.logout()
        url = '%s?report_id=%s' % (reverse('search_ticket'), report_id)
        response = self.client.get(url, follow=True)
        self.assertEquals(response.status_code, 200)
        report = Report.objects.get(id=report_id)
        activities = report.activities.all()
        self.assertEqual(activities.all().count(), 3)
        self.assertNotContains(response, self.calculatePrint(activities[2]))
        self.assertNotContains(response, self.calculatePrintPro(activities[2]))

    def testAssignToImpetrant(self):
        response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post_citizen, follow=True)
        self.assertEquals(response.status_code, 200)
        report_id = response.context['report'].id
         #first accept the report before citizen can update
        self.client.login(username='******', password='******')
        url = reverse('report_accept_pro', args=[report_id])
        response = self.client.get(url, follow=True)
        self.assertEqual(response.status_code, 200)
        report = response.context['report']
        self.assertTrue(report.accepted_at is not None)
        self.client.login(username='******', password='******')
        response = self.client.get(reverse('report_change_contractor_pro', args=[report_id]) + '?contractorId=' + str(self.impetrant.id), {}, follow=True)
        self.assertEquals(response.status_code, 200)
        report = Report.objects.get(id=report_id)
        activities = report.activities.all()
        self.assertEquals(activities.all().count(), 3)
        url = '%s?report_id=%s' % (reverse('search_ticket_pro'), report_id)
        response = self.client.get(url, follow=True)
        self.assertEquals(response.status_code, 200)
        self.calculatePrintPro(activities[2])
        self.assertContains(response, self.calculatePrintPro(activities[2]).replace("'", '&#39;'))
        #Now see if the information for the citizen is ok
        self.client.logout()
        url = '%s?report_id=%s' % (reverse('search_ticket'), report_id)
        response = self.client.get(url, follow=True)
        self.assertEquals(response.status_code, 200)
        report = Report.objects.get(id=report_id)
        activities = report.activities.all()
        self.assertEqual(activities.all().count(), 3)
        self.assertContains(response, self.calculatePrint(activities[2]).replace("'", '&#39;'))

    def test_make_comment_public(self):
        response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post_citizen, follow=True)

        report = response.context['report']
        report.accepted_at = datetime.now()
        report.save()

        # Reset event
        report.activities.all().delete()

        # Now add comment
        self.client.login(username='******', password='******')
        response = self.client.post(
            reverse('report_show_pro', kwargs={
                'report_id': report.id,
                'slug': 'hello'
            }), {
                'comment-text': 'new created comment',
                'files-TOTAL_FORMS': 0,
                'files-INITIAL_FORMS': 0,
                'files-MAX_NUM_FORMS': 0
            }, follow=True)

        report = response.context['report']

        # 1 new comment and 1 activity
        self.assertEqual(report.comments().count(), 2)
        self.assertEqual(report.activities.all().count(), 1)

        # Now make the comment public
        response = self.client.get(
            reverse('report_update_attachment', args=[report.id]),
            {
                'updateType': '1',
                'attachmentId': report.comments()[1].id
            }, follow=True)

        report     = Report.objects.get(id=report.id)
        activities = report.activities.all()

        # 1 new activity
        self.assertEqual(response.status_code, 200)
        self.assertEqual(activities.count(), 2)

        # Test history for pro
        url        = '%s?report_id=%s' % (reverse('search_ticket_pro'), report.id)
        response   = self.client.get(url, follow=True)

        self.assertEquals(response.status_code, 200)

        # Pro see both update en published event
        self.assertContains(response, self.calculatePrintPro(activities[0]))
        self.assertContains(response, self.calculatePrintPro(activities[1]))

        # Test history for citizen
        self.client.logout()
        url      = '%s?report_id=%s' % (reverse('search_ticket'), report.id)
        response = self.client.get(url, follow=True)

        self.assertEquals(response.status_code, 200)

        # Citizen cannot see the update event
        self.assertNotContains(response, self.calculatePrint(activities[0]))
        self.assertNotContains(response, self.calculatePrintPro(activities[0]))

        # Citizen can see the published update event
        self.assertContains(response, self.calculatePrint(activities[1]))
        self.assertNotContains(response, self.calculatePrintPro(activities[1]))

    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 calculatePrint(self, activity):
        user_to_display = _("a citizen")

        if activity.user:
            if activity.user.fmsuser.is_citizen():
                user_to_display = _("a citizen")

            if activity.user.fmsuser.is_pro():
                user_to_display = activity.user.fmsuser.get_organisation()

        return activity.EVENT_TYPE_TEXT[activity.event_type].format(
            user=user_to_display,
            organisation=activity.organisation,
            related_new=activity.related_new,
            related_old=activity.related_old
        )

    def calculatePrintPro(self, activity):
        user_to_display = _("a citizen")

        if activity.user:
            if activity.user.fmsuser.is_citizen():
                user_to_display = activity.user.get_full_name() or activity.user

            if activity.user.fmsuser.is_pro():
                user_to_display = u'%s %s' % (activity.user.fmsuser.get_organisation(), activity.user.get_full_name() or activity.user)

        return activity.EVENT_TYPE_TEXT[activity.event_type].format(
            user=user_to_display,
            organisation=activity.organisation,
            related_new=activity.related_new,
            related_old=activity.related_old
        )
Пример #29
0
    def setUp(self):
        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 = OrganisationEntity.objects.get(pk=14)
        self.manager.save()

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

        self.group1 = OrganisationEntity(
            name_fr="groupe1",
            name_nl="groep1",
            phone="00000000",
            email="*****@*****.**",
            type='D',
            dependency=OrganisationEntity.objects.get(pk=14)
        )
        self.group1.save()

        self.group_mail_config1       = GroupMailConfig()
        self.group_mail_config1.group = self.group1
        self.group_mail_config1.save()

        self.group2 = OrganisationEntity(
            name_fr="groupe2",
            name_nl="groep2",
            phone="00000000",
            email="*****@*****.**",
            type='D',
            dependency=OrganisationEntity.objects.get(pk=11)
        )
        self.group2.save()

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

        self.creategroup_post = {
            'name_fr': 'groupe3',
            'name_nl': 'groep3',
            'phone': '0000000000',
            'email': '*****@*****.**',
            'type': 'D',
            'notify_group': True
        }

        self.creategroup_post2 = {
            'name_fr': 'groupe4',
            'name_nl': 'groep4',
            'phone': '0000000000',
            'email': '*****@*****.**',
            'type': 'S',
            'notify_group': True
        }

        self.editgroup_post = {
            'name_fr': 'groupe1nouveau',
            'name_nl': 'groep1nieuw',
            'phone': '111111',
            'email': '*****@*****.**',
            'type': 'D',

            ### Mail Config ###
            'groupmailconfig-TOTAL_FORMS'   : u'1',
            'groupmailconfig-INITIAL_FORMS' : u'1',
            'groupmailconfig-MAX_NUM_FORMS' : u'1',

            'groupmailconfig-0-notify_group'      : True,
            'groupmailconfig-0-notify_members'    : True,
            'groupmailconfig-0-digest_created'    : True,
            'groupmailconfig-0-digest_inprogress' : True,
            'groupmailconfig-0-digest_closed'     : True,
            'groupmailconfig-0-digest_other'      : True,
        }
        self.editgroup_post2 = {
            'name_fr': 'groupe2nouveau',
            'name_nl': 'groep2nieuw',
            'phone': '2222222',
            'email': '*****@*****.**',
            'type': 'S',
        }
Пример #30
0
    def setUp(self):
        self.citizen = FMSUser(
            telephone="0123456789",
            last_used_language="fr",
            first_name="Fake first name",
            last_name="Fake last name",
            email="*****@*****.**"
        )
        self.citizen.save()
        self.citizen2 = FMSUser(
            telephone="9876543210",
            last_used_language="nl",
            first_name="Fake first name2",
            last_name="Fake last name2",
            email="*****@*****.**"
        )
        self.citizen2.save()
        self.citizen3 = FMSUser(
            telephone="5649783210",
            last_used_language="nl",
            first_name="Fake first name3",
            last_name="Fake last name3",
            email="*****@*****.**"
        )
        self.citizen3.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 = OrganisationEntity.objects.get(pk=14)
        self.manager.save()

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

        surface = OrganisationEntitySurface(
            geom=Polygon([p1, p2, p3, p4, p1]),
            owner=OrganisationEntity.objects.get(pk=14),
        )
        surface.save()

        self.group = OrganisationEntity(
            type="D",
            name_nl="Werken",
            name_fr="Travaux",
            phone="090987",
            dependency=OrganisationEntity.objects.get(pk=14),
            email="*****@*****.**"
            )
        self.group.save()
        self.group.dispatch_categories.add(ReportCategory.objects.get(pk=1))
        self.group.dispatch_categories.add(ReportCategory.objects.get(pk=2))

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

        self.manager.memberships.create(organisation=self.group, contact_user=True)

        self.manager2 = FMSUser(
            is_active=True,
            telephone="9876543210",
            last_used_language="nl",
            password='******',
            first_name="manager2",
            last_name="manager2",
            email="*****@*****.**",
            manager=True
        )
        self.manager2.set_password('test2')
        self.manager2.organisation = OrganisationEntity.objects.get(pk=14)
        self.manager2.save()

        self.manager2.memberships.create(organisation=self.group)

        self.manager3 = FMSUser(
            is_active=True,
            telephone="000000000",
            last_used_language="nl",
            password='******',
            first_name="manager3",
            last_name="manager3",
            email="*****@*****.**",
            manager=True
        )
        self.manager3.set_password('test3')
        self.manager3.organisation = OrganisationEntity.objects.get(pk=21)
        self.manager3.save()

        self.group2 = OrganisationEntity(
            type="D",
            name_nl="Werken",
            name_fr="Travaux",
            phone="090987",
            dependency=OrganisationEntity.objects.get(pk=21),
            email="*****@*****.**"
            )
        self.group2.save()
        self.group2.dispatch_categories.add(ReportCategory.objects.get(pk=1))

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

        self.manager3.memberships.create(organisation=self.group2)

        self.impetrant = OrganisationEntity(
            name_nl="MIVB",
            name_fr="STIB",
            type=OrganisationEntity.APPLICANT)
        self.impetrant.save()

        self.contractor = OrganisationEntity(
            name_nl="Fabricom GDF",
            name_fr="Fabricom GDF",
            type=OrganisationEntity.SUBCONTRACTOR)
        self.contractor.save()

        self.client = Client()

        self.sample_post_citizen = {
            'report-x': '150056.538',
            'report-y': '170907.56',
            'report-address_fr': 'Avenue des Arts, 3',
            'report-address_nl': 'Kunstlaan, 3',
            'report-address_number': '3',
            'report-postalcode': '1210',
            'report-category': '1',
            'report-secondary_category': '1',
            'report-subscription': 'on',
            'citizen-quality': '1',
            'comment-text': 'test',
            'files-TOTAL_FORMS': 0,
            'files-INITIAL_FORMS': 0,
            'files-MAX_NUM_FORMS': 0,
            'citizen-email': self.citizen.email,
            'citizen-firstname': self.citizen.first_name,
            'citizen-lastname': self.citizen.last_name,
            'report-terms_of_use_validated': True
        }

        self.sample_post_pro = {
            'report-x': '150056.538',
            'report-y': '170907.56',
            'report-address_fr': 'Avenue des Arts, 3',
            'report-address_nl': 'Kunstlaan, 3',
            'report-address_number': '3',
            'report-postalcode': '1210',
            'report-category': '1',
            'report-secondary_category': '1',
            'report-subscription': 'on',
            'comment-text': 'test',
            'files-TOTAL_FORMS': 0,
            'files-INITIAL_FORMS': 0,
            'files-MAX_NUM_FORMS': 0,
            'report-terms_of_use_validated': True
        }

        self.sample_post_comment = {
            'text' : 'Ceci est un commentaire'
        }
Пример #31
0
    def setUp(self):
        '''
        Create organisations and surfaces
        '''

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

        self.region = OrganisationEntity(
            type=OrganisationEntity.REGION,
            name_nl="Region",
            name_fr="Region"
        )
        self.region.save()
        self.region_group = OrganisationEntity(
            type=OrganisationEntity.DEPARTMENT,
            name_nl="Werken",
            name_fr="Travaux",
            phone="090987",
            dependency=self.region,
            email="*****@*****.**"
        )
        self.region_group.save()

        self.region_group_mail_config       = GroupMailConfig()
        self.region_group_mail_config.group = self.region_group
        self.region_group_mail_config.save()

        self.commune = OrganisationEntity(
            name_nl="Commune",
            name_fr="Commune",
        )
        self.commune.save()
        self.commune_group = OrganisationEntity(
            type=OrganisationEntity.DEPARTMENT,
            name_nl="Werken",
            name_fr="Travaux",
            phone="090987",
            dependency=self.commune,
            email="*****@*****.**"
        )
        self.commune_group.save()
        self.commune_group.dispatch_categories.add(self.secondary_category)

        self.commune_group_mail_config       = GroupMailConfig()
        self.commune_group_mail_config.group = self.commune_group
        self.commune_group_mail_config.save()

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

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

        p1 = (149756, 169985)
        p2 = (149796, 169985)
        p3 = (149796, 170025)
        p4 = (149756, 170025)

        self.street_surface = StreetSurface(
            geom=Polygon([p1, p2, p3, p4, p1]),
            administrator=StreetSurface.REGION,
        )
        self.street_surface.save()
Пример #32
0
class GeographicDispatchingTest(FMSTestCase):
    def setUp(self):
        '''
        Create organisations and surfaces
        '''

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

        self.region = OrganisationEntity(type=OrganisationEntity.REGION,
                                         name_nl="Region",
                                         name_fr="Region")
        self.region.save()
        self.region_group = OrganisationEntity(
            type=OrganisationEntity.DEPARTMENT,
            name_nl="Werken",
            name_fr="Travaux",
            phone="090987",
            dependency=self.region,
            email="*****@*****.**")
        self.region_group.save()

        self.region_group_mail_config = GroupMailConfig()
        self.region_group_mail_config.group = self.region_group
        self.region_group_mail_config.save()

        self.commune = OrganisationEntity(
            name_nl="Commune",
            name_fr="Commune",
        )
        self.commune.save()
        self.commune_group = OrganisationEntity(
            type=OrganisationEntity.DEPARTMENT,
            name_nl="Werken",
            name_fr="Travaux",
            phone="090987",
            dependency=self.commune,
            email="*****@*****.**")
        self.commune_group.save()
        self.commune_group.dispatch_categories.add(self.secondary_category)

        self.commune_group_mail_config = GroupMailConfig()
        self.commune_group_mail_config.group = self.commune_group
        self.commune_group_mail_config.save()

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

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

        p1 = (149756, 169985)
        p2 = (149796, 169985)
        p3 = (149796, 170025)
        p4 = (149756, 170025)

        self.street_surface = StreetSurface(
            geom=Polygon([p1, p2, p3, p4, p1]),
            administrator=StreetSurface.REGION,
        )
        self.street_surface.save()

    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)

    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)

    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)

    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()
    def setUp(self):
        self.citizen = FMSUser(telephone="0123456789",
                               last_used_language="fr",
                               first_name="citizen",
                               last_name="citizen",
                               email="*****@*****.**")
        self.citizen.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 = OrganisationEntity.objects.get(pk=14)
        self.manager.save()

        self.group = OrganisationEntity(
            type="D",
            name_nl="Werken",
            name_fr="Travaux",
            phone="090987",
            dependency=OrganisationEntity.objects.get(pk=14),
            email="*****@*****.**")
        self.group.save()
        self.group.dispatch_categories.add(ReportCategory.objects.get(pk=1))

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

        self.manager.memberships.create(organisation=self.group,
                                        contact_user=True)

        self.client = Client()

        self.manager2 = FMSUser(is_active=True,
                                telephone="9876543210",
                                last_used_language="nl",
                                password='******',
                                first_name="manager2",
                                last_name="manager2",
                                email="*****@*****.**",
                                manager=True)
        self.manager2.set_password('test2')
        self.manager2.organisation = OrganisationEntity.objects.get(pk=14)
        self.manager2.save()

        self.group2 = OrganisationEntity(
            type="D",
            name_nl="Werken",
            name_fr="Travaux",
            phone="090987",
            dependency=OrganisationEntity.objects.get(pk=21),
            email="*****@*****.**")
        self.group2.save()
        self.group2.dispatch_categories.add(ReportCategory.objects.get(pk=2))
        self.group2.dispatch_categories.add(ReportCategory.objects.get(pk=1))

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

        surface = OrganisationEntitySurface(
            geom=Polygon([p1, p2, p3, p4, p1]),
            owner=OrganisationEntity.objects.get(pk=14),
        )
        surface.save()

        self.manager2.memberships.create(organisation=self.group2)

        self.manager3 = FMSUser(is_active=True,
                                telephone="000000000",
                                last_used_language="nl",
                                password='******',
                                first_name="manager3",
                                last_name="manager3",
                                email="*****@*****.**",
                                manager=True)
        self.manager3.set_password('test3')
        self.manager3.organisation = OrganisationEntity.objects.get(pk=21)
        self.manager3.save()

        self.manager3.memberships.create(organisation=self.group2)

        self.impetrant = OrganisationEntity(name_nl="MIVB",
                                            name_fr="STIB",
                                            email="*****@*****.**")

        self.impetrant.save()

        self.contractor = OrganisationEntity(name_nl="Fabricom GDF",
                                             name_fr="Fabricom GDF",
                                             email="*****@*****.**")
        self.contractor.save()

        self.sample_post = {
            'report-x': '150056.538',
            'report-y': '170907.56',
            'report-address_fr': 'Avenue des Arts, 3',
            'report-address_nl': 'Kunstlaan, 3',
            'report-address_number': '3',
            'report-postalcode': '1210',
            'report-category': '1',
            'report-secondary_category': '1',
            'report-subscription': 'on',
            'citizen-quality': '1',
            'comment-text': 'test',
            'files-TOTAL_FORMS': 0,
            'files-INITIAL_FORMS': 0,
            'files-MAX_NUM_FORMS': 0,
            'citizen-email': self.citizen.email,
            'citizen-firstname': self.citizen.first_name,
            'citizen-lastname': self.citizen.last_name,
            'report-terms_of_use_validated': True
        }

        ##### Following data was created specifically for the reopen_request tests #######

        self.citizen_reopen_request = FMSUser(
            telephone="987654321",
            last_used_language="fr",
            first_name="citizen_reopen_request",
            last_name="citizen_reopen_request",
            email="*****@*****.**")
        self.citizen_reopen_request.save()

        self.sample_post_reopen_request_pro = {
            'reopen-text': 'this is the reopen request comment',
            'reopen-reason': 1
        }

        self.sample_post_reopen_request = {
            'reopen-text': 'this is the reopen request comment',
            'reopen-reason': 1,
            'citizen-quality': 2,
            'citizen-email': self.citizen_reopen_request.email,
            'citizen-telephone': self.citizen_reopen_request.telephone,
            'citizen-last_name': self.citizen_reopen_request.last_name,
        }
Пример #34
0
    def setUp(self):
        '''
        Create organisations and surfaces
        '''

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

        self.region = OrganisationEntity(type=OrganisationEntity.REGION,
                                         name_nl="Region",
                                         name_fr="Region")
        self.region.save()
        self.region_group = OrganisationEntity(
            type=OrganisationEntity.DEPARTMENT,
            name_nl="Werken",
            name_fr="Travaux",
            phone="090987",
            dependency=self.region,
            email="*****@*****.**")
        self.region_group.save()

        self.region_group_mail_config = GroupMailConfig()
        self.region_group_mail_config.group = self.region_group
        self.region_group_mail_config.save()

        self.commune = OrganisationEntity(
            name_nl="Commune",
            name_fr="Commune",
        )
        self.commune.save()
        self.commune_group = OrganisationEntity(
            type=OrganisationEntity.DEPARTMENT,
            name_nl="Werken",
            name_fr="Travaux",
            phone="090987",
            dependency=self.commune,
            email="*****@*****.**")
        self.commune_group.save()
        self.commune_group.dispatch_categories.add(self.secondary_category)

        self.commune_group_mail_config = GroupMailConfig()
        self.commune_group_mail_config.group = self.commune_group
        self.commune_group_mail_config.save()

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

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

        p1 = (149756, 169985)
        p2 = (149796, 169985)
        p3 = (149796, 170025)
        p4 = (149756, 170025)

        self.street_surface = StreetSurface(
            geom=Polygon([p1, p2, p3, p4, p1]),
            administrator=StreetSurface.REGION,
        )
        self.street_surface.save()
Пример #35
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)
Пример #36
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=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()
Пример #37
0
    def setUp(self):

        self.user = FMSUser(username='******', email='*****@*****.**', password='******')
        self.user.save()

        self.client = Client()

        self.citizen = FMSUser(
            telephone="0123456789",
            last_used_language="fr",
            first_name="citizen",
            last_name="citizen",
            email="*****@*****.**"
        )
        self.citizen.save()

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

        self.group_mail_config       = GroupMailConfig()
        self.group_mail_config.group = self.group
        self.group_mail_config.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 = OrganisationEntity.objects.get(pk=14)
        self.manager.save()
        self.group.dispatch_categories.add(ReportCategory.objects.get(pk=1))

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

        surface = OrganisationEntitySurface(
            geom=Polygon([p1, p2, p3, p4, p1]),
            owner=OrganisationEntity.objects.get(pk=14),
        )
        surface.save()

        self.manager.memberships.create(organisation=self.group, contact_user=True)

        self.sample_post = {
            'report-x': '150056.538',
            'report-y': '170907.56',
            'report-address_fr': 'Avenue des Arts, 3',
            'report-address_nl': 'Kunstlaan, 3',
            'report-address_number': '3',
            'report-postalcode': '1210',
            'report-category': '1',
            'report-secondary_category': '1',
            'report-subscription': 'on',
            'comment-text': 'test',
            'files-TOTAL_FORMS': 0,
            'files-INITIAL_FORMS': 0,
            'files-MAX_NUM_FORMS': 0,
            'citizen-email': self.citizen.email,
            'citizen-firstname': self.citizen.first_name,
            'citizen-lastname': self.citizen.last_name,
            'citizen-quality': '1',
            'report-terms_of_use_validated': True
        }
        self.sample_post_2 = {
            'report-x': '150056',
            'report-y': '170907.56',
            'report-address_fr': 'Avenue des Arts, 3',
            'report-address_nl': 'Kunstlaan, 3',
            'report-address_number': '5',
            'report-postalcode': '1210',
            'report-category': '1',
            'report-secondary_category': '1',
            'report-subscription': 'on',
            'comment-text': 'test2',
            'files-TOTAL_FORMS': 0,
            'files-INITIAL_FORMS': 0,
            'files-MAX_NUM_FORMS': 0,
            'citizen-email': self.citizen.email,
            'citizen-firstname': self.citizen.first_name,
            'citizen-lastname': self.citizen.last_name,
            'citizen-quality': '1',
            'report-terms_of_use_validated': True
        }
Пример #38
0
class ExportPDFTest(FMSTestCase):
    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()

    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['visibility'], '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['visibility'], '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')
Пример #39
0
    def setUp(self):
        self.citizen = FMSUser(
            telephone="0123456789",
            last_used_language="fr",
            first_name="citizen",
            last_name="citizen",
            email="*****@*****.**"
        )
        self.citizen.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 = OrganisationEntity.objects.get(pk=14)
        self.manager.save()

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

        self.group = OrganisationEntity(
            type="D",
            name_nl="Werken",
            name_fr="Travaux",
            phone="090987",
            dependency=OrganisationEntity.objects.get(pk=14),
            email="*****@*****.**"
            )
        self.group.save()
        self.group.dispatch_categories.add(ReportCategory.objects.get(pk=1))

        # Mail config: notify group and members in real time
        self.group_mail_config                = GroupMailConfig()
        self.group_mail_config.group          = self.group
        self.group_mail_config.notify_group   = True
        self.group_mail_config.notify_members = True
        self.group_mail_config.save()

        self.manager.memberships.create(organisation=self.group, contact_user=True)
        self.manager4.memberships.create(organisation=self.group, contact_user=True)

        self.client = Client()

        self.manager2 = FMSUser(
            is_active=True,
            telephone="9876543210",
            last_used_language="nl",
            password='******',
            first_name="manager2",
            last_name="manager2",
            email="*****@*****.**",
            manager=True
        )
        self.manager2.set_password('test2')
        self.manager2.organisation = OrganisationEntity.objects.get(pk=14)
        self.manager2.save()

        self.group2 = OrganisationEntity(
            type="D",
            name_nl="Werken",
            name_fr="Travaux",
            phone="090987",
            dependency=OrganisationEntity.objects.get(pk=21),
            email="*****@*****.**"
        )
        self.group2.save()
        self.group2.dispatch_categories.add(ReportCategory.objects.get(pk=2))
        self.group2.dispatch_categories.add(ReportCategory.objects.get(pk=1))

        # Mail config: notify group and members in real time
        self.group_mail_config2                = GroupMailConfig()
        self.group_mail_config2.group          = self.group2
        self.group_mail_config2.notify_group   = True
        self.group_mail_config2.notify_members = True
        self.group_mail_config2.save()

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

        surface = OrganisationEntitySurface(
            geom=Polygon([p1, p2, p3, p4, p1]),
            owner=OrganisationEntity.objects.get(pk=14),
        )
        surface.save()

        self.manager2.memberships.create(organisation=self.group2)

        self.manager3 = FMSUser(
            is_active=True,
            telephone="000000000",
            last_used_language="nl",
            password='******',
            first_name="manager3",
            last_name="manager3",
            email="*****@*****.**",
            manager=True
        )
        self.manager3.set_password('test3')
        self.manager3.organisation = OrganisationEntity.objects.get(pk=21)
        self.manager3.save()

        self.manager3.memberships.create(organisation=self.group2)

        self.impetrant = OrganisationEntity(
            name_nl="MIVB",
            name_fr="STIB",
            email="*****@*****.**")

        self.impetrant.save()

        self.contractor = OrganisationEntity(
            name_nl="Fabricom GDF",
            name_fr="Fabricom GDF",
            email="*****@*****.**")
        self.contractor.save()

        self.sample_post = {
            'report-x': '150056.538',
            'report-y': '170907.56',
            'report-address_fr': 'Avenue des Arts, 3',
            'report-address_nl': 'Kunstlaan, 3',
            'report-address_number': '3',
            'report-postalcode': '1210',
            'report-category': '1',
            'report-secondary_category': '1',
            'report-subscription': 'on',
            'citizen-quality': '1',
            'comment-text': 'test',
            'files-TOTAL_FORMS': 0,
            'files-INITIAL_FORMS': 0,
            'files-MAX_NUM_FORMS': 0,
            'citizen-email': self.citizen.email,
            'citizen-firstname': self.citizen.first_name,
            'citizen-lastname': self.citizen.last_name,
            'report-terms_of_use_validated': True
        }

        self.sample_post_pro = {
            'report-x': '150056.538',
            'report-y': '170907.56',
            'report-address_fr': 'Avenue des Arts, 3',
            'report-address_nl': 'Kunstlaan, 3',
            'report-address_number': '3',
            'report-postalcode': '1210',
            'report-category': '1',
            'report-secondary_category': '1',
            'report-subscription': 'on',
            'comment-text': 'test',
            'files-TOTAL_FORMS': 0,
            'files-INITIAL_FORMS': 0,
            'files-MAX_NUM_FORMS': 0,
            'report-terms_of_use_validated': True
        }

        self.sample_post_mail_pdf_pro = {
            'comments': 'test comment',
            'visibility': 'private',
            'to': '[email protected],[email protected];[email protected]'
        }

        self.sample_post_mail_pdf_citzen = {
            'comments': 'test comment',
            'visibility': 'public',
            'to': '[email protected],[email protected];[email protected]'
        }
Пример #40
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.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()
Пример #41
0
    def setUp(self):
        self.secondary_category = ReportCategory.objects.all()[0]
        self.category = self.secondary_category.category_class

        self.bxl = OrganisationEntity.objects.get(id=4)  # postal code = 1000 Bxl
        self.bxl.save()

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

        surface = OrganisationEntitySurface(geom=Polygon([p1, p2, p3, p4, p1]), owner=self.bxl)
        surface.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.agent = FMSUser(
            is_active=True,
            email="*****@*****.**",
            telephone="0123456789",
            last_used_language="fr",
            agent=True,
            organisation=self.bxl,
        )
        self.agent.save()

        self.stib = OrganisationEntity.objects.get(id=21)
        self.stib.dependency = self.bxl
        self.stib.save()

        self.contractor = FMSUser(
            is_active=True,
            email="*****@*****.**",
            telephone="0123456789",
            last_used_language="fr",
            contractor=True,
            organisation=self.bxl,
        )
        self.contractor.save()

        self.contractor_manager = FMSUser(
            is_active=True,
            email="*****@*****.**",
            telephone="90870870",
            last_used_language="fr",
            contractor=True,
            organisation=self.bxl,
            manager=True,
        )
        self.contractor_manager.save()
        uom = UserOrganisationMembership(user=self.contractor_manager, organisation=self.group)
        uom.save()

        self.entity_manager = FMSUser(
            is_active=True,
            email="*****@*****.**",
            telephone="90870870",
            last_used_language="fr",
            leader=True,
            organisation=self.bxl,
            manager=True,
        )
        self.entity_manager.save()
        self.usergroupmembership = UserOrganisationMembership(
            user_id=self.entity_manager.id, organisation_id=self.group.id
        )
        self.usergroupmembership.save()

        self.manager = FMSUser(
            is_active=True,
            email="*****@*****.**",
            telephone="0123456789",
            last_used_language="fr",
            manager=True,
            organisation=self.bxl,
        )
        self.manager.save()
        self.usergroupmembership2 = UserOrganisationMembership(
            user_id=self.manager.id, organisation_id=self.group.id, contact_user=True
        )
        self.usergroupmembership2.save()

        self.citizen = FMSUser(email="*****@*****.**", telephone="0123456789", last_used_language="fr")
        self.citizen.save()
Пример #42
0
class ListTest(FMSTestCase):
    def setUp(self):
        self.secondary_category = ReportCategory.objects.all()[0]
        self.category = self.secondary_category.category_class

        self.bxl = OrganisationEntity.objects.get(
            id=4)  # postal code = 1000 Bxl
        self.bxl.save()

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

        surface = OrganisationEntitySurface(
            geom=Polygon([p1, p2, p3, p4, p1]),
            owner=self.bxl,
        )
        surface.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.agent = FMSUser(is_active=True,
                             email="*****@*****.**",
                             telephone="0123456789",
                             last_used_language="fr",
                             agent=True,
                             organisation=self.bxl)
        self.agent.save()

        self.stib = OrganisationEntity.objects.get(id=21)
        self.stib.dependency = self.bxl
        self.stib.save()

        self.contractor = FMSUser(is_active=True,
                                  email="*****@*****.**",
                                  telephone="0123456789",
                                  last_used_language="fr",
                                  contractor=True,
                                  organisation=self.bxl)
        self.contractor.save()

        self.contractor_manager = FMSUser(is_active=True,
                                          email="*****@*****.**",
                                          telephone="90870870",
                                          last_used_language="fr",
                                          contractor=True,
                                          organisation=self.bxl,
                                          manager=True)
        self.contractor_manager.save()
        uom = UserOrganisationMembership(user=self.contractor_manager,
                                         organisation=self.group)
        uom.save()

        self.entity_manager = FMSUser(is_active=True,
                                      email="*****@*****.**",
                                      telephone="90870870",
                                      last_used_language="fr",
                                      leader=True,
                                      organisation=self.bxl,
                                      manager=True)
        self.entity_manager.save()
        self.usergroupmembership = UserOrganisationMembership(
            user_id=self.entity_manager.id, organisation_id=self.group.id)
        self.usergroupmembership.save()

        self.manager = FMSUser(is_active=True,
                               email="*****@*****.**",
                               telephone="0123456789",
                               last_used_language="fr",
                               manager=True,
                               organisation=self.bxl)
        self.manager.save()
        self.usergroupmembership2 = UserOrganisationMembership(
            user_id=self.manager.id,
            organisation_id=self.group.id,
            contact_user=True)
        self.usergroupmembership2.save()

        self.citizen = FMSUser(email="*****@*****.**",
                               telephone="0123456789",
                               last_used_language="fr")
        self.citizen.save()

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

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

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

    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)))
Пример #43
0
    def setUp(self):

        self.user = FMSUser(username='******',
                            email='*****@*****.**',
                            password='******')
        self.user.save()

        self.client = Client()

        self.citizen = FMSUser(telephone="0123456789",
                               last_used_language="fr",
                               first_name="citizen",
                               last_name="citizen",
                               email="*****@*****.**")
        self.citizen.save()

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

        self.group_mail_config = GroupMailConfig()
        self.group_mail_config.group = self.group
        self.group_mail_config.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 = OrganisationEntity.objects.get(pk=14)
        self.manager.save()
        self.group.dispatch_categories.add(ReportCategory.objects.get(pk=1))

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

        surface = OrganisationEntitySurface(
            geom=Polygon([p1, p2, p3, p4, p1]),
            owner=OrganisationEntity.objects.get(pk=14),
        )
        surface.save()

        self.manager.memberships.create(organisation=self.group,
                                        contact_user=True)

        self.sample_post = {
            'report-x': '150056.538',
            'report-y': '170907.56',
            'report-address_fr': 'Avenue des Arts, 3',
            'report-address_nl': 'Kunstlaan, 3',
            'report-address_number': '3',
            'report-postalcode': '1210',
            'report-category': '1',
            'report-secondary_category': '1',
            'report-subscription': 'on',
            'comment-text': 'test',
            'files-TOTAL_FORMS': 0,
            'files-INITIAL_FORMS': 0,
            'files-MAX_NUM_FORMS': 0,
            'citizen-email': self.citizen.email,
            'citizen-firstname': self.citizen.first_name,
            'citizen-lastname': self.citizen.last_name,
            'citizen-quality': '1',
            'report-terms_of_use_validated': True
        }
        self.sample_post_2 = {
            'report-x': '150056',
            'report-y': '170907.56',
            'report-address_fr': 'Avenue des Arts, 3',
            'report-address_nl': 'Kunstlaan, 3',
            'report-address_number': '5',
            'report-postalcode': '1210',
            'report-category': '1',
            'report-secondary_category': '1',
            'report-subscription': 'on',
            'comment-text': 'test2',
            'files-TOTAL_FORMS': 0,
            'files-INITIAL_FORMS': 0,
            'files-MAX_NUM_FORMS': 0,
            'citizen-email': self.citizen.email,
            'citizen-firstname': self.citizen.first_name,
            'citizen-lastname': self.citizen.last_name,
            'citizen-quality': '1',
            'report-terms_of_use_validated': True
        }
Пример #44
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_visibility", args=[self.report.id]),
            {"visibility": "true"})
        self.assertTrue(Report.objects.get(id=self.report.id).private)
        self.client.get(
            reverse("report_change_switch_visibility", args=[self.report.id]),
            {"visibility": "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_visibility", args=[self.report.id]) +
            "?visibility=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_visibility", args=[self.report.id]) +
            "?visibility=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'])