Exemplo n.º 1
0
    def test_parse_collection_udf_fail_nondatenumeric_comparison(self):
        self._setup_tree_and_collection_udf()

        with self.assertRaises(search.ParseException):
            search._parse_query_dict(
                {'udf:tree:%s.date' % self.treestew.pk: {'MAX': "foo"}},
                mapping=search.DEFAULT_MAPPING)
Exemplo n.º 2
0
    def test_parse_collection_udf_fail_nondatenumeric_comparison(self):
        self._setup_tree_and_collection_udf()

        with self.assertRaises(search.ParseException):
            search._parse_query_dict(
                {'udf:tree:%s.date' % self.treestew.pk: {
                    'MAX': "foo"
                }},
                mapping=search.DEFAULT_MAPPING)
Exemplo n.º 3
0
    def test_parse_collection_udf_date_and_action_should_fail(self):
        point = Point(0, 0)
        instance = make_instance(point=point)
        commander = make_commander_user(instance)

        plotstew, treestew = _setup_collection_udfs(instance, commander)
        _setup_models_for_collections(instance, commander, point, plotstew,
                                      treestew)

        pred = search._parse_query_dict(
            {
                'udf:plot:%s.action' % plotstew.pk: {
                    'IS': 'water'
                },
                'udf:plot:%s.date' % plotstew.pk:
                # Range encompasses p1's prune but not p1's water action
                {
                    'MIN': '2013-09-01 00:00:00',
                    'MAX': '2013-10-31 00:00:00'
                }
            },
            mapping=search.DEFAULT_MAPPING)

        connector, predset = destructure_query_set(pred)

        self.assertEqual(connector, 'AND')
        target = ('id__in', tuple())
        self.assertIn(target, predset)
Exemplo n.º 4
0
    def test_parse_collection_udf_simple_predicate(self):
        self._setup_tree_and_collection_udf()
        pred = search._parse_query_dict(
            {'udf:plot:%s.action' % self.plotstew.pk: 'prune'},
            mapping=search.DEFAULT_MAPPING)

        target = ('AND', {('id__in', (self.plot.pk,))})

        self.assertEqual(destructure_query_set(pred), target)
Exemplo n.º 5
0
    def test_parse_collection_udf_simple_predicate(self):
        self._setup_tree_and_collection_udf()
        pred = search._parse_query_dict(
            {'udf:plot:%s.action' % self.plotstew.pk: 'prune'},
            mapping=search.DEFAULT_MAPPING)

        target = ('AND', {('id__in', (self.plot.pk, ))})

        self.assertEqual(destructure_query_set(pred), target)
Exemplo n.º 6
0
    def test_parse_collection_udf_nested_pass_date_comparison(self):
        self._setup_tree_and_collection_udf()

        pred = search._parse_query_dict(
            {'udf:tree:%s.date' % self.treestew.pk:
             {'MAX': '2014-05-01 00:00:00'}},
            mapping=search.DEFAULT_MAPPING)

        target = ('AND', {('tree__id__in', (self.tree.pk,))})

        self.assertEqual(destructure_query_set(pred), target)
Exemplo n.º 7
0
    def test_parse_collection_udf_nested_pass_date_comparison(self):
        self._setup_tree_and_collection_udf()

        pred = search._parse_query_dict(
            {
                'udf:tree:%s.date' % self.treestew.pk: {
                    'MAX': '2014-05-01 00:00:00'
                }
            },
            mapping=search.DEFAULT_MAPPING)

        target = ('AND', {('tree__id__in', (self.tree.pk, ))})

        self.assertEqual(destructure_query_set(pred), target)
Exemplo n.º 8
0
    def test_parse_collection_udf_nested_pass_numeric_comparison(self):
        self._setup_tree_and_collection_udf()
        agility = make_collection_udf(self.instance, model='Tree',
                                      name='Agility',
                                      datatype=[{'type': 'float',
                                                 'name': 'current'}])
        set_write_permissions(self.instance, self.commander,
                              'Tree', ['udf:Agility'])
        new_tree = Tree(instance=self.instance, plot=self.plot)
        new_tree.udfs[agility.name] = [{'current': '1.5'}]
        new_tree.save_with_user(self.commander)

        pred = search._parse_query_dict(
            {'udf:tree:%s.current' % agility.pk: {'MIN': 1}},
            mapping=search.DEFAULT_MAPPING)

        target = ('AND', {('tree__id__in', (new_tree.pk,))})

        self.assertEqual(destructure_query_set(pred), target)
Exemplo n.º 9
0
    def test_parse_collection_udf_date_and_action_should_fail(self):
        point = Point(0, 0)
        instance = make_instance(point=point)
        commander = make_commander_user(instance)

        plotstew, treestew = _setup_collection_udfs(instance, commander)
        _setup_models_for_collections(instance, commander, point,
                                      plotstew, treestew)

        pred = search._parse_query_dict(
            {'udf:plot:%s.action' % plotstew.pk: {'IS': 'water'},
             'udf:plot:%s.date' % plotstew.pk:
                # Range encompasses p1's prune but not p1's water action
                {'MIN': '2013-09-01 00:00:00',
                 'MAX': '2013-10-31 00:00:00'}},
            mapping=search.DEFAULT_MAPPING)

        connector, predset = destructure_query_set(pred)

        self.assertEqual(connector, 'AND')
        target = ('id__in', tuple())
        self.assertIn(target, predset)
Exemplo n.º 10
0
    def test_parse_collection_udf_nested_pass_numeric_comparison(self):
        self._setup_tree_and_collection_udf()
        agility = make_collection_udf(self.instance,
                                      model='Tree',
                                      name='Agility',
                                      datatype=[{
                                          'type': 'float',
                                          'name': 'current'
                                      }])
        set_write_permissions(self.instance, self.commander, 'Tree',
                              ['udf:Agility'])
        new_tree = Tree(instance=self.instance, plot=self.plot)
        new_tree.udfs[agility.name] = [{'current': '1.5'}]
        new_tree.save_with_user(self.commander)

        pred = search._parse_query_dict(
            {'udf:tree:%s.current' % agility.pk: {
                'MIN': 1
            }},
            mapping=search.DEFAULT_MAPPING)

        target = ('AND', {('tree__id__in', (new_tree.pk, ))})

        self.assertEqual(destructure_query_set(pred), target)