def setUp(self):
        self.main_category = ParentCategoryFactory.create(name='main',
                                                          slug='main')
        self.link_main_category = '/signals/v1/public/terms/categories/main'

        self.sub_category_1 = CategoryFactory.create(name='sub1',
                                                     slug='sub1',
                                                     parent=self.main_category)
        self.link_sub_category_1 = f'{self.link_main_category}/sub_categories/sub1'

        self.sub_category_2 = CategoryFactory.create(name='sub2',
                                                     slug='sub2',
                                                     parent=self.main_category)
        self.link_sub_category_2 = f'{self.link_main_category}/sub_categories/sub2'

        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)

        self.initial_data_base = dict(
            text='Mensen in het cafe maken erg veel herrie',
            location=dict(geometrie=dict(
                type='point', coordinates=[4.90022563, 52.36768424])),
            category=dict(category_url=self.link_sub_category_1),
            reporter=dict(email='*****@*****.**'),
            incident_date_start=timezone.now().strftime('%Y-%m-%dT%H:%M'),
            source='Telefoon – ASC',
        )

        self.retrieve_signal_schema = self.load_json_schema(
            os.path.join(THIS_DIR, 'json_schema',
                         'get_signals_v1_private_signals_{pk}.json'))
Example #2
0
    def test_post_category_backwards_compatibility_style(self):
        """
        Note, this is a backwards compatibility test for changing the category "old-style" posting.
        Implementation and test should be removed after the FE is updated to "new-style" of changing
        categories.
        """
        category_name = 'Overlast op het water - snel varen'
        CategoryFactory.create(name=category_name,
                               parent__name='Overlast op het water')

        # Asserting that we don't change the category to the same value the signal object
        # already has.
        self.assertNotEqual(self.signal.category_assignment.category.name, category_name)

        url = '/signals/auth/category/'
        postjson = {
            '_signal': self.signal.id,
            'main': 'Overlast op het water',
            'sub': category_name,
        }
        response = self.client.post(url, postjson, format='json')
        self.assertEqual(response.status_code, 201)

        result = response.json()
        self.assertEqual(result['sub'], category_name)

        self.signal.refresh_from_db()

        self.assertEqual(self.signal.category_assignment.category.name, category_name)
        self.assertEqual(self.signal.category_assignment.created_by, self.superuser.username)
Example #3
0
    def setUp(self):
        self.sub_cat_1 = CategoryFactory.create()
        self.sub_cat_2 = CategoryFactory.create()

        self.s1 = SignalFactory.create(category_assignment__category=self.sub_cat_1)
        self.s2 = SignalFactory.create(category_assignment__category=self.sub_cat_2)

        # We are testing the authenticated part of the API, hence:
        self.client.force_authenticate(user=self.superuser)
    def setUp(self):
        sia_category_write_permission = Permission.objects.get(codename='sia_category_write')
        self.sia_read_write_user.user_permissions.add(sia_category_write_permission)

        self.parent_category = ParentCategoryFactory.create()

        CategoryFactory.create_batch(5, parent=self.parent_category)
        self.parent_category.refresh_from_db()

        super(TestPrivateCategoryEndpoint, self).setUp()
Example #5
0
    def setUp(self):
        self.retrieve_sub_category_question_schema = self.load_json_schema(
            os.path.join(
                THIS_DIR,
                'json_schema',
                'get_signals_v1_public_questions_categories_{slug}_sub_categories_{sub_slug}.json'
            )
        )

        question = QuestionFactory.create_batch(1)
        question2 = QuestionFactory.create_batch(1)
        self.parent_category = ParentCategoryFactory.create(questions=question2)
        CategoryFactory.create_batch(1, parent=self.parent_category, questions=question)
        self.parent_category.refresh_from_db()
        super(TestCategoryQuestionEndpoints, self).setUp()
Example #6
0
    def _create_signals(cls):
        """
        Creates SIGNALS_DISTRIBUTE_DAYS_CNT signals. One per day backwards starting from yesterday
        current time.
        Creates SIGNALS_DISTRIBUTE_HOURS_CNT signals every hour backwards from now

        If today is Friday 16:00, and SIGNALS_DISTRIBUTE_DAYS_CNT and SIGNALS_DISTRIBUTE_HOURS_CNT
        are both set to 3, we will generate the following signals:
        - Per day: Thursday (yesterday) 16:00, Wednesday (day before yesterday) 16:00, Tuesday 16:00
        - Per hour: Friday 16:00 (now), Friday 15:00 (now minus 1 hour), Friday 14:00 (now minus 2h)
        """
        now = datetime.utcnow()

        # Generate created/updated times for new signals.
        times = [now - timedelta(days=idx + 1)
                 for idx in range(cls.SIGNALS_DISTRIBUTE_DAYS_CNT)] + \
                [now - timedelta(hours=idx)
                 for idx in range(cls.SIGNALS_DISTRIBUTE_HOURS_CNT)]

        cls.states = 3 * [BEHANDELING] + 2 * [ON_HOLD] + (len(times) - 3 - 2) * [GEMELD]
        shuffle(cls.states)

        cls.sub_categories = [CategoryFactory.create() for _ in range(cls.SUBCATEGORY_CNT)]

        for idx, time in enumerate(times):
            with freeze_time(time):
                signal = SignalFactory.create()
                StatusFactory(_signal=signal, state=cls.states[idx])
                category_assignment = CategoryAssignmentFactory(_signal=signal,
                                                                category=cls.sub_categories[
                                                                    idx % len(cls.sub_categories)])
                signal.category_assignment = category_assignment
                signal.save()

                cls.signals.append(signal)
