示例#1
0
    def setUp(self):
        self.bxl = OrganisationEntity.objects.get(id=4)
        self.manager_bxl = FMSUser(
            is_active=True,
            email="*****@*****.**",
            telephone="0123456789",
            last_used_language="fr",
            manager=True,
            organisation=self.bxl)
        self.manager_bxl.set_password('test')
        self.manager_bxl.save()
        self.group = OrganisationEntity(
            type="D",
            name_nl="Werken",
            name_fr="Travaux",
            phone="090987",
            dependency=self.bxl,
            email="*****@*****.**"
            )
        self.group.save()
        self.usergroupmembership = UserOrganisationMembership(user_id=self.manager_bxl.id, organisation_id=self.group.id, contact_user=True)
        self.usergroupmembership.save()
        self.citizen = FMSUser(email="*****@*****.**", telephone="0123456789", last_used_language="fr")
        self.citizen.save()

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

        self.client.login(username=self.manager_bxl.email, password='******')
        self.report = Report(
            status=Report.CREATED,
            secondary_category=self.secondary_category,
            category=self.category,
            description='Just a test',
            postalcode=1000,
            address='my address',
            point=dict_to_point({"x": '149776', "y": '170005'}),
            address_number='6h',
            created_by=self.manager_bxl
        )
        self.report.save()

        self.report.attachments.add(ReportComment(
            text='test comment 1',
            security_level=ReportComment.PRIVATE
        ))

        self.client.logout()

        self.report.attachments.add(ReportComment(
            text='test comment 2',
            security_level=ReportComment.PUBLIC
        ))
        self.report.attachments.add(ReportComment(
            text='test comment 3',
            logical_deleted=True,
            security_level=ReportComment.PUBLIC
        ))

        self.client = Client()
