Ejemplo n.º 1
0
    def test_public_name_isset(self):
        """
        An empty public_name (None) must fallback to the name
        """
        parent_category = ParentCategoryFactory.create()
        child_category = CategoryFactory.create(parent=parent_category,
                                                public_name='test',
                                                is_public_accessible=True)
        SignalFactoryValidLocation.create(
            category_assignment__category=child_category)

        response = self.client.get(
            f'{self.geography_endpoint}/?maincategory_slug={parent_category.slug}'
            f'&category_slug={child_category.slug}&bbox=4.700000,52.200000,5.000000,52.500000'
        )
        self.assertEqual(200, response.status_code)
        self.assertEqual(1, int(response.headers['X-Total-Count']))

        data = response.json()
        self.assertEqual(1, len(data['features']))
        self.assertEqual(child_category.public_name,
                         data['features'][0]['properties']['category']['name'])
        self.assertNotEqual(
            child_category.name,
            data['features'][0]['properties']['category']['name'])
Ejemplo n.º 2
0
    def test_only_main_category_filter(self):
        """
        unit test to only filter items with the main category
        create 5 signals and only 3 under the main category 'trash' that should be returned
        """
        parent_cat = ParentCategoryFactory.create(name='trash')
        child_category = CategoryFactory.create(parent=parent_cat,
                                                public_name='',
                                                is_public_accessible=True)
        child_category_2 = CategoryFactory.create(parent=parent_cat,
                                                  public_name='',
                                                  is_public_accessible=True)

        SignalFactoryValidLocation.create(
            category_assignment__category=child_category)
        SignalFactoryValidLocation.create(
            category_assignment__category=child_category)
        SignalFactoryValidLocation.create(
            category_assignment__category=child_category_2)

        parent_cat_2 = ParentCategoryFactory.create(name='animal')
        child_animal = CategoryFactory.create(parent=parent_cat_2,
                                              public_name='',
                                              is_public_accessible=True)
        SignalFactoryValidLocation.create(
            category_assignment__category=child_animal)
        SignalFactoryValidLocation.create(
            category_assignment__category=child_animal)

        response = self.client.get(
            f'{self.geography_endpoint}/?bbox=4.700000,52.200000,5.000000,52.500000&'
            f'maincategory_slug={parent_cat.slug}')

        data = response.json()
        self.assertEqual(3, len(data['features']))
Ejemplo n.º 3
0
    def test_get_geojson(self):
        """
        Return the GEOJson containing all signals in the child category
        """
        parent_category = ParentCategoryFactory.create()
        child_category = CategoryFactory.create(
            parent=parent_category,
            public_name='Public category for testing',
            is_public_accessible=True)

        now = timezone.now()
        for x in range(5):
            with (freeze_time(now - timedelta(days=x))):
                SignalFactoryValidLocation.create(
                    category_assignment__category=child_category)

        response = self.client.get(
            f'{self.geography_endpoint}/?maincategory_slug={parent_category.slug}'
            f'&category_slug={child_category.slug}&bbox=4.700000,52.200000,5.000000,52.500000'
        )
        self.assertEqual(200, response.status_code)
        self.assertEqual(5, int(response.headers['X-Total-Count']))

        data = response.json()
        self.assertEqual(5, len(data['features']))

        for feature in data['features']:
            self.assertEqual(feature['properties']['category']['name'],
                             child_category.public_name)
Ejemplo n.º 4
0
    def test_with_signal_for_message_wrong_state(self):
        signal = SignalFactoryValidLocation.create()
        self.assertEqual(Signal.objects.count(), 1)

        incoming_msg = render_to_string('sigmax/actualiseerZaakstatus_Lk01.xml', {
            'signal': signal,
            'tijdstipbericht': '20180927100000',
            'resultaat_omschrijving': 'HALLO',
        })

        # authenticate
        self.client.force_authenticate(user=self.superuser)

        # call our SOAP endpoint
        response = self.client.post(
            SOAP_ENDPOINT, data=incoming_msg, HTTP_SOAPACTION=ACTUALISEER_ZAAK_STATUS,
            content_type='text/xml',
        )

        self.assertEqual(response.status_code, 500)
        self.assertIn(str(signal.sia_id), response.content.decode('utf-8', 'strict'))
        self.assertIn('Fo03', response.content.decode('utf-8', 'strict'))

        last_update = History.objects.filter(_signal__id=signal.pk).order_by('-when').first()
        self.assertEqual(last_update.what, 'CREATE_NOTE')
        self.assertTrue(last_update.description.startswith(
            'Zaak status update ontvangen van CityControl terwijl SIA melding niet in verzonden staat was.'))  # noqa