Example #7
0
    def test_post_category(self):
        category_name = 'Overlast op het water - snel varen'
        category = CategoryFactory.create(name=category_name,
                                          parent__name='Overlast op het water')

        # Asserting that we don't change the category to the same value the signal object
        # already has.
        self.assertNotEqual(self.signal.category_assignment.category.name, category_name)

        url = '/signals/auth/category/'
        postjson = {
            '_signal': self.signal.id,
            'sub_category': '/signals/v1/public/terms/categories/{}/sub_categories/{}'.format(
                category.parent.slug, category.slug),
        }
        response = self.client.post(url, postjson, format='json')
        self.assertEqual(response.status_code, 201)

        result = response.json()
        self.assertEqual(result['sub'], category_name)

        self.signal.refresh_from_db()

        self.assertEqual(self.signal.category_assignment.category, category)
        self.assertEqual(self.signal.category_assignment.created_by, self.superuser.username)
Example #8
0
    def setUp(self):
        self.signal = SignalFactory()
        self.category = CategoryFactory()
        self.category_assignment = CategoryAssignment.objects.create(
            category=self.category, _signal_id=self.signal.id)

        self.link_category = '/signals/v1/public/terms/categories/{}/sub_categories/{}'.format(
            self.category.parent.slug, self.category.slug)
    def setUp(self):
        self.list_categories_schema = self.load_json_schema(
            os.path.join(THIS_DIR, 'json_schema',
                         'get_signals_v1_public_terms_categories.json'))
        self.retrieve_category_schema = self.load_json_schema(
            os.path.join(THIS_DIR, 'json_schema',
                         'get_signals_v1_public_terms_categories_{slug}.json'))
        self.retrieve_sub_category_schema = self.load_json_schema(
            os.path.join(
                THIS_DIR, 'json_schema',
                'get_signals_v1_public_terms_categories_{slug}_sub_categories_{sub_slug}.json'
            ))

        self.parent_category = ParentCategoryFactory.create()
        CategoryFactory.create_batch(5, parent=self.parent_category)
        self.parent_category.refresh_from_db()

        super(TestCategoryTermsEndpoints, self).setUp()
Example #10
0
    def setUp(self):
        """Setup test environment"""
        # Create a test user for Techtek.
        self.techtek_user = UserFactory(email='*****@*****.**')
        # Give the Techtek user the correct permissions.
        required_permissions = Permission.objects.filter(
            codename__in=['sia_read', 'sia_write'])
        self.techtek_user.user_permissions.set(required_permissions)

        # Various relevant endpoints
        self.signals_list = '/signals/v1/private/signals/'
        self.signal_detail = '/signals/v1/private/signals/{pk}'
        self.category_url_template = \
            '{server}/signals/v1/public/terms/categories/{main_slug}/sub_categories/{sub_slug}'

        # Fill test database with some signals to demonstrate filtering.
        techtek_parent_category = ParentCategoryFactory.create(
            slug=TECHTEK_MAIN_SLUG)
        techtek_sub_cat = CategoryFactory.create(
            slug=TECHTEK_SUB_SLUG, parent=techtek_parent_category)

        self._techtek_signal_1 = SignalFactoryValidLocation(
            category_assignment__category=techtek_sub_cat,
            text='De straatverlichting werkt niet.',
            status__state=workflow.GEMELD,
        )
        self._techtek_signal_2 = SignalFactoryValidLocation(
            category_assignment__category=techtek_sub_cat,
            text='De openbare klok op de hoek werkt niet.',
            status__state=workflow.AFGEHANDELD,
        )

        other_parent_cat = ParentCategoryFactory.create(
            slug=NOT_TECHTEK_MAIN_SLUG)
        other_cat = CategoryFactory.create(slug=NOT_TECHTEK_SUB_SLUG,
                                           parent=other_parent_cat)
        self._signal = SignalFactory(
            category_assignment__category=other_cat,
            text='Er ligt een accu in de sloot.',
            status__state=workflow.GEMELD,
        )
Example #11
0
    def setUp(self):
        self.department_read = Permission.objects.get(
            codename='sia_department_read')
        self.department_write = Permission.objects.get(
            codename='sia_department_write')
        self.sia_read_write_user.user_permissions.add(self.department_read)
        self.sia_read_write_user.user_permissions.add(self.department_write)

        self.department = DepartmentFactory.create()

        self.maincategory = ParentCategoryFactory.create()
        self.subcategory = CategoryFactory.create(parent=self.maincategory)
