class ValueUpdate(FMSTestCase): def setUp(self): self.secondary_category = ReportCategory.objects.all()[0] self.category = self.secondary_category.category_class #Create a FMSUser self.etterbeek = OrganisationEntity.objects.get(id=5) # postal code = 1040 Etterbeek self.etterbeek.save() self.bxl = OrganisationEntity.objects.get(id=4) # postal code = 1000 Bxl self.bxl.save() 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()
def test_assign_to_contractor_mail(self): response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post, follow=True) report = response.context['report'] report.accepted_at = datetime.now() report.save() # Add a worker for this entity worker = FMSUser(email="*****@*****.**", telephone="0123456789") worker.save() worker.memberships.create(organisation=self.contractor) # Reset outbox mail.outbox = [] self.client.login(username='******', password='******') response = self.client.get( reverse('report_change_contractor_pro', args=[report.id]) + '?contractorId=' + str(self.contractor.id), {}, follow=True) # 1 mail sent in real time to contractor self.assertEquals(len(mail.outbox), 1) self.assertIn(self.contractor.email, mail.outbox[0].to)
def test_assign_to_impetrant_mail(self): response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post, follow=True) report = response.context['report'] # Add a worker for this entity worker = FMSUser(email="*****@*****.**", telephone="0123456789") worker.save() worker.memberships.create(organisation=self.impetrant) # Login to access the pro page self.client.login(username='******', password='******') # Publish the created report response = self.client.post(reverse('report_accept_pro', args=[report.id]), follow=True) # Reset outbox mail.outbox = [] # Assign to another impetrant response = self.client.get( reverse('report_change_contractor_pro', args=[report.id]) + '?contractorId=' + str(self.impetrant.id), {}, follow=True) # 1 mail sent in real time to impetrant self.assertEquals(len(mail.outbox), 1) self.assertIn(self.impetrant.email, mail.outbox[0].to)
def test_citizen_with_pro_email(self): manager = FMSUser( is_active=True, telephone="0123456789", last_used_language="fr", password='******', first_name="manager", last_name="manager", email="*****@*****.**", manager=True ) manager.save() citizen_data = { "email" : manager.email, "last_name": "user", "telephone": "123456789", "quality" : 1 } # Create a citizen user citizen_form = CitizenForm(citizen_data) # Form has to be INVALID because the citizen use a pro email self.assertFalse(citizen_form.is_valid()) self.assertTrue(citizen_form.errors)
class ReportProViewsTest(FMSTestCase): 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.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, }
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()
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 test_citizen_form_update(self): my_user = FMSUser( is_active=True, telephone="0123456789", last_used_language="nl", password='******', first_name="my_user", last_name="my_user", email="*****@*****.**", manager=False ) my_user.save() #Change values citizen_data = { "email" : "*****@*****.**", "last_name": "user modified", "telephone": "987654321", "quality" : 2 } citizen_form = CitizenForm(citizen_data) self.assertTrue(citizen_form.is_valid()) citizen_form.save() my_user = FMSUser.objects.filter(username__iexact=citizen_data['email']).get() self.assertEqual(my_user.last_name, citizen_data["last_name"]) self.assertEqual(my_user.telephone, citizen_data["telephone"]) self.assertEqual(my_user.quality, citizen_data["quality"]) self.assertEqual(my_user.last_used_language, "fr")
class ReportProViewsTest(FMSTestCase): 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.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 }
def setUp(self): # Create a FMSUser self.fmsuser = FMSUser( telephone="0123456789", last_used_language="fr", username="******", first_name="aaa", last_name="aaa", email="*****@*****.**") self.fmsuser.save()
def handle(self, *args, **options): from apps.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)
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 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 retrive_user(self): try: user = FMSUser.objects.get(email=self.cleaned_data['email']) user.__dict__.update(self.cleaned_data) print "retrieved" self.instance_retrived = True return user except FMSUser.DoesNotExist: self.instance_retrived = False return FMSUser(**self.cleaned_data)
def test_assign_to_contractor_mail(self): response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post, follow=True) report = response.context['report'] report.accepted_at = datetime.now() report.save() # Add a worker for this entity worker = FMSUser(email="*****@*****.**", telephone="0123456789") worker.save() worker.memberships.create(organisation=self.contractor) # Reset outbox mail.outbox = [] self.client.login(username='******', password='******') response = self.client.get(reverse('report_change_contractor_pro', args=[report.id]) + '?contractorId=' + str(self.contractor.id), {}, follow=True) # 1 mail sent in real time to contractor self.assertEquals(len(mail.outbox), 1) self.assertIn(self.contractor.email, mail.outbox[0].to)
def 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 test_pro_with_citizen_email(self): citizen = FMSUser( telephone="0123456789", first_name="citizen", last_name="citizen", email="*****@*****.**", ) citizen.save() pro_data = { "email" : citizen.email, "last_name": "user", "telephone": "123456789", "quality" : 1 } # Create a pro user pro_form = FmsUserForm(pro_data) # Form has to be INVALID because a citizen uses this email self.assertFalse(pro_form.is_valid()) self.assertTrue(pro_form.errors)
def test_pro_with_citizen_email(self): citizen = FMSUser( telephone="0123456789", first_name="citizen", last_name="citizen", email="*****@*****.**", ) citizen.save() pro_data = { "email": citizen.email, "last_name": "user", "telephone": "123456789", "quality": 1 } # Create a pro user pro_form = FmsUserForm(pro_data) # Form has to be INVALID because a citizen uses this email self.assertFalse(pro_form.is_valid()) self.assertTrue(pro_form.errors)
def test_assign_to_impetrant_mail(self): response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post, follow=True) report = response.context['report'] # Add a worker for this entity worker = FMSUser(email="*****@*****.**", telephone="0123456789") worker.save() worker.memberships.create(organisation=self.impetrant) # Login to access the pro page self.client.login(username='******', password='******') # Publish the created report response = self.client.post(reverse('report_accept_pro', args=[report.id]), follow=True) # Reset outbox mail.outbox = [] # Assign to another impetrant response = self.client.get(reverse('report_change_contractor_pro', args=[report.id]) + '?contractorId=' + str(self.impetrant.id), {}, follow=True) # 1 mail sent in real time to impetrant self.assertEquals(len(mail.outbox), 1) self.assertIn(self.impetrant.email, mail.outbox[0].to)
def test_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_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 setUp(self): try: organisation = OrganisationEntity.objects.get(id=1) except ObjectDoesNotExist: organisation = OrganisationEntity(id=1, name="Test organisation") organisation.save() p1 = (148776, 171005) p2 = (150776, 171005) p3 = (150776, 169005) p4 = (148776, 169005) surface = OrganisationEntitySurface( geom=Polygon([p1, p2, p3, p4, p1]), owner=OrganisationEntity.objects.get(pk=14)) surface.save() #user_auth = User.objects.create_user(username='******', email='*****@*****.**', password='******') #user_auth.save() user = FMSUser(is_active=True, password="******", email="*****@*****.**", first_name="zaza", telephone="00000000", last_used_language="fr", organisation=organisation, username='******') user.save() #~ main_category = ReportMainCategoryClass(id=2,name_en='test main en',name_nl='test main nl',name_fr='test main fr') #~ main_category.save() #~ #~ secondary_category = ReportSecondaryCategoryClass(id=2,name_en='test second en',name_nl='test second nl',name_fr='test second fr') #~ secondary_category.save() #~ #~ category = ReportCategory(id=2,name_en='test parent en',name_nl='test parent nl',name_fr='test parent fr', public=True, category_class=main_category, secondary_category_class=secondary_category) #~ category.save() self.citizen = FMSUser(telephone="0123456789", last_used_language="fr", first_name="citizen", last_name="citizen", email="*****@*****.**") self.citizen.save() self.manager = FMSUser(is_active=True, telephone="0123456789", last_used_language="fr", password='******', first_name="manager", last_name="manager", email="*****@*****.**", manager=True) self.manager.set_password('test') self.manager.organisation = OrganisationEntity.objects.get(pk=14) self.manager.save() self.group = OrganisationEntity( type="D", name_nl="Werken", name_fr="Travaux", phone="090987", dependency=OrganisationEntity.objects.get(pk=14), email="*****@*****.**") self.group.save() self.group_mail_config = GroupMailConfig() self.group_mail_config.group = self.group self.group_mail_config.save() self.usergroupmembership = UserOrganisationMembership( user_id=self.manager.id, organisation_id=self.group.id, contact_user=True) self.usergroupmembership.save() self.sample_post = { 'report-x': '150056.538', 'report-y': '170907.56', 'report-address_fr': 'Avenue des Arts, 3', 'report-address_nl': 'Kunstlaan, 3', 'report-address_number': '3', 'report-postalcode': '1210', 'report-category': '1', 'report-secondary_category': '1', 'report-subscription': 'on', 'report-terms_of_use_validated': True, 'comment-text': 'test', 'files-TOTAL_FORMS': 0, 'files-INITIAL_FORMS': 0, 'files-MAX_NUM_FORMS': 1000, 'citizen-quality': '1', 'citizen-email': self.citizen.email, 'citizen-firstname': self.citizen.first_name, 'citizen-lastname': self.citizen.last_name }
class MailTest(FMSTestCase): def setUp(self): self.citizen = FMSUser( telephone="0123456789", last_used_language="fr", first_name="citizen", last_name="citizen", email="*****@*****.**" ) self.citizen.save() self.manager = FMSUser( is_active=True, telephone="0123456789", last_used_language="fr", password='******', first_name="manager", last_name="manager", email="*****@*****.**", manager=True ) self.manager.set_password('test') self.manager.organisation = OrganisationEntity.objects.get(pk=14) self.manager.save() self.manager4 = FMSUser( is_active=True, telephone="0123456789", last_used_language="fr", password='******', first_name="manager4", last_name="manager4", email="*****@*****.**", manager=True ) self.manager4.set_password('test') self.manager4.organisation = OrganisationEntity.objects.get(pk=14) self.manager4.save() self.group = OrganisationEntity( type="D", name_nl="Werken", name_fr="Travaux", phone="090987", dependency=OrganisationEntity.objects.get(pk=14), email="*****@*****.**" ) self.group.save() self.group.dispatch_categories.add(ReportCategory.objects.get(pk=1)) # Mail config: notify group and members in real time self.group_mail_config = GroupMailConfig() self.group_mail_config.group = self.group self.group_mail_config.notify_group = True self.group_mail_config.notify_members = True self.group_mail_config.save() self.manager.memberships.create(organisation=self.group, contact_user=True) self.manager4.memberships.create(organisation=self.group, contact_user=True) self.client = Client() self.manager2 = FMSUser( is_active=True, telephone="9876543210", last_used_language="nl", password='******', first_name="manager2", last_name="manager2", email="*****@*****.**", manager=True ) self.manager2.set_password('test2') self.manager2.organisation = OrganisationEntity.objects.get(pk=14) self.manager2.save() self.group2 = OrganisationEntity( type="D", name_nl="Werken", name_fr="Travaux", phone="090987", dependency=OrganisationEntity.objects.get(pk=21), email="*****@*****.**" ) self.group2.save() self.group2.dispatch_categories.add(ReportCategory.objects.get(pk=2)) self.group2.dispatch_categories.add(ReportCategory.objects.get(pk=1)) # Mail config: notify group and members in real time self.group_mail_config2 = GroupMailConfig() self.group_mail_config2.group = self.group2 self.group_mail_config2.notify_group = True self.group_mail_config2.notify_members = True self.group_mail_config2.save() p1 = (148776, 171005) p2 = (150776, 171005) p3 = (150776, 169005) p4 = (148776, 169005) surface = OrganisationEntitySurface( geom=Polygon([p1, p2, p3, p4, p1]), owner=OrganisationEntity.objects.get(pk=14), ) surface.save() self.manager2.memberships.create(organisation=self.group2) self.manager3 = FMSUser( is_active=True, telephone="000000000", last_used_language="nl", password='******', first_name="manager3", last_name="manager3", email="*****@*****.**", manager=True ) self.manager3.set_password('test3') self.manager3.organisation = OrganisationEntity.objects.get(pk=21) self.manager3.save() self.manager3.memberships.create(organisation=self.group2) self.impetrant = OrganisationEntity( name_nl="MIVB", name_fr="STIB", email="*****@*****.**") self.impetrant.save() self.contractor = OrganisationEntity( name_nl="Fabricom GDF", name_fr="Fabricom GDF", email="*****@*****.**") self.contractor.save() self.sample_post = { 'report-x': '150056.538', 'report-y': '170907.56', 'report-address_fr': 'Avenue des Arts, 3', 'report-address_nl': 'Kunstlaan, 3', 'report-address_number': '3', 'report-postalcode': '1210', 'report-category': '1', 'report-secondary_category': '1', 'report-subscription': 'on', 'citizen-quality': '1', 'comment-text': 'test', 'files-TOTAL_FORMS': 0, 'files-INITIAL_FORMS': 0, 'files-MAX_NUM_FORMS': 0, 'citizen-email': self.citizen.email, 'citizen-firstname': self.citizen.first_name, 'citizen-lastname': self.citizen.last_name, 'report-terms_of_use_validated': True } self.sample_post_pro = { 'report-x': '150056.538', 'report-y': '170907.56', 'report-address_fr': 'Avenue des Arts, 3', 'report-address_nl': 'Kunstlaan, 3', 'report-address_number': '3', 'report-postalcode': '1210', 'report-category': '1', 'report-secondary_category': '1', 'report-subscription': 'on', 'comment-text': 'test', 'files-TOTAL_FORMS': 0, 'files-INITIAL_FORMS': 0, 'files-MAX_NUM_FORMS': 0, 'report-terms_of_use_validated': True } self.sample_post_mail_pdf_pro = { 'comments': 'test comment', 'visibility': 'private', 'to': '[email protected],[email protected];[email protected]' } self.sample_post_mail_pdf_citzen = { 'comments': 'test comment', 'visibility': 'public', 'to': '[email protected],[email protected];[email protected]' } def test_create_report_mail(self): # Send a post request filling in the form to create a report response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post, follow=True) # Mails are sent to responsibles according to mail config of the group: 1 for group + members expected_recipients = self.group_mail_config.get_manager_recipients() # 1 more mail is sent to creator in real time expected_recipients.append(self.citizen.email) self.assertTrue(mail.outbox) self.assertEquals(len(mail.outbox), len(expected_recipients)) for email in mail.outbox: self.assertIn(email.to[0], expected_recipients) def test_close_report_mail(self): # Send a post request filling in the form to create a report response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post, follow=True) report = response.context['report'] report = response.context['report'] report.accepted_at = datetime.now() report.save() # Reset outbox mail.outbox = [] # Close the report self.client.login(username='******', password='******') response = self.client.get(reverse('report_close_pro', args=[report.id]), follow=True) report = Report.objects.get(id=report.id) self.assertEquals(report.status, Report.PROCESSED) # One mail is sent in real time to the creator if citizen. All others are digest to subscribers. self.assertEquals(len(mail.outbox), 1) self.assertIn(self.citizen.email, mail.outbox[0].to) def test_refuse_report_mail(self): # Send a post request filling in the form to create a report response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post, follow=True) report = response.context['report'] # Reset outbox mail.outbox = [] # Login to access the pro page to create a user self.client.login(username='******', password='******') # Refuse the created report refused_url = reverse('report_refuse_pro', args=[report.id]) refused_params = {'text': 'more info'} response = self.client.post(refused_url, refused_params, follow=True) report = Report.objects.get(id=report.id) # The status of the report must now be REFUSED self.assertEquals(report.status, Report.REFUSED) # All mail are sent as digest to subscribers self.assertEquals(len(mail.outbox), 0) def test_subscription_for_citizen_mail(self): # Send a post request filling in the form to create a report response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post, follow=True) report = response.context['report'] # Reset outobox mail.outbox = [] # Send a post request subscribing a citizen to the just created report subscribe_url = reverse('subscribe', args=[report.id]) subscribe_email = '*****@*****.**' subscribe_params = {'citizen_email': subscribe_email} response = self.client.post(subscribe_url, subscribe_params, follow=True) # 1 mail sent in real-time to subscriber self.assertEquals(len(mail.outbox), 1) self.assertTrue(subscribe_email in mail.outbox[0].to) def test_mark_report_as_done_mail(self): # Send a post request filling in the form to create a report response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post, follow=True) report = response.context['report'] # Login to access the pro page self.client.login(username='******', password='******') # Publish the created report response = self.client.post(reverse('report_accept_pro', args=[report.id]), follow=True) # Reset outbox mail.outbox = [] # Send a post request to mark the report as done update_url = reverse('report_fix_pro', args=[report.id]) update_params = {'text':'My comment'} response = self.client.post(update_url, update_params) # Mails are sent to responsibles according to mail config of the group: 1 for group + members without the author expected_recipients = self.group_mail_config.get_manager_recipients(self.manager) self.assertTrue(mail.outbox) self.assertEquals(len(mail.outbox), len(expected_recipients)) for email in mail.outbox: self.assertIn(email.to[0], expected_recipients) def test_accept_report_mail(self): # Send a post request filling in the form to create a report response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post, follow=True) report = response.context['report'] # Reset outbox mail.outbox = [] self.client.login(username='******', password='******') url = reverse('report_accept_pro', args=[report.id]) response = self.client.get(url, follow=True) # All mails are sent to subscribers as digest self.assertEquals(len(mail.outbox), 0) def test_planned_report_mail(self): # Send a post request filling in the form to create a report response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post, follow=True) report = response.context['report'] report.accepted_at = datetime.now() report.save() # Reset outbox mail.outbox = [] # Set as planned date_planned = (datetime.now() + timedelta(days=1)).strftime("%m/%Y") url = '%s?date_planned=%s' % (reverse('report_planned_pro', args=[report.id]), date_planned) self.client.login(username='******', password='******') response = self.client.get(url, follow=True) report = response.context['report'] self.assertTrue(report.is_planned()) self.assertEqual(date_planned, report.date_planned.strftime("%m/%Y")) # Only digest are sent to subscribers self.assertEquals(len(mail.outbox), 0) # Planned another date date_planned = (datetime.now() + timedelta(days=40)).strftime("%m/%Y") url = '%s?date_planned=%s' % (reverse('report_planned_pro', args=[report.id]), date_planned) self.client.login(username='******', password='******') response = self.client.get(url, follow=True) report = response.context['report'] self.assertTrue(report.is_planned()) self.assertEqual(date_planned, report.date_planned.strftime("%m/%Y")) # Only digest are sent to subscribers self.assertEquals(len(mail.outbox), 0) def test_create_report_as_pro_mail(self): # Create a report self.client.login(username='******', password='******') response = self.client.post(reverse('report_new_pro') + '?x=150056.538&y=170907.56', self.sample_post_pro, follow=True) # Mails are sent to responsibles according to mail config of the group: 1 for group + members without the author expected_recipients = self.group_mail_config.get_manager_recipients(self.manager) self.assertTrue(mail.outbox) self.assertEquals(len(mail.outbox), len(expected_recipients)) for email in mail.outbox: self.assertIn(email.to[0], expected_recipients) def test_report_resolved_as_pro_mail(self): response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post, follow=True) report_id = response.context['report'].id # Login to access the pro page self.client.login(username='******', password='******') # Publish the created report response = self.client.post(reverse('report_accept_pro', args=[report_id]), follow=True) self.assertEquals(response.status_code, 200) # Clear outbox mail.outbox = [] params = { 'text' : 'Ceci est un commentaire' } response = self.client.post(reverse('report_fix_pro', args=[report_id]), params, follow=True) self.assertEquals(response.status_code, 200) self.assertEquals(Report.objects.get(id=report_id).status, Report.SOLVED) # Mails are sent to responsibles according to mail config of the group: 1 for group + members without the author expected_recipients = self.group_mail_config.get_manager_recipients(self.manager) self.assertTrue(mail.outbox) self.assertEquals(len(mail.outbox), len(expected_recipients)) for email in mail.outbox: self.assertIn(email.to[0], expected_recipients) def test_assign_to_other_member_of_same_entity_mail(self): response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post, follow=True) report = response.context['report'] # Login to access the pro page self.client.login(username='******', password='******') # Publish the created report response = self.client.post(reverse('report_accept_pro', args=[report.id]), follow=True) # Restet outbox mail.outbox = [] # Change manager in the same entity response = self.client.post(reverse('report_change_manager_pro', args=[report.id]), {'man_id' : 'department_' + str(self.group2.id), 'transfer':0}, follow=True) # Mails are sent to responsibles according to mail config of the group: 1 for group + members expected_recipients = self.group_mail_config2.get_manager_recipients() self.assertTrue(mail.outbox) self.assertEquals(len(mail.outbox), len(expected_recipients)) for email in mail.outbox: self.assertIn(email.to[0], expected_recipients) def test_assign_to_another_entity_mail(self): response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post, follow=True) report = response.context['report'] # Login to access the pro page self.client.login(username='******', password='******') # Publish the created report response = self.client.post(reverse('report_accept_pro', args=[report.id]), follow=True) # Restet outbox mail.outbox = [] # Change to another entity response = self.client.post(reverse('report_change_manager_pro', args=[report.id]), {"man_id": "entity_21", "transfer": 0}, follow=True) # Mails are sent to responsibles according to mail config of the group: 1 for group + members expected_recipients = self.group_mail_config2.get_manager_recipients() self.assertTrue(mail.outbox) self.assertEquals(len(mail.outbox), len(expected_recipients)) for email in mail.outbox: self.assertIn(email.to[0], expected_recipients) def test_assign_to_impetrant_mail(self): response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post, follow=True) report = response.context['report'] # Add a worker for this entity worker = FMSUser(email="*****@*****.**", telephone="0123456789") worker.save() worker.memberships.create(organisation=self.impetrant) # Login to access the pro page self.client.login(username='******', password='******') # Publish the created report response = self.client.post(reverse('report_accept_pro', args=[report.id]), follow=True) # Reset outbox mail.outbox = [] # Assign to another impetrant response = self.client.get(reverse('report_change_contractor_pro', args=[report.id]) + '?contractorId=' + str(self.impetrant.id), {}, follow=True) # 1 mail sent in real time to impetrant self.assertEquals(len(mail.outbox), 1) self.assertIn(self.impetrant.email, mail.outbox[0].to) def test_assign_to_contractor_mail(self): response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post, follow=True) report = response.context['report'] report.accepted_at = datetime.now() report.save() # Add a worker for this entity worker = FMSUser(email="*****@*****.**", telephone="0123456789") worker.save() worker.memberships.create(organisation=self.contractor) # Reset outbox mail.outbox = [] self.client.login(username='******', password='******') response = self.client.get(reverse('report_change_contractor_pro', args=[report.id]) + '?contractorId=' + str(self.contractor.id), {}, follow=True) # 1 mail sent in real time to contractor self.assertEquals(len(mail.outbox), 1) self.assertIn(self.contractor.email, mail.outbox[0].to) def test_citizen_updates_report_mail(self): response = self.client.post( reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post, follow=True) report = response.context['report'] report.accepted_at = datetime.now() report.save() # Reset outbox mail.outbox = [] # A citizen documents a report response = self.client.post(reverse('report_document', kwargs={'report_id': report.id, 'slug': 'hello'}), { 'comment-text': 'new created comment', 'citizen-email': self.citizen.email, 'citizen-quality': 1, 'files-TOTAL_FORMS': 0, 'files-INITIAL_FORMS': 0, 'files-MAX_NUM_FORMS': 0 }, follow=True) report = response.context['report'] # Mails are sent to responsibles according to mail config of the group: 1 for group + members expected_recipients = self.group_mail_config.get_manager_recipients() self.assertTrue(mail.outbox) self.assertEquals(len(mail.outbox), len(expected_recipients)) for email in mail.outbox: self.assertIn(email.to[0], expected_recipients) def test_pro_updates_report_mail(self): response = self.client.post( reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post, follow=True) report = response.context['report'] # Login to access the pro page self.client.login(username='******', password='******') # Publish the created report response = self.client.post(reverse('report_accept_pro', args=[report.id]), follow=True) # Reset outbox mail.outbox = [] # Document report as pro response = self.client.post(reverse('report_show_pro', kwargs={'report_id': report.id, 'slug': 'hello'}), { 'comment-text': 'new created comment', 'files-TOTAL_FORMS': 0, 'files-INITIAL_FORMS': 0, 'files-MAX_NUM_FORMS': 0 }, follow=True) # Mails are sent to responsibles according to mail config of the group: 1 for group + members without the author expected_recipients = self.group_mail_config.get_manager_recipients(self.manager) self.assertTrue(mail.outbox) self.assertEquals(len(mail.outbox), len(expected_recipients)) for email in mail.outbox: self.assertIn(email.to[0], expected_recipients) def test_publish_comment_mail(self): response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post, follow=True) report = response.context['report'] # Login to access the pro page self.client.login(username='******', password='******') # Accept and publish the created report report.private = False report.accepted_at = datetime.now() report.save() # Assure that comment is private self.assertEqual(ReportAttachment.PRIVATE, report.comments()[0].security_level) # Reset outbox mail.outbox = [] # Now make the comment public response = self.client.get( reverse('report_update_attachment', args=[report.id]), { 'updateType': 1, 'attachmentId': report.comments()[0].id }, follow=True) self.assertEqual(ReportAttachment.PUBLIC, report.comments()[0].security_level) # All notifications are sent to subscribers as digest self.assertEquals(len(mail.outbox), 0) def test_subscription_for_pro_mail(self): response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post, follow=True) report = response.context['report'] # Login to access the pro page self.client.login(username='******', password='******') # Publish the created report response = self.client.post(reverse('report_accept_pro', args=[report.id]), follow=True) self.client.logout() # Reset outbox mail.outbox = [] self.client.login(username='******', password='******') response = self.client.get(reverse('subscribe_pro', args=[report.id]), {}, follow=True) # 1 mail sent in real-time to subscriber self.assertEquals(len(mail.outbox), 1) self.assertTrue(self.manager2.email in mail.outbox[0].to) def test_make_report_switch_visibility(self): response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post, follow=True) # Assure that report is public report = response.context['report'] self.assertFalse(report.private) # Login to access the pro page self.client.login(username='******', password='******') # Publish the created report response = self.client.post(reverse('report_accept_pro', args=[report.id]), follow=True) # Reset outbox mail.outbox = [] # 1/ Now make the report private response = self.client.get(reverse('report_change_switch_visibility', args=[report.id]) + '?visibility=true', follow=True) report = Report.objects.get(id=report.id) self.assertTrue(report.private) # Mails are sent in real time self.assertEquals(len(mail.outbox), 1) # Reset outbox mail.outbox = [] # 2/ Now make the report public response = self.client.get(reverse('report_change_switch_visibility', args=[report.id]) + '?visibility=false', follow=True) report = Report.objects.get(id=report.id) self.assertFalse(report.private) # Mails are sent in real time self.assertEquals(len(mail.outbox), 1) #def testMergeReportMail(self): # #Login to access the pro page # self.client.login(username='******', password='******') # #Send a post request filling in the form to create a report # response = self.client.post(reverse('report_new_pro') + '?x=150056.538&y=170907.56', self.sample_post, follow=True) # self.assertEquals(response.status_code, 200) # self.assertIn('report', response.context) # report_id = response.context['report'].id # self.assertEquals(len(mail.outbox), 1) # one for creator subscription, one for manager # self.client.logout() # response = self.client.post( # reverse('report_new') + '?x=150056.538&y=170907.56', # self.sample_post, # follow=True) # self.assertEquals(response.status_code, 200) # Should send mail only to responsible # self.assertEquals(len(mail.outbox), 3) # report2_id = response.context['report'].id # self.client.login(username='******', password='******') # Publish the created report # response3 = self.client.post(reverse('report_accept_pro', args=[report2_id]), follow=True) # self.assertEquals(response3.status_code, 200) # self.assertEquals(len(mail.outbox), 4) # Merge reports # url2 = reverse('report_do_merge_pro', args=[report_id]) # self.client.post(url2, {"mergeId": report2_id}) # self.assertTrue(Report.objects.all().visible().filter(id=report_id).exists()) # self.assertFalse(Report.objects.all().visible().filter(id=report2_id).exists()) #Reference from merged to kept report # self.assertEqual(report_id, Report.objects.get(id=report2_id).merged_with.id) #A mail has been sent to the creator of the first report to notify him that his report has been merged # self.assertEquals(len(mail.outbox), 5) def test_send_PDF_to_pro_mail(self): response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post, follow=True) report = response.context['report'] # Login to access the pro page self.client.login(username='******', password='******') # Publish the created report response = self.client.post(reverse('report_accept_pro', args=[report.id]), follow=True) # Reset outbox mail.outbox = [] # Send Pro PDF response = self.client.post(reverse('send_pdf', args=[report.id]), self.sample_post_mail_pdf_pro) # 3 mails should be sent self.assertEquals(len(mail.outbox), 3) def test_send_PDF_to_citizen_mail(self): response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post, follow=True) report = response.context['report'] report.accepted_at = datetime.now() report.save() # Reset outbox mail.outbox = [] # Login to access the pro page self.client.login(username='******', password='******') # Now send Pro PDF response = self.client.post(reverse('send_pdf', args=[report.id]), self.sample_post_mail_pdf_citzen) # 3 mails should be sent to citizens self.assertEquals(len(mail.outbox), 3) def test_reopen_report(self): # New report response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post, follow=True) report = response.context['report'] comment = ReportComment(report_id=report.id, text='test', type=3) comment.save() # Set status to REFUSED report.status = Report.REFUSED report.save() # Login to access the pro page self.client.login(username='******', password='******') # Clear mail outbox mail.outbox = [] # Reopen reports url = reverse('report_reopen_pro', args=[report.id]) response = self.client.get(url, follow=True) report = response.context['report'] # Assert self.assertEquals(Report.MANAGER_ASSIGNED, report.status) # No mail sent in real-time self.assertEquals(len(mail.outbox), 0) def test_recipient_for_everyone(self): """ recipients must contains everyone (group, manager and manager4) """ recipients = self.group_mail_config.get_manager_recipients() self.assertEquals(len(recipients), 3) self.assertIn(self.group.email, recipients) self.assertIn(self.manager.email, recipients) self.assertIn(self.manager4.email, recipients) def test_recipient_exclude_author(self): """ recipients must contains everyone (group, manager and manager4) """ recipients = self.group_mail_config.get_manager_recipients(self.manager) self.assertEquals(len(recipients), 2) self.assertIn(self.group.email, recipients) self.assertIn(self.manager4.email, recipients) def test_recipient_for_manager_as_group(self): """ if email group is same as manager then recipients must contains ony once this email (distinct values) (group email and manager4) """ self.group.email = self.manager.email self.group.save() self.group_mail_config.notify_group = False self.group_mail_config.save() recipients = self.group_mail_config.get_manager_recipients() self.assertEquals(len(recipients), 2) self.assertIn(self.manager.email, recipients) self.assertIn(self.manager4.email, recipients) def test_recipient_for_manager_as_group_author(self): """ if email group is same as manager then recipients and also is the author this email must be excluded """ self.group.email = self.manager.email recipients = self.group_mail_config.get_manager_recipients(self.manager) self.assertEquals(len(recipients), 2) self.assertIn(self.manager4.email, recipients) self.assertIn(self.group.email, recipients)
class ReportViewsTest(FMSTestCase): def setUp(self): self.user = FMSUser(username='******', email='*****@*****.**', password='******') self.user.save() self.client = Client() self.citizen = FMSUser( telephone="0123456789", last_used_language="fr", first_name="citizen", last_name="citizen", email="*****@*****.**" ) self.citizen.save() self.group = OrganisationEntity( type="D", name_nl="Werken", name_fr="Travaux", phone="090987", dependency=OrganisationEntity.objects.get(pk=14), email="*****@*****.**" ) self.group.save() self.group_mail_config = GroupMailConfig() self.group_mail_config.group = self.group self.group_mail_config.save() self.manager = FMSUser( is_active=True, telephone="0123456789", last_used_language="fr", password='******', first_name="manager", last_name="manager", email="*****@*****.**", manager=True ) self.manager.set_password('test') self.manager.organisation = OrganisationEntity.objects.get(pk=14) self.manager.save() self.group.dispatch_categories.add(ReportCategory.objects.get(pk=1)) p1 = (148776, 171005) p2 = (150776, 171005) p3 = (150776, 169005) p4 = (148776, 169005) surface = OrganisationEntitySurface( geom=Polygon([p1, p2, p3, p4, p1]), owner=OrganisationEntity.objects.get(pk=14), ) surface.save() self.manager.memberships.create(organisation=self.group, contact_user=True) self.sample_post = { 'report-x': '150056.538', 'report-y': '170907.56', 'report-address_fr': 'Avenue des Arts, 3', 'report-address_nl': 'Kunstlaan, 3', 'report-address_number': '3', 'report-postalcode': '1210', 'report-category': '1', 'report-secondary_category': '1', 'report-subscription': 'on', 'comment-text': 'test', 'files-TOTAL_FORMS': 0, 'files-INITIAL_FORMS': 0, 'files-MAX_NUM_FORMS': 0, 'citizen-email': self.citizen.email, 'citizen-firstname': self.citizen.first_name, 'citizen-lastname': self.citizen.last_name, 'citizen-quality': '1', 'report-terms_of_use_validated': True } self.sample_post_2 = { 'report-x': '150056', 'report-y': '170907.56', 'report-address_fr': 'Avenue des Arts, 3', 'report-address_nl': 'Kunstlaan, 3', 'report-address_number': '5', 'report-postalcode': '1210', 'report-category': '1', 'report-secondary_category': '1', 'report-subscription': 'on', 'comment-text': 'test2', 'files-TOTAL_FORMS': 0, 'files-INITIAL_FORMS': 0, 'files-MAX_NUM_FORMS': 0, 'citizen-email': self.citizen.email, 'citizen-firstname': self.citizen.first_name, 'citizen-lastname': self.citizen.last_name, 'citizen-quality': '1', 'report-terms_of_use_validated': True } def test_home(self): """Tests the new report view.""" response = self.client.get(reverse('home'), follow=True) self.assertEqual(response.status_code, 200) self.assertTrue('report_counts' in response.context) self.assertTrue('zipcodes' in response.context) #Are the zipcodes well loaded from DB?? self.assertTrue(len(response.context['zipcodes']) > 0) @skip('replaced by database pages') def test_about(self): """Tests the about view.""" response = self.client.get(reverse('about'), follow=True) self.assertEqual(response.status_code, 200) @skip('replaced by database pages') def test_term_of_use(self): """Tests the term of use view.""" response = self.client.get(reverse('terms_of_use'), follow=True) self.assertEqual(response.status_code, 200) def test_new_report(self): """Tests the new report page.""" url = reverse('report_new') response = self.client.get(url, {'x': '148360', 'y': '171177'}, follow=True) self.assertEqual(response.status_code, 200) def test_verify_report(self): """Tests the new report page get verify existings.""" url = "%s?x=148360&y=171177" % reverse('report_new') response = self.client.post(url, self.sample_post, follow=True) self.assertEqual(response.status_code, 200) url = reverse('report_verify') response = self.client.get(url, {'x': '150056', 'y': '170907'}, follow=True) self.assertEqual(response.status_code, 200) self.assertIn('reports_nearby', response.context) # Assert that the list view displays minimal information about reports last_dist = 0 for report in response.context['reports_nearby']: self.assertContains(response, report.get_absolute_url()) self.assertTrue(report.distance.m <= 20) # limit to 1km around self.assertTrue(report.distance.m >= last_dist) # ordered by distance last_dist = report.distance.m def test_create_report(self): """Tests the creation of a report and test the view of it.""" url = "%s?x=148360&y=171177" % reverse('report_new') response = self.client.post(url, self.sample_post, follow=True) self.assertEqual(response.status_code, 200) self.assertIn('report', response.context) report = response.context['report'] self.assertContains(response, report.postalcode) self.assertContains(response, report.status) self.assertEqual(1, len(Report.objects.all())) # Get in the DB the created report report = Report.objects.all()[0] # Check that source is correct self.assertEqual(Report.SOURCES['WEB'], report.source) def test_create_report_double(self): """Tests the creation of a double report and test the view of it.""" url = "%s?x=148360&y=171177" % reverse('report_new') self.client.post(url, self.sample_post, follow=True) self.client.post(url, self.sample_post, follow=True) self.client.post(url, self.sample_post, follow=True) self.client.post(url, self.sample_post, follow=True) self.assertEqual(1, len(Report.objects.all())) def test_accept_report(self): """Tests acceptation a report and test the view of it.""" url = "%s?x=148360&y=171177" % reverse('report_new') response = self.client.post(url, self.sample_post, follow=True) self.assertEqual(response.status_code, 200) report = response.context['report'] self.client.login(username='******', password='******') url = reverse('report_accept_pro', args=[report.id]) response = self.client.get(url, follow=True) self.assertEqual(response.status_code, 200) report = response.context['report'] self.assertTrue(report.accepted_at is not None) def test_refuse_report(self): """Tests refuse a report and test the view of it.""" url = "%s?x=148360&y=171177" % reverse('report_new') response = self.client.post(url, self.sample_post, follow=True) self.assertEqual(response.status_code, 200) report = response.context['report'] # Be sure it's private report.private = True report.save() self.client.login(username='******', password='******') url = reverse('report_refuse_pro', args=[report.id]) response = self.client.post(url, {'text': "Message de refus"}, follow=True) self.assertEqual(response.status_code, 200) report = response.context['report'] self.assertTrue(report.accepted_at is None) self.assertEqual(report.status, Report.REFUSED) comment = ReportComment.objects.get(report_id=report.id, type=ReportAttachment.REFUSED) self.assertEqual(comment.security_level, ReportComment.PRIVATE) def test_refuse_report_comment_visible_for_citizen(self): """Tests refuse a report and test the view of it.""" url = "%s?x=148360&y=171177" % reverse('report_new') response = self.client.post(url, self.sample_post, follow=True) self.assertEqual(response.status_code, 200) report = response.context['report'] # Be sure it's public report.private = False report.save() self.client.login(username='******', password='******') url = reverse('report_refuse_pro', args=[report.id]) response = self.client.post(url, {'text': "Message de refus"}, follow=True) self.assertEqual(response.status_code, 200) report = response.context['report'] self.assertTrue(report.accepted_at is None) self.assertEqual(report.status, Report.REFUSED) comment = ReportComment.objects.get(report_id=report.id, type=ReportAttachment.REFUSED) self.assertEqual(comment.security_level, ReportComment.PUBLIC) def test_add_comment(self): """Tests the update of a report.""" url = "%s?x=148360&y=171177" % reverse('report_new') response = self.client.post(url, self.sample_post, follow=True) report = response.context['report'] self.assertEqual(report.comments().count(), 1) self.assertEqual(report.comments()[0].created_by, self.citizen) report.save() response = self.client.post(reverse('report_document', kwargs={'report_id': report.id, 'slug': 'hello'}), { 'comment-text': 'new created comment', 'citizen-email': self.user.email, 'citizen-quality': 1, 'files-TOTAL_FORMS': 0, 'files-INITIAL_FORMS': 0, 'files-MAX_NUM_FORMS': 0 }, follow=True) self.assertEqual(response.status_code, 200) url = reverse('report_show2', args=[report.id]) self.assertRedirects(response, url) self.assertEqual(report.comments().count(), 2) self.assertEqual(report.comments()[1].created_by, self.user) def test_add_comment_as_pro(self): """Tests the update of a report as a pro.""" self.client.login(username='******', password='******') url = "%s?x=148360&y=171177" % reverse('report_new_pro') response = self.client.post(url, self.sample_post, follow=True) report = response.context['report'] self.assertEqual(report.comments().count(), 1) self.assertEqual(report.comments()[0].created_by, self.manager) report.save() response = self.client.post(reverse('report_show_pro', kwargs={'report_id': report.id, 'slug': 'hello'}), { 'comment-text': 'new created comment', 'files-TOTAL_FORMS': 0, 'files-INITIAL_FORMS': 0, 'files-MAX_NUM_FORMS': 0 }, follow=True) self.assertEqual(response.status_code, 200) self.assertRedirects(response, report.get_absolute_url_pro()) self.assertEqual(report.comments().count(), 2) self.assertEqual(report.comments()[1].created_by, self.manager) def test_change_category_private(self): self.client.login(username='******', password='******') url = "%s?x=148360&y=171177" % reverse('report_new') response = self.client.post(url, self.sample_post, follow=True) report = response.context['report'] self.assertEqual(Report.objects.get(id=report.id).category.id, 1) self.assertEqual(Report.objects.get(id=report.id).secondary_category.id, 1) # Setting a private sec_cat to a public report is not allowed self.client.post(reverse('update_category_for_report', args=[report.id]), {"main_category": "2", "secondary_category": "32"}) # So, cat not changed self.assertEqual(Report.objects.get(id=report.id).category.id, 1) self.assertEqual(Report.objects.get(id=report.id).secondary_category.id, 1) def test_change_category_public(self): self.client.login(username='******', password='******') url = "%s?x=148360&y=171177" % reverse('report_new') response = self.client.post(url, self.sample_post, follow=True) report = response.context['report'] self.assertEqual(Report.objects.get(id=report.id).category.id, 1) self.assertEqual(Report.objects.get(id=report.id).secondary_category.id, 1) self.client.post(reverse('update_category_for_report', args=[report.id]), {"main_category": "2", "secondary_category": "2"}) self.assertEqual(Report.objects.get(id=report.id).category.id, 2) self.assertEqual(Report.objects.get(id=report.id).secondary_category.id, 2) def test_subscription(self): """Tests the subscription of a report.""" url = "%s?x=148360&y=171177" % reverse('report_new') response = self.client.post(url, self.sample_post, follow=True) report = response.context['report'] # responsible manager is NOT subscribed by default self.assertFalse(report.subscriptions.filter(subscriber=self.manager).exists()) self.client.login(username='******', password='******') # subscribe to the report response = self.client.get(reverse('subscribe_pro', args=[report.id]), {}, follow=True) self.assertRedirects(response, report.get_absolute_url_pro()) self.assertEqual(response.status_code, 200) #current user is subscribed self.assertTrue(report.subscriptions.filter(subscriber=self.manager).exists()) def test_subscription_citizen(self): """Tests the subscription of a report.""" url = "%s?x=148360&y=171177" % reverse('report_new') response = self.client.post(url, self.sample_post, follow=True) report = response.context['report'] # current user is not subscribed yet self.assertTrue(report.subscriptions.filter(subscriber=self.citizen).exists()) #unsubscribe to the report response = self.client.get(reverse('unsubscribe', args=[report.id]) + '?citizen_email=' + self.citizen.email, {}, follow=True) url = reverse('report_show2', args=[report.id]) self.assertRedirects(response, url) self.assertEqual(response.status_code, 200) #current user is no more subscribed self.assertFalse(report.subscriptions.filter(subscriber=self.citizen).exists()) def test_do_merge_reports(self): """Test do merge reports. """ #Add first report url = "%s?x=148360&y=171177" % reverse('report_new') response = self.client.post(url, self.sample_post, follow=True) report = response.context['report'] #Add second report response2 = self.client.post(url, self.sample_post_2, follow=True) report2 = response2.context['report'] #Login user params = { 'username': self.manager.email, 'password': '******' } self.client.post(reverse('login'), params) #Merge reports url2 = reverse('report_do_merge_pro', args=[report.id]) self.client.post(url2, {"mergeId": report2.id}) #Reference from merged to kept report self.assertEqual(report.id, Report.objects.get(id=report2.id).merged_with.id) #The first one (oldest one) is kept self.assertEqual(Report.objects.all().visible()[0].id, report.id) #The comment of the second one is added to the first one self.assertEqual(Report.objects.get(id=report.id).comments().count(), 2) def test_merge_reports(self): """Test merge reports. """ # Add first report url = "%s?x=148360&y=171177" % reverse('report_new') response = self.client.post(url, self.sample_post, follow=True) report = response.context['report'] # Add second report response2 = self.client.post(url, self.sample_post_2, follow=True) report2 = response2.context['report'] report2.status = Report.IN_PROGRESS report2.save() # Login user params = { 'username': self.manager.email, 'password': '******' } self.client.post(reverse('login'), params) # Display mergeable reports list url = reverse('report_merge_pro', args=[report.get_slug(), report.id]) response = self.client.get(url) self.assertEqual(report, response.context['report']) self.assertEqual(1, len(response.context['reports_nearby'])) def test_merge_reports_search_ticket(self): """Test merge reports with search of ticket number """ # Add first report url = "%s?x=148360&y=171177" % reverse('report_new') response = self.client.post(url, self.sample_post, follow=True) report = response.context['report'] # Add second report response2 = self.client.post(url, self.sample_post_2, follow=True) report2 = response2.context['report'] report2.status = Report.IN_PROGRESS #necessary otherwise both report will be with "CREATED" status # and you can't merge 2 reports with 2 "CREATED" status report2.save() # Login user params = { 'username': self.manager.email, 'password': '******' } self.client.post(reverse('login'), params) # Display mergeable report according to ticket number url2 = reverse('report_merge_pro', args=[report.get_slug(), report.id]) response = self.client.get("%s?ticketNumber=%s" % (url2, report2.id)) self.assertEqual(report, response.context['report']) self.assertEqual(1, len(response.context['reports_nearby'])) self.assertEqual(report2.id, response.context['reports_nearby'][0].id) def test_mark_done_as_user(self): """Tests marking report as done.""" url = "%s?x=148360&y=171177" % reverse('report_new') response = self.client.post(url, self.sample_post, follow=True) report = response.context['report'] self.client.login(username='******', password='******') url = reverse('report_accept_pro', args=[report.id]) response = self.client.get(url, follow=True) # Mark as done as citizen self.client.logout() response = self.client.post(reverse('report_update', args=[report.id]), {'is_fixed': 'True'}, follow=True) self.assertEqual(response.status_code, 200) report = response.context['report'] self.assertTrue(report.fixed_at) self.assertEqual(report.status, Report.SOLVED) self.assertFalse(ReportComment.objects.filter(type=ReportAttachment.MARK_AS_DONE, report=report).exists()) def test_mark_done_as_pro(self): """Tests marking report as done.""" url = "%s?x=148360&y=171177" % reverse('report_new') response = self.client.post(url, self.sample_post, follow=True) report = response.context['report'] self.client.login(username='******', password='******') url = reverse('report_accept_pro', args=[report.id]) response = self.client.get(url, follow=True) self.assertEqual(response.status_code, 200) # Mark as done as pro response = self.client.post(reverse('report_fix_pro', args=[report.id]), {'text': 'commentaire'}, follow=True) self.assertEquals(response.status_code, 200) report = response.context['report'] self.assertTrue(report.fixed_at) self.assertTrue(ReportComment.objects.filter(type=ReportAttachment.MARK_AS_DONE, report=report).exists()) self.assertEquals(report.status, Report.SOLVED) def test_mark_done_as_user_denied(self): """Tests marking report not done if denied.""" url = "%s?x=148360&y=171177" % reverse('report_new') response = self.client.post(url, self.sample_post, follow=True) report = response.context['report'] self.client.login(username='******', password='******') url = reverse('report_accept_pro', args=[report.id]) response = self.client.get(url, follow=True) # Change status to refused report.status = report.REFUSED report.save() # Try to mark as done as citizen self.client.logout() response = self.client.post(reverse('report_update', args=[report.id]), {'is_fixed': 'True'}, follow=True) self.assertEqual(response.status_code, 200) report = response.context['report'] self.assertFalse(report.fixed_at) self.assertEqual(report.status, Report.REFUSED) self.assertFalse(ReportComment.objects.filter(type=ReportAttachment.MARK_AS_DONE, report=report).exists()) def test_mark_done_as_pro_denied(self): """Tests marking report as done.""" url = "%s?x=148360&y=171177" % reverse('report_new') response = self.client.post(url, self.sample_post, follow=True) report = response.context['report'] self.client.login(username='******', password='******') url = reverse('report_accept_pro', args=[report.id]) response = self.client.get(url, follow=True) self.assertEqual(response.status_code, 200) # Change status to refused report.status = report.REFUSED report.save() # Try to mark as done as pro response = self.client.post(reverse('report_fix_pro', args=[report.id]), {'text': 'commentaire'}, follow=True) self.assertEquals(response.status_code, 200) report = response.context['report'] self.assertFalse(report.fixed_at) self.assertFalse(ReportComment.objects.filter(type=ReportAttachment.MARK_AS_DONE, report=report).exists()) self.assertEquals(report.status, Report.REFUSED) def test_mark_done_as_user_denied(self): """Tests marking report not done if denied.""" url = "%s?x=148360&y=171177" % reverse('report_new') response = self.client.post(url, self.sample_post, follow=True) report = response.context['report'] self.client.login(username='******', password='******') url = reverse('report_accept_pro', args=[report.id]) response = self.client.get(url, follow=True) # Change status to refused report.status = report.REFUSED report.save() # Try to mark as done as citizen self.client.logout() response = self.client.post(reverse('report_update', args=[report.id]), {'is_fixed': 'True'}, follow=True) self.assertEqual(response.status_code, 200) report = response.context['report'] self.assertFalse(report.fixed_at) self.assertEqual(report.status, Report.REFUSED) self.assertFalse(ReportComment.objects.filter(type=ReportAttachment.MARK_AS_DONE, report=report).exists()) def test_mark_done_as_pro_denied(self): """Tests marking report as done.""" url = "%s?x=148360&y=171177" % reverse('report_new') response = self.client.post(url, self.sample_post, follow=True) report = response.context['report'] self.client.login(username='******', password='******') url = reverse('report_accept_pro', args=[report.id]) response = self.client.get(url, follow=True) self.assertEqual(response.status_code, 200) # Change status to refused report.status = report.REFUSED report.save() # Try to mark as done as pro response = self.client.post(reverse('report_fix_pro', args=[report.id]), {'text': 'commentaire'}, follow=True) self.assertEquals(response.status_code, 200) report = response.context['report'] self.assertFalse(report.fixed_at) self.assertFalse(ReportComment.objects.filter(type=ReportAttachment.MARK_AS_DONE, report=report).exists()) self.assertEquals(report.status, Report.REFUSED) def test_search_ticket(self): """Tests searching ticket.""" url = "%s?x=148360&y=171177" % reverse('report_new') response = self.client.post(url, self.sample_post, follow=True) report = response.context['report'] url = '%s?report_id=%s' % (reverse('search_ticket'), report.id) response = self.client.get(url, follow=True) self.assertEqual(response.status_code, 200) report_result = response.context['report'] self.assertEqual(report, report_result) def test_login_user(self): params = { 'username': self.manager.email, 'password': '******' } response = self.client.post(reverse('login'), params) self.assertEqual(response.status_code, 302) def test_login_user_with_redirect(self): params = { 'username': self.manager.email, 'password': '******' } url = '%s?next=/fr/pro/reports/' % reverse('login') response = self.client.post(url, params) self.assertEqual(response.status_code, 302) def test_login_user_fail(self): params = { 'username': self.manager.email, 'password': '******' } response = self.client.post(reverse('login'), params) self.assertEqual(response.status_code, 200) escaped = escape(ugettext('Please enter a correct username and password. Note that both fields are case-sensitive.')) self.assertContains(response, escaped) def test_logout_user(self): params = { 'username': self.manager.email, 'password': '******' } self.client.post(reverse('login'), params) response = self.client.post(reverse('logout')) self.assertEqual(response.status_code, 302) def test_marker_detail_citizen(self): url = "%s?x=148360&y=171177" % reverse('report_new') response = self.client.post(url, self.sample_post, follow=True) self.assertEqual(response.status_code, 200) self.assertIn('report', response.context) report = response.context['report'] jsonResult = report.full_marker_detail_JSON() #Now test on all mandatory fields self.assertIn('id', jsonResult) self.assertIn('point', jsonResult) self.assertIn('category', jsonResult) self.assertIn('address', jsonResult) self.assertIn('address_number', jsonResult) self.assertIn('postalcode', jsonResult) self.assertIn('address_commune_name', jsonResult) self.assertIn('address_regional', jsonResult) self.assertIn('thumb', jsonResult) self.assertIn('contractor', jsonResult) self.assertIn('date_planned', jsonResult) self.assertNotIn('is_closed', jsonResult) self.assertNotIn('citizen', jsonResult) self.assertNotIn('priority', jsonResult) def test_marker_detail_pro(self): url = "%s?x=148360&y=171177" % reverse('report_new') response = self.client.post(url, self.sample_post, follow=True) self.assertEqual(response.status_code, 200) self.assertIn('report', response.context) report = response.context['report'] jsonResult = report.full_marker_detail_pro_JSON() #Now test on all mandatory fields self.assertIn('id', jsonResult) self.assertIn('point', jsonResult) self.assertIn('category', jsonResult) self.assertIn('address', jsonResult) self.assertIn('address_number', jsonResult) self.assertIn('postalcode', jsonResult) self.assertIn('address_commune_name', jsonResult) self.assertIn('address_regional', jsonResult) self.assertIn('thumb', jsonResult) self.assertIn('contractor', jsonResult) self.assertIn('date_planned', jsonResult) self.assertIn('is_closed', jsonResult) self.assertIn('citizen', jsonResult) self.assertIn('priority', jsonResult) def test_reopen_report_refused(self): url = "%s?x=148360&y=171177" % reverse('report_new') response = self.client.post(url, self.sample_post, follow=True) self.assertEqual(response.status_code, 200) report = response.context['report'] comment = ReportComment(report_id=report.id, text='test', type=3) comment.save() report.status = Report.REFUSED report.save() self.client.login(username='******', password='******') url = reverse('report_reopen_pro', args=[report.id]) response = self.client.get(url, follow=True) self.assertEqual(response.status_code, 200) report_reopen = response.context['report'] self.assertEqual(Report.MANAGER_ASSIGNED, report_reopen.status) self.assertNotEqual(report.status , report_reopen.status) self.assertEqual(report.created , report_reopen.created) self.assertEqual(report.close_date , report_reopen.close_date) # accepted_at need to be initialized self.assertFalse(report.accepted_at) self.assertTrue(report_reopen.accepted_at) self.assertEqual(report.subscriptions.all().count(), report_reopen.subscriptions.all().count()) self.assertEqual(report.responsible_entity , report_reopen.responsible_entity) self.assertEqual(report.responsible_department , report_reopen.responsible_department) def test_reopen_report_processed(self): url = "%s?x=148360&y=171177" % reverse('report_new') response = self.client.post(url, self.sample_post, follow=True) self.assertEqual(response.status_code, 200) report = response.context['report'] report.status = Report.PROCESSED report.accepted_at = datetime.now() report.save() self.client.login(username='******', password='******') url = reverse('report_reopen_pro', args=[report.id]) response = self.client.get(url, follow=True) self.assertEqual(response.status_code, 200) report_reopen = response.context['report'] self.assertEqual(Report.MANAGER_ASSIGNED, report_reopen.status) self.assertNotEqual(report.status , report_reopen.status) self.assertEqual(report.created , report_reopen.created) self.assertEqual(report.accepted_at, report_reopen.accepted_at) self.assertEqual(report.close_date , report_reopen.close_date) self.assertEqual(report.subscriptions.all().count(), report_reopen.subscriptions.all().count()) self.assertEqual(report.responsible_entity , report_reopen.responsible_entity) self.assertEqual(report.responsible_department , report_reopen.responsible_department) def test_reopen_report_badstatus(self): url = "%s?x=148360&y=171177" % reverse('report_new') response = self.client.post(url, self.sample_post, follow=True) self.assertEqual(response.status_code, 200) report = response.context['report'] report.accepted_at = datetime.now() report.save() self.client.login(username='******', password='******') url = reverse('report_reopen_pro', args=[report.id]) response = self.client.get(url, follow=True) self.assertEqual(response.status_code, 200) report_not_reopen = response.context['report'] self.assertNotEqual(Report.MANAGER_ASSIGNED, report_not_reopen.status) self.assertEqual(report.status , report_not_reopen.status) self.assertEqual(report.created , report_not_reopen.created) self.assertEqual(report.modified , report_not_reopen.modified) self.assertEqual(report.accepted_at , report_not_reopen.accepted_at) self.assertEqual(report.close_date , report_not_reopen.close_date) self.assertEqual(report.subscriptions.all().count(), report_not_reopen.subscriptions.all().count()) self.assertEqual(report.responsible_entity , report_not_reopen.responsible_entity) self.assertEqual(report.responsible_department , report_not_reopen.responsible_department) def test_auto_assign(self): # Associate a category to an organisation for auto-dispatching entity = OrganisationEntity() entity.name_fr = "My entity" entity.type = OrganisationEntity.COMMUNE entity.email = "*****@*****.**" entity.save() # Associate a category to an organisation for auto-dispatching department = OrganisationEntity() department.name_fr = "My group" department.type = OrganisationEntity.DEPARTMENT department.dependency = entity department.email = "*****@*****.**" department.save() self.group_mail_config.group = department self.group_mail_config.save() category = ReportCategory.objects.get(id=self.sample_post['report-category']) category.organisation_communal = entity category.save() department.dispatch_categories.add(category) # Create new report url = "%s?x=148360&y=171177" % reverse('report_new') response = self.client.post(url, self.sample_post, follow=True) self.assertEqual(response.status_code, 200) report = response.context['report'] # Auto-dispatching working for commune self.assertFalse(report.is_regional()) self.assertEqual(report.responsible_department, department) self.assertEqual(report.responsible_entity, entity) def test_not_auto_assign_if_report_already_exists(self): # Create new report url = "%s?x=148360&y=171177" % reverse('report_new') response = self.client.post(url, self.sample_post, follow=True) self.assertEqual(response.status_code, 200) report = response.context['report'] # Associate a category to an organisation for auto-dispatching entity = OrganisationEntity() entity.name_fr = "My entity" entity.type = OrganisationEntity.COMMUNE entity.email = "*****@*****.**" entity.save() # Associate a category to an organisation for auto-dispatching department = OrganisationEntity() department.name_fr = "My group" department.type = OrganisationEntity.DEPARTMENT department.dependency = entity department.email = "*****@*****.**" department.save() self.group_mail_config.group = department self.group_mail_config.save() category = ReportCategory.objects.get(id=self.sample_post['report-category']) category.organisation_communal = entity category.save() department.dispatch_categories.add(category) # Assign report to another entity report.responsible_entity = self.group.dependency report.responsible_department = None report.save() # Check it's not auto-dispatching report = Report.objects.get(id=report.id) self.assertFalse(report.is_regional()) self.assertNotEqual(report.responsible_department, department) self.assertNotEqual(report.responsible_entity, entity) self.assertEqual(report.responsible_entity, self.group.dependency) self.assertEqual(report.responsible_department, self.group)
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) def test_double_pro_case_insensitive(self): pro_data = { "email" : "*****@*****.**", "last_name": "user", "telephone": "123456789", "quality" : 1 } # Create first pro pro_form = FmsUserForm(pro_data) # Form has to be valid self.assertTrue(pro_form.is_valid()) pro_form.save() # Create second pro with a caps in email pro_data['email'] = pro_data['email'].upper() pro_form = FmsUserForm(pro_data) # Form has to be INVALID because the email is already existing self.assertFalse(pro_form.is_valid()) self.assertTrue(pro_form.errors) def test_pro_with_citizen_email(self): citizen = FMSUser( telephone="0123456789", first_name="citizen", last_name="citizen", email="*****@*****.**", ) citizen.save() pro_data = { "email" : citizen.email, "last_name": "user", "telephone": "123456789", "quality" : 1 } # Create a pro user pro_form = FmsUserForm(pro_data) # Form has to be INVALID because a citizen uses this email self.assertFalse(pro_form.is_valid()) self.assertTrue(pro_form.errors)
class FMSUserTest(FMSTestCase): def setUp(self): # 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) def test_double_citizen_case_insensitive(self): citizen_data = {"email": "*****@*****.**", "last_name": "user", "telephone": "123456789", "quality": 1} # Create first citizen citizen_form = CitizenForm(citizen_data) # Form has to be valid self.assertTrue(citizen_form.is_valid()) citizen_form.save() # Create second citizen with a caps in email citizen_data["email"] = citizen_data["email"].upper() citizen_form = CitizenForm(citizen_data) # Form has to be valid self.assertTrue(citizen_form.is_valid()) citizen_form.save() # And only one user with the same email case insensitive is created (it's the same citizen in both cases) self.assertEqual(1, FMSUser.objects.filter(username__iexact=citizen_data["email"]).count()) def test_citizen_with_pro_email(self): manager = FMSUser( is_active=True, telephone="0123456789", last_used_language="fr", password="******", first_name="manager", last_name="manager", email="*****@*****.**", manager=True, ) manager.save() citizen_data = {"email": manager.email, "last_name": "user", "telephone": "123456789", "quality": 1} # Create a citizen user citizen_form = CitizenForm(citizen_data) # Form has to be INVALID because the citizen use a pro email self.assertFalse(citizen_form.is_valid()) self.assertTrue(citizen_form.errors)
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)
def setUp(self): self.bxl = OrganisationEntity.objects.get(id=4) self.manager_bxl = FMSUser(is_active=True, email="*****@*****.**", telephone="0123456789", last_used_language="fr", manager=True, organisation=self.bxl) self.manager_bxl.set_password('test') self.manager_bxl.save() self.group = OrganisationEntity(type="D", name_nl="Werken", name_fr="Travaux", phone="090987", dependency=self.bxl, email="*****@*****.**") self.group.save() self.group_mail_config = GroupMailConfig() self.group_mail_config.group = self.group self.group_mail_config.save() self.usergroupmembership = UserOrganisationMembership( user_id=self.manager_bxl.id, organisation_id=self.group.id, contact_user=True) self.usergroupmembership.save() self.citizen = FMSUser(email="*****@*****.**", telephone="0123456789", last_used_language="fr") self.citizen.save() self.secondary_category = ReportCategory.objects.all()[0] self.category = self.secondary_category.category_class self.client.login(username=self.manager_bxl.email, password='******') self.report = Report(status=Report.CREATED, secondary_category=self.secondary_category, category=self.category, description='Just a test', postalcode=1000, address='my address', point=dict_to_point({ "x": '149776', "y": '170005' }), address_number='6h', created_by=self.manager_bxl) self.report.save() self.report.attachments.add( ReportComment(text='test comment 1', security_level=ReportComment.PRIVATE)) self.client.logout() self.report.attachments.add( ReportComment(text='test comment 2', security_level=ReportComment.PUBLIC)) self.report.attachments.add( ReportComment(text='test comment 3', logical_deleted=True, security_level=ReportComment.PUBLIC)) self.client = Client()
def 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()
class MailTest(FMSTestCase): def setUp(self): self.citizen = FMSUser(telephone="0123456789", last_used_language="fr", first_name="citizen", last_name="citizen", email="*****@*****.**") self.citizen.save() self.manager = FMSUser(is_active=True, telephone="0123456789", last_used_language="fr", password='******', first_name="manager", last_name="manager", email="*****@*****.**", manager=True) self.manager.set_password('test') self.manager.organisation = OrganisationEntity.objects.get(pk=14) self.manager.save() self.manager4 = FMSUser(is_active=True, telephone="0123456789", last_used_language="fr", password='******', first_name="manager4", last_name="manager4", email="*****@*****.**", manager=True) self.manager4.set_password('test') self.manager4.organisation = OrganisationEntity.objects.get(pk=14) self.manager4.save() self.group = OrganisationEntity( type="D", name_nl="Werken", name_fr="Travaux", phone="090987", dependency=OrganisationEntity.objects.get(pk=14), email="*****@*****.**") self.group.save() self.group.dispatch_categories.add(ReportCategory.objects.get(pk=1)) # Mail config: notify group and members in real time self.group_mail_config = GroupMailConfig() self.group_mail_config.group = self.group self.group_mail_config.notify_group = True self.group_mail_config.notify_members = True self.group_mail_config.save() self.manager.memberships.create(organisation=self.group, contact_user=True) self.manager4.memberships.create(organisation=self.group, contact_user=True) self.client = Client() self.manager2 = FMSUser(is_active=True, telephone="9876543210", last_used_language="nl", password='******', first_name="manager2", last_name="manager2", email="*****@*****.**", manager=True) self.manager2.set_password('test2') self.manager2.organisation = OrganisationEntity.objects.get(pk=14) self.manager2.save() self.group2 = OrganisationEntity( type="D", name_nl="Werken", name_fr="Travaux", phone="090987", dependency=OrganisationEntity.objects.get(pk=21), email="*****@*****.**") self.group2.save() self.group2.dispatch_categories.add(ReportCategory.objects.get(pk=2)) self.group2.dispatch_categories.add(ReportCategory.objects.get(pk=1)) # Mail config: notify group and members in real time self.group_mail_config2 = GroupMailConfig() self.group_mail_config2.group = self.group2 self.group_mail_config2.notify_group = True self.group_mail_config2.notify_members = True self.group_mail_config2.save() p1 = (148776, 171005) p2 = (150776, 171005) p3 = (150776, 169005) p4 = (148776, 169005) surface = OrganisationEntitySurface( geom=Polygon([p1, p2, p3, p4, p1]), owner=OrganisationEntity.objects.get(pk=14), ) surface.save() self.manager2.memberships.create(organisation=self.group2) self.manager3 = FMSUser(is_active=True, telephone="000000000", last_used_language="nl", password='******', first_name="manager3", last_name="manager3", email="*****@*****.**", manager=True) self.manager3.set_password('test3') self.manager3.organisation = OrganisationEntity.objects.get(pk=21) self.manager3.save() self.manager3.memberships.create(organisation=self.group2) self.impetrant = OrganisationEntity(name_nl="MIVB", name_fr="STIB", email="*****@*****.**") self.impetrant.save() self.contractor = OrganisationEntity(name_nl="Fabricom GDF", name_fr="Fabricom GDF", email="*****@*****.**") self.contractor.save() self.sample_post = { 'report-x': '150056.538', 'report-y': '170907.56', 'report-address_fr': 'Avenue des Arts, 3', 'report-address_nl': 'Kunstlaan, 3', 'report-address_number': '3', 'report-postalcode': '1210', 'report-category': '1', 'report-secondary_category': '1', 'report-subscription': 'on', 'citizen-quality': '1', 'comment-text': 'test', 'files-TOTAL_FORMS': 0, 'files-INITIAL_FORMS': 0, 'files-MAX_NUM_FORMS': 0, 'citizen-email': self.citizen.email, 'citizen-firstname': self.citizen.first_name, 'citizen-lastname': self.citizen.last_name, 'report-terms_of_use_validated': True } self.sample_post_pro = { 'report-x': '150056.538', 'report-y': '170907.56', 'report-address_fr': 'Avenue des Arts, 3', 'report-address_nl': 'Kunstlaan, 3', 'report-address_number': '3', 'report-postalcode': '1210', 'report-category': '1', 'report-secondary_category': '1', 'report-subscription': 'on', 'comment-text': 'test', 'files-TOTAL_FORMS': 0, 'files-INITIAL_FORMS': 0, 'files-MAX_NUM_FORMS': 0, 'report-terms_of_use_validated': True } self.sample_post_mail_pdf_pro = { 'comments': 'test comment', 'visibility': 'private', 'to': '[email protected],[email protected];[email protected]' } self.sample_post_mail_pdf_citzen = { 'comments': 'test comment', 'visibility': 'public', 'to': '[email protected],[email protected];[email protected]' } def test_create_report_mail(self): # Send a post request filling in the form to create a report response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post, follow=True) # Mails are sent to responsibles according to mail config of the group: 1 for group + members expected_recipients = self.group_mail_config.get_manager_recipients() # 1 more mail is sent to creator in real time expected_recipients.append(self.citizen.email) self.assertTrue(mail.outbox) self.assertEquals(len(mail.outbox), len(expected_recipients)) for email in mail.outbox: self.assertIn(email.to[0], expected_recipients) def test_close_report_mail(self): # Send a post request filling in the form to create a report response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post, follow=True) report = response.context['report'] report = response.context['report'] report.accepted_at = datetime.now() report.save() # Reset outbox mail.outbox = [] # Close the report self.client.login(username='******', password='******') response = self.client.get(reverse('report_close_pro', args=[report.id]), follow=True) report = Report.objects.get(id=report.id) self.assertEquals(report.status, Report.PROCESSED) # One mail is sent in real time to the creator if citizen. All others are digest to subscribers. self.assertEquals(len(mail.outbox), 1) self.assertIn(self.citizen.email, mail.outbox[0].to) def test_refuse_report_mail(self): # Send a post request filling in the form to create a report response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post, follow=True) report = response.context['report'] # Reset outbox mail.outbox = [] # Login to access the pro page to create a user self.client.login(username='******', password='******') # Refuse the created report refused_url = reverse('report_refuse_pro', args=[report.id]) refused_params = {'text': 'more info'} response = self.client.post(refused_url, refused_params, follow=True) report = Report.objects.get(id=report.id) # The status of the report must now be REFUSED self.assertEquals(report.status, Report.REFUSED) # All mail are sent as digest to subscribers self.assertEquals(len(mail.outbox), 1) def test_subscription_for_citizen_mail(self): # Send a post request filling in the form to create a report response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post, follow=True) report = response.context['report'] # Reset outobox mail.outbox = [] # Send a post request subscribing a citizen to the just created report subscribe_url = reverse('subscribe', args=[report.id]) subscribe_email = '*****@*****.**' subscribe_params = {'citizen_email': subscribe_email} response = self.client.post(subscribe_url, subscribe_params, follow=True) # 1 mail sent in real-time to subscriber self.assertEquals(len(mail.outbox), 1) self.assertTrue(subscribe_email in mail.outbox[0].to) def test_mark_report_as_done_mail(self): # Send a post request filling in the form to create a report response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post, follow=True) report = response.context['report'] # Login to access the pro page self.client.login(username='******', password='******') # Publish the created report response = self.client.post(reverse('report_accept_pro', args=[report.id]), follow=True) # Reset outbox mail.outbox = [] # Send a post request to mark the report as done update_url = reverse('report_fix_pro', args=[report.id]) update_params = {'text': 'My comment'} response = self.client.post(update_url, update_params) # Mails are sent to responsibles according to mail config of the group: 1 for group + members without the author expected_recipients = self.group_mail_config.get_manager_recipients( self.manager) self.assertTrue(mail.outbox) self.assertEquals(len(mail.outbox), len(expected_recipients)) for email in mail.outbox: self.assertIn(email.to[0], expected_recipients) def test_accept_report_mail(self): # Send a post request filling in the form to create a report response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post, follow=True) report = response.context['report'] # Reset outbox mail.outbox = [] self.client.login(username='******', password='******') url = reverse('report_accept_pro', args=[report.id]) response = self.client.get(url, follow=True) # All mails are sent to subscribers as digest self.assertEquals(len(mail.outbox), 0) def test_planned_report_mail(self): # Send a post request filling in the form to create a report response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post, follow=True) report = response.context['report'] report.accepted_at = datetime.now() report.save() # Reset outbox mail.outbox = [] # Set as planned date_planned = (datetime.now() + timedelta(days=1)).strftime("%m/%Y") url = '%s?date_planned=%s' % (reverse('report_planned_pro', args=[report.id]), date_planned) self.client.login(username='******', password='******') response = self.client.get(url, follow=True) report = response.context['report'] self.assertTrue(report.is_planned()) self.assertEqual(date_planned, report.date_planned.strftime("%m/%Y")) # Only digest are sent to subscribers self.assertEquals(len(mail.outbox), 0) # Planned another date date_planned = (datetime.now() + timedelta(days=40)).strftime("%m/%Y") url = '%s?date_planned=%s' % (reverse('report_planned_pro', args=[report.id]), date_planned) self.client.login(username='******', password='******') response = self.client.get(url, follow=True) report = response.context['report'] self.assertTrue(report.is_planned()) self.assertEqual(date_planned, report.date_planned.strftime("%m/%Y")) # Only digest are sent to subscribers self.assertEquals(len(mail.outbox), 0) def test_create_report_as_pro_mail(self): # Create a report self.client.login(username='******', password='******') response = self.client.post(reverse('report_new_pro') + '?x=150056.538&y=170907.56', self.sample_post_pro, follow=True) # Mails are sent to responsibles according to mail config of the group: 1 for group + members without the author expected_recipients = self.group_mail_config.get_manager_recipients( self.manager) self.assertTrue(mail.outbox) self.assertEquals(len(mail.outbox), len(expected_recipients)) for email in mail.outbox: self.assertIn(email.to[0], expected_recipients) def test_report_resolved_as_pro_mail(self): response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post, follow=True) report_id = response.context['report'].id # Login to access the pro page self.client.login(username='******', password='******') # Publish the created report response = self.client.post(reverse('report_accept_pro', args=[report_id]), follow=True) self.assertEquals(response.status_code, 200) # Clear outbox mail.outbox = [] params = {'text': 'Ceci est un commentaire'} response = self.client.post(reverse('report_fix_pro', args=[report_id]), params, follow=True) self.assertEquals(response.status_code, 200) self.assertEquals( Report.objects.get(id=report_id).status, Report.SOLVED) # Mails are sent to responsibles according to mail config of the group: 1 for group + members without the author expected_recipients = self.group_mail_config.get_manager_recipients( self.manager) self.assertTrue(mail.outbox) self.assertEquals(len(mail.outbox), len(expected_recipients)) for email in mail.outbox: self.assertIn(email.to[0], expected_recipients) def test_assign_to_other_member_of_same_entity_mail(self): response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post, follow=True) report = response.context['report'] # Login to access the pro page self.client.login(username='******', password='******') # Publish the created report response = self.client.post(reverse('report_accept_pro', args=[report.id]), follow=True) # Restet outbox mail.outbox = [] # Change manager in the same entity response = self.client.post( reverse('report_change_manager_pro', args=[report.id]), { 'man_id': 'department_' + str(self.group2.id), 'transfer': 0 }, follow=True) # Mails are sent to responsibles according to mail config of the group: 1 for group + members expected_recipients = self.group_mail_config2.get_manager_recipients() self.assertTrue(mail.outbox) self.assertEquals(len(mail.outbox), len(expected_recipients)) for email in mail.outbox: self.assertIn(email.to[0], expected_recipients) def test_assign_to_another_entity_mail(self): response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post, follow=True) report = response.context['report'] # Login to access the pro page self.client.login(username='******', password='******') # Publish the created report response = self.client.post(reverse('report_accept_pro', args=[report.id]), follow=True) # Restet outbox mail.outbox = [] # Change to another entity response = self.client.post(reverse('report_change_manager_pro', args=[report.id]), { "man_id": "entity_21", "transfer": 0 }, follow=True) # Mails are sent to responsibles according to mail config of the group: 1 for group + members expected_recipients = self.group_mail_config2.get_manager_recipients() self.assertTrue(mail.outbox) self.assertEquals(len(mail.outbox), len(expected_recipients)) for email in mail.outbox: self.assertIn(email.to[0], expected_recipients) def test_assign_to_impetrant_mail(self): response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post, follow=True) report = response.context['report'] # Add a worker for this entity worker = FMSUser(email="*****@*****.**", telephone="0123456789") worker.save() worker.memberships.create(organisation=self.impetrant) # Login to access the pro page self.client.login(username='******', password='******') # Publish the created report response = self.client.post(reverse('report_accept_pro', args=[report.id]), follow=True) # Reset outbox mail.outbox = [] # Assign to another impetrant response = self.client.get( reverse('report_change_contractor_pro', args=[report.id]) + '?contractorId=' + str(self.impetrant.id), {}, follow=True) # 1 mail sent in real time to impetrant self.assertEquals(len(mail.outbox), 1) self.assertIn(self.impetrant.email, mail.outbox[0].to) def test_assign_to_contractor_mail(self): response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post, follow=True) report = response.context['report'] report.accepted_at = datetime.now() report.save() # Add a worker for this entity worker = FMSUser(email="*****@*****.**", telephone="0123456789") worker.save() worker.memberships.create(organisation=self.contractor) # Reset outbox mail.outbox = [] self.client.login(username='******', password='******') response = self.client.get( reverse('report_change_contractor_pro', args=[report.id]) + '?contractorId=' + str(self.contractor.id), {}, follow=True) # 1 mail sent in real time to contractor self.assertEquals(len(mail.outbox), 1) self.assertIn(self.contractor.email, mail.outbox[0].to) def test_citizen_updates_report_mail(self): response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post, follow=True) report = response.context['report'] report.accepted_at = datetime.now() report.save() # Reset outbox mail.outbox = [] # A citizen documents a report response = self.client.post(reverse('report_document', kwargs={ 'report_id': report.id, 'slug': 'hello' }), { 'comment-text': 'new created comment', 'citizen-email': self.citizen.email, 'citizen-quality': 1, 'files-TOTAL_FORMS': 0, 'files-INITIAL_FORMS': 0, 'files-MAX_NUM_FORMS': 0 }, follow=True) report = response.context['report'] # Mails are sent to responsibles according to mail config of the group: 1 for group + members expected_recipients = self.group_mail_config.get_manager_recipients() self.assertTrue(mail.outbox) self.assertEquals(len(mail.outbox), len(expected_recipients)) for email in mail.outbox: self.assertIn(email.to[0], expected_recipients) def test_pro_updates_report_mail(self): response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post, follow=True) report = response.context['report'] # Login to access the pro page self.client.login(username='******', password='******') # Publish the created report response = self.client.post(reverse('report_accept_pro', args=[report.id]), follow=True) # Reset outbox mail.outbox = [] # Document report as pro response = self.client.post(reverse('report_show_pro', kwargs={ 'report_id': report.id, 'slug': 'hello' }), { 'comment-text': 'new created comment', 'files-TOTAL_FORMS': 0, 'files-INITIAL_FORMS': 0, 'files-MAX_NUM_FORMS': 0 }, follow=True) # Mails are sent to responsibles according to mail config of the group: 1 for group + members without the author expected_recipients = self.group_mail_config.get_manager_recipients( self.manager) self.assertTrue(mail.outbox) self.assertEquals(len(mail.outbox), len(expected_recipients)) for email in mail.outbox: self.assertIn(email.to[0], expected_recipients) def test_publish_comment_mail(self): response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post, follow=True) report = response.context['report'] # Login to access the pro page self.client.login(username='******', password='******') # Accept and publish the created report report.private = False report.accepted_at = datetime.now() report.save() # Assure that comment is private self.assertEqual(ReportAttachment.PRIVATE, report.comments()[0].security_level) # Reset outbox mail.outbox = [] # Now make the comment public response = self.client.get(reverse('report_update_attachment', args=[report.id]), { 'updateType': 1, 'attachmentId': report.comments()[0].id }, follow=True) self.assertEqual(ReportAttachment.PUBLIC, report.comments()[0].security_level) # All notifications are sent to subscribers as digest self.assertEquals(len(mail.outbox), 0) def test_subscription_for_pro_mail(self): response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post, follow=True) report = response.context['report'] # Login to access the pro page self.client.login(username='******', password='******') # Publish the created report response = self.client.post(reverse('report_accept_pro', args=[report.id]), follow=True) self.client.logout() # Reset outbox mail.outbox = [] self.client.login(username='******', password='******') response = self.client.get(reverse('subscribe_pro', args=[report.id]), {}, follow=True) # 1 mail sent in real-time to subscriber self.assertEquals(len(mail.outbox), 1) self.assertTrue(self.manager2.email in mail.outbox[0].to) def test_make_report_switch_visibility(self): response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post, follow=True) # Assure that report is public report = response.context['report'] self.assertFalse(report.private) # Login to access the pro page self.client.login(username='******', password='******') # Publish the created report response = self.client.post(reverse('report_accept_pro', args=[report.id]), follow=True) # Reset outbox mail.outbox = [] # 1/ Now make the report private response = self.client.get( reverse('report_change_switch_visibility', args=[report.id]) + '?visibility=true', follow=True) report = Report.objects.get(id=report.id) self.assertTrue(report.private) # Mails are sent in real time self.assertEquals(len(mail.outbox), 1) # Reset outbox mail.outbox = [] # 2/ Now make the report public response = self.client.get( reverse('report_change_switch_visibility', args=[report.id]) + '?visibility=false', follow=True) report = Report.objects.get(id=report.id) self.assertFalse(report.private) # Mails are sent in real time self.assertEquals(len(mail.outbox), 1) #def testMergeReportMail(self): # #Login to access the pro page # self.client.login(username='******', password='******') # #Send a post request filling in the form to create a report # response = self.client.post(reverse('report_new_pro') + '?x=150056.538&y=170907.56', self.sample_post, follow=True) # self.assertEquals(response.status_code, 200) # self.assertIn('report', response.context) # report_id = response.context['report'].id # self.assertEquals(len(mail.outbox), 1) # one for creator subscription, one for manager # self.client.logout() # response = self.client.post( # reverse('report_new') + '?x=150056.538&y=170907.56', # self.sample_post, # follow=True) # self.assertEquals(response.status_code, 200) # Should send mail only to responsible # self.assertEquals(len(mail.outbox), 3) # report2_id = response.context['report'].id # self.client.login(username='******', password='******') # Publish the created report # response3 = self.client.post(reverse('report_accept_pro', args=[report2_id]), follow=True) # self.assertEquals(response3.status_code, 200) # self.assertEquals(len(mail.outbox), 4) # Merge reports # url2 = reverse('report_do_merge_pro', args=[report_id]) # self.client.post(url2, {"mergeId": report2_id}) # self.assertTrue(Report.objects.all().visible().filter(id=report_id).exists()) # self.assertFalse(Report.objects.all().visible().filter(id=report2_id).exists()) #Reference from merged to kept report # self.assertEqual(report_id, Report.objects.get(id=report2_id).merged_with.id) #A mail has been sent to the creator of the first report to notify him that his report has been merged # self.assertEquals(len(mail.outbox), 5) def test_send_PDF_to_pro_mail(self): response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post, follow=True) report = response.context['report'] # Login to access the pro page self.client.login(username='******', password='******') # Publish the created report response = self.client.post(reverse('report_accept_pro', args=[report.id]), follow=True) # Reset outbox mail.outbox = [] # Send Pro PDF response = self.client.post(reverse('send_pdf', args=[report.id]), self.sample_post_mail_pdf_pro) # 3 mails should be sent self.assertEquals(len(mail.outbox), 3) def test_send_PDF_to_citizen_mail(self): response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post, follow=True) report = response.context['report'] report.accepted_at = datetime.now() report.save() # Reset outbox mail.outbox = [] # Login to access the pro page self.client.login(username='******', password='******') # Now send Pro PDF response = self.client.post(reverse('send_pdf', args=[report.id]), self.sample_post_mail_pdf_citzen) # 3 mails should be sent to citizens self.assertEquals(len(mail.outbox), 3) def test_reopen_report(self): # New report response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post, follow=True) report = response.context['report'] comment = ReportComment(report_id=report.id, text='test', type=3) comment.save() # Set status to REFUSED report.status = Report.REFUSED report.save() # Login to access the pro page self.client.login(username='******', password='******') # Clear mail outbox mail.outbox = [] # Reopen reports url = reverse('report_reopen_pro', args=[report.id]) response = self.client.get(url, follow=True) report = response.context['report'] # Assert self.assertEquals(Report.MANAGER_ASSIGNED, report.status) # No mail sent in real-time self.assertEquals(len(mail.outbox), 0) def test_recipient_for_everyone(self): """ recipients must contains everyone (group, manager and manager4) """ recipients = self.group_mail_config.get_manager_recipients() self.assertEquals(len(recipients), 3) self.assertIn(self.group.email, recipients) self.assertIn(self.manager.email, recipients) self.assertIn(self.manager4.email, recipients) def test_recipient_exclude_author(self): """ recipients must contains everyone (group, manager and manager4) """ recipients = self.group_mail_config.get_manager_recipients( self.manager) self.assertEquals(len(recipients), 2) self.assertIn(self.group.email, recipients) self.assertIn(self.manager4.email, recipients) def test_recipient_for_manager_as_group(self): """ if email group is same as manager then recipients must contains ony once this email (distinct values) (group email and manager4) """ self.group.email = self.manager.email self.group.save() self.group_mail_config.notify_group = False self.group_mail_config.save() recipients = self.group_mail_config.get_manager_recipients() self.assertEquals(len(recipients), 2) self.assertIn(self.manager.email, recipients) self.assertIn(self.manager4.email, recipients) def test_recipient_for_manager_as_group_author(self): """ if email group is same as manager then recipients and also is the author this email must be excluded """ self.group.email = self.manager.email recipients = self.group_mail_config.get_manager_recipients( self.manager) self.assertEquals(len(recipients), 2) self.assertIn(self.manager4.email, recipients) self.assertIn(self.group.email, recipients)
def setUp(self): try: organisation = OrganisationEntity.objects.get(id=1) except ObjectDoesNotExist: organisation = OrganisationEntity(id=1, name="Test organisation") organisation.save() p1 = (148776, 171005) p2 = (150776, 171005) p3 = (150776, 169005) p4 = (148776, 169005) surface = OrganisationEntitySurface( geom=Polygon([p1, p2, p3, p4, p1]), owner=OrganisationEntity.objects.get(pk=14) ) surface.save() #user_auth = User.objects.create_user(username='******', email='*****@*****.**', password='******') #user_auth.save() user = FMSUser( is_active=True, password="******", email="*****@*****.**", first_name="zaza", telephone="00000000", last_used_language="fr", organisation=organisation, username='******') user.save() #~ main_category = ReportMainCategoryClass(id=2,name_en='test main en',name_nl='test main nl',name_fr='test main fr') #~ main_category.save() #~ #~ secondary_category = ReportSecondaryCategoryClass(id=2,name_en='test second en',name_nl='test second nl',name_fr='test second fr') #~ secondary_category.save() #~ #~ category = ReportCategory(id=2,name_en='test parent en',name_nl='test parent nl',name_fr='test parent fr', public=True, category_class=main_category, secondary_category_class=secondary_category) #~ category.save() self.citizen = FMSUser( telephone="0123456789", last_used_language="fr", first_name="citizen", last_name="citizen", email="*****@*****.**" ) self.citizen.save() self.manager = FMSUser( is_active=True, telephone="0123456789", last_used_language="fr", password='******', first_name="manager", last_name="manager", email="*****@*****.**", manager=True ) self.manager.set_password('test') self.manager.organisation = OrganisationEntity.objects.get(pk=14) self.manager.save() self.group = OrganisationEntity( type="D", name_nl="Werken", name_fr="Travaux", phone="090987", dependency=OrganisationEntity.objects.get(pk=14), email="*****@*****.**" ) self.group.save() self.group_mail_config = GroupMailConfig() self.group_mail_config.group = self.group self.group_mail_config.save() self.usergroupmembership = UserOrganisationMembership(user_id=self.manager.id, organisation_id=self.group.id, contact_user=True) self.usergroupmembership.save() self.sample_post = { 'report-x': '150056.538', 'report-y': '170907.56', 'report-address_fr': 'Avenue des Arts, 3', 'report-address_nl': 'Kunstlaan, 3', 'report-address_number': '3', 'report-postalcode': '1210', 'report-category': '1', 'report-secondary_category': '1', 'report-subscription': 'on', 'report-terms_of_use_validated': True, 'comment-text': 'test', 'files-TOTAL_FORMS': 0, 'files-INITIAL_FORMS': 0, 'files-MAX_NUM_FORMS': 1000, 'citizen-quality': '1', 'citizen-email': self.citizen.email, 'citizen-firstname': self.citizen.first_name, 'citizen-lastname': self.citizen.last_name }
class ApiTest(FMSTestCase): def setUp(self): try: organisation = OrganisationEntity.objects.get(id=1) except ObjectDoesNotExist: organisation = OrganisationEntity(id=1, name="Test organisation") organisation.save() p1 = (148776, 171005) p2 = (150776, 171005) p3 = (150776, 169005) p4 = (148776, 169005) surface = OrganisationEntitySurface( geom=Polygon([p1, p2, p3, p4, p1]), owner=OrganisationEntity.objects.get(pk=14) ) surface.save() #user_auth = User.objects.create_user(username='******', email='*****@*****.**', password='******') #user_auth.save() user = FMSUser( is_active=True, password="******", email="*****@*****.**", first_name="zaza", telephone="00000000", last_used_language="fr", organisation=organisation, username='******') user.save() #~ main_category = ReportMainCategoryClass(id=2,name_en='test main en',name_nl='test main nl',name_fr='test main fr') #~ main_category.save() #~ #~ secondary_category = ReportSecondaryCategoryClass(id=2,name_en='test second en',name_nl='test second nl',name_fr='test second fr') #~ secondary_category.save() #~ #~ category = ReportCategory(id=2,name_en='test parent en',name_nl='test parent nl',name_fr='test parent fr', public=True, category_class=main_category, secondary_category_class=secondary_category) #~ category.save() self.citizen = FMSUser( telephone="0123456789", last_used_language="fr", first_name="citizen", last_name="citizen", email="*****@*****.**" ) self.citizen.save() self.manager = FMSUser( is_active=True, telephone="0123456789", last_used_language="fr", password='******', first_name="manager", last_name="manager", email="*****@*****.**", manager=True ) self.manager.set_password('test') self.manager.organisation = OrganisationEntity.objects.get(pk=14) self.manager.save() self.group = OrganisationEntity( type="D", name_nl="Werken", name_fr="Travaux", phone="090987", dependency=OrganisationEntity.objects.get(pk=14), email="*****@*****.**" ) self.group.save() self.group_mail_config = GroupMailConfig() self.group_mail_config.group = self.group self.group_mail_config.save() self.usergroupmembership = UserOrganisationMembership(user_id=self.manager.id, organisation_id=self.group.id, contact_user=True) self.usergroupmembership.save() self.sample_post = { 'report-x': '150056.538', 'report-y': '170907.56', 'report-address_fr': 'Avenue des Arts, 3', 'report-address_nl': 'Kunstlaan, 3', 'report-address_number': '3', 'report-postalcode': '1210', 'report-category': '1', 'report-secondary_category': '1', 'report-subscription': 'on', 'report-terms_of_use_validated': True, 'comment-text': 'test', 'files-TOTAL_FORMS': 0, 'files-INITIAL_FORMS': 0, 'files-MAX_NUM_FORMS': 1000, 'citizen-quality': '1', 'citizen-email': self.citizen.email, 'citizen-firstname': self.citizen.first_name, 'citizen-lastname': self.citizen.last_name } def testCreateReportCitizen(self): #Create a client to launch requests client = Client() #Get the request response response = client.post(reverse('create_report_citizen'), self.sample_post, follow=True) #Test the http response code (200 = OK) self.assertEqual(response.status_code, 200) #Test if the response if JSON structured. self.assertEqual(response['Content-Type'], 'application/json; charset=utf-8') self.assertEqual(1, len(Report.objects.all())) #Load the response data as JSON object result = json.loads(response.content) # Get in the DB the created report report = Report.objects.get(id=result['id']) # Check that source is correct self.assertEqual(Report.SOURCES['MOBILE'], report.source) def testCreateReportDoubleCitizen(self): #Parameters to save the report in database. #Create a client to launch requests client = Client() #Get the request response response = client.post(reverse('create_report_citizen'), self.sample_post, follow=True) response = client.post(reverse('create_report_citizen'), self.sample_post, follow=True) response = client.post(reverse('create_report_citizen'), self.sample_post, follow=True) response = client.post(reverse('create_report_citizen'), self.sample_post, follow=True) self.assertEqual(1, len(Report.objects.all())) #Load the response data as JSON object result = json.loads(response.content) def testCreateReportPro(self): self.sample_post['username'] = self.manager.username self.sample_post['password'] = '******' #Create a client to launch requests client = Client() #Get the request response response = client.post('/fr/api/login/', { 'username': self.manager.username, 'password': '******' }, follow=True) self.assertEqual(response.status_code, 200) #Load the response data as JSON object result = json.loads(response.content) self.assertIn('email', result) response = client.post(reverse('create_report_citizen'), self.sample_post, follow=True) #Test the http response code (200 = OK) self.assertEqual(response.status_code, 200) #Test if the response if JSON structured. self.assertEqual(response['Content-Type'], 'application/json; charset=utf-8') #Load the response data as JSON object result = json.loads(response.content) #Verify if the report_id is returned by the webservice self.assertTrue(result['id']) #Get in the DB the created report report = Report.objects.get(id=result['id']) #Verify the persisted data for the new created report self.assertEquals(report.address, self.sample_post['report-address_fr']) self.assertTrue(report.is_pro()) # Check that source is correct self.assertEqual(Report.SOURCES['MOBILE'], report.source) def testCreateReportDoublePro(self): self.sample_post['username'] = self.manager.username self.sample_post['password'] = '******' #Create a client to launch requests client = Client() #Get the request response client.post(reverse('create_report_citizen'), self.sample_post, follow=True) client.post(reverse('create_report_citizen'), self.sample_post, follow=True) client.post(reverse('create_report_citizen'), self.sample_post, follow=True) client.post(reverse('create_report_citizen'), self.sample_post, follow=True) self.assertEqual(1, len(Report.objects.all())) def testLoadCategories(self): #Parameters to save the report in database. params = { "user_name": "superuser" } #Create a client to launch requests client = Client() #Get the request response response = client.get(reverse('load_categories'), params, follow=True) #Test the http response code (200 = OK) self.assertEqual(response.status_code, 200) #Test if the response if JSON structured. self.assertEqual(response['Content-Type'], 'application/json') #Load the response data as JSON object result = json.loads(response.content) def test_login_user(self): params = { 'username': self.manager.email, 'password': '******' } response = self.client.post(reverse('login_user'), params) self.assertEqual(response.status_code, 200) result = json.loads(response.content) self.assertEqual(result['id'], self.manager.id) self.assertEqual(result['first_name'], self.manager.first_name) def test_login_user_fail(self): params = { 'username': self.manager.email, 'password': '******' } response = self.client.post(reverse('login_user'), params) self.assertEqual(response.status_code, 403) result = json.loads(response.content) self.assertEqual("ERROR_LOGIN_INVALID_PARAMETERS", result["error_key"]) def test_login_user_fail_empty_field(self): params = { 'username': self.manager.email } response = self.client.post(reverse('login_user'), params) self.assertEqual(response.status_code, 400) result = json.loads(response.content) self.assertEqual("ERROR_LOGIN_INVALID_PARAMETERS", result["error_key"]) def test_login_user_bad_username(self): params = { 'username': "******", 'password': "******" } response = self.client.post(reverse('login_user'), params) self.assertEqual(response.status_code, 403) result = json.loads(response.content) self.assertEqual("ERROR_LOGIN_INVALID_PARAMETERS", result["error_key"]) def test_logout_user(self): response = self.client.post(reverse('logout_user')) self.assertEqual(response.status_code, 200) self.assertEqual('', response.content)
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()
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)))
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)))
class ReportViewsTest(FMSTestCase): def setUp(self): self.user = FMSUser(username='******', email='*****@*****.**', password='******') self.user.save() self.client = Client() self.citizen = FMSUser(telephone="0123456789", last_used_language="fr", first_name="citizen", last_name="citizen", email="*****@*****.**") self.citizen.save() self.group = OrganisationEntity( type="D", name_nl="Werken", name_fr="Travaux", phone="090987", dependency=OrganisationEntity.objects.get(pk=14), email="*****@*****.**") self.group.save() self.group_mail_config = GroupMailConfig() self.group_mail_config.group = self.group self.group_mail_config.save() self.manager = FMSUser(is_active=True, telephone="0123456789", last_used_language="fr", password='******', first_name="manager", last_name="manager", email="*****@*****.**", manager=True) self.manager.set_password('test') self.manager.organisation = OrganisationEntity.objects.get(pk=14) self.manager.save() self.group.dispatch_categories.add(ReportCategory.objects.get(pk=1)) p1 = (148776, 171005) p2 = (150776, 171005) p3 = (150776, 169005) p4 = (148776, 169005) surface = OrganisationEntitySurface( geom=Polygon([p1, p2, p3, p4, p1]), owner=OrganisationEntity.objects.get(pk=14), ) surface.save() self.manager.memberships.create(organisation=self.group, contact_user=True) self.sample_post = { 'report-x': '150056.538', 'report-y': '170907.56', 'report-address_fr': 'Avenue des Arts, 3', 'report-address_nl': 'Kunstlaan, 3', 'report-address_number': '3', 'report-postalcode': '1210', 'report-category': '1', 'report-secondary_category': '1', 'report-subscription': 'on', 'comment-text': 'test', 'files-TOTAL_FORMS': 0, 'files-INITIAL_FORMS': 0, 'files-MAX_NUM_FORMS': 0, 'citizen-email': self.citizen.email, 'citizen-firstname': self.citizen.first_name, 'citizen-lastname': self.citizen.last_name, 'citizen-quality': '1', 'report-terms_of_use_validated': True } self.sample_post_2 = { 'report-x': '150056', 'report-y': '170907.56', 'report-address_fr': 'Avenue des Arts, 3', 'report-address_nl': 'Kunstlaan, 3', 'report-address_number': '5', 'report-postalcode': '1210', 'report-category': '1', 'report-secondary_category': '1', 'report-subscription': 'on', 'comment-text': 'test2', 'files-TOTAL_FORMS': 0, 'files-INITIAL_FORMS': 0, 'files-MAX_NUM_FORMS': 0, 'citizen-email': self.citizen.email, 'citizen-firstname': self.citizen.first_name, 'citizen-lastname': self.citizen.last_name, 'citizen-quality': '1', 'report-terms_of_use_validated': True } def test_home(self): """Tests the new report view.""" response = self.client.get(reverse('home'), follow=True) self.assertEqual(response.status_code, 200) self.assertTrue('report_counts' in response.context) self.assertTrue('zipcodes' in response.context) #Are the zipcodes well loaded from DB?? self.assertTrue(len(response.context['zipcodes']) > 0) @skip('replaced by database pages') def test_about(self): """Tests the about view.""" response = self.client.get(reverse('about'), follow=True) self.assertEqual(response.status_code, 200) @skip('replaced by database pages') def test_term_of_use(self): """Tests the term of use view.""" response = self.client.get(reverse('terms_of_use'), follow=True) self.assertEqual(response.status_code, 200) def test_new_report(self): """Tests the new report page.""" url = reverse('report_new') response = self.client.get(url, { 'x': '148360', 'y': '171177' }, follow=True) self.assertEqual(response.status_code, 200) def test_verify_report(self): """Tests the new report page get verify existings.""" url = "%s?x=148360&y=171177" % reverse('report_new') response = self.client.post(url, self.sample_post, follow=True) self.assertEqual(response.status_code, 200) url = reverse('report_verify') response = self.client.get(url, { 'x': '150056', 'y': '170907' }, follow=True) self.assertEqual(response.status_code, 200) self.assertIn('reports_nearby', response.context) # Assert that the list view displays minimal information about reports last_dist = 0 for report in response.context['reports_nearby']: self.assertContains(response, report.get_absolute_url()) self.assertTrue(report.distance.m <= 20) # limit to 1km around self.assertTrue( report.distance.m >= last_dist) # ordered by distance last_dist = report.distance.m def test_create_report(self): """Tests the creation of a report and test the view of it.""" url = "%s?x=148360&y=171177" % reverse('report_new') response = self.client.post(url, self.sample_post, follow=True) self.assertEqual(response.status_code, 200) self.assertIn('report', response.context) report = response.context['report'] self.assertContains(response, report.postalcode) self.assertContains(response, report.status) self.assertEqual(1, len(Report.objects.all())) # Get in the DB the created report report = Report.objects.all()[0] # Check that source is correct self.assertEqual(Report.SOURCES['WEB'], report.source) def test_create_report_double(self): """Tests the creation of a double report and test the view of it.""" url = "%s?x=148360&y=171177" % reverse('report_new') self.client.post(url, self.sample_post, follow=True) self.client.post(url, self.sample_post, follow=True) self.client.post(url, self.sample_post, follow=True) self.client.post(url, self.sample_post, follow=True) self.assertEqual(1, len(Report.objects.all())) def test_accept_report(self): """Tests acceptation a report and test the view of it.""" url = "%s?x=148360&y=171177" % reverse('report_new') response = self.client.post(url, self.sample_post, follow=True) self.assertEqual(response.status_code, 200) report = response.context['report'] self.client.login(username='******', password='******') url = reverse('report_accept_pro', args=[report.id]) response = self.client.get(url, follow=True) self.assertEqual(response.status_code, 200) report = response.context['report'] self.assertTrue(report.accepted_at is not None) def test_refuse_report(self): """Tests refuse a report and test the view of it.""" url = "%s?x=148360&y=171177" % reverse('report_new') response = self.client.post(url, self.sample_post, follow=True) self.assertEqual(response.status_code, 200) report = response.context['report'] # Be sure it's private report.private = True report.save() self.client.login(username='******', password='******') url = reverse('report_refuse_pro', args=[report.id]) response = self.client.post(url, {'text': "Message de refus"}, follow=True) self.assertEqual(response.status_code, 200) report = response.context['report'] self.assertTrue(report.accepted_at is None) self.assertEqual(report.status, Report.REFUSED) comment = ReportComment.objects.get(report_id=report.id, type=ReportAttachment.REFUSED) self.assertEqual(comment.security_level, ReportComment.PRIVATE) def test_refuse_report_comment_visible_for_citizen(self): """Tests refuse a report and test the view of it.""" url = "%s?x=148360&y=171177" % reverse('report_new') response = self.client.post(url, self.sample_post, follow=True) self.assertEqual(response.status_code, 200) report = response.context['report'] # Be sure it's public report.private = False report.save() self.client.login(username='******', password='******') url = reverse('report_refuse_pro', args=[report.id]) response = self.client.post(url, {'text': "Message de refus"}, follow=True) self.assertEqual(response.status_code, 200) report = response.context['report'] self.assertTrue(report.accepted_at is None) self.assertEqual(report.status, Report.REFUSED) comment = ReportComment.objects.get(report_id=report.id, type=ReportAttachment.REFUSED) self.assertEqual(comment.security_level, ReportComment.PUBLIC) def test_add_comment(self): """Tests the update of a report.""" url = "%s?x=148360&y=171177" % reverse('report_new') response = self.client.post(url, self.sample_post, follow=True) report = response.context['report'] self.assertEqual(report.comments().count(), 1) self.assertEqual(report.comments()[0].created_by, self.citizen) report.save() response = self.client.post(reverse('report_document', kwargs={ 'report_id': report.id, 'slug': 'hello' }), { 'comment-text': 'new created comment', 'citizen-email': self.user.email, 'citizen-quality': 1, 'files-TOTAL_FORMS': 0, 'files-INITIAL_FORMS': 0, 'files-MAX_NUM_FORMS': 0 }, follow=True) self.assertEqual(response.status_code, 200) url = reverse('report_show2', args=[report.id]) self.assertRedirects(response, url) self.assertEqual(report.comments().count(), 2) self.assertEqual(report.comments()[1].created_by, self.user) def test_add_comment_as_pro(self): """Tests the update of a report as a pro.""" self.client.login(username='******', password='******') url = "%s?x=148360&y=171177" % reverse('report_new_pro') response = self.client.post(url, self.sample_post, follow=True) report = response.context['report'] self.assertEqual(report.comments().count(), 1) self.assertEqual(report.comments()[0].created_by, self.manager) report.save() response = self.client.post(reverse('report_show_pro', kwargs={ 'report_id': report.id, 'slug': 'hello' }), { 'comment-text': 'new created comment', 'files-TOTAL_FORMS': 0, 'files-INITIAL_FORMS': 0, 'files-MAX_NUM_FORMS': 0 }, follow=True) self.assertEqual(response.status_code, 200) self.assertRedirects(response, report.get_absolute_url_pro()) self.assertEqual(report.comments().count(), 2) self.assertEqual(report.comments()[1].created_by, self.manager) def test_change_category_private(self): self.client.login(username='******', password='******') url = "%s?x=148360&y=171177" % reverse('report_new') response = self.client.post(url, self.sample_post, follow=True) report = response.context['report'] self.assertEqual(Report.objects.get(id=report.id).category.id, 1) self.assertEqual( Report.objects.get(id=report.id).secondary_category.id, 1) # Setting a private sec_cat to a public report is not allowed self.client.post( reverse('update_category_for_report', args=[report.id]), { "main_category": "2", "secondary_category": "32" }) # So, cat not changed self.assertEqual(Report.objects.get(id=report.id).category.id, 1) self.assertEqual( Report.objects.get(id=report.id).secondary_category.id, 1) def test_change_category_public(self): self.client.login(username='******', password='******') url = "%s?x=148360&y=171177" % reverse('report_new') response = self.client.post(url, self.sample_post, follow=True) report = response.context['report'] self.assertEqual(Report.objects.get(id=report.id).category.id, 1) self.assertEqual( Report.objects.get(id=report.id).secondary_category.id, 1) self.client.post( reverse('update_category_for_report', args=[report.id]), { "main_category": "2", "secondary_category": "2" }) self.assertEqual(Report.objects.get(id=report.id).category.id, 2) self.assertEqual( Report.objects.get(id=report.id).secondary_category.id, 2) def test_subscription(self): """Tests the subscription of a report.""" url = "%s?x=148360&y=171177" % reverse('report_new') response = self.client.post(url, self.sample_post, follow=True) report = response.context['report'] # responsible manager is NOT subscribed by default self.assertFalse( report.subscriptions.filter(subscriber=self.manager).exists()) self.client.login(username='******', password='******') # subscribe to the report response = self.client.get(reverse('subscribe_pro', args=[report.id]), {}, follow=True) self.assertRedirects(response, report.get_absolute_url_pro()) self.assertEqual(response.status_code, 200) #current user is subscribed self.assertTrue( report.subscriptions.filter(subscriber=self.manager).exists()) def test_subscription_citizen(self): """Tests the subscription of a report.""" url = "%s?x=148360&y=171177" % reverse('report_new') response = self.client.post(url, self.sample_post, follow=True) report = response.context['report'] # current user is not subscribed yet self.assertTrue( report.subscriptions.filter(subscriber=self.citizen).exists()) #unsubscribe to the report response = self.client.get(reverse('unsubscribe', args=[report.id]) + '?citizen_email=' + self.citizen.email, {}, follow=True) url = reverse('report_show2', args=[report.id]) self.assertRedirects(response, url) self.assertEqual(response.status_code, 200) #current user is no more subscribed self.assertFalse( report.subscriptions.filter(subscriber=self.citizen).exists()) def test_do_merge_reports(self): """Test do merge reports. """ #Add first report url = "%s?x=148360&y=171177" % reverse('report_new') response = self.client.post(url, self.sample_post, follow=True) report = response.context['report'] #Add second report response2 = self.client.post(url, self.sample_post_2, follow=True) report2 = response2.context['report'] #Login user params = {'username': self.manager.email, 'password': '******'} self.client.post(reverse('login'), params) #Merge reports url2 = reverse('report_do_merge_pro', args=[report.id]) self.client.post(url2, {"mergeId": report2.id}) #Reference from merged to kept report self.assertEqual(report.id, Report.objects.get(id=report2.id).merged_with.id) #The first one (oldest one) is kept self.assertEqual(Report.objects.all().visible()[0].id, report.id) #The comment of the second one is added to the first one self.assertEqual( Report.objects.get(id=report.id).comments().count(), 2) def test_merge_reports(self): """Test merge reports. """ # Add first report url = "%s?x=148360&y=171177" % reverse('report_new') response = self.client.post(url, self.sample_post, follow=True) report = response.context['report'] # Add second report response2 = self.client.post(url, self.sample_post_2, follow=True) report2 = response2.context['report'] report2.status = Report.IN_PROGRESS report2.save() # Login user params = {'username': self.manager.email, 'password': '******'} self.client.post(reverse('login'), params) # Display mergeable reports list url = reverse('report_merge_pro', args=[report.get_slug(), report.id]) response = self.client.get(url) self.assertEqual(report, response.context['report']) self.assertEqual(1, len(response.context['reports_nearby'])) def test_merge_reports_search_ticket(self): """Test merge reports with search of ticket number """ # Add first report url = "%s?x=148360&y=171177" % reverse('report_new') response = self.client.post(url, self.sample_post, follow=True) report = response.context['report'] # Add second report response2 = self.client.post(url, self.sample_post_2, follow=True) report2 = response2.context['report'] report2.status = Report.IN_PROGRESS #necessary otherwise both report will be with "CREATED" status # and you can't merge 2 reports with 2 "CREATED" status report2.save() # Login user params = {'username': self.manager.email, 'password': '******'} self.client.post(reverse('login'), params) # Display mergeable report according to ticket number url2 = reverse('report_merge_pro', args=[report.get_slug(), report.id]) response = self.client.get("%s?ticketNumber=%s" % (url2, report2.id)) self.assertEqual(report, response.context['report']) self.assertEqual(1, len(response.context['reports_nearby'])) self.assertEqual(report2.id, response.context['reports_nearby'][0].id) def test_mark_done_as_user(self): """Tests marking report as done.""" url = "%s?x=148360&y=171177" % reverse('report_new') response = self.client.post(url, self.sample_post, follow=True) report = response.context['report'] self.client.login(username='******', password='******') url = reverse('report_accept_pro', args=[report.id]) response = self.client.get(url, follow=True) # Mark as done as citizen self.client.logout() response = self.client.post(reverse('report_update', args=[report.id]), {'is_fixed': 'True'}, follow=True) self.assertEqual(response.status_code, 200) report = response.context['report'] self.assertTrue(report.fixed_at) self.assertEqual(report.status, Report.SOLVED) self.assertFalse( ReportComment.objects.filter(type=ReportAttachment.MARK_AS_DONE, report=report).exists()) def test_mark_done_as_pro(self): """Tests marking report as done.""" url = "%s?x=148360&y=171177" % reverse('report_new') response = self.client.post(url, self.sample_post, follow=True) report = response.context['report'] self.client.login(username='******', password='******') url = reverse('report_accept_pro', args=[report.id]) response = self.client.get(url, follow=True) self.assertEqual(response.status_code, 200) # Mark as done as pro response = self.client.post(reverse('report_fix_pro', args=[report.id]), {'text': 'commentaire'}, follow=True) self.assertEquals(response.status_code, 200) report = response.context['report'] self.assertTrue(report.fixed_at) self.assertTrue( ReportComment.objects.filter(type=ReportAttachment.MARK_AS_DONE, report=report).exists()) self.assertEquals(report.status, Report.SOLVED) def test_mark_done_as_user_denied(self): """Tests marking report not done if denied.""" url = "%s?x=148360&y=171177" % reverse('report_new') response = self.client.post(url, self.sample_post, follow=True) report = response.context['report'] self.client.login(username='******', password='******') url = reverse('report_accept_pro', args=[report.id]) response = self.client.get(url, follow=True) # Change status to refused report.status = report.REFUSED report.save() # Try to mark as done as citizen self.client.logout() response = self.client.post(reverse('report_update', args=[report.id]), {'is_fixed': 'True'}, follow=True) self.assertEqual(response.status_code, 200) report = response.context['report'] self.assertFalse(report.fixed_at) self.assertEqual(report.status, Report.REFUSED) self.assertFalse( ReportComment.objects.filter(type=ReportAttachment.MARK_AS_DONE, report=report).exists()) def test_mark_done_as_pro_denied(self): """Tests marking report as done.""" url = "%s?x=148360&y=171177" % reverse('report_new') response = self.client.post(url, self.sample_post, follow=True) report = response.context['report'] self.client.login(username='******', password='******') url = reverse('report_accept_pro', args=[report.id]) response = self.client.get(url, follow=True) self.assertEqual(response.status_code, 200) # Change status to refused report.status = report.REFUSED report.save() # Try to mark as done as pro response = self.client.post(reverse('report_fix_pro', args=[report.id]), {'text': 'commentaire'}, follow=True) self.assertEquals(response.status_code, 200) report = response.context['report'] self.assertFalse(report.fixed_at) self.assertFalse( ReportComment.objects.filter(type=ReportAttachment.MARK_AS_DONE, report=report).exists()) self.assertEquals(report.status, Report.REFUSED) def test_mark_done_as_user_denied(self): """Tests marking report not done if denied.""" url = "%s?x=148360&y=171177" % reverse('report_new') response = self.client.post(url, self.sample_post, follow=True) report = response.context['report'] self.client.login(username='******', password='******') url = reverse('report_accept_pro', args=[report.id]) response = self.client.get(url, follow=True) # Change status to refused report.status = report.REFUSED report.save() # Try to mark as done as citizen self.client.logout() response = self.client.post(reverse('report_update', args=[report.id]), {'is_fixed': 'True'}, follow=True) self.assertEqual(response.status_code, 200) report = response.context['report'] self.assertFalse(report.fixed_at) self.assertEqual(report.status, Report.REFUSED) self.assertFalse( ReportComment.objects.filter(type=ReportAttachment.MARK_AS_DONE, report=report).exists()) def test_mark_done_as_pro_denied(self): """Tests marking report as done.""" url = "%s?x=148360&y=171177" % reverse('report_new') response = self.client.post(url, self.sample_post, follow=True) report = response.context['report'] self.client.login(username='******', password='******') url = reverse('report_accept_pro', args=[report.id]) response = self.client.get(url, follow=True) self.assertEqual(response.status_code, 200) # Change status to refused report.status = report.REFUSED report.save() # Try to mark as done as pro response = self.client.post(reverse('report_fix_pro', args=[report.id]), {'text': 'commentaire'}, follow=True) self.assertEquals(response.status_code, 200) report = response.context['report'] self.assertFalse(report.fixed_at) self.assertFalse( ReportComment.objects.filter(type=ReportAttachment.MARK_AS_DONE, report=report).exists()) self.assertEquals(report.status, Report.REFUSED) def test_search_ticket(self): """Tests searching ticket.""" url = "%s?x=148360&y=171177" % reverse('report_new') response = self.client.post(url, self.sample_post, follow=True) report = response.context['report'] url = '%s?report_id=%s' % (reverse('search_ticket'), report.id) response = self.client.get(url, follow=True) self.assertEqual(response.status_code, 200) report_result = response.context['report'] self.assertEqual(report, report_result) def test_login_user(self): params = {'username': self.manager.email, 'password': '******'} response = self.client.post(reverse('login'), params) self.assertEqual(response.status_code, 302) def test_login_user_with_redirect(self): params = {'username': self.manager.email, 'password': '******'} url = '%s?next=/fr/pro/reports/' % reverse('login') response = self.client.post(url, params) self.assertEqual(response.status_code, 302) def test_login_user_fail(self): params = {'username': self.manager.email, 'password': '******'} response = self.client.post(reverse('login'), params) self.assertEqual(response.status_code, 200) escaped = escape( ugettext( 'Please enter a correct username and password. Note that both fields are case-sensitive.' )) self.assertContains(response, escaped) def test_logout_user(self): params = {'username': self.manager.email, 'password': '******'} self.client.post(reverse('login'), params) response = self.client.post(reverse('logout')) self.assertEqual(response.status_code, 302) def test_marker_detail_citizen(self): url = "%s?x=148360&y=171177" % reverse('report_new') response = self.client.post(url, self.sample_post, follow=True) self.assertEqual(response.status_code, 200) self.assertIn('report', response.context) report = response.context['report'] jsonResult = report.full_marker_detail_JSON() #Now test on all mandatory fields self.assertIn('id', jsonResult) self.assertIn('point', jsonResult) self.assertIn('category', jsonResult) self.assertIn('address', jsonResult) self.assertIn('address_number', jsonResult) self.assertIn('postalcode', jsonResult) self.assertIn('address_commune_name', jsonResult) self.assertIn('address_regional', jsonResult) self.assertIn('thumb', jsonResult) self.assertIn('contractor', jsonResult) self.assertIn('date_planned', jsonResult) self.assertNotIn('is_closed', jsonResult) self.assertNotIn('citizen', jsonResult) self.assertNotIn('priority', jsonResult) def test_marker_detail_pro(self): url = "%s?x=148360&y=171177" % reverse('report_new') response = self.client.post(url, self.sample_post, follow=True) self.assertEqual(response.status_code, 200) self.assertIn('report', response.context) report = response.context['report'] jsonResult = report.full_marker_detail_pro_JSON() #Now test on all mandatory fields self.assertIn('id', jsonResult) self.assertIn('point', jsonResult) self.assertIn('category', jsonResult) self.assertIn('address', jsonResult) self.assertIn('address_number', jsonResult) self.assertIn('postalcode', jsonResult) self.assertIn('address_commune_name', jsonResult) self.assertIn('address_regional', jsonResult) self.assertIn('thumb', jsonResult) self.assertIn('contractor', jsonResult) self.assertIn('date_planned', jsonResult) self.assertIn('is_closed', jsonResult) self.assertIn('citizen', jsonResult) self.assertIn('priority', jsonResult) def test_reopen_report_refused(self): url = "%s?x=148360&y=171177" % reverse('report_new') response = self.client.post(url, self.sample_post, follow=True) self.assertEqual(response.status_code, 200) report = response.context['report'] comment = ReportComment(report_id=report.id, text='test', type=3) comment.save() report.status = Report.REFUSED report.save() self.client.login(username='******', password='******') url = reverse('report_reopen_pro', args=[report.id]) response = self.client.get(url, follow=True) self.assertEqual(response.status_code, 200) report_reopen = response.context['report'] self.assertEqual(Report.MANAGER_ASSIGNED, report_reopen.status) self.assertNotEqual(report.status, report_reopen.status) self.assertEqual(report.created, report_reopen.created) self.assertEqual(report.close_date, report_reopen.close_date) # accepted_at need to be initialized self.assertFalse(report.accepted_at) self.assertTrue(report_reopen.accepted_at) self.assertEqual(report.subscriptions.all().count(), report_reopen.subscriptions.all().count()) self.assertEqual(report.responsible_entity, report_reopen.responsible_entity) self.assertEqual(report.responsible_department, report_reopen.responsible_department) def test_reopen_report_processed(self): url = "%s?x=148360&y=171177" % reverse('report_new') response = self.client.post(url, self.sample_post, follow=True) self.assertEqual(response.status_code, 200) report = response.context['report'] report.status = Report.PROCESSED report.accepted_at = datetime.now() report.save() self.client.login(username='******', password='******') url = reverse('report_reopen_pro', args=[report.id]) response = self.client.get(url, follow=True) self.assertEqual(response.status_code, 200) report_reopen = response.context['report'] self.assertEqual(Report.MANAGER_ASSIGNED, report_reopen.status) self.assertNotEqual(report.status, report_reopen.status) self.assertEqual(report.created, report_reopen.created) self.assertEqual(report.accepted_at, report_reopen.accepted_at) self.assertEqual(report.close_date, report_reopen.close_date) self.assertEqual(report.subscriptions.all().count(), report_reopen.subscriptions.all().count()) self.assertEqual(report.responsible_entity, report_reopen.responsible_entity) self.assertEqual(report.responsible_department, report_reopen.responsible_department) def test_reopen_report_badstatus(self): url = "%s?x=148360&y=171177" % reverse('report_new') response = self.client.post(url, self.sample_post, follow=True) self.assertEqual(response.status_code, 200) report = response.context['report'] report.accepted_at = datetime.now() report.save() self.client.login(username='******', password='******') url = reverse('report_reopen_pro', args=[report.id]) response = self.client.get(url, follow=True) self.assertEqual(response.status_code, 200) report_not_reopen = response.context['report'] self.assertNotEqual(Report.MANAGER_ASSIGNED, report_not_reopen.status) self.assertEqual(report.status, report_not_reopen.status) self.assertEqual(report.created, report_not_reopen.created) self.assertEqual(report.modified, report_not_reopen.modified) self.assertEqual(report.accepted_at, report_not_reopen.accepted_at) self.assertEqual(report.close_date, report_not_reopen.close_date) self.assertEqual(report.subscriptions.all().count(), report_not_reopen.subscriptions.all().count()) self.assertEqual(report.responsible_entity, report_not_reopen.responsible_entity) self.assertEqual(report.responsible_department, report_not_reopen.responsible_department) def test_auto_assign(self): # Associate a category to an organisation for auto-dispatching entity = OrganisationEntity() entity.name_fr = "My entity" entity.type = OrganisationEntity.COMMUNE entity.email = "*****@*****.**" entity.save() # Associate a category to an organisation for auto-dispatching department = OrganisationEntity() department.name_fr = "My group" department.type = OrganisationEntity.DEPARTMENT department.dependency = entity department.email = "*****@*****.**" department.save() self.group_mail_config.group = department self.group_mail_config.save() category = ReportCategory.objects.get( id=self.sample_post['report-category']) category.organisation_communal = entity category.save() department.dispatch_categories.add(category) # Create new report url = "%s?x=148360&y=171177" % reverse('report_new') response = self.client.post(url, self.sample_post, follow=True) self.assertEqual(response.status_code, 200) report = response.context['report'] # Auto-dispatching working for commune self.assertFalse(report.is_regional()) self.assertEqual(report.responsible_department, department) self.assertEqual(report.responsible_entity, entity) def test_not_auto_assign_if_report_already_exists(self): # Create new report url = "%s?x=148360&y=171177" % reverse('report_new') response = self.client.post(url, self.sample_post, follow=True) self.assertEqual(response.status_code, 200) report = response.context['report'] # Associate a category to an organisation for auto-dispatching entity = OrganisationEntity() entity.name_fr = "My entity" entity.type = OrganisationEntity.COMMUNE entity.email = "*****@*****.**" entity.save() # Associate a category to an organisation for auto-dispatching department = OrganisationEntity() department.name_fr = "My group" department.type = OrganisationEntity.DEPARTMENT department.dependency = entity department.email = "*****@*****.**" department.save() self.group_mail_config.group = department self.group_mail_config.save() category = ReportCategory.objects.get( id=self.sample_post['report-category']) category.organisation_communal = entity category.save() department.dispatch_categories.add(category) # Assign report to another entity report.responsible_entity = self.group.dependency report.responsible_department = None report.save() # Check it's not auto-dispatching report = Report.objects.get(id=report.id) self.assertFalse(report.is_regional()) self.assertNotEqual(report.responsible_department, department) self.assertNotEqual(report.responsible_entity, entity) self.assertEqual(report.responsible_entity, self.group.dependency) self.assertEqual(report.responsible_department, self.group)
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)
class ReopenRequestTest(FMSTestCase): def setUp(self): self.citizen = FMSUser( telephone="0123456789", last_used_language="fr", first_name="citizen", last_name="citizen", email="*****@*****.**" ) self.citizen.save() self.manager = FMSUser( is_active=True, telephone="0123456789", last_used_language="fr", password='******', first_name="manager", last_name="manager", email="*****@*****.**", manager=True ) self.manager.set_password('test') self.manager.organisation = OrganisationEntity.objects.get(pk=14) self.manager.save() self.group = OrganisationEntity( type="D", name_nl="Werken", name_fr="Travaux", phone="090987", dependency=OrganisationEntity.objects.get(pk=14), email="*****@*****.**" ) self.group.save() self.group.dispatch_categories.add(ReportCategory.objects.get(pk=1)) self.group_mail_config = GroupMailConfig() self.group_mail_config.group = self.group self.group_mail_config.save() self.manager.memberships.create(organisation=self.group, contact_user=True) self.client = Client() self.manager2 = FMSUser( is_active=True, telephone="9876543210", last_used_language="nl", password='******', first_name="manager2", last_name="manager2", email="*****@*****.**", manager=True ) self.manager2.set_password('test2') self.manager2.organisation = OrganisationEntity.objects.get(pk=14) self.manager2.save() self.group2 = OrganisationEntity( type="D", name_nl="Werken", name_fr="Travaux", phone="090987", dependency=OrganisationEntity.objects.get(pk=21), email="*****@*****.**" ) self.group2.save() self.group2.dispatch_categories.add(ReportCategory.objects.get(pk=2)) self.group2.dispatch_categories.add(ReportCategory.objects.get(pk=1)) p1 = (148776, 171005) p2 = (150776, 171005) p3 = (150776, 169005) p4 = (148776, 169005) surface = OrganisationEntitySurface( geom=Polygon([p1, p2, p3, p4, p1]), owner=OrganisationEntity.objects.get(pk=14), ) surface.save() self.manager2.memberships.create(organisation=self.group2) self.manager3 = FMSUser( is_active=True, telephone="000000000", last_used_language="nl", password='******', first_name="manager3", last_name="manager3", email="*****@*****.**", manager=True ) self.manager3.set_password('test3') self.manager3.organisation = OrganisationEntity.objects.get(pk=21) self.manager3.save() self.manager3.memberships.create(organisation=self.group2) self.impetrant = OrganisationEntity( name_nl="MIVB", name_fr="STIB", email="*****@*****.**") self.impetrant.save() self.contractor = OrganisationEntity( name_nl="Fabricom GDF", name_fr="Fabricom GDF", email="*****@*****.**") self.contractor.save() self.sample_post = { 'report-x': '150056.538', 'report-y': '170907.56', 'report-address_fr': 'Avenue des Arts, 3', 'report-address_nl': 'Kunstlaan, 3', 'report-address_number': '3', 'report-postalcode': '1210', 'report-category': '1', 'report-secondary_category': '1', 'report-subscription': 'on', 'citizen-quality': '1', 'comment-text': 'test', 'files-TOTAL_FORMS': 0, 'files-INITIAL_FORMS': 0, 'files-MAX_NUM_FORMS': 0, 'citizen-email': self.citizen.email, 'citizen-firstname': self.citizen.first_name, 'citizen-lastname': self.citizen.last_name, 'report-terms_of_use_validated': True } ##### Following data was created specifically for the reopen_request tests ####### self.citizen_reopen_request = FMSUser( telephone="987654321", last_used_language="fr", first_name="citizen_reopen_request", last_name="citizen_reopen_request", email="*****@*****.**" ) self.citizen_reopen_request.save() self.sample_post_reopen_request_pro = { 'reopen-text': 'this is the reopen request comment', 'reopen-reason': 1 } self.sample_post_reopen_request = { 'reopen-text': 'this is the reopen request comment', 'reopen-reason': 1, 'citizen-quality': 2, 'citizen-email': self.citizen_reopen_request.email, 'citizen-telephone': self.citizen_reopen_request.telephone, 'citizen-last_name': self.citizen_reopen_request.last_name, } def testReopenRequestMailByPro(self): # New report response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post, follow=True) report = response.context['report'] # Set status to Processed report.status = Report.PROCESSED report.close_date = datetime.now() report.save() # Login to access the pro page self.client.login(username='******', password='******') # Request reopen report response = self.client.post(reverse('report_reopen_request_pro', args=["hello", report.id]), self.sample_post_reopen_request_pro, follow=True) #check redirect url_redirect = reverse('report_show_pro', args=[report.get_slug(), report.id]) self.assertRedirects(response, url_redirect, status_code=302, target_status_code=200) #test there is a message success_msg = str(list(response.context["messages"])[0]) self.assertEqual(success_msg, str(gettext(SUCCESS_MSG_REOPEN_REQUEST_CONFIRM))) # Fetch activities activities = report.activities.all() # Assert self.assertEqual(activities.count(), 3) self.assertEquals(ReportEventLog.REOPEN_REQUEST, activities[2].event_type) def testReopenRequestMailByCitizen(self): # New report response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post, follow=True) report = response.context['report'] # Set status to Processed report.status = Report.PROCESSED report.close_date = datetime.now() report.save() # Request reopen report response = self.client.post(reverse('report_reopen_request', args=["hello", report.id]), self.sample_post_reopen_request, follow=True) url = reverse('report_show', args=[report.get_slug(), report.id]) self.assertRedirects(response, url, status_code=302, target_status_code=200) #test there is a message success_msg = str(list(response.context["messages"])[0]) self.assertEqual(success_msg, str(gettext(SUCCESS_MSG_REOPEN_REQUEST_CONFIRM))) # Fetch activities activities = report.activities.all() # Assert self.assertEqual(activities.count(), 3) self.assertEquals(ReportEventLog.REOPEN_REQUEST, activities[2].event_type) #Test that you cannot access the page if you don't have status closed. (Should be tested with all status #except PROCESSED but let's test it with REFUSED) def testReopenRequestOnlyForProcessed(self): # New report response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post, follow=True) report = response.context['report'] comment = ReportComment(report_id=report.id, text='test', type=3) comment.save() # Set status to REFUSED (we want a status different that report.status = Report.REFUSED report.close_date = datetime.now() report.save() # Request reopen report response = self.client.post(reverse('report_reopen_request', args=["hello", report.id]), self.sample_post_reopen_request, follow=True) url = reverse('report_show', args=[report.get_slug(), report.id]) self.assertRedirects(response, url, status_code=302, target_status_code=200) error_msg = str(list(response.context["messages"])[0]) self.assertEqual(error_msg, str(gettext(ERROR_MSG_REOPEN_REQUEST_ONLY_CLOSED))) # Fetch activities activities = report.activities.all() # Assert self.assertEqual(activities.count(), 2) self.assertEquals(ReportEventLog.REFUSE, activities[1].event_type) #this can't be ReportEventLog.REOPEN_REQUEST def testReopenRequestNotAfter90Days(self): # New report response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post, follow=True) report = response.context['report'] #limit date is 90 days. let's check a report closed 91 days ago report.status = Report.PROCESSED limit_date_plus_one = datetime.now() - timedelta(days=91) report.close_date = limit_date_plus_one report.save() # Request reopen report response = self.client.post(reverse('report_reopen_request', args=["hello", report.id]), self.sample_post_reopen_request, follow=True) url = reverse('report_show', args=[report.get_slug(), report.id]) self.assertRedirects(response, url, status_code=302, target_status_code=200) error_msg = str(list(response.context["messages"])[0]) self.assertEqual(error_msg, str(gettext(ERROR_MSG_REOPEN_REQUEST_90_DAYS))) # Fetch activities activities = report.activities.all() # Assert self.assertEqual(activities.count(), 2) self.assertEquals(ReportEventLog.CLOSE, activities[1].event_type)
def setUp(self): self.citizen = FMSUser( telephone="0123456789", last_used_language="fr", first_name="citizen", last_name="citizen", email="*****@*****.**", ) self.citizen.save() self.manager = FMSUser( is_active=True, telephone="0123456789", last_used_language="fr", password="******", first_name="manager", last_name="manager", email="*****@*****.**", manager=True, ) self.manager.set_password("test") self.manager.organisation = OrganisationEntity.objects.get(pk=14) self.manager.save() self.group = OrganisationEntity( type="D", name_nl="Werken", name_fr="Travaux", phone="090987", dependency=OrganisationEntity.objects.get(pk=14), email="*****@*****.**", ) self.group.save() self.group.dispatch_categories.add(ReportCategory.objects.get(pk=1)) self.group_mail_config = GroupMailConfig() self.group_mail_config.group = self.group self.group_mail_config.save() self.manager.memberships.create(organisation=self.group, contact_user=True) self.client = Client() self.manager2 = FMSUser( is_active=True, telephone="9876543210", last_used_language="nl", password="******", first_name="manager2", last_name="manager2", email="*****@*****.**", manager=True, ) self.manager2.set_password("test2") self.manager2.organisation = OrganisationEntity.objects.get(pk=14) self.manager2.save() self.group2 = OrganisationEntity( type="D", name_nl="Werken", name_fr="Travaux", phone="090987", dependency=OrganisationEntity.objects.get(pk=21), email="*****@*****.**", ) self.group2.save() self.group2.dispatch_categories.add(ReportCategory.objects.get(pk=2)) self.group2.dispatch_categories.add(ReportCategory.objects.get(pk=1)) p1 = (148776, 171005) p2 = (150776, 171005) p3 = (150776, 169005) p4 = (148776, 169005) surface = OrganisationEntitySurface( geom=Polygon([p1, p2, p3, p4, p1]), owner=OrganisationEntity.objects.get(pk=14) ) surface.save() self.manager2.memberships.create(organisation=self.group2) self.manager3 = FMSUser( is_active=True, telephone="000000000", last_used_language="nl", password="******", first_name="manager3", last_name="manager3", email="*****@*****.**", manager=True, ) self.manager3.set_password("test3") self.manager3.organisation = OrganisationEntity.objects.get(pk=21) self.manager3.save() self.manager3.memberships.create(organisation=self.group2) self.impetrant = OrganisationEntity(name_nl="MIVB", name_fr="STIB", email="*****@*****.**") self.impetrant.save() self.contractor = OrganisationEntity( name_nl="Fabricom GDF", name_fr="Fabricom GDF", email="*****@*****.**" ) self.contractor.save() self.sample_post = { "report-x": "150056.538", "report-y": "170907.56", "report-address_fr": "Avenue des Arts, 3", "report-address_nl": "Kunstlaan, 3", "report-address_number": "3", "report-postalcode": "1210", "report-category": "1", "report-secondary_category": "1", "report-subscription": "on", "citizen-quality": "1", "comment-text": "test", "files-TOTAL_FORMS": 0, "files-INITIAL_FORMS": 0, "files-MAX_NUM_FORMS": 0, "citizen-email": self.citizen.email, "citizen-firstname": self.citizen.first_name, "citizen-lastname": self.citizen.last_name, "report-terms_of_use_validated": True, } ##### Following data was created specifically for the reopen_request tests ####### self.citizen_reopen_request = FMSUser( telephone="987654321", last_used_language="fr", first_name="citizen_reopen_request", last_name="citizen_reopen_request", email="*****@*****.**", ) self.citizen_reopen_request.save() self.sample_post_reopen_request_pro = {"reopen-text": "this is the reopen request comment", "reopen-reason": 1} self.sample_post_reopen_request = { "reopen-text": "this is the reopen request comment", "reopen-reason": 1, "citizen-quality": 2, "citizen-email": self.citizen_reopen_request.email, "citizen-telephone": self.citizen_reopen_request.telephone, "citizen-last_name": self.citizen_reopen_request.last_name, }
def setUp(self): self.citizen = FMSUser( telephone="0123456789", last_used_language="fr", first_name="Fake first name", last_name="Fake last name", email="*****@*****.**" ) self.citizen.save() self.citizen2 = FMSUser( telephone="9876543210", last_used_language="nl", first_name="Fake first name2", last_name="Fake last name2", email="*****@*****.**" ) self.citizen2.save() self.citizen3 = FMSUser( telephone="5649783210", last_used_language="nl", first_name="Fake first name3", last_name="Fake last name3", email="*****@*****.**" ) self.citizen3.save() self.manager = FMSUser( is_active=True, telephone="0123456789", last_used_language="fr", password='******', first_name="manager", last_name="manager", email="*****@*****.**", manager=True ) self.manager.set_password('test') self.manager.organisation = OrganisationEntity.objects.get(pk=14) self.manager.save() p1 = (148776, 171005) p2 = (150776, 171005) p3 = (150776, 169005) p4 = (148776, 169005) surface = OrganisationEntitySurface( geom=Polygon([p1, p2, p3, p4, p1]), owner=OrganisationEntity.objects.get(pk=14), ) surface.save() self.group = OrganisationEntity( type="D", name_nl="Werken", name_fr="Travaux", phone="090987", dependency=OrganisationEntity.objects.get(pk=14), email="*****@*****.**" ) self.group.save() self.group.dispatch_categories.add(ReportCategory.objects.get(pk=1)) self.group.dispatch_categories.add(ReportCategory.objects.get(pk=2)) self.group_mail_config = GroupMailConfig() self.group_mail_config.group = self.group self.group_mail_config.save() self.manager.memberships.create(organisation=self.group, contact_user=True) self.manager2 = FMSUser( is_active=True, telephone="9876543210", last_used_language="nl", password='******', first_name="manager2", last_name="manager2", email="*****@*****.**", manager=True ) self.manager2.set_password('test2') self.manager2.organisation = OrganisationEntity.objects.get(pk=14) self.manager2.save() self.manager2.memberships.create(organisation=self.group) self.manager3 = FMSUser( is_active=True, telephone="000000000", last_used_language="nl", password='******', first_name="manager3", last_name="manager3", email="*****@*****.**", manager=True ) self.manager3.set_password('test3') self.manager3.organisation = OrganisationEntity.objects.get(pk=21) self.manager3.save() self.group2 = OrganisationEntity( type="D", name_nl="Werken", name_fr="Travaux", phone="090987", dependency=OrganisationEntity.objects.get(pk=21), email="*****@*****.**" ) self.group2.save() self.group2.dispatch_categories.add(ReportCategory.objects.get(pk=1)) self.group_mail_config2 = GroupMailConfig() self.group_mail_config2.group = self.group2 self.group_mail_config2.save() self.manager3.memberships.create(organisation=self.group2) self.impetrant = OrganisationEntity( name_nl="MIVB", name_fr="STIB", type=OrganisationEntity.APPLICANT) self.impetrant.save() self.contractor = OrganisationEntity( name_nl="Fabricom GDF", name_fr="Fabricom GDF", type=OrganisationEntity.SUBCONTRACTOR) self.contractor.save() self.client = Client() self.sample_post_citizen = { 'report-x': '150056.538', 'report-y': '170907.56', 'report-address_fr': 'Avenue des Arts, 3', 'report-address_nl': 'Kunstlaan, 3', 'report-address_number': '3', 'report-postalcode': '1210', 'report-category': '1', 'report-secondary_category': '1', 'report-subscription': 'on', 'citizen-quality': '1', 'comment-text': 'test', 'files-TOTAL_FORMS': 0, 'files-INITIAL_FORMS': 0, 'files-MAX_NUM_FORMS': 0, 'citizen-email': self.citizen.email, 'citizen-firstname': self.citizen.first_name, 'citizen-lastname': self.citizen.last_name, 'report-terms_of_use_validated': True } self.sample_post_pro = { 'report-x': '150056.538', 'report-y': '170907.56', 'report-address_fr': 'Avenue des Arts, 3', 'report-address_nl': 'Kunstlaan, 3', 'report-address_number': '3', 'report-postalcode': '1210', 'report-category': '1', 'report-secondary_category': '1', 'report-subscription': 'on', 'comment-text': 'test', 'files-TOTAL_FORMS': 0, 'files-INITIAL_FORMS': 0, 'files-MAX_NUM_FORMS': 0, 'report-terms_of_use_validated': True } self.sample_post_comment = { 'text' : 'Ceci est un commentaire' }
class HistoryTest(FMSTestCase): def setUp(self): self.citizen = FMSUser( telephone="0123456789", last_used_language="fr", first_name="Fake first name", last_name="Fake last name", email="*****@*****.**" ) self.citizen.save() self.citizen2 = FMSUser( telephone="9876543210", last_used_language="nl", first_name="Fake first name2", last_name="Fake last name2", email="*****@*****.**" ) self.citizen2.save() self.citizen3 = FMSUser( telephone="5649783210", last_used_language="nl", first_name="Fake first name3", last_name="Fake last name3", email="*****@*****.**" ) self.citizen3.save() self.manager = FMSUser( is_active=True, telephone="0123456789", last_used_language="fr", password='******', first_name="manager", last_name="manager", email="*****@*****.**", manager=True ) self.manager.set_password('test') self.manager.organisation = OrganisationEntity.objects.get(pk=14) self.manager.save() p1 = (148776, 171005) p2 = (150776, 171005) p3 = (150776, 169005) p4 = (148776, 169005) surface = OrganisationEntitySurface( geom=Polygon([p1, p2, p3, p4, p1]), owner=OrganisationEntity.objects.get(pk=14), ) surface.save() self.group = OrganisationEntity( type="D", name_nl="Werken", name_fr="Travaux", phone="090987", dependency=OrganisationEntity.objects.get(pk=14), email="*****@*****.**" ) self.group.save() self.group.dispatch_categories.add(ReportCategory.objects.get(pk=1)) self.group.dispatch_categories.add(ReportCategory.objects.get(pk=2)) self.group_mail_config = GroupMailConfig() self.group_mail_config.group = self.group self.group_mail_config.save() self.manager.memberships.create(organisation=self.group, contact_user=True) self.manager2 = FMSUser( is_active=True, telephone="9876543210", last_used_language="nl", password='******', first_name="manager2", last_name="manager2", email="*****@*****.**", manager=True ) self.manager2.set_password('test2') self.manager2.organisation = OrganisationEntity.objects.get(pk=14) self.manager2.save() self.manager2.memberships.create(organisation=self.group) self.manager3 = FMSUser( is_active=True, telephone="000000000", last_used_language="nl", password='******', first_name="manager3", last_name="manager3", email="*****@*****.**", manager=True ) self.manager3.set_password('test3') self.manager3.organisation = OrganisationEntity.objects.get(pk=21) self.manager3.save() self.group2 = OrganisationEntity( type="D", name_nl="Werken", name_fr="Travaux", phone="090987", dependency=OrganisationEntity.objects.get(pk=21), email="*****@*****.**" ) self.group2.save() self.group2.dispatch_categories.add(ReportCategory.objects.get(pk=1)) self.group_mail_config2 = GroupMailConfig() self.group_mail_config2.group = self.group2 self.group_mail_config2.save() self.manager3.memberships.create(organisation=self.group2) self.impetrant = OrganisationEntity( name_nl="MIVB", name_fr="STIB", type=OrganisationEntity.APPLICANT) self.impetrant.save() self.contractor = OrganisationEntity( name_nl="Fabricom GDF", name_fr="Fabricom GDF", type=OrganisationEntity.SUBCONTRACTOR) self.contractor.save() self.client = Client() self.sample_post_citizen = { 'report-x': '150056.538', 'report-y': '170907.56', 'report-address_fr': 'Avenue des Arts, 3', 'report-address_nl': 'Kunstlaan, 3', 'report-address_number': '3', 'report-postalcode': '1210', 'report-category': '1', 'report-secondary_category': '1', 'report-subscription': 'on', 'citizen-quality': '1', 'comment-text': 'test', 'files-TOTAL_FORMS': 0, 'files-INITIAL_FORMS': 0, 'files-MAX_NUM_FORMS': 0, 'citizen-email': self.citizen.email, 'citizen-firstname': self.citizen.first_name, 'citizen-lastname': self.citizen.last_name, 'report-terms_of_use_validated': True } self.sample_post_pro = { 'report-x': '150056.538', 'report-y': '170907.56', 'report-address_fr': 'Avenue des Arts, 3', 'report-address_nl': 'Kunstlaan, 3', 'report-address_number': '3', 'report-postalcode': '1210', 'report-category': '1', 'report-secondary_category': '1', 'report-subscription': 'on', 'comment-text': 'test', 'files-TOTAL_FORMS': 0, 'files-INITIAL_FORMS': 0, 'files-MAX_NUM_FORMS': 0, 'report-terms_of_use_validated': True } self.sample_post_comment = { 'text' : 'Ceci est un commentaire' } def testCreateReportHistoryCitizen(self): #Send a post request filling in the form to create a report response = self.client.post( reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post_citizen, follow=True) self.assertEquals(response.status_code, 200) # self.assertIn( # '/en/report/trou-en-revetements-en-trottoir-en-saint-josse-ten-noode/1', # response['Location']) # check the history if it contains 1 line and that the content is correct report_id = response.context['report'].id report = Report.objects.get(id=report_id) activities = report.activities.all() self.assertEquals(activities.all().count(), 1) url = '%s?report_id=%s' % (reverse('search_ticket'), report.id) response = self.client.get(url, follow=True) self.assertEquals(response.status_code, 200) self.assertContains(response, self.calculatePrint(activities[0])) self.assertNotContains(response, self.calculatePrintPro(activities[0])) #Now redo the test with a manager user self.client.login(username='******', password='******') url = '%s?report_id=%s' % (reverse('search_ticket_pro'), report.id) response = self.client.get(url, follow=True) report = Report.objects.get(id=report_id) activities = report.activities.all() self.assertEquals(activities.all().count(), 1) #check if the page contains the exact string as it should be generated self.assertEquals(response.status_code, 200) self.assertContains(response, self.calculatePrintPro(activities[0])) def testCreateReportHistoryPro(self): self.client.login(username='******', password='******') response = self.client.post( reverse('report_new_pro') + '?x=150056.538&y=170907.56', self.sample_post_pro, follow=True) self.assertEquals(response.status_code, 200) report_id = response.context['report'].id report = Report.objects.get(id=report_id) activities = report.activities.all() self.assertEquals(activities.all().count(), 1) url = reverse('report_change_switch_visibility', args=[report_id]) response = self.client.get(url, { 'visibility': 'false' }, follow=True) self.assertEqual(response.status_code, 200) report = response.context['report'] self.assertFalse(report.private) url = '%s?report_id=%s' % (reverse('search_ticket_pro'), report.id) self.client.login(username='******', password='******') response = self.client.get(url, follow=True) self.assertEquals(response.status_code, 200) self.assertContains(response, self.calculatePrintPro(activities[0])) self.client.logout() #now test as citizen url = '%s?report_id=%s' % (reverse('search_ticket'), report.id) response = self.client.get(url, follow=True) self.assertEquals(response.status_code, 200) self.assertContains(response, self.calculatePrint(activities[0])) self.assertNotContains(response, self.calculatePrintPro(activities[0])) def testValidateReport(self): response = self.client.post( reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post_citizen, follow=True) report = response.context['report'] # Validate report self.client.login(username='******', password='******') url = reverse('report_accept_pro', args=[report.id]) response = self.client.get(url, follow=True) report = response.context['report'] activities = report.activities.all() self.assertEqual(response.status_code, 200) self.assertIsNotNone(report.accepted_at) self.assertEquals(activities.all().count(), 2) # now check status as pro self.client.login(username='******', password='******') url = '%s?report_id=%s' % (reverse('search_ticket_pro'), report.id) response = self.client.get(url, follow=True) self.assertContains(response, self.calculatePrintPro(activities[1])) # check if the status as citizen self.client.logout() url = '%s?report_id=%s' % (reverse('search_ticket'), report.id) response = self.client.get(url, follow=True) report = Report.objects.get(id=report.id) activities = report.activities.all() self.assertEquals(activities.all().count(), 2) self.assertContains(response, self.calculatePrint(activities[1])) self.assertNotContains(response, self.calculatePrintPro(activities[1])) def testInvalidateReport(self): response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post_citizen, follow=True) self.assertEquals(response.status_code, 200) report_id = response.context['report'].id self.client.login(username='******', password='******') url = reverse('report_refuse_pro', args=[report_id]) response = self.client.post(url, self.sample_post_comment, follow=True) self.assertEqual(response.status_code, 200) self.client.logout() #check if the status is updated url = '%s?report_id=%s' % (reverse('search_ticket'), report_id) response = self.client.get(url, follow=True) report = Report.objects.get(id=report_id) activities = report.activities.all() self.assertEquals(response.status_code, 200) self.assertEquals(activities.all().count(), 2) self.assertContains(response, self.calculatePrint(activities[1])) self.assertNotContains(response, self.calculatePrintPro(activities[1])) #now check status as pro self.client.login(username='******', password='******') url = '%s?report_id=%s' % (reverse('search_ticket_pro'), report_id) response = self.client.get(url, follow=True) self.assertEquals(response.status_code, 200) report = Report.objects.get(id=report_id) activities = report.activities.all() self.assertEquals(activities.all().count(), 2) self.assertContains(response, self.calculatePrintPro(activities[1])) def testClosureReport(self): response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post_citizen, follow=True) self.assertEquals(response.status_code, 200) report_id = response.context['report'].id self.client.login(username='******', password='******') url = reverse('report_close_pro', args=[report_id]) response = self.client.get(url, follow=True) self.assertEqual(response.status_code, 200) report = response.context['report'] self.assertTrue(report.close_date is not None) self.client.logout() #check if the status is updated url = '%s?report_id=%s' % (reverse('search_ticket'), report_id) response = self.client.get(url, follow=True) self.assertEquals(response.status_code, 200) report = Report.objects.get(id=report_id) activities = report.activities.all() self.assertEquals(activities.all().count(), 2) self.assertContains(response, self.calculatePrint(activities[1])) self.assertNotContains(response, self.calculatePrintPro(activities[1])) #now check status as pro self.client.login(username='******', password='******') url = '%s?report_id=%s' % (reverse('search_ticket_pro'), report_id) response = self.client.get(url, follow=True) self.assertEquals(response.status_code, 200) report = Report.objects.get(id=report_id) activities = report.activities.all() self.assertEquals(activities.all().count(), 2) self.assertContains(response, self.calculatePrintPro(activities[1])) @skip("mark as done is actually disabled for citizen") def testResolvedByCitizenReport(self): response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post_citizen, follow=True) self.assertEquals(response.status_code, 200) report_id = response.context['report'].id #first accept the report before citizen can update self.client.login(username='******', password='******') url = reverse('report_accept_pro', args=[report_id]) response = self.client.get(url, follow=True) self.assertEqual(response.status_code, 200) report = response.context['report'] self.assertTrue(report.accepted_at is not None) self.client.logout() response = self.client.post(reverse('report_update', args=[report_id]), {'is_fixed': 'True'}, follow=True) self.assertEqual(response.status_code, 200) #check that activity is not visible to citizen url = '%s?report_id=%s' % (reverse('search_ticket'), report_id) response = self.client.get(url, follow=True) self.assertEquals(response.status_code, 200) report = Report.objects.get(id=report_id) activities = report.activities.all() self.assertEquals(activities.all().count(), 3) self.assertNotContains(response, self.calculatePrint(activities[2])) self.assertNotContains(response, self.calculatePrintPro(activities[2])) #check that activity is visible to pro self.client.login(username='******', password='******') url = '%s?report_id=%s' % (reverse('search_ticket_pro'), report_id) response = self.client.get(url, follow=True) self.assertEquals(response.status_code, 200) report = Report.objects.get(id=report_id) activities = report.activities.all() self.assertEquals(activities.all().count(), 3) self.assertContains(response, self.calculatePrintPro(activities[2])) def testResolvedByProReport(self): response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post_citizen, follow=True) self.assertEquals(response.status_code, 200) report_id = response.context['report'].id #first accept the report before citizen can update self.client.login(username='******', password='******') url = reverse('report_accept_pro', args=[report_id]) response = self.client.get(url, follow=True) self.assertEqual(response.status_code, 200) report = response.context['report'] self.assertTrue(report.accepted_at is not None) response = self.client.post(reverse('report_fix_pro', args=[report_id]), self.sample_post_comment, follow=True) self.assertEqual(response.status_code, 200) #first check that pro has right status url = '%s?report_id=%s' % (reverse('search_ticket_pro'), report_id) response = self.client.get(url, follow=True) self.assertEquals(response.status_code, 200) report = Report.objects.get(id=report_id) activities = report.activities.all() self.assertEquals(activities.all().count(), 3) self.assertContains(response, self.calculatePrintPro(activities[2])) self.client.logout() #Now check for citizen url = '%s?report_id=%s' % (reverse('search_ticket'), report_id) response = self.client.get(url, follow=True) self.assertEquals(response.status_code, 200) report = Report.objects.get(id=report_id) activities = report.activities.all() self.assertEquals(activities.all().count(), 3) self.assertNotContains(response, self.calculatePrint(activities[2])) self.assertNotContains(response, self.calculatePrintPro(activities[2])) def testCitizenUpdatesReport(self): response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post_citizen, follow=True) self.assertEquals(response.status_code, 200) report_id = response.context['report'].id #first accept the report before citizen can update self.client.login(username='******', password='******') url = reverse('report_accept_pro', args=[report_id]) response = self.client.get(url, follow=True) self.assertEqual(response.status_code, 200) report = response.context['report'] self.assertTrue(report.accepted_at is not None) self.client.logout() response = self.client.post(reverse('report_document', kwargs={'report_id': report_id, 'slug': 'hello'}), { 'comment-text': 'new created comment', 'citizen-email': self.citizen.email, 'citizen-quality': 1, 'files-TOTAL_FORMS': 0, 'files-INITIAL_FORMS': 0, 'files-MAX_NUM_FORMS': 0 }, follow=True) self.assertEqual(response.status_code, 200) report = Report.objects.get(id=report_id) activities = report.activities.all() self.assertEqual(report.comments().count(), 2) #check that there is no message url = '%s?report_id=%s' % (reverse('search_ticket'), report_id) response = self.client.get(url, follow=True) self.assertEquals(response.status_code, 200) self.assertEqual(activities.all().count(), 3) self.assertNotContains(response, self.calculatePrint(activities[2])) self.assertNotContains(response, self.calculatePrintPro(activities[2])) #Now check the message for pro users self.client.login(username='******', password='******') url = '%s?report_id=%s' % (reverse('search_ticket_pro'), report_id) response = self.client.get(url, follow=True) self.assertEquals(response.status_code, 200) report = Report.objects.get(id=report_id) activities = report.activities.all() self.assertEquals(activities.all().count(), 3) self.assertContains(response, self.calculatePrintPro(activities[2])) self.client.logout() def testProUpdatesReport(self): response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post_citizen, follow=True) self.assertEquals(response.status_code, 200) report_id = response.context['report'].id report = Report.objects.get(id=report_id) activities = report.activities self.assertEquals(activities.count(), 1) self.assertEquals(activities.all()[0].event_type, ReportEventLog.CREATED) #first accept the report before citizen can update self.client.login(username='******', password='******') url = reverse('report_accept_pro', args=[report_id]) response = self.client.get(url, follow=True) self.assertEquals(response.status_code, 200) report = response.context['report'] self.assertIsNotNone(report.accepted_at) self.assertEquals(activities.count(), 2) self.assertEquals(activities.all()[1].event_type, ReportEventLog.VALID) response = self.client.post(reverse('report_show_pro', kwargs={'report_id': report_id, 'slug': 'hello'}), { 'comment-text': 'new created comment', 'files-TOTAL_FORMS': 0, 'files-INITIAL_FORMS': 0, 'files-MAX_NUM_FORMS': 0 }, follow=True) self.assertEqual(response.status_code, 200) report = Report.objects.get(id=report_id) self.assertEqual(report.comments().count(), 2) #Check for pro user first url = '%s?report_id=%s' % (reverse('search_ticket_pro'), report_id) response = self.client.get(url, follow=True) self.assertEquals(response.status_code, 200) report = Report.objects.get(id=report_id) self.assertEquals(activities.count(), 3) self.assertEquals(activities.all()[2].event_type, ReportEventLog.UPDATED) self.assertContains(response, self.calculatePrintPro(activities.all()[2])) self.client.logout() #Check for citizen user url = '%s?report_id=%s' % (reverse('search_ticket'), report_id) response = self.client.get(url, follow=True) self.assertEquals(response.status_code, 200) self.assertEqual(activities.all().count(), 3) self.assertNotContains(response, self.calculatePrint(activities.all()[2])) self.assertNotContains(response, self.calculatePrintPro(activities.all()[2])) def test_assign_to_other_member_of_same_entity(self): response = self.client.post( reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post_citizen, follow=True) report = response.context['report'] report.accepted_at = datetime.now() report.status = Report.MANAGER_ASSIGNED report.save() # Reset events report.activities.all().delete() # Change manager self.client.login(username='******', password='******') response = self.client.post( reverse('report_change_manager_pro', args=[report.id]), { 'man_id': 'department_' + str(self.group2.id), 'transfer': 0 }, follow=True) report = Report.objects.get(id=report.id) activities = report.activities.all() self.assertEquals(response.status_code, 200) # 1 activity for changing manager group self.assertEquals(activities.count(), 1) self.assertEqual(activities[0].event_type, ReportEventLog.MANAGER_ASSIGNED) # History for pro url = '%s?report_id=%s' % (reverse('search_ticket_pro'), report.id) response = self.client.get(url, follow=True) self.assertContains(response, self.calculatePrintPro(activities[0])) # History for citizen self.client.logout() url = '%s?report_id=%s' % (reverse('search_ticket'), report.id) response = self.client.get(url, follow=True) self.assertNotContains(response, self.calculatePrint(activities[0])) self.assertNotContains(response, self.calculatePrintPro(activities[0])) def test_assign_to_other_entity(self): response = self.client.post( reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post_citizen, follow=True) report = response.context['report'] report.accepted_at = datetime.now() report.status = Report.MANAGER_ASSIGNED report.save() # Reset events report.activities.all().delete() # Change manager self.client.login(username='******', password='******') response = self.client.post( reverse('report_change_manager_pro', args=[report.id]), { 'man_id' : 'entity_21', 'transfer': 0 }, follow=True) report = Report.objects.get(id=report.id) activities = report.activities.all() self.assertEquals(response.status_code, 200) # 1 activity for changing manager and 1 for entity change self.assertEqual(activities.count(), 2) self.assertEqual(activities[0].event_type, ReportEventLog.MANAGER_ASSIGNED) self.assertEqual(activities[1].event_type, ReportEventLog.ENTITY_ASSIGNED) # Test history of pro url = '%s?report_id=%s' % (reverse('search_ticket_pro'), report.id) response = self.client.get(url, follow=True) self.assertEquals(response.status_code, 200) self.assertContains(response, self.calculatePrintPro(activities[0])) # Test history of citizen self.client.logout() url = '%s?report_id=%s' % (reverse('search_ticket'), report.id) response = self.client.get(url, follow=True) self.assertEquals(response.status_code, 200) self.assertNotContains(response, self.calculatePrint(activities[0])) self.assertNotContains(response, self.calculatePrintPro(activities[0])) self.assertContains(response, self.calculatePrint(activities[1])) def testMergeReports(self): #Send a post request filling in the form to create a report response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post_citizen, follow=True) self.assertEquals(response.status_code, 200) self.assertIn('report', response.context) report_id = response.context['report'].id #Login to access the pro page self.client.login(username='******', password='******') response = self.client.post(reverse('report_new_pro') + '?x=150056.538&y=170907.56', self.sample_post_pro, follow=True) self.assertEquals(response.status_code, 200) #Should send mail only to responsible report2_id = response.context['report'].id #Publish the created report response = self.client.post(reverse('report_accept_pro', args=[report2_id]), follow=True) self.assertEquals(response.status_code, 200) #Merge reports url2 = reverse('report_do_merge_pro', args=[report_id]) response = self.client.post(url2, {"mergeId": report2_id}, follow=True) self.assertEquals(response.status_code, 200) # keep older, remove newer self.assertTrue(Report.objects.all().visible().filter(id=report_id).exists()) self.assertFalse(Report.objects.all().visible().filter(id=report2_id).exists()) # Reference from merged to kept report self.assertEqual(report_id, Report.objects.get(id=report2_id).merged_with.id) report = Report.objects.get(id=report_id) activities = report.activities.all() #2 activities are present: 1 for creation and 1 for merge self.assertEquals(activities.all().count(), 2) #Type of the second activity = merge (18) self.assertEqual(18, activities[1].event_type) report2 = Report.objects.get(id=report2_id) activities2 = report2.activities.all() #3 activities are present: 1 for creation, 1 for acception and 1 for merge self.assertEquals(activities2.all().count(), 3) #Type of the third activity = merge (18) self.assertEquals(18, activities2[2].event_type) def testAssignToContractor(self): response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post_citizen, follow=True) self.assertEquals(response.status_code, 200) report_id = response.context['report'].id report = Report.objects.get(id=report_id) activities = report.activities.all() self.assertEquals(activities.all().count(), 1) #first accept the report before citizen can update self.client.login(username='******', password='******') url = reverse('report_accept_pro', args=[report_id]) response = self.client.get(url, follow=True) self.assertEqual(response.status_code, 200) self.assertEquals(activities.all().count(), 2) report = response.context['report'] self.assertTrue(report.accepted_at is not None) self.client.login(username='******', password='******') response = self.client.get( reverse('report_change_contractor_pro', args=[report_id]), { 'contractorId': self.contractor.id }, follow=True) self.assertEquals(response.status_code, 200) self.assertEquals(activities.all().count(), 3) url = '%s?report_id=%s' % (reverse('search_ticket_pro'), report_id) response = self.client.get(url, follow=True) self.assertEquals(response.status_code, 200) self.assertContains(response, escape(self.calculatePrintPro(activities[2]))) #Now see if the information for the citizen is ok self.client.logout() url = '%s?report_id=%s' % (reverse('search_ticket'), report_id) response = self.client.get(url, follow=True) self.assertEquals(response.status_code, 200) report = Report.objects.get(id=report_id) activities = report.activities.all() self.assertEqual(activities.all().count(), 3) self.assertNotContains(response, self.calculatePrint(activities[2])) self.assertNotContains(response, self.calculatePrintPro(activities[2])) def testAssignToImpetrant(self): response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post_citizen, follow=True) self.assertEquals(response.status_code, 200) report_id = response.context['report'].id #first accept the report before citizen can update self.client.login(username='******', password='******') url = reverse('report_accept_pro', args=[report_id]) response = self.client.get(url, follow=True) self.assertEqual(response.status_code, 200) report = response.context['report'] self.assertTrue(report.accepted_at is not None) self.client.login(username='******', password='******') response = self.client.get(reverse('report_change_contractor_pro', args=[report_id]) + '?contractorId=' + str(self.impetrant.id), {}, follow=True) self.assertEquals(response.status_code, 200) report = Report.objects.get(id=report_id) activities = report.activities.all() self.assertEquals(activities.all().count(), 3) url = '%s?report_id=%s' % (reverse('search_ticket_pro'), report_id) response = self.client.get(url, follow=True) self.assertEquals(response.status_code, 200) self.calculatePrintPro(activities[2]) self.assertContains(response, self.calculatePrintPro(activities[2]).replace("'", ''')) #Now see if the information for the citizen is ok self.client.logout() url = '%s?report_id=%s' % (reverse('search_ticket'), report_id) response = self.client.get(url, follow=True) self.assertEquals(response.status_code, 200) report = Report.objects.get(id=report_id) activities = report.activities.all() self.assertEqual(activities.all().count(), 3) self.assertContains(response, self.calculatePrint(activities[2]).replace("'", ''')) def test_make_comment_public(self): response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post_citizen, follow=True) report = response.context['report'] report.accepted_at = datetime.now() report.save() # Reset event report.activities.all().delete() # Now add comment self.client.login(username='******', password='******') response = self.client.post( reverse('report_show_pro', kwargs={ 'report_id': report.id, 'slug': 'hello' }), { 'comment-text': 'new created comment', 'files-TOTAL_FORMS': 0, 'files-INITIAL_FORMS': 0, 'files-MAX_NUM_FORMS': 0 }, follow=True) report = response.context['report'] # 1 new comment and 1 activity self.assertEqual(report.comments().count(), 2) self.assertEqual(report.activities.all().count(), 1) # Now make the comment public response = self.client.get( reverse('report_update_attachment', args=[report.id]), { 'updateType': '1', 'attachmentId': report.comments()[1].id }, follow=True) report = Report.objects.get(id=report.id) activities = report.activities.all() # 1 new activity self.assertEqual(response.status_code, 200) self.assertEqual(activities.count(), 2) # Test history for pro url = '%s?report_id=%s' % (reverse('search_ticket_pro'), report.id) response = self.client.get(url, follow=True) self.assertEquals(response.status_code, 200) # Pro see both update en published event self.assertContains(response, self.calculatePrintPro(activities[0])) self.assertContains(response, self.calculatePrintPro(activities[1])) # Test history for citizen self.client.logout() url = '%s?report_id=%s' % (reverse('search_ticket'), report.id) response = self.client.get(url, follow=True) self.assertEquals(response.status_code, 200) # Citizen cannot see the update event self.assertNotContains(response, self.calculatePrint(activities[0])) self.assertNotContains(response, self.calculatePrintPro(activities[0])) # Citizen can see the published update event self.assertContains(response, self.calculatePrint(activities[1])) self.assertNotContains(response, self.calculatePrintPro(activities[1])) def test_reopen_report(self): # New report response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post_citizen, follow=True) report = response.context['report'] comment = ReportComment(report_id=report.id, text='test', type=3) comment.save() # Set status to REFUSED report.status = Report.REFUSED report.save() # Login to access the pro page self.client.login(username='******', password='******') # Reopen reports url = reverse('report_reopen_pro', args=[report.id]) response = self.client.get(url) # Fetch activities activities = report.activities.all() # Assert self.assertEqual(activities.count(), 3) self.assertEquals(ReportEventLog.REOPEN, activities[2].event_type) def calculatePrint(self, activity): user_to_display = _("a citizen") if activity.user: if activity.user.fmsuser.is_citizen(): user_to_display = _("a citizen") if activity.user.fmsuser.is_pro(): user_to_display = activity.user.fmsuser.get_organisation() return activity.EVENT_TYPE_TEXT[activity.event_type].format( user=user_to_display, organisation=activity.organisation, related_new=activity.related_new, related_old=activity.related_old ) def calculatePrintPro(self, activity): user_to_display = _("a citizen") if activity.user: if activity.user.fmsuser.is_citizen(): user_to_display = activity.user.get_full_name() or activity.user if activity.user.fmsuser.is_pro(): user_to_display = u'%s %s' % (activity.user.fmsuser.get_organisation(), activity.user.get_full_name() or activity.user) return activity.EVENT_TYPE_TEXT[activity.event_type].format( user=user_to_display, organisation=activity.organisation, related_new=activity.related_new, related_old=activity.related_old )
def handle(self, *args, **options): from apps.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.event_type)) # 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, None, activities_list, YESTERDAY)
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) def test_double_pro_case_insensitive(self): pro_data = { "email": "*****@*****.**", "last_name": "user", "telephone": "123456789", "quality": 1 } # Create first pro pro_form = FmsUserForm(pro_data) # Form has to be valid self.assertTrue(pro_form.is_valid()) pro_form.save() # Create second pro with a caps in email pro_data['email'] = pro_data['email'].upper() pro_form = FmsUserForm(pro_data) # Form has to be INVALID because the email is already existing self.assertFalse(pro_form.is_valid()) self.assertTrue(pro_form.errors) def test_pro_with_citizen_email(self): citizen = FMSUser( telephone="0123456789", first_name="citizen", last_name="citizen", email="*****@*****.**", ) citizen.save() pro_data = { "email": citizen.email, "last_name": "user", "telephone": "123456789", "quality": 1 } # Create a pro user pro_form = FmsUserForm(pro_data) # Form has to be INVALID because a citizen uses this email self.assertFalse(pro_form.is_valid()) self.assertTrue(pro_form.errors)
class FMSUserTest(FMSTestCase): def setUp(self): # 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) def test_double_citizen_case_insensitive(self): citizen_data = { "email" : "*****@*****.**", "last_name": "user", "telephone": "123456789", "quality" : 1 } # Create first citizen citizen_form = CitizenForm(citizen_data) # Form has to be valid self.assertTrue(citizen_form.is_valid()) citizen_form.save() # Create second citizen with a caps in email citizen_data['email'] = citizen_data['email'].upper() citizen_form = CitizenForm(citizen_data) # Form has to be valid self.assertTrue(citizen_form.is_valid()) citizen_form.save() # And only one user with the same email case insensitive is created (it's the same citizen in both cases) self.assertEqual(1, FMSUser.objects.filter(username__iexact=citizen_data['email']).count()) def test_citizen_with_pro_email(self): manager = FMSUser( is_active=True, telephone="0123456789", last_used_language="fr", password='******', first_name="manager", last_name="manager", email="*****@*****.**", manager=True ) manager.save() citizen_data = { "email" : manager.email, "last_name": "user", "telephone": "123456789", "quality" : 1 } # Create a citizen user citizen_form = CitizenForm(citizen_data) # Form has to be INVALID because the citizen use a pro email self.assertFalse(citizen_form.is_valid()) self.assertTrue(citizen_form.errors) def test_citizen_form_update(self): my_user = FMSUser( is_active=True, telephone="0123456789", last_used_language="nl", password='******', first_name="my_user", last_name="my_user", email="*****@*****.**", manager=False ) my_user.save() #Change values citizen_data = { "email" : "*****@*****.**", "last_name": "user modified", "telephone": "987654321", "quality" : 2 } citizen_form = CitizenForm(citizen_data) self.assertTrue(citizen_form.is_valid()) citizen_form.save() my_user = FMSUser.objects.filter(username__iexact=citizen_data['email']).get() self.assertEqual(my_user.last_name, citizen_data["last_name"]) self.assertEqual(my_user.telephone, citizen_data["telephone"]) self.assertEqual(my_user.quality, citizen_data["quality"]) self.assertEqual(my_user.last_used_language, "fr")
def setUp(self): self.client = Client() self.secondary_category = ReportCategory.objects.all()[0] self.category = self.secondary_category.category_class self.organisation = OrganisationEntity.objects.get(pk=4) self.department = OrganisationEntity(type="D", name_nl="Werken", name_fr="Travaux", phone="090987", dependency=self.organisation, email="*****@*****.**") self.department.save() self.group_mail_config = GroupMailConfig() self.group_mail_config.group = self.department self.group_mail_config.save() p1 = (148776, 171005) p2 = (150776, 171005) p3 = (150776, 169005) p4 = (148776, 169005) surface = OrganisationEntitySurface( geom=Polygon([p1, p2, p3, p4, p1]), owner=self.organisation, ) surface.save() self.manager = FMSUser(is_active=True, telephone="0123456789", last_used_language="fr", password='******', first_name="manager", last_name="manager", email="*****@*****.**", manager=True) self.manager.set_password('test') self.manager.organisation = self.organisation self.manager.save() self.department.dispatch_categories.add(self.secondary_category) self.usergroupmembership = UserOrganisationMembership( user=self.manager, organisation=self.department, contact_user=True) self.usergroupmembership.save() self.applicant_group = OrganisationEntity(type="A", name_nl="Belgacom", name_fr="Belgacom", phone="090987", email="*****@*****.**") self.applicant_group.save() self.applicant = FMSUser(is_active=True, telephone="0123456789", last_used_language="fr", password='******', first_name="manager", last_name="manager", email="*****@*****.**", manager=True) self.applicant.set_password('test') self.applicant.save() self.applicantmembership = UserOrganisationMembership( user=self.applicant, organisation=self.applicant_group, contact_user=True) self.applicantmembership.save()
def setUp(self): self.user = FMSUser(username='******', email='*****@*****.**', password='******') self.user.save() self.client = Client() self.citizen = FMSUser( telephone="0123456789", last_used_language="fr", first_name="citizen", last_name="citizen", email="*****@*****.**" ) self.citizen.save() self.group = OrganisationEntity( type="D", name_nl="Werken", name_fr="Travaux", phone="090987", dependency=OrganisationEntity.objects.get(pk=14), email="*****@*****.**" ) self.group.save() self.group_mail_config = GroupMailConfig() self.group_mail_config.group = self.group self.group_mail_config.save() self.manager = FMSUser( is_active=True, telephone="0123456789", last_used_language="fr", password='******', first_name="manager", last_name="manager", email="*****@*****.**", manager=True ) self.manager.set_password('test') self.manager.organisation = OrganisationEntity.objects.get(pk=14) self.manager.save() self.group.dispatch_categories.add(ReportCategory.objects.get(pk=1)) p1 = (148776, 171005) p2 = (150776, 171005) p3 = (150776, 169005) p4 = (148776, 169005) surface = OrganisationEntitySurface( geom=Polygon([p1, p2, p3, p4, p1]), owner=OrganisationEntity.objects.get(pk=14), ) surface.save() self.manager.memberships.create(organisation=self.group, contact_user=True) self.sample_post = { 'report-x': '150056.538', 'report-y': '170907.56', 'report-address_fr': 'Avenue des Arts, 3', 'report-address_nl': 'Kunstlaan, 3', 'report-address_number': '3', 'report-postalcode': '1210', 'report-category': '1', 'report-secondary_category': '1', 'report-subscription': 'on', 'comment-text': 'test', 'files-TOTAL_FORMS': 0, 'files-INITIAL_FORMS': 0, 'files-MAX_NUM_FORMS': 0, 'citizen-email': self.citizen.email, 'citizen-firstname': self.citizen.first_name, 'citizen-lastname': self.citizen.last_name, 'citizen-quality': '1', 'report-terms_of_use_validated': True } self.sample_post_2 = { 'report-x': '150056', 'report-y': '170907.56', 'report-address_fr': 'Avenue des Arts, 3', 'report-address_nl': 'Kunstlaan, 3', 'report-address_number': '5', 'report-postalcode': '1210', 'report-category': '1', 'report-secondary_category': '1', 'report-subscription': 'on', 'comment-text': 'test2', 'files-TOTAL_FORMS': 0, 'files-INITIAL_FORMS': 0, 'files-MAX_NUM_FORMS': 0, 'citizen-email': self.citizen.email, 'citizen-firstname': self.citizen.first_name, 'citizen-lastname': self.citizen.last_name, 'citizen-quality': '1', 'report-terms_of_use_validated': True }
class GroupsTest(FMSTestCase): def setUp(self): self.manager = FMSUser( is_active=True, telephone="0123456789", last_used_language="fr", password='******', first_name="manager", last_name="manager", email="*****@*****.**", manager=True ) self.manager.set_password('test') self.manager.organisation = OrganisationEntity.objects.get(pk=14) self.manager.save() self.leader = FMSUser( is_active=True, telephone="0123456789", last_used_language="fr", password='******', first_name="leader", last_name="leader", email="*****@*****.**", manager=True, leader=True ) self.leader.set_password('test') self.leader.organisation = OrganisationEntity.objects.get(pk=14) self.leader.save() self.group1 = OrganisationEntity( name_fr="groupe1", name_nl="groep1", phone="00000000", email="*****@*****.**", type='D', dependency=OrganisationEntity.objects.get(pk=14) ) self.group1.save() self.group_mail_config1 = GroupMailConfig() self.group_mail_config1.group = self.group1 self.group_mail_config1.save() self.group2 = OrganisationEntity( name_fr="groupe2", name_nl="groep2", phone="00000000", email="*****@*****.**", type='D', dependency=OrganisationEntity.objects.get(pk=11) ) self.group2.save() self.group_mail_config2 = GroupMailConfig() self.group_mail_config2.group = self.group2 self.group_mail_config2.save() self.creategroup_post = { 'name_fr': 'groupe3', 'name_nl': 'groep3', 'phone': '0000000000', 'email': '*****@*****.**', 'type': 'D', 'notify_group': True } self.creategroup_post2 = { 'name_fr': 'groupe4', 'name_nl': 'groep4', 'phone': '0000000000', 'email': '*****@*****.**', 'type': 'S', 'notify_group': True } self.editgroup_post = { 'name_fr': 'groupe1nouveau', 'name_nl': 'groep1nieuw', 'phone': '111111', 'email': '*****@*****.**', 'type': 'D', ### Mail Config ### 'groupmailconfig-TOTAL_FORMS' : u'1', 'groupmailconfig-INITIAL_FORMS' : u'1', 'groupmailconfig-MAX_NUM_FORMS' : u'1', 'groupmailconfig-0-notify_group' : True, 'groupmailconfig-0-notify_members' : True, 'groupmailconfig-0-digest_created' : True, 'groupmailconfig-0-digest_inprogress' : True, 'groupmailconfig-0-digest_closed' : True, 'groupmailconfig-0-digest_other' : True, } self.editgroup_post2 = { 'name_fr': 'groupe2nouveau', 'name_nl': 'groep2nieuw', 'phone': '2222222', 'email': '*****@*****.**', 'type': 'S', } def testListGroups(self): self.client.login(username='******', password='******') response = self.client.post(reverse('list_groups'), follow=True) self.assertEquals(response.status_code, 200) self.assertTrue('groups' in response.context) self.assertTrue('can_create' in response.context) can_create = response.context['can_create'] #This user should not be able to create groups = response.context['groups'] self.assertFalse(can_create) #now check that all groups are groups of organisation should only be group1 as the other is assigned to other entity #check to see only your groups is back enabled self.assertEquals(groups.count(), 1) self.assertEquals(self.group1, groups[0]) #now do same test with leader user the result should be the same only can_create has to be true self.client.logout() self.client.login(username='******', password='******') response = self.client.post(reverse('list_groups'), follow=True) self.assertEquals(response.status_code, 200) self.assertTrue('groups' in response.context) self.assertTrue('can_create' in response.context) can_create = response.context['can_create'] #This user should not be able to create groups = response.context['groups'] self.assertTrue(can_create) #now check that all groups are groups of organisation should only be group1 as the other is assigned to other entity #test if the security to show only groups of your organisation is enabled self.assertEquals(groups.count(), 1) self.assertEquals(self.group1, groups[0]) def testCreateGroups(self): self.client.login(username='******', password='******') response = self.client.post(reverse('create_group'), self.creategroup_post) self.assertEquals(response.status_code, 302) response = self.client.post(reverse('list_groups'), follow=True) #now check if we have 2 groups and that the 2nd is group3 self.assertEquals(response.status_code, 200) self.assertTrue('groups' in response.context) self.assertTrue('can_create' in response.context) groups = response.context['groups'] can_create = response.context['can_create'] self.assertTrue(can_create) #check to see only your organisation's groups is enabled again also update the number of the element we get from the array self.assertEquals(groups.count(), 2) if groups[0].name_fr == 'groupe3': group = groups[0] else: group = groups[1] self.assertEquals(group.name_fr, 'groupe3') self.assertEquals(group.name_nl, 'groep3') self.assertEquals(group.phone, '0000000000') self.assertEquals(group.email, '*****@*****.**') self.assertEquals(group.type, 'D') self.assertEquals(group.dependency, self.leader.organisation) #now test create with user who is not leader self.client.logout() self.client.login(username='******', password='******') response = self.client.post(reverse('create_group'), self.creategroup_post2) self.assertEquals(response.status_code, 200) response = self.client.post(reverse('list_groups'), follow=True) #now check if we have 2 groups and that the 2nd is group3 self.assertEquals(response.status_code, 200) self.assertTrue('groups' in response.context) self.assertTrue('can_create' in response.context) can_create = response.context['can_create'] self.assertFalse(can_create) groups = response.context['groups'] self.assertEquals(groups.count(), 2) def testEditGroups(self): self.client.login(username='******', password='******') self.editgroup_post['groupmailconfig-0-group'] = self.group1.id self.editgroup_post['groupmailconfig-0-id'] = self.group_mail_config1.id response = self.client.post(reverse('edit_group', args=[self.group1.id]), self.editgroup_post) self.assertEquals(response.status_code, 302) response = self.client.post(reverse('list_groups'), follow=True) #now check if we have 2 groups and that the 2nd is group3 self.assertEquals(response.status_code, 200) self.assertTrue('groups' in response.context) self.assertTrue('can_create' in response.context) groups = response.context['groups'] can_create = response.context['can_create'] self.assertTrue(can_create) self.assertEquals(groups.count(), 1) self.assertEquals(groups[0].name_fr, 'groupe1nouveau') self.assertEquals(groups[0].name_nl, 'groep1nieuw') self.assertEquals(groups[0].phone, '111111') self.assertEquals(groups[0].email, '*****@*****.**') self.assertEquals(groups[0].type, 'D') self.assertEquals(groups[0].dependency, self.leader.organisation) #now do the test with a non leader self.client.logout() self.client.login(username='******', password='******') response = self.client.post(reverse('edit_group', args=[self.group1.id]), self.editgroup_post2) self.assertEquals(response.status_code, 200) response = self.client.post(reverse('list_groups'), follow=True) #now check if we have 1 group that depends of my organisation self.assertEquals(response.status_code, 200) self.assertTrue('groups' in response.context) self.assertTrue('can_create' in response.context) groups = response.context['groups'] can_create = response.context['can_create'] self.assertFalse(can_create) self.assertEquals(groups.count(), 1) #should still be the same as this user does not have the rights to update groups self.assertEquals(groups[0].name_fr, 'groupe1nouveau') self.assertEquals(groups[0].name_nl, 'groep1nieuw') self.assertEquals(groups[0].phone, '111111') self.assertEquals(groups[0].email, '*****@*****.**') self.assertEquals(groups[0].type, 'D') self.assertEquals(groups[0].dependency, self.leader.organisation) def testDeleteGroups(self): #first try to delete with user who has no permissions self.client.login(username='******', password='******') response = self.client.get(reverse('delete_group', args=[self.group1.id]), follow=True) self.assertEquals(response.status_code, 200) response = self.client.post(reverse('list_groups'), follow=True) #now check if we have 1 group that depends of my organisation self.assertEquals(response.status_code, 200) self.assertTrue('groups' in response.context) self.assertTrue('can_create' in response.context) groups = response.context['groups'] can_create = response.context['can_create'] self.assertFalse(can_create) self.assertEquals(groups.count(), 1) self.assertIn(self.group1, groups) self.client.logout() #now try to delete with user who can self.client.login(username='******', password='******') response = self.client.get(reverse('delete_group', args=[self.group1.id]), follow=True) self.assertEquals(response.status_code, 200) response = self.client.post(reverse('list_groups'), follow=True) #now check if we have 2 groups and that the 2nd is group3 self.assertEquals(response.status_code, 200) self.assertTrue('groups' in response.context) self.assertTrue('can_create' in response.context) groups = response.context['groups'] can_create = response.context['can_create'] self.assertTrue(can_create) self.assertEquals(groups.count(), 1) # not deleted, linked to categories self.assertGreater(groups[0].dispatch_categories.count(), 0) self.assertIn(self.group1, groups) group2 = OrganisationEntity( name_fr="group2", name_nl="group2", phone="00000000", email="*****@*****.**", type='D', dependency=OrganisationEntity.objects.get(pk=14) ) group2.save() response = self.client.post(reverse('list_groups'), follow=True) self.assertEquals(response.status_code, 200) self.assertTrue('groups' in response.context) groups = response.context['groups'] self.assertEquals(groups.count(), 2) self.assertEquals(group2.dispatch_categories.count(), 0) response = self.client.get(reverse('delete_group', args=[group2.id]), follow=True) self.assertEquals(response.status_code, 200) response = self.client.post(reverse('list_groups'), follow=True) #now check if we have 2 groups and that the 2nd is group3 self.assertEquals(response.status_code, 200) self.assertTrue('groups' in response.context) groups = response.context['groups'] self.assertEquals(groups.count(), 1) self.assertNotIn(group2, groups) def testAssignMemberToGroup(self): #first try to add with user who has not enough rights self.client.login(username='******', password='******') response = self.client.get(reverse('add_membership', args=[self.group1.id, self.manager.id]), follow=True) self.assertEquals(response.status_code, 200) returnobject = json.loads(str(response.content)) self.assertTrue('status' in returnobject) self.assertFalse('membership_id' in returnobject) status = returnobject['status'] self.assertEquals('Permission Denied', status) self.client.logout() self.client.login(username='******', password='******') response = self.client.get(reverse('add_membership', args=[self.group1.id, self.manager.id]), follow=True) self.assertEquals(response.status_code, 200) returnobject = json.loads(str(response.content)) self.assertTrue('status' in returnobject) self.assertTrue('membership_id' in returnobject) status = returnobject['status'] membership_id = returnobject['membership_id'] self.assertEquals('OK', status) organisationMemberShip = UserOrganisationMembership.objects.get(id=membership_id) self.assertEquals(self.manager, organisationMemberShip.user) self.assertEquals(self.group1, organisationMemberShip.organisation) def testRemoveMemberFromGroup(self): #first assign a member to a group self.client.login(username='******', password='******') response = self.client.get(reverse('add_membership', args=[self.group1.id, self.manager.id]), follow=True) self.assertEquals(response.status_code, 200) returnobject = json.loads(str(response.content)) self.assertTrue('status' in returnobject) self.assertTrue('membership_id' in returnobject) status = returnobject['status'] membership1_id = returnobject['membership_id'] self.assertEquals('OK', status) response = self.client.get(reverse('add_membership', args=[self.group1.id, self.leader.id]), follow=True) self.assertEquals(response.status_code, 200) returnobject = json.loads(str(response.content)) self.assertTrue('status' in returnobject) self.assertTrue('membership_id' in returnobject) membership2_id = returnobject['membership_id'] self.assertTrue(UserOrganisationMembership.objects.get(id=membership1_id).contact_user) self.assertFalse(UserOrganisationMembership.objects.get(id=membership2_id).contact_user) #try with user who has no rights to remove it self.client.logout() self.client.login(username='******', password='******') response = self.client.get(reverse('remove_membership', args=[membership1_id]), follow=True) self.assertEquals(response.status_code, 200) self.assertIn('Permission Denied', response.content) #now try with user who has rights to remove self.client.logout() self.client.login(username='******', password='******') response = self.client.get(reverse('remove_membership', args=[membership1_id]), follow=True) self.assertEquals(response.status_code, 200) self.assertNotIn('OK', response.content) # can not remove contact membership response = self.client.get(reverse('remove_membership', args=[membership2_id]), follow=True) self.assertEquals(response.status_code, 200) self.assertIn('OK', response.content) self.assertTrue(UserOrganisationMembership.objects.filter(id=membership1_id).exists()) self.assertFalse(UserOrganisationMembership.objects.filter(id=membership2_id).exists())
def setUp(self): self.citizen = FMSUser( telephone="0123456789", last_used_language="fr", first_name="citizen", last_name="citizen", email="*****@*****.**" ) self.citizen.save() self.manager = FMSUser( is_active=True, telephone="0123456789", last_used_language="fr", password='******', first_name="manager", last_name="manager", email="*****@*****.**", manager=True ) self.manager.set_password('test') self.manager.organisation = OrganisationEntity.objects.get(pk=14) self.manager.save() self.manager4 = FMSUser( is_active=True, telephone="0123456789", last_used_language="fr", password='******', first_name="manager4", last_name="manager4", email="*****@*****.**", manager=True ) self.manager4.set_password('test') self.manager4.organisation = OrganisationEntity.objects.get(pk=14) self.manager4.save() self.group = OrganisationEntity( type="D", name_nl="Werken", name_fr="Travaux", phone="090987", dependency=OrganisationEntity.objects.get(pk=14), email="*****@*****.**" ) self.group.save() self.group.dispatch_categories.add(ReportCategory.objects.get(pk=1)) # Mail config: notify group and members in real time self.group_mail_config = GroupMailConfig() self.group_mail_config.group = self.group self.group_mail_config.notify_group = True self.group_mail_config.notify_members = True self.group_mail_config.save() self.manager.memberships.create(organisation=self.group, contact_user=True) self.manager4.memberships.create(organisation=self.group, contact_user=True) self.client = Client() self.manager2 = FMSUser( is_active=True, telephone="9876543210", last_used_language="nl", password='******', first_name="manager2", last_name="manager2", email="*****@*****.**", manager=True ) self.manager2.set_password('test2') self.manager2.organisation = OrganisationEntity.objects.get(pk=14) self.manager2.save() self.group2 = OrganisationEntity( type="D", name_nl="Werken", name_fr="Travaux", phone="090987", dependency=OrganisationEntity.objects.get(pk=21), email="*****@*****.**" ) self.group2.save() self.group2.dispatch_categories.add(ReportCategory.objects.get(pk=2)) self.group2.dispatch_categories.add(ReportCategory.objects.get(pk=1)) # Mail config: notify group and members in real time self.group_mail_config2 = GroupMailConfig() self.group_mail_config2.group = self.group2 self.group_mail_config2.notify_group = True self.group_mail_config2.notify_members = True self.group_mail_config2.save() p1 = (148776, 171005) p2 = (150776, 171005) p3 = (150776, 169005) p4 = (148776, 169005) surface = OrganisationEntitySurface( geom=Polygon([p1, p2, p3, p4, p1]), owner=OrganisationEntity.objects.get(pk=14), ) surface.save() self.manager2.memberships.create(organisation=self.group2) self.manager3 = FMSUser( is_active=True, telephone="000000000", last_used_language="nl", password='******', first_name="manager3", last_name="manager3", email="*****@*****.**", manager=True ) self.manager3.set_password('test3') self.manager3.organisation = OrganisationEntity.objects.get(pk=21) self.manager3.save() self.manager3.memberships.create(organisation=self.group2) self.impetrant = OrganisationEntity( name_nl="MIVB", name_fr="STIB", email="*****@*****.**") self.impetrant.save() self.contractor = OrganisationEntity( name_nl="Fabricom GDF", name_fr="Fabricom GDF", email="*****@*****.**") self.contractor.save() self.sample_post = { 'report-x': '150056.538', 'report-y': '170907.56', 'report-address_fr': 'Avenue des Arts, 3', 'report-address_nl': 'Kunstlaan, 3', 'report-address_number': '3', 'report-postalcode': '1210', 'report-category': '1', 'report-secondary_category': '1', 'report-subscription': 'on', 'citizen-quality': '1', 'comment-text': 'test', 'files-TOTAL_FORMS': 0, 'files-INITIAL_FORMS': 0, 'files-MAX_NUM_FORMS': 0, 'citizen-email': self.citizen.email, 'citizen-firstname': self.citizen.first_name, 'citizen-lastname': self.citizen.last_name, 'report-terms_of_use_validated': True } self.sample_post_pro = { 'report-x': '150056.538', 'report-y': '170907.56', 'report-address_fr': 'Avenue des Arts, 3', 'report-address_nl': 'Kunstlaan, 3', 'report-address_number': '3', 'report-postalcode': '1210', 'report-category': '1', 'report-secondary_category': '1', 'report-subscription': 'on', 'comment-text': 'test', 'files-TOTAL_FORMS': 0, 'files-INITIAL_FORMS': 0, 'files-MAX_NUM_FORMS': 0, 'report-terms_of_use_validated': True } self.sample_post_mail_pdf_pro = { 'comments': 'test comment', 'visibility': 'private', 'to': '[email protected],[email protected];[email protected]' } self.sample_post_mail_pdf_citzen = { 'comments': 'test comment', 'visibility': 'public', 'to': '[email protected],[email protected];[email protected]' }
def setUp(self): self.manager = FMSUser( is_active=True, telephone="0123456789", last_used_language="fr", password='******', first_name="manager", last_name="manager", email="*****@*****.**", manager=True ) self.manager.set_password('test') self.manager.organisation = OrganisationEntity.objects.get(pk=14) self.manager.save() self.leader = FMSUser( is_active=True, telephone="0123456789", last_used_language="fr", password='******', first_name="leader", last_name="leader", email="*****@*****.**", manager=True, leader=True ) self.leader.set_password('test') self.leader.organisation = OrganisationEntity.objects.get(pk=14) self.leader.save() self.group1 = OrganisationEntity( name_fr="groupe1", name_nl="groep1", phone="00000000", email="*****@*****.**", type='D', dependency=OrganisationEntity.objects.get(pk=14) ) self.group1.save() self.group_mail_config1 = GroupMailConfig() self.group_mail_config1.group = self.group1 self.group_mail_config1.save() self.group2 = OrganisationEntity( name_fr="groupe2", name_nl="groep2", phone="00000000", email="*****@*****.**", type='D', dependency=OrganisationEntity.objects.get(pk=11) ) self.group2.save() self.group_mail_config2 = GroupMailConfig() self.group_mail_config2.group = self.group2 self.group_mail_config2.save() self.creategroup_post = { 'name_fr': 'groupe3', 'name_nl': 'groep3', 'phone': '0000000000', 'email': '*****@*****.**', 'type': 'D', 'notify_group': True } self.creategroup_post2 = { 'name_fr': 'groupe4', 'name_nl': 'groep4', 'phone': '0000000000', 'email': '*****@*****.**', 'type': 'S', 'notify_group': True } self.editgroup_post = { 'name_fr': 'groupe1nouveau', 'name_nl': 'groep1nieuw', 'phone': '111111', 'email': '*****@*****.**', 'type': 'D', ### Mail Config ### 'groupmailconfig-TOTAL_FORMS' : u'1', 'groupmailconfig-INITIAL_FORMS' : u'1', 'groupmailconfig-MAX_NUM_FORMS' : u'1', 'groupmailconfig-0-notify_group' : True, 'groupmailconfig-0-notify_members' : True, 'groupmailconfig-0-digest_created' : True, 'groupmailconfig-0-digest_inprogress' : True, 'groupmailconfig-0-digest_closed' : True, 'groupmailconfig-0-digest_other' : True, } self.editgroup_post2 = { 'name_fr': 'groupe2nouveau', 'name_nl': 'groep2nieuw', 'phone': '2222222', 'email': '*****@*****.**', 'type': 'S', }
class ApiTest(FMSTestCase): def setUp(self): try: organisation = OrganisationEntity.objects.get(id=1) except ObjectDoesNotExist: organisation = OrganisationEntity(id=1, name="Test organisation") organisation.save() p1 = (148776, 171005) p2 = (150776, 171005) p3 = (150776, 169005) p4 = (148776, 169005) surface = OrganisationEntitySurface( geom=Polygon([p1, p2, p3, p4, p1]), owner=OrganisationEntity.objects.get(pk=14)) surface.save() #user_auth = User.objects.create_user(username='******', email='*****@*****.**', password='******') #user_auth.save() user = FMSUser(is_active=True, password="******", email="*****@*****.**", first_name="zaza", telephone="00000000", last_used_language="fr", organisation=organisation, username='******') user.save() #~ main_category = ReportMainCategoryClass(id=2,name_en='test main en',name_nl='test main nl',name_fr='test main fr') #~ main_category.save() #~ #~ secondary_category = ReportSecondaryCategoryClass(id=2,name_en='test second en',name_nl='test second nl',name_fr='test second fr') #~ secondary_category.save() #~ #~ category = ReportCategory(id=2,name_en='test parent en',name_nl='test parent nl',name_fr='test parent fr', public=True, category_class=main_category, secondary_category_class=secondary_category) #~ category.save() self.citizen = FMSUser(telephone="0123456789", last_used_language="fr", first_name="citizen", last_name="citizen", email="*****@*****.**") self.citizen.save() self.manager = FMSUser(is_active=True, telephone="0123456789", last_used_language="fr", password='******', first_name="manager", last_name="manager", email="*****@*****.**", manager=True) self.manager.set_password('test') self.manager.organisation = OrganisationEntity.objects.get(pk=14) self.manager.save() self.group = OrganisationEntity( type="D", name_nl="Werken", name_fr="Travaux", phone="090987", dependency=OrganisationEntity.objects.get(pk=14), email="*****@*****.**") self.group.save() self.group_mail_config = GroupMailConfig() self.group_mail_config.group = self.group self.group_mail_config.save() self.usergroupmembership = UserOrganisationMembership( user_id=self.manager.id, organisation_id=self.group.id, contact_user=True) self.usergroupmembership.save() self.sample_post = { 'report-x': '150056.538', 'report-y': '170907.56', 'report-address_fr': 'Avenue des Arts, 3', 'report-address_nl': 'Kunstlaan, 3', 'report-address_number': '3', 'report-postalcode': '1210', 'report-category': '1', 'report-secondary_category': '1', 'report-subscription': 'on', 'report-terms_of_use_validated': True, 'comment-text': 'test', 'files-TOTAL_FORMS': 0, 'files-INITIAL_FORMS': 0, 'files-MAX_NUM_FORMS': 1000, 'citizen-quality': '1', 'citizen-email': self.citizen.email, 'citizen-firstname': self.citizen.first_name, 'citizen-lastname': self.citizen.last_name } def testCreateReportCitizen(self): #Create a client to launch requests client = Client() #Get the request response response = client.post(reverse('create_report_citizen'), self.sample_post, follow=True) #Test the http response code (200 = OK) self.assertEqual(response.status_code, 200) #Test if the response if JSON structured. self.assertEqual(response['Content-Type'], 'application/json; charset=utf-8') self.assertEqual(1, len(Report.objects.all())) #Load the response data as JSON object result = json.loads(response.content) # Get in the DB the created report report = Report.objects.get(id=result['id']) # Check that source is correct self.assertEqual(Report.SOURCES['MOBILE'], report.source) def testCreateReportDoubleCitizen(self): #Parameters to save the report in database. #Create a client to launch requests client = Client() #Get the request response response = client.post(reverse('create_report_citizen'), self.sample_post, follow=True) response = client.post(reverse('create_report_citizen'), self.sample_post, follow=True) response = client.post(reverse('create_report_citizen'), self.sample_post, follow=True) response = client.post(reverse('create_report_citizen'), self.sample_post, follow=True) self.assertEqual(1, len(Report.objects.all())) #Load the response data as JSON object result = json.loads(response.content) def testCreateReportPro(self): self.sample_post['username'] = self.manager.username self.sample_post['password'] = '******' #Create a client to launch requests client = Client() #Get the request response response = client.post('/fr/api/login/', { 'username': self.manager.username, 'password': '******' }, follow=True) self.assertEqual(response.status_code, 200) #Load the response data as JSON object result = json.loads(response.content) self.assertIn('email', result) response = client.post(reverse('create_report_citizen'), self.sample_post, follow=True) #Test the http response code (200 = OK) self.assertEqual(response.status_code, 200) #Test if the response if JSON structured. self.assertEqual(response['Content-Type'], 'application/json; charset=utf-8') #Load the response data as JSON object result = json.loads(response.content) #Verify if the report_id is returned by the webservice self.assertTrue(result['id']) #Get in the DB the created report report = Report.objects.get(id=result['id']) #Verify the persisted data for the new created report self.assertEquals(report.address, self.sample_post['report-address_fr']) self.assertTrue(report.is_pro()) # Check that source is correct self.assertEqual(Report.SOURCES['MOBILE'], report.source) def testCreateReportDoublePro(self): self.sample_post['username'] = self.manager.username self.sample_post['password'] = '******' #Create a client to launch requests client = Client() #Get the request response client.post(reverse('create_report_citizen'), self.sample_post, follow=True) client.post(reverse('create_report_citizen'), self.sample_post, follow=True) client.post(reverse('create_report_citizen'), self.sample_post, follow=True) client.post(reverse('create_report_citizen'), self.sample_post, follow=True) self.assertEqual(1, len(Report.objects.all())) def testLoadCategories(self): #Parameters to save the report in database. params = {"user_name": "superuser"} #Create a client to launch requests client = Client() #Get the request response response = client.get(reverse('load_categories'), params, follow=True) #Test the http response code (200 = OK) self.assertEqual(response.status_code, 200) #Test if the response if JSON structured. self.assertEqual(response['Content-Type'], 'application/json') #Load the response data as JSON object result = json.loads(response.content) def test_login_user(self): params = {'username': self.manager.email, 'password': '******'} response = self.client.post(reverse('login_user'), params) self.assertEqual(response.status_code, 200) result = json.loads(response.content) self.assertEqual(result['id'], self.manager.id) self.assertEqual(result['first_name'], self.manager.first_name) def test_login_user_fail(self): params = {'username': self.manager.email, 'password': '******'} response = self.client.post(reverse('login_user'), params) self.assertEqual(response.status_code, 403) result = json.loads(response.content) self.assertEqual("ERROR_LOGIN_INVALID_PARAMETERS", result["error_key"]) def test_login_user_fail_empty_field(self): params = {'username': self.manager.email} response = self.client.post(reverse('login_user'), params) self.assertEqual(response.status_code, 400) result = json.loads(response.content) self.assertEqual("ERROR_LOGIN_INVALID_PARAMETERS", result["error_key"]) def test_login_user_bad_username(self): params = {'username': "******", 'password': "******"} response = self.client.post(reverse('login_user'), params) self.assertEqual(response.status_code, 403) result = json.loads(response.content) self.assertEqual("ERROR_LOGIN_INVALID_PARAMETERS", result["error_key"]) def test_logout_user(self): response = self.client.post(reverse('logout_user')) self.assertEqual(response.status_code, 200) self.assertEqual('', response.content)
class ReopenRequestTest(FMSTestCase): def setUp(self): self.citizen = FMSUser(telephone="0123456789", last_used_language="fr", first_name="citizen", last_name="citizen", email="*****@*****.**") self.citizen.save() self.manager = FMSUser(is_active=True, telephone="0123456789", last_used_language="fr", password='******', first_name="manager", last_name="manager", email="*****@*****.**", manager=True) self.manager.set_password('test') self.manager.organisation = OrganisationEntity.objects.get(pk=14) self.manager.save() self.group = OrganisationEntity( type="D", name_nl="Werken", name_fr="Travaux", phone="090987", dependency=OrganisationEntity.objects.get(pk=14), email="*****@*****.**") self.group.save() self.group.dispatch_categories.add(ReportCategory.objects.get(pk=1)) self.group_mail_config = GroupMailConfig() self.group_mail_config.group = self.group self.group_mail_config.save() self.manager.memberships.create(organisation=self.group, contact_user=True) self.client = Client() self.manager2 = FMSUser(is_active=True, telephone="9876543210", last_used_language="nl", password='******', first_name="manager2", last_name="manager2", email="*****@*****.**", manager=True) self.manager2.set_password('test2') self.manager2.organisation = OrganisationEntity.objects.get(pk=14) self.manager2.save() self.group2 = OrganisationEntity( type="D", name_nl="Werken", name_fr="Travaux", phone="090987", dependency=OrganisationEntity.objects.get(pk=21), email="*****@*****.**") self.group2.save() self.group2.dispatch_categories.add(ReportCategory.objects.get(pk=2)) self.group2.dispatch_categories.add(ReportCategory.objects.get(pk=1)) p1 = (148776, 171005) p2 = (150776, 171005) p3 = (150776, 169005) p4 = (148776, 169005) surface = OrganisationEntitySurface( geom=Polygon([p1, p2, p3, p4, p1]), owner=OrganisationEntity.objects.get(pk=14), ) surface.save() self.manager2.memberships.create(organisation=self.group2) self.manager3 = FMSUser(is_active=True, telephone="000000000", last_used_language="nl", password='******', first_name="manager3", last_name="manager3", email="*****@*****.**", manager=True) self.manager3.set_password('test3') self.manager3.organisation = OrganisationEntity.objects.get(pk=21) self.manager3.save() self.manager3.memberships.create(organisation=self.group2) self.impetrant = OrganisationEntity(name_nl="MIVB", name_fr="STIB", email="*****@*****.**") self.impetrant.save() self.contractor = OrganisationEntity(name_nl="Fabricom GDF", name_fr="Fabricom GDF", email="*****@*****.**") self.contractor.save() self.sample_post = { 'report-x': '150056.538', 'report-y': '170907.56', 'report-address_fr': 'Avenue des Arts, 3', 'report-address_nl': 'Kunstlaan, 3', 'report-address_number': '3', 'report-postalcode': '1210', 'report-category': '1', 'report-secondary_category': '1', 'report-subscription': 'on', 'citizen-quality': '1', 'comment-text': 'test', 'files-TOTAL_FORMS': 0, 'files-INITIAL_FORMS': 0, 'files-MAX_NUM_FORMS': 0, 'citizen-email': self.citizen.email, 'citizen-firstname': self.citizen.first_name, 'citizen-lastname': self.citizen.last_name, 'report-terms_of_use_validated': True } ##### Following data was created specifically for the reopen_request tests ####### self.citizen_reopen_request = FMSUser( telephone="987654321", last_used_language="fr", first_name="citizen_reopen_request", last_name="citizen_reopen_request", email="*****@*****.**") self.citizen_reopen_request.save() self.sample_post_reopen_request_pro = { 'reopen-text': 'this is the reopen request comment', 'reopen-reason': 1 } self.sample_post_reopen_request = { 'reopen-text': 'this is the reopen request comment', 'reopen-reason': 1, 'citizen-quality': 2, 'citizen-email': self.citizen_reopen_request.email, 'citizen-telephone': self.citizen_reopen_request.telephone, 'citizen-last_name': self.citizen_reopen_request.last_name, } def testReopenRequestMailByPro(self): # New report response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post, follow=True) report = response.context['report'] # Set status to Processed report.status = Report.PROCESSED report.close_date = datetime.now() report.save() # Login to access the pro page self.client.login(username='******', password='******') # Request reopen report response = self.client.post(reverse('report_reopen_request_pro', args=["hello", report.id]), self.sample_post_reopen_request_pro, follow=True) #check redirect url_redirect = reverse('report_show_pro', args=[report.get_slug(), report.id]) self.assertRedirects(response, url_redirect, status_code=302, target_status_code=200) #test there is a message success_msg = str(list(response.context["messages"])[0]) self.assertEqual(success_msg, str(gettext(SUCCESS_MSG_REOPEN_REQUEST_CONFIRM))) # Fetch activities activities = report.activities.all() # Assert self.assertEqual(activities.count(), 3) self.assertEquals(ReportEventLog.REOPEN_REQUEST, activities[2].event_type) def testReopenRequestMailByCitizen(self): # New report response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post, follow=True) report = response.context['report'] # Set status to Processed report.status = Report.PROCESSED report.close_date = datetime.now() report.save() # Request reopen report response = self.client.post(reverse('report_reopen_request', args=["hello", report.id]), self.sample_post_reopen_request, follow=True) url = reverse('report_show2', args=[report.id]) self.assertRedirects(response, url, status_code=302, target_status_code=200) #test there is a message success_msg = str(list(response.context["messages"])[0]) self.assertEqual(success_msg, str(gettext(SUCCESS_MSG_REOPEN_REQUEST_CONFIRM))) # Fetch activities activities = report.activities.all() # Assert self.assertEqual(activities.count(), 3) self.assertEquals(ReportEventLog.REOPEN_REQUEST, activities[2].event_type) #Test that you cannot access the page if you don't have status closed. (Should be tested with all status def testReopenRequestOnlyForProcessed(self): # New report response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post, follow=True) report = response.context['report'] comment = ReportComment(report_id=report.id, text='test', type=3) comment.save() # Set status to IN_PROGRESS (we want a status different that report.status = Report.IN_PROGRESS report.close_date = datetime.now() report.save() # Request reopen report response = self.client.post(reverse('report_reopen_request', args=["hello", report.id]), self.sample_post_reopen_request, follow=True) url = reverse('report_show2', args=[report.id]) self.assertRedirects(response, url, status_code=302, target_status_code=200) error_msg = str(list(response.context["messages"])[0]) self.assertEqual(error_msg, str(gettext(ERROR_MSG_REOPEN_REQUEST_ONLY_CLOSED))) # Fetch activities activities = report.activities.all() # Assert self.assertEqual(activities.count(), 2) self.assertEquals(ReportEventLog.VALID, activities[1].event_type ) #this can't be ReportEventLog.REOPEN_REQUEST def testReopenRequestNotAfter90Days(self): # New report response = self.client.post(reverse('report_new') + '?x=150056.538&y=170907.56', self.sample_post, follow=True) report = response.context['report'] #limit date is 90 days. let's check a report closed 91 days ago report.status = Report.PROCESSED limit_date_plus_one = datetime.now() - timedelta(days=91) report.close_date = limit_date_plus_one report.save() # Request reopen report response = self.client.post(reverse('report_reopen_request', args=["hello", report.id]), self.sample_post_reopen_request, follow=True) url = reverse('report_show2', args=[report.id]) self.assertRedirects(response, url, status_code=302, target_status_code=200) error_msg = str(list(response.context["messages"])[0]) self.assertEqual(error_msg, str(gettext(ERROR_MSG_REOPEN_REQUEST_90_DAYS))) # Fetch activities activities = report.activities.all() # Assert self.assertEqual(activities.count(), 2) self.assertEquals(ReportEventLog.CLOSE, activities[1].event_type)
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 setUp(self): self.citizen = FMSUser(telephone="0123456789", last_used_language="fr", first_name="citizen", last_name="citizen", email="*****@*****.**") self.citizen.save() self.manager = FMSUser(is_active=True, telephone="0123456789", last_used_language="fr", password='******', first_name="manager", last_name="manager", email="*****@*****.**", manager=True) self.manager.set_password('test') self.manager.organisation = OrganisationEntity.objects.get(pk=14) self.manager.save() self.group = OrganisationEntity( type="D", name_nl="Werken", name_fr="Travaux", phone="090987", dependency=OrganisationEntity.objects.get(pk=14), email="*****@*****.**") self.group.save() self.group.dispatch_categories.add(ReportCategory.objects.get(pk=1)) self.group_mail_config = GroupMailConfig() self.group_mail_config.group = self.group self.group_mail_config.save() self.manager.memberships.create(organisation=self.group, contact_user=True) self.client = Client() self.manager2 = FMSUser(is_active=True, telephone="9876543210", last_used_language="nl", password='******', first_name="manager2", last_name="manager2", email="*****@*****.**", manager=True) self.manager2.set_password('test2') self.manager2.organisation = OrganisationEntity.objects.get(pk=14) self.manager2.save() self.group2 = OrganisationEntity( type="D", name_nl="Werken", name_fr="Travaux", phone="090987", dependency=OrganisationEntity.objects.get(pk=21), email="*****@*****.**") self.group2.save() self.group2.dispatch_categories.add(ReportCategory.objects.get(pk=2)) self.group2.dispatch_categories.add(ReportCategory.objects.get(pk=1)) p1 = (148776, 171005) p2 = (150776, 171005) p3 = (150776, 169005) p4 = (148776, 169005) surface = OrganisationEntitySurface( geom=Polygon([p1, p2, p3, p4, p1]), owner=OrganisationEntity.objects.get(pk=14), ) surface.save() self.manager2.memberships.create(organisation=self.group2) self.manager3 = FMSUser(is_active=True, telephone="000000000", last_used_language="nl", password='******', first_name="manager3", last_name="manager3", email="*****@*****.**", manager=True) self.manager3.set_password('test3') self.manager3.organisation = OrganisationEntity.objects.get(pk=21) self.manager3.save() self.manager3.memberships.create(organisation=self.group2) self.impetrant = OrganisationEntity(name_nl="MIVB", name_fr="STIB", email="*****@*****.**") self.impetrant.save() self.contractor = OrganisationEntity(name_nl="Fabricom GDF", name_fr="Fabricom GDF", email="*****@*****.**") self.contractor.save() self.sample_post = { 'report-x': '150056.538', 'report-y': '170907.56', 'report-address_fr': 'Avenue des Arts, 3', 'report-address_nl': 'Kunstlaan, 3', 'report-address_number': '3', 'report-postalcode': '1210', 'report-category': '1', 'report-secondary_category': '1', 'report-subscription': 'on', 'citizen-quality': '1', 'comment-text': 'test', 'files-TOTAL_FORMS': 0, 'files-INITIAL_FORMS': 0, 'files-MAX_NUM_FORMS': 0, 'citizen-email': self.citizen.email, 'citizen-firstname': self.citizen.first_name, 'citizen-lastname': self.citizen.last_name, 'report-terms_of_use_validated': True } ##### Following data was created specifically for the reopen_request tests ####### self.citizen_reopen_request = FMSUser( telephone="987654321", last_used_language="fr", first_name="citizen_reopen_request", last_name="citizen_reopen_request", email="*****@*****.**") self.citizen_reopen_request.save() self.sample_post_reopen_request_pro = { 'reopen-text': 'this is the reopen request comment', 'reopen-reason': 1 } self.sample_post_reopen_request = { 'reopen-text': 'this is the reopen request comment', 'reopen-reason': 1, 'citizen-quality': 2, 'citizen-email': self.citizen_reopen_request.email, 'citizen-telephone': self.citizen_reopen_request.telephone, 'citizen-last_name': self.citizen_reopen_request.last_name, }
def setUp(self): self.user = FMSUser(username='******', email='*****@*****.**', password='******') self.user.save() self.client = Client() self.citizen = FMSUser(telephone="0123456789", last_used_language="fr", first_name="citizen", last_name="citizen", email="*****@*****.**") self.citizen.save() self.group = OrganisationEntity( type="D", name_nl="Werken", name_fr="Travaux", phone="090987", dependency=OrganisationEntity.objects.get(pk=14), email="*****@*****.**") self.group.save() self.group_mail_config = GroupMailConfig() self.group_mail_config.group = self.group self.group_mail_config.save() self.manager = FMSUser(is_active=True, telephone="0123456789", last_used_language="fr", password='******', first_name="manager", last_name="manager", email="*****@*****.**", manager=True) self.manager.set_password('test') self.manager.organisation = OrganisationEntity.objects.get(pk=14) self.manager.save() self.group.dispatch_categories.add(ReportCategory.objects.get(pk=1)) p1 = (148776, 171005) p2 = (150776, 171005) p3 = (150776, 169005) p4 = (148776, 169005) surface = OrganisationEntitySurface( geom=Polygon([p1, p2, p3, p4, p1]), owner=OrganisationEntity.objects.get(pk=14), ) surface.save() self.manager.memberships.create(organisation=self.group, contact_user=True) self.sample_post = { 'report-x': '150056.538', 'report-y': '170907.56', 'report-address_fr': 'Avenue des Arts, 3', 'report-address_nl': 'Kunstlaan, 3', 'report-address_number': '3', 'report-postalcode': '1210', 'report-category': '1', 'report-secondary_category': '1', 'report-subscription': 'on', 'comment-text': 'test', 'files-TOTAL_FORMS': 0, 'files-INITIAL_FORMS': 0, 'files-MAX_NUM_FORMS': 0, 'citizen-email': self.citizen.email, 'citizen-firstname': self.citizen.first_name, 'citizen-lastname': self.citizen.last_name, 'citizen-quality': '1', 'report-terms_of_use_validated': True } self.sample_post_2 = { 'report-x': '150056', 'report-y': '170907.56', 'report-address_fr': 'Avenue des Arts, 3', 'report-address_nl': 'Kunstlaan, 3', 'report-address_number': '5', 'report-postalcode': '1210', 'report-category': '1', 'report-secondary_category': '1', 'report-subscription': 'on', 'comment-text': 'test2', 'files-TOTAL_FORMS': 0, 'files-INITIAL_FORMS': 0, 'files-MAX_NUM_FORMS': 0, 'citizen-email': self.citizen.email, 'citizen-firstname': self.citizen.first_name, 'citizen-lastname': self.citizen.last_name, 'citizen-quality': '1', 'report-terms_of_use_validated': True }
class ExportPDFTest(FMSTestCase): def setUp(self): self.bxl = OrganisationEntity.objects.get(id=4) self.manager_bxl = FMSUser(is_active=True, email="*****@*****.**", telephone="0123456789", last_used_language="fr", manager=True, organisation=self.bxl) self.manager_bxl.set_password('test') self.manager_bxl.save() self.group = OrganisationEntity(type="D", name_nl="Werken", name_fr="Travaux", phone="090987", dependency=self.bxl, email="*****@*****.**") self.group.save() self.group_mail_config = GroupMailConfig() self.group_mail_config.group = self.group self.group_mail_config.save() self.usergroupmembership = UserOrganisationMembership( user_id=self.manager_bxl.id, organisation_id=self.group.id, contact_user=True) self.usergroupmembership.save() self.citizen = FMSUser(email="*****@*****.**", telephone="0123456789", last_used_language="fr") self.citizen.save() self.secondary_category = ReportCategory.objects.all()[0] self.category = self.secondary_category.category_class self.client.login(username=self.manager_bxl.email, password='******') self.report = Report(status=Report.CREATED, secondary_category=self.secondary_category, category=self.category, description='Just a test', postalcode=1000, address='my address', point=dict_to_point({ "x": '149776', "y": '170005' }), address_number='6h', created_by=self.manager_bxl) self.report.save() self.report.attachments.add( ReportComment(text='test comment 1', security_level=ReportComment.PRIVATE)) self.client.logout() self.report.attachments.add( ReportComment(text='test comment 2', security_level=ReportComment.PUBLIC)) self.report.attachments.add( ReportComment(text='test comment 3', logical_deleted=True, security_level=ReportComment.PUBLIC)) self.client = Client() def test_pdf_attachment(self): response = self.client.get( reverse('report_pdf', args=[self.report.id]) + '?output=html', follow=True) self.assertEqual(response.status_code, 200) self.assertIn('comments', response.context) self.assertEqual(len(response.context['comments']), 1) self.assertEqual(response.context['comments'][0].text, 'test comment 2') self.assertEqual(response.context['visibility'], 'public') def test_attachment_private(self): self.assertTrue( self.client.login(username=self.manager_bxl.email, password='******')) response = self.client.get( reverse('report_pdf_pro', args=[self.report.id]) + '?output=html', follow=True) self.assertEqual(response.status_code, 200) self.assertTrue(hasattr(response.context['request'], 'fmsuser')) self.assertIn('comments', response.context) self.assertEqual(len(response.context['comments']), 2) self.assertEqual(response.context['comments'][0].text, 'test comment 1') self.assertEqual(response.context['comments'][1].text, 'test comment 2') self.assertEqual(response.context['visibility'], 'private') def test_show_attachment(self): response = self.client.get(reverse('report_show', kwargs={ 'report_id': self.report.id, 'slug': '' }), follow=True) self.assertEqual(response.status_code, 200) self.assertNotContains(response, 'test comment 1') self.assertContains(response, 'test comment 2') self.assertNotContains(response, 'test comment 3') def test_show_attachment_private(self): self.assertTrue( self.client.login(username=self.manager_bxl.email, password='******')) response = self.client.get(reverse('report_show_pro', kwargs={ 'report_id': self.report.id, 'slug': '' }), follow=True) self.assertEqual(response.status_code, 200) self.assertContains(response, 'test comment 1') self.assertContains(response, 'test comment 2') self.assertNotContains(response, 'test comment 3')