示例#2
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()
     self.manager_etterbeek = FMSUser(email="*****@*****.**", telephone="0123456789", last_used_language="fr", manager=True, organisation=self.etterbeek)
     self.manager_etterbeek.save()
     self.manager_bxl = FMSUser(email="*****@*****.**", telephone="0123456789", last_used_language="fr", manager=True, organisation=self.bxl)
     self.manager_bxl.save()
     self.citizen = FMSUser(email="*****@*****.**", telephone="0123456789", last_used_language="fr")
     self.citizen.save()
     self.client = Client()
     self.manager = FMSUser(
         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()
示例#3
0
    def setUp(self):
        self.user = User.objects.create_user(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.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.manager.categories.add(ReportCategory.objects.get(pk=1))

        self.super_user = FMSUser(
            is_active=True,
            telephone="0123456789",
            last_used_language="fr",
            first_name="superuser",
            last_name="superuser",
            email="*****@*****.**"
        )
        self.super_user.set_password('test')
        self.super_user.is_superuser = True
        self.super_user.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',
            '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
        }
示例#4
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.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()
示例#5
0
class PhotosTest(FMSTestCase):

    def setUp(self):
        self.user = User.objects.create_user('test', '*****@*****.**', 'pwd')
        self.user.save()
        self.category = ReportMainCategoryClass.objects.all()[0]
        #Create a FMSUser
        self.fmsuser = FMSUser(telephone="0123456789", last_used_language="fr", agent=False, manager=False, leader=False, applicant=False, contractor=False)
        self.fmsuser.save()
    def handle(self, *args, **options):
        from django_fixmystreet.fixmystreet.models import GroupMailConfig, OrganisationEntity, ReportEventLog, UserOrganisationMembership

        # Date of yesterday (or specific date)
        if options['date']:
            YESTERDAY = datetime.datetime.strptime(options['date'], "%d/%m/%Y").date()
        else:
            YESTERDAY = datetime.date.today() - datetime.timedelta(days=1)

        logger.info('DIGEST OF NOTIFICATIONS FOR ACTVITIES OF %s' % YESTERDAY)

        # All group mail configurations with at least 1 digest config
        group_mail_configs = GroupMailConfig.objects.filter(group__type=OrganisationEntity.DEPARTMENT).filter(Q(digest_closed=True) | Q(digest_created=True) | Q(digest_inprogress=True) | Q(digest_other=True))
        logger.info('group_mail_configs %s' % group_mail_configs)

        # All group having digest config
        groups = group_mail_configs.values_list('group', flat=True)
        logger.info('groups %s' % groups)

        # All events of yesterday related to groups
        events_yesterday = ReportEventLog.objects.filter(event_at__contains=YESTERDAY, report__responsible_department__in=groups)
        logger.info('events_yesterday %s' % events_yesterday)

        for mail_config in group_mail_configs:
            group = mail_config.group

            # Returns all activities of yesterday grouped by reports where and related to group
            activities_list = events_yesterday.filter(report__responsible_department=group)

            if not activities_list:
                continue

            # Send digest to responsibles according to mail config
            recipients = mail_config.get_manager_recipients()

            logger.info('Digest of %s %s' % (group, recipients))
            logger.info('   Number of activities: %s' % activities_list.count())

            for activity in activities_list:
                logger.info('   %s %s %s' % (activity.event_at, activity.report.id, activity))

            # If NOT option send, do not send email
            if not options['send']:
                continue

            for recipient in recipients:
                # Because recipients are email and can be a user or group email, have to mock a user
                user = FMSUser()
                user.email = recipient
                user.is_pro = lambda: True
                user.last_used_language = "fr"

                # Render and send the digest by mail
                send_digest(user, activity, activities_list, YESTERDAY)
示例#7
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()
     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.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.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()
示例#8
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.createuser_post = {
            'telephone': '123456',
            'is_active': True,
            'first_name': 'david',
            'last_name': 'hasselhof',
            'email': '*****@*****.**'
        }
        self.edituser_post = {
            'telephone': '654321',
            'is_active': True,
            'first_name': 'new_manager',
            'last_name': 'new_manager',
            'email': '*****@*****.**',
            'manager': True
        }
示例#9
0
    def testAssignToImpetrantMail(self):
        settings.CACHE_TIMEOUT = 0;

        response = self.client.post(reverse('report_new') + '?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), 2)  # one for creator subscription, one for manager

        # 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)
        self.assertEquals(response.status_code, 200)
        self.assertEquals(len(mail.outbox), 3)
        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)

        # Should be 6 mails: 2 for creation, 1 for acceptance and
        # 1 for assigning the issue to impetrant,
        # 1 to subcribers (user, not to manager because he comment)
        self.assertEquals(len(mail.outbox), 5)
        self.assertIn(self.impetrant.email, mail.outbox[3].to)
        self.assertIn(self.citizen.email, mail.outbox[4].to)
        #if the gestionnaire updates the report the impetrant should be informed by mail
        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)
        # One notification should be sent to impetrant to inform him of new comment
        # One notification should be sent to responsible demartment
        self.assertEquals(len(mail.outbox), 7)
        self.assertIn(self.impetrant.email, mail.outbox[5].to + mail.outbox[6].to)
        self.assertIn(self.group.email, mail.outbox[5].to + mail.outbox[6].to)
示例#10
0
    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)
示例#11
0
    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)
示例#12
0
    def setUp(self):
        self.user = User.objects.create_user('admin', '*****@*****.**', 'pwd')
        self.user.save()

        # these are from the fixtures file.
        self.category = ReportCategory.objects.all()[0]
        self.categoryclass = self.category.category_class

        self.commune = OrganisationEntity(name='test ward')
        #Create a FMSUser
        self.fmsuser = FMSUser(
            telephone="0123456789",
            last_used_language="fr",
            username="******",
            first_name="aaa",
            last_name="aaa",
            email="*****@*****.**")
        self.fmsuser.save()
示例#13
0
 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)