Example #12
0
    def test_filter_maincategory_and_category_slugs_not_a_unique_slug(self):
        parent_category = ParentCategoryFactory.create(name='not_unique')
        category = CategoryFactory.create(name='not_unique', parent=parent_category)

        SignalFactory.create(category_assignment__category=category)

        params = {
            'maincategory_slug': [parent_category.slug, ],
            'category_slug': [category.slug, ]
        }

        result_ids = self._request_filter_signals(params)
        self.assertEqual(1, len(result_ids))
Example #13
0
    def setUp(self):
        self.signal = SignalFactory()
        self.category = CategoryFactory()
        self.category_assignment = CategoryAssignment.objects.create(category=self.category,
                                                                     _signal_id=self.signal.id)

        self.link_category = '/signals/v1/public/terms/categories/{}/sub_categories/{}'.format(
            self.category.parent.slug, self.category.slug
        )
        geometry = MultiPolygon([Polygon.from_bbox([4.877157, 52.357204, 4.929686, 52.385239])], srid=4326)
        self.pt_in_center = Point(4.88, 52.36)
        self.pt_out_center = Point(6, 53)
        self.area = AreaFactory.create(geometry=geometry, name='Centrum', code='centrum', _type__code='district')
Example #14
0
    def setUp(self):
        statusmessagetemplate_write_permission = Permission.objects.get(
            codename='sia_statusmessagetemplate_write')
        self.sia_read_write_user.user_permissions.add(
            statusmessagetemplate_write_permission)
        self.sia_read_write_user.save()
        self.client.force_authenticate(user=self.sia_read_write_user)

        self.subcategory = CategoryFactory.create()
        self.link_cat_sub_templates = '/signals/v1/private/terms/categories/{}/sub_categories/{}/status-message-templates'.format(  # noqa
            self.subcategory.parent.slug, self.subcategory.slug)

        self.link_cat_parent_templates = '/signals/v1/private/terms/categories/{}/status-message-templates'.format(  # noqa
            self.subcategory.parent.slug)
Example #15
0
    def setUp(self):
        self.test_parentcategory_overig = Category.objects.get(
            slug='overig',
            parent__isnull=True,
        )
        self.test_subcategory_overig = Category.objects.get(
            parent=self.test_parentcategory_overig,
            slug='overig',
            parent__isnull=False,
        )
        self.link_test_subcategory_overig = '/signals/v1/public/terms/categories/{}/sub_categories/{}'.format(  # noqa
            self.test_host,
            self.test_subcategory_overig.parent.slug,
            self.test_subcategory_overig.slug,
        )

        self.test_subcategory = CategoryFactory.create()
        self.link_test_subcategory = '{}/signals/v1/public/terms/categories/{}/sub_categories/{}'.format(  # noqa
            self.test_host,
            self.test_subcategory.parent.slug,
            self.test_subcategory.slug,
        )

        self.test_subcategory_translated = CategoryFactory.create(is_active=False)
        self.link_test_subcategory_translated = '{}/signals/v1/public/terms/categories/{}/sub_categories/{}'.format(  # noqa
            self.test_host,
            self.test_subcategory_translated.parent.slug,
            self.test_subcategory_translated.slug,
        )

        self.link_test_subcategory_translation = CategoryTranslation.objects.create(
            old_category=self.test_subcategory_translated,
            new_category=self.test_subcategory,
            text='For testing purposes we translate this category',
            created_by='*****@*****.**',
        )
Example #16
0
    def setUp(self):
        with open(self.fixture_file, 'r') as f:
            self.create_initial_data = json.load(f)

        self.subcategory = CategoryFactory.create()

        self.link_test_cat_sub = '/signals/v1/public/terms/categories/{}/sub_categories/{}'.format(
            self.subcategory.parent.slug, self.subcategory.slug)

        self.create_initial_data['category'] = {
            'sub_category': self.link_test_cat_sub
        }

        self.retrieve_schema = self.load_json_schema(
            os.path.join(THIS_DIR, 'json_schema',
                         'get_signals_v1_public_signals_{uuid}.json'))
        self.create_schema = self.load_json_schema(
            os.path.join(THIS_DIR, 'json_schema',
                         'post_signals_v1_public_signals.json'))
        self.create_attachment_schema = self.load_json_schema(
            os.path.join(THIS_DIR, 'json_schema',
                         'post_signals_v1_public_signals_attachment.json'))
Example #17
0
 def setUp(self):
     self.signal = SignalFactory()
     self.category = CategoryFactory()
     self.category_assignment = CategoryAssignment.objects.create(
         category=self.category, _signal_id=self.signal.id)
Example #18
0
 def setUp(self):
     self.test_cat_a = CategoryFactory.create(name='sub-a', parent__name='main-a')
     self.maxDiff = None