Ejemplo n.º 5
0
    def test_lon_lat_parameters(self):
        """
        Return the GEOJson containing all signals in the child category
        """
        parent_category = ParentCategoryFactory.create()
        child_category = CategoryFactory.create(
            parent=parent_category,
            public_name='Public category for testing',
            is_public_accessible=True)

        signal = SignalFactoryValidLocation.create(
            category_assignment__category=child_category)
        lon = signal.location.geometrie.x
        lat = signal.location.geometrie.y

        response = self.client.get(
            f'{self.geography_endpoint}/?maincategory_slug={parent_category.slug}'
            f'&category_slug={child_category.slug}&lon={lon}&lat={lat}')

        self.assertEqual(200, response.status_code)
        self.assertEqual(1, int(response.headers['X-Total-Count']))

        data = response.json()
        self.assertEqual(1, len(data['features']))

        for feature in data['features']:
            self.assertEqual(feature['properties']['category']['name'],
                             child_category.public_name)
    def test_generate_voegZaakdocumentToe_Lk01(self):
        signal = SignalFactoryValidLocation.create()
        seq_no = _generate_sequence_number(signal)
        xml_message = _generate_voegZaakdocumentToe_Lk01(signal, seq_no)
        self.assertXmlDocument(xml_message)

        self.assertIn(
            f'<ZKN:identificatie>{signal.sia_id}.{seq_no}</ZKN:identificatie>',
            xml_message)
Ejemplo n.º 7
0
    def test_only_category_filter(self):
        """
        unit test to only filter items with the category
        create 3 signals and only 2 signals with the category 'plastic_trash"
        """
        cat1 = ParentCategoryFactory.create(name='trash')
        plastic = CategoryFactory.create(parent=cat1,
                                         public_name='plastic_trash',
                                         is_public_accessible=True)
        compost = CategoryFactory.create(parent=cat1,
                                         public_name='compost_trash',
                                         is_public_accessible=True)

        SignalFactoryValidLocation.create(
            category_assignment__category=plastic)
        SignalFactoryValidLocation.create(
            category_assignment__category=plastic)

        SignalFactoryValidLocation.create(
            category_assignment__category=compost)

        response = self.client.get(
            f'{self.geography_endpoint}/?bbox=4.700000,52.200000,5.000000,52.500000&'
            f'category_slug={plastic.slug}')

        data = response.json()
        self.assertEqual(2, len(data['features']))
Ejemplo n.º 8
0
    def test_with_signal_for_message_correct_state_no_resultaat_toelichting(
            self):
        signal = SignalFactoryValidLocation.create()
        signal.status.state = workflow.VERZONDEN
        signal.status.save()
        signal.refresh_from_db()

        self.assertEqual(Signal.objects.count(), 1)

        incoming_context = {
            'signal': signal,
            'tijdstipbericht': '20180927100000',
            'resultaat_omschrijving': 'Op locatie geweest, niets aangetroffen',
            'resultaat_toelichting':
            '',  # is translated to 'reden' upon reception
            'resultaat_datum': '2018101111485276',
        }
        incoming_msg = render_to_string(
            'sigmax/actualiseerZaakstatus_Lk01.xml', incoming_context)

        # authenticate
        self.client.force_authenticate(user=self.superuser)

        # call our SOAP endpoint
        response = self.client.post(
            SOAP_ENDPOINT,
            data=incoming_msg,
            HTTP_SOAPACTION=ACTUALISEER_ZAAK_STATUS,
            content_type='text/xml',
        )

        self.assertEqual(response.status_code, 200)
        self.assertIn(str(signal.sia_id),
                      response.content.decode('utf-8', 'strict'))
        self.assertIn('Bv03', response.content.decode('utf-8', 'strict'))

        signal.refresh_from_db()
        self.assertEqual(signal.status.state, workflow.AFGEHANDELD_EXTERN)
        self.assertEqual(
            signal.status.text,
            'Op locatie geweest, niets aangetroffen: Geen reden aangeleverd vanuit THOR'
        )
        self.assertEqual(
            signal.status.extra_properties, {
                'sigmax_datum_afgehandeld':
                incoming_context['resultaat_datum'],
                'sigmax_resultaat': incoming_context['resultaat_omschrijving'],
                'sigmax_reden': incoming_context['resultaat_toelichting'],
            })
        self.assertEqual(signal.status.state, workflow.AFGEHANDELD_EXTERN)
        self.assertEqual(signal.status.state, workflow.AFGEHANDELD_EXTERN)