示例#14
0
class ExportPDFTest(SampleFilesTestCase):

    def setUp(self):
        self.bxl = OrganisationEntity.objects.get(id=4)
        self.manager_bxl = FMSUser(
            is_active=True,
            email="*****@*****.**",
            telephone="0123456789",
            last_used_language="fr",
            manager=True,
            organisation=self.bxl)
        self.manager_bxl.set_password('test')
        self.manager_bxl.save()
        self.group = OrganisationEntity(
            type="D",
            name_nl="Werken",
            name_fr="Travaux",
            phone="090987",
            dependency=self.bxl,
            email="*****@*****.**"
            )
        self.group.save()
        self.usergroupmembership = UserOrganisationMembership(user_id=self.manager_bxl.id, organisation_id=self.group.id, contact_user=True)
        self.usergroupmembership.save()
        self.citizen = FMSUser(email="*****@*****.**", telephone="0123456789", last_used_language="fr")
        self.citizen.save()

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

        self.client.login(username=self.manager_bxl.email, password='******')
        self.report = Report(
            status=Report.CREATED,
            secondary_category=self.secondary_category,
            category=self.category,
            description='Just a test',
            postalcode=1000,
            address='my address',
            point=dict_to_point({"x": '149776', "y": '170005'}),
            address_number='6h',
            created_by=self.manager_bxl
        )
        self.report.save()

        self.report.attachments.add(ReportComment(
            text='test comment 1',
            security_level=ReportComment.PRIVATE
        ))

        self.client.logout()

        self.report.attachments.add(ReportComment(
            text='test comment 2',
            security_level=ReportComment.PUBLIC
        ))
        self.report.attachments.add(ReportComment(
            text='test comment 3',
            logical_deleted=True,
            security_level=ReportComment.PUBLIC
        ))

        self.client = Client()

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

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

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

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

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

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

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

        response = self.client.get(reverse('report_show_pro', kwargs={'report_id': self.report.id, 'slug': ''}), follow=True)
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, 'test comment 1')
        self.assertContains(response, 'test comment 2')
        self.assertNotContains(response, 'test comment 3')
示例#15
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()

        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.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.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
        }
示例#16
0
class HistoryTest(TestCase):

    fixtures = ["bootstrap", "list_items"]

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

        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.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.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
        }

    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_privacy', args=[report_id])
        response = self.client.get(url, {
            'privacy': '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)
        self.assertEquals(response.status_code, 200)
        report_id = response.context['report'].id

        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.assertIsNotNone(report.accepted_at)

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

    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.get(url, 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)
        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]))

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

    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]), {'is_fixed': 'True'}, 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 testCitizenSubscribesToReport(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

        response = self.client.get(
            reverse('subscribe', args=[report_id]), {
                'citizen_email': self.citizen2.email
            },
            follow=True)
        report = Report.objects.get(id=report_id)
        activities = report.activities.all()
        self.assertEqual(response.status_code, 200)
        self.assertTrue(report.subscriptions.filter(subscriber=self.citizen).exists())
        self.assertTrue(report.subscriptions.filter(subscriber=self.citizen2).exists())
        self.assertFalse(report.subscriptions.filter(subscriber=self.citizen3).exists())
        self.assertTrue(report.subscriptions.filter(subscriber=self.manager).exists())
        self.assertTrue(report.subscriptions.filter(subscriber=self.manager2).exists())
        self.assertFalse(report.subscriptions.filter(subscriber=self.manager3).exists())
        self.assertEquals(report.subscriptions.all().count(), 4)
        self.assertEquals(activities.all().count(), 1)

    def testProSubscribesToReport(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='******')
        response = self.client.get(reverse('subscribe_pro', args=[report_id]), {}, follow=True)
        report = Report.objects.get(id=report_id)
        activities = report.activities.all()
        self.assertTrue(report.subscriptions.filter(subscriber=self.citizen).exists())
        self.assertFalse(report.subscriptions.filter(subscriber=self.citizen2).exists())
        self.assertFalse(report.subscriptions.filter(subscriber=self.citizen3).exists())
        self.assertTrue(report.subscriptions.filter(subscriber=self.manager2).exists())
        self.assertEquals(activities.all().count(), 1)

    def testAssignToOtherMemberOfSameEntity(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.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)
        report = response.context['report']
        self.assertIsNotNone(report.accepted_at)
        self.assertEquals(activities.all().count(), 2)

        response = self.client.get(
            reverse('report_change_manager_pro', args=[report_id]), {
                'manId': 'department_' + str(self.group2.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)
        report = Report.objects.get(id=report_id)
        activities = report.activities.all()
        self.assertEquals(activities.all().count(), 3)
        self.assertContains(response, self.calculatePrintPro(activities[2]))

        #now check as citizen no status update should be visible
        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)
        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 testAssignToOtherEntity(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_manager_pro', args=[report_id]) + '?', {
                'manId': 'entity_21'
            },
            follow=True)
        self.assertEquals(response.status_code, 200)
        report = Report.objects.get(id=report_id)
        activities = report.activities.all()
        self.assertEquals(activities.all().count(), 4)
        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[2]))

        #Now test to see that citizen sees the correct information
        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(), 4)

        self.assertEqual(activities[2].event_type, ReportEventLog.MANAGER_ASSIGNED)
        self.assertEqual(activities[3].event_type, ReportEventLog.ENTITY_ASSIGNED)

        self.assertNotContains(response, unicode(activities[2]))
        self.assertContains(response, activities[3].get_public_activity_text())

    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.assertContains(response, 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.assertContains(response, self.calculatePrint(activities[2]))

    def testMakeCommentPublic(self):
        settings.CACHE_TIMEOUT = 0;

        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)
        #now add comment
        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)
        #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)
        self.assertEqual(response.status_code, 200)
        report = Report.objects.get(id=report_id)
        activities = report.activities.all()
        # A cache prevents to create too much log during publication if already sent
        self.assertEqual(activities.all().count(), 4)  # still does not work as the message is not shown yet
        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[3]))

        #now test 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)
        report = Report.objects.get(id=report_id)
        activities = report.activities.all()
        self.assertEqual(activities.all().count(), 4)
        self.assertContains(response, self.calculatePrint(activities[3]))
        self.assertNotContains(response, self.calculatePrintPro(activities[3]))

    def testPublish(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.get(reverse('report_publish_pro', args=[report_id]), {}, follow=True)
        self.assertEqual(response.status_code, 200)
        url = '%s?report_id=%s' % (reverse('search_ticket_pro'), report_id)
        response = self.client.get(url, follow=True)
        self.assertEquals(response.status_code, 200)

    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
        )
示例#17
0
class GroupsTest(TestCase):

    fixtures = ["bootstrap", "list_items"]

    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.group2 = OrganisationEntity(
            name_fr="groupe2",
            name_nl="groep2",
            phone="00000000",
            email="*****@*****.**",
            type='D',
            dependency=OrganisationEntity.objects.get(pk=11)
        )
        self.group2.save()

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

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

        self.editgroup_post = {
            'name_fr': 'groupe1nouveau',
            'name_nl': 'groep1nieuw',
            'phone': '111111',
            'email': '*****@*****.**',
            'type': 'D'
        }
        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='******')
        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())