Ejemplo n.º 9
0
    def setUp(self):
        self.signal = SignalFactoryValidLocation.create()

        self.sia_read_write_user.user_permissions.add(
            Permission.objects.get(codename='sia_can_view_all_categories'))
        self.client.force_authenticate(user=self.sia_read_write_user)

        # 2 templates for the special cases where there are URL's in the body. All other templates will use the fallback
        EmailTemplate.objects.create(
            key=EmailTemplate.SIGNAL_STATUS_CHANGED_AFGEHANDELD,
            title='Uw melding {{ signal_id }}'
            f' {EmailTemplate.SIGNAL_STATUS_CHANGED_AFGEHANDELD}',
            body=
            '{{ text }} {{ created_at }} {{ status_text }} {{ positive_feedback_url }} '
            '{{ negative_feedback_url }}{{ ORGANIZATION_NAME }}')
        EmailTemplate.objects.create(
            key=EmailTemplate.SIGNAL_STATUS_CHANGED_REACTIE_GEVRAAGD,
            title='Uw melding {{ signal_id }}'
            f' {EmailTemplate.SIGNAL_STATUS_CHANGED_REACTIE_GEVRAAGD}',
            body=
            '{{ text }} {{ created_at }} {{ status_text }} {{ reaction_url }} '
            '{{ ORGANIZATION_NAME }}')
Ejemplo n.º 10
0
    def test_no_category_filters(self):
        """
        Get all the signals when no category is set
        """
        cat1 = ParentCategoryFactory.create(name='trash')

        SignalFactoryValidLocation.create(category_assignment__category=cat1)

        cat2 = ParentCategoryFactory.create(name='animals')
        SignalFactoryValidLocation.create(category_assignment__category=cat2)
        SignalFactoryValidLocation.create(category_assignment__category=cat2)

        response = self.client.get(
            f'{self.geography_endpoint}/?bbox=4.700000,52.200000,5.000000,52.500000'
        )

        data = response.json()
        self.assertEqual(3, len(data['features']))
Ejemplo n.º 11
0
 def setUp(self):
     self.signal: Signal = SignalFactoryValidLocation.create(
         incident_date_start=timezone.now() - timedelta(days=1),
         incident_date_end=timezone.now())
     self.seq_no = _generate_sequence_number(self.signal)
Ejemplo n.º 12
0
 def setUp(self):
     self.endpoint_url = '/public/map-signals/'
     self.signal1 = SignalFactoryValidLocation.create()
     self.signal2 = SignalFactoryValidLocation.create()
     super().setUp()
Ejemplo n.º 13
0
    def setUp(self):
        self.signal = SignalFactoryValidLocation.create()

        # Some Signals that should not have and get any log rules during these tests
        self.signals_no_log = SignalFactoryValidLocation.create_batch(4)
 def setUp(self):
     self.signal: Signal = SignalFactoryValidLocation.create()
     self.seq_no = _generate_sequence_number(self.signal)
 def test_generate_voegZaakdocumentToe_Lk01_escaping(self):
     poison = SignalFactoryValidLocation.create()
     poison.text = '<poison>tastes nice</poison>'
     seq_no = '02'
     xml_message = _generate_voegZaakdocumentToe_Lk01(poison, seq_no)
     self.assertTrue('<poison>' not in xml_message)