示例#18
0
    def setUp(self):
        self.client = Client()

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

        self.organisation = OrganisationEntity.objects.get(pk=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()
示例#19
0
class ReportViewsTest(SampleFilesTestCase):

    fixtures = ["bootstrap", "list_items"]

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

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

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

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

        url = reverse('report_refuse_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 None)

    def test_publish_report(self):
        """Tests publishing 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_publish_pro', args=[report.id])
        response = self.client.get(url, {}, follow=True)

        report = response.context['report']

        self.assertTrue(report.accepted_at is not None)
        self.assertFalse(report.private)

    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)
        self.assertRedirects(response, report.get_absolute_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(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": "32"})

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

    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 has subscribed by default
        self.assertTrue(report.subscriptions.filter(subscriber=self.manager).exists())

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

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

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

        # 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)
        self.assertRedirects(response, report.get_absolute_url())
        self.assertEqual(response.status_code, 200)

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

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

        #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_mark_done(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)
        self.client.logout()

        self.assertFalse(report.mark_as_done_user)
        self.assertFalse(report.fixed_at)

        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.assertFalse(report.mark_as_done_user)
        self.assertEqual(report.status, Report.SOLVED)

        self.client.login(username=self.manager.email, password='******')
        response = self.client.post(reverse('report_close_pro', args=[report.id]), follow=True)
        self.assertEqual(response.status_code, 200)
        report = response.context['report']
        self.assertTrue(report.fixed_at)
        self.assertEqual(report.status, Report.PROCESSED)

    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.assertFalse(report.mark_as_done_user)
        self.assertFalse(report.fixed_at)

        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)

        response = self.client.post(
            reverse('report_fix_pro', args=[report.id]),
            {'is_fixed': 'True'},
            follow=True)
        self.assertEquals(response.status_code, 200)

        report = response.context['report']
        self.assertTrue(report.fixed_at)
        self.assertTrue(report.mark_as_done_user)
        self.assertEquals(report.status, Report.SOLVED)

        self.client.login(username=self.manager.email, password='******')
        response = self.client.post(reverse('report_close_pro', args=[report.id]), follow=True)
        self.assertEquals(response.status_code, 200)
        report = response.context['report']
        self.assertTrue(report.fixed_at)
        self.assertTrue(report.close_date)
        self.assertEquals(report.status, Report.PROCESSED)

    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)
        self.assertContains(response, 'Please enter a correct username and password. Note that both fields are case-sensitive.')

    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)
示例#20
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="******",
            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
        }

        """
        self.steven = self.users['100003558692539']

        params = {
            'client_id': settings.FACEBOOK_APP_ID,
            'client_secret': settings.FACEBOOK_API_SECRET,
            'grant_type': 'client_credentials'
        }
        url='https://graph.facebook.com/oauth/access_token?{0}'.format(urlencode(params))
        request = Request(url)
        try:
            response = urlparse.parse_qs(urlopen(request).read())
            self.app_access_token = response['access_token'][0]
            #print settings.FACEBOOK_APP_ID,self.app_access_token
        except HTTPError as e:
            print e.code
            print simplejson.loads(e.read())['error']['message']
            raise e

        url = 'https://graph.facebook.com/{0}/accounts/test-users?access_token={1}'\
                .format(settings.FACEBOOK_APP_ID,self.app_access_token)
        try:
            response = simplejson.loads(urlopen(url).read())
            for user in response['data']:
                if user['id'] not in self.users:
                    self.users[user['id']] = {}
                self.users[user['id']]['access_token'] = user['access_token']
            # print self.users
        except HTTPError as e:
            print e.code
            print simplejson.loads(e.read())['error']['message']
            raise e
        """

    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 = simplejson.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 = simplejson.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 = simplejson.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 = simplejson.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 = simplejson.loads(response.content)

    """
    def testLoadReports(self):
        client = Client()
        response = client.get(reverse('api_reports'), {'x':1000,'y':1000}, follow=True)
        self.assertEqual(response.status_code, 200)
        result = simplejson.loads(response.content)
        self.assertEquals(result['status'], 'success')
        self.assertEquals(len(result['results']), 13) # sample contains 14 reports but 1 is fixed
    """

    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 = simplejson.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 = simplejson.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 = simplejson.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 = simplejson.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)
示例#21
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)))
示例#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
class UpdatesTest(FMSTestCase):

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

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

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

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

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

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

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

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

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

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

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

        self.report = Report(
            status=Report.CREATED,
            secondary_category=self.secondary_category,
            category=self.category,
            description='Just a test',
            postalcode=1000,
            address='my address',
            point=dict_to_point({"x": '149776', "y": '170005'}),
            address_number='6h',
            created_by=self.manager,
            accepted_at=datetime.now()
        )
        self.report.save()

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

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

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

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

        self.assertIsNotNone(report.responsible_department)

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

        self.assertIsNotNone(report.responsible_department)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        first_date_planned = datetime.now()

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

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

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

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

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

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

    def test_update_priority(self):
        #Test default value of priority set to 1
        new_report = Report(
            status=Report.CREATED,
            secondary_category=self.secondary_category,
            category=self.category,
            description='Just a test',
            postalcode=1000,
            address='my address',
            point=dict_to_point({"x": '149776', "y": '170005'}),
            address_number='6h',
            created_by=self.manager
        )
        new_report.save()
        self.assertEquals(new_report.gravity, 0)
        self.assertEquals(new_report.probability, 0)
        self.assertEquals(new_report.get_priority(), 0)
        self.client.login(username='******', password='******')

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

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

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

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

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

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

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

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

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

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

        report = Report.objects.get(id=self.report.id)
        self.assertEquals(response.status_code, 200)
        self.assertEqual(report.false_address, post_data['false_address'])
示例#24
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_set-TOTAL_FORMS'   : u'1',
            'groupmailconfig_set-INITIAL_FORMS' : u'1',
            'groupmailconfig_set-MAX_NUM_FORMS' : u'1',

            'groupmailconfig_set-0-notify_group'      : True,
            'groupmailconfig_set-0-notify_members'    : True,
            'groupmailconfig_set-0-digest_created'    : True,
            'groupmailconfig_set-0-digest_inprogress' : True,
            'groupmailconfig_set-0-digest_closed'     : True,
            'groupmailconfig_set-0-digest_other'      : True,
        }
        self.editgroup_post2 = {
            'name_fr': 'groupe2nouveau',
            'name_nl': 'groep2nieuw',
            'phone': '2222222',
            'email': '*****@*****.**',
            'type': 'S',
        }
示例#25
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()
示例#26
0
class UsersTest(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.createuser_post = {
            'telephone': '123456',
            'is_active': True,
            'first_name': 'david',
            'last_name': 'hasselhof',
            'email': '*****@*****.**'
        }
        self.edituser_post = {
            'telephone': '654321',
            'is_active': True,
            'first_name': 'new_manager',
            'last_name': 'new_manager',
            'email': '*****@*****.**',
            'manager': True
        }

    def testListUser(self):
        self.client.login(username='******', password='******')
        response = self.client.post(reverse('list_users'), follow=True)
        self.assertEquals(response.status_code, 200)
        self.assertTrue('users' in response.context)
        self.assertTrue('can_create' in response.context)
        can_create = response.context['can_create']
        self.assertFalse(can_create)
        #This user should not be able to create
        users = response.context['users']
        self.assertEquals(users.count(), 2)
        self.assertIn(self.manager, users)
        self.assertIn(self.leader, users)
        #same result for leader
        self.client.logout()
        self.client.login(username='******', password='******')
        response = self.client.post(reverse('list_users'), follow=True)
        self.assertEquals(response.status_code, 200)
        self.assertTrue('users' in response.context)
        self.assertTrue('can_create' in response.context)
        can_create = response.context['can_create']
        self.assertTrue(can_create)
        #This user should not be able to create
        users = response.context['users']
        self.assertEquals(users.count(), 2)
        self.assertIn(self.manager, users)
        self.assertIn(self.leader, users)

    def testCreateUser(self):
        self.client.login(username='******', password='******')
        response = self.client.post(reverse('create_user'), self.createuser_post, follow=True)
        self.assertEquals(response.status_code, 200)
        response = self.client.post(reverse('list_users'), follow=True)

        self.assertEquals(response.status_code, 200)
        self.assertTrue('users' in response.context)
        self.assertTrue('can_create' in response.context)
        can_create = response.context['can_create']
        users = response.context['users']
        self.assertTrue(can_create)
        self.assertEquals(users.count(), 3)
        self.assertContains(response, self.createuser_post["email"])

        new_user = FMSUser.objects.get(email=self.createuser_post['email'])
        self.assertTrue(new_user.password)
        self.assertNotEqual('!', new_user.password)
        self.assertEquals(len(mail.outbox), 1)

    def testUpdateLeaderAsLeader(self):
        self.client.login(username='******', password='******')
        response = self.client.post(reverse('edit_user', args=[self.leader.id]), self.edituser_post, follow=True)
        self.assertEquals(response.status_code, 200)
        self.assertTrue('can_edit' in response.context)
        self.assertFalse(response.context['can_edit'])

    def testUpdateUserAsLeader(self):
        self.client.login(username='******', password='******')
        response = self.client.get(reverse('edit_user', args=[self.manager.id]), follow=True)

        self.assertEquals(response.status_code, 200)
        self.assertTrue('can_edit' in response.context)
        self.assertTrue(response.context['can_edit'])

        response = self.client.post(reverse('edit_user', args=[self.manager.id]), self.edituser_post, follow=True)

        self.assertEquals(response.status_code, 200)
        self.assertTrue('users' in response.context)
        self.assertTrue('can_create' in response.context)

        can_create = response.context['can_create']
        users = response.context['users']
        self.assertTrue(can_create)

        founduser = False
        for user in users:
            if (user.id == self.manager.id):
                self.assertEquals(user.first_name, self.edituser_post['first_name'])
                self.assertEquals(user.last_name,  self.edituser_post['last_name'])
                self.assertEquals(user.telephone,  self.edituser_post['telephone'])
                self.assertEquals(user.email,      self.edituser_post['email'])
                founduser = True
        self.assertTrue(founduser)

        #now try to update a leader user this should not be allowed
        response = self.client.post(reverse('edit_user', args=[self.leader.id]), self.edituser_post, follow=True)
        self.assertEquals(response.status_code, 200)
        self.assertTrue('can_edit' in response.context)
        self.assertFalse(response.context['can_edit'])
        response = self.client.post(reverse('list_users'), follow=True)
        self.assertEquals(response.status_code, 200)
        self.assertTrue('users' in response.context)
        self.assertTrue('can_create' in response.context)
        can_create = response.context['can_create']
        users = response.context['users']
        self.assertTrue(can_create)
        self.assertNotContains(response, self.manager.email)  # the old one
        self.assertContains(response, self.edituser_post["email"])

        founduser = False

        for user in users:
            if (user.id == self.leader.id):
                self.assertEquals(user.first_name, self.leader.first_name)
                self.assertEquals(user.last_name, self.leader.last_name)
                self.assertEquals(user.telephone, self.leader.telephone)
                self.assertEquals(user.email, self.leader.email)
                founduser = True
        self.assertTrue(founduser)

    def testUpdateUserAsPro(self):
        self.client.login(username='******', password='******')
        response = self.client.post(reverse('edit_user', args=[self.manager.id]), self.edituser_post, follow=True)
        self.assertEquals(response.status_code, 200)
        response = self.client.post(reverse('list_users'), follow=True)
        self.assertEquals(response.status_code, 200)
        self.assertTrue('users' in response.context)
        self.assertTrue('can_create' in response.context)
        can_create = response.context['can_create']
        users = response.context['users']
        self.assertFalse(can_create)
        founduser = False
        for user in users:
            if (user.id == self.manager.id):
                self.assertNotEquals(user.first_name, 'new_manager')
                self.assertNotEquals(user.last_name, 'new_manager')
                self.assertNotEquals(user.telephone, '654321')
                self.assertNotEquals(user.email, '*****@*****.**')
                founduser = True
        self.assertTrue(founduser)

    def testDeleteUser(self):
        self.client.login(username='******', password='******')
        response = self.client.get(reverse('delete_user', args=[self.manager.id]), follow=True)
        self.assertEquals(response.status_code, 200)
        response = self.client.post(reverse('list_users'), follow=True)
        self.assertEquals(response.status_code, 200)
        self.assertTrue('users' in response.context)
        self.assertTrue('can_create' in response.context)
        can_create = response.context['can_create']
        users = response.context['users']
        self.assertEquals(users.count(), 1)
        self.assertTrue(can_create)
        self.assertNotIn(self.manager, users)

    def testDeleteUserAsPro(self):
        self.client.login(username='******', password='******')
        response = self.client.get(reverse('delete_user', args=[self.manager.id]), follow=True)
        self.assertEquals(response.status_code, 200)
        response = self.client.post(reverse('list_users'), follow=True)
        self.assertEquals(response.status_code, 200)
        self.assertTrue('users' in response.context)
        self.assertTrue('can_create' in response.context)
        can_create = response.context['can_create']
        users = response.context['users']
        self.assertEquals(users.count(), 2)
        self.assertFalse(can_create)
        self.assertIn(self.manager, users)
示例#27
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="******",
            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
        }

        """
示例#28
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.group2 = OrganisationEntity(
            name_fr="groupe2",
            name_nl="groep2",
            phone="00000000",
            email="*****@*****.**",
            type='D',
            dependency=OrganisationEntity.objects.get(pk=11)
        )
        self.group2.save()

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

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

        self.editgroup_post = {
            'name_fr': 'groupe1nouveau',
            'name_nl': 'groep1nieuw',
            'phone': '111111',
            'email': '*****@*****.**',
            'type': 'D'
        }
        self.editgroup_post2 = {
            'name_fr': 'groupe2nouveau',
            'name_nl': 'groep2nieuw',
            'phone': '2222222',
            'email': '*****@*****.**',
            'type': 'S'
        }
示例#29
0
class FMSUserTest(TestCase):

    fixtures = ["bootstrap", "list_items"]

    def setUp(self):
        self.user = User.objects.create_user('admin', '*****@*****.**', 'pwd')
        self.user.save()

        # these are from the fixtures file.
        self.category = ReportCategory.objects.all()[0]
        self.categoryclass = self.category.category_class

        self.commune = OrganisationEntity(name='test ward')
        #Create a FMSUser
        self.fmsuser = FMSUser(
            telephone="0123456789",
            last_used_language="fr",
            username="******",
            first_name="aaa",
            last_name="aaa",
            email="*****@*****.**")
        self.fmsuser.save()

    def testCreationOfFMSUser(self):
       '''Create a user and check if the row in database has been created'''
       self.assertTrue(self.fmsuser.id > 0)

    def testFMSCitizenOrProRole(self):
       '''Test the roles of the FMSUser created'''
       self.assertTrue(self.fmsuser.is_citizen())
       self.assertFalse(self.fmsuser.is_pro())
       self.fmsuser.agent = True
       self.assertFalse(self.fmsuser.is_citizen())
       self.assertTrue(self.fmsuser.is_pro())
       self.fmsuser.agent = False
       self.fmsuser.manager = True
       self.assertFalse(self.fmsuser.is_citizen())
       self.assertTrue(self.fmsuser.is_pro())
       self.fmsuser.manager = False
       self.fmsuser.leader = True
       self.assertFalse(self.fmsuser.is_citizen())
       self.assertTrue(self.fmsuser.is_pro())
       self.fmsuser.leader = False
       self.fmsuser.applicant = True
       self.assertFalse(self.fmsuser.is_citizen())
       self.assertTrue(self.fmsuser.is_pro())
       self.fmsuser.applicant = False
       self.fmsuser.contractor = True
       self.assertFalse(self.fmsuser.is_citizen())
       self.assertTrue(self.fmsuser.is_pro())
       self.fmsuser.contractor = False
       self.assertTrue(self.fmsuser.is_citizen())
       self.assertFalse(self.fmsuser.is_pro())

    def testFMSLanguage(self):
       '''Test the user language'''
       self.assertEquals(self.fmsuser.last_used_language, "fr")

    def testFMSSpecificRoles(self):
       '''Test the user roles boolean values'''
       self.assertFalse(self.fmsuser.agent)
       self.assertFalse(self.fmsuser.manager)
       self.assertFalse(self.fmsuser.leader)
       self.assertFalse(self.fmsuser.applicant)
       self.assertFalse(self.fmsuser.contractor)
示例#30
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)