Exemplo n.º 1
0
    def test_parse_predicate(self):
        pred = search._parse_predicate(
            {'plot.width':
             {'MIN': 5,
              'MAX': {'VALUE': 9,
                      'EXCLUSIVE': False}},
             'tree.height': 9},
            mapping=search.DEFAULT_MAPPING)

        p1 = ('AND', {('width__lte', 9),
                      ('width__gte', 5),
                      ('tree__height', 9)})

        self.assertEqual(self.destructure_query_set(pred),
                         p1)

        pred = search._parse_predicate(
            {'tree.leaf_type': {'IS': 9},
             'tree.last_updated_by': 4},
            mapping=search.DEFAULT_MAPPING)

        p2 = ('AND', {('tree__leaf_type', 9),
                      ('tree__last_updated_by', 4)})

        self.assertEqual(self.destructure_query_set(pred),
                         p2)
Exemplo n.º 2
0
    def test_parse_collection_udf_fail_nondate_comparison(self):
        self._setup_tree_and_collection_udf()

        with self.assertRaises(search.ParseException):
            search._parse_predicate(
                {'udf:tree:%s.date' % self.treestew.pk: {'MAX': 3}},
                mapping=search.DEFAULT_MAPPING)
Exemplo n.º 3
0
    def test_parse_collection_udf_fail_nondate_comparison(self):
        self._setup_tree_and_collection_udf()

        with self.assertRaises(search.ParseException):
            search._parse_predicate(
                {'udf:tree:%s.date' % self.treestew.pk: {'MAX': 3}},
                mapping=search.DEFAULT_MAPPING)
Exemplo n.º 4
0
    def test_parse_predicate(self):
        pred = search._parse_predicate(
            {
                'plot.width': {
                    'MIN': 5,
                    'MAX': {
                        'VALUE': 9,
                        'EXCLUSIVE': False
                    }
                },
                'tree.height': 9
            },
            mapping=search.DEFAULT_MAPPING)

        p1 = ('AND', {('width__lte', 9), ('width__gte', 5),
                      ('tree__height', 9)})

        self.assertEqual(self.destructure_query_set(pred), p1)

        pred = search._parse_predicate(
            {
                'tree.leaf_type': {
                    'IS': 9
                },
                'tree.last_updated_by': 4
            },
            mapping=search.DEFAULT_MAPPING)

        p2 = ('AND', {('tree__leaf_type', 9), ('tree__last_updated_by', 4)})

        self.assertEqual(self.destructure_query_set(pred), p2)
Exemplo n.º 5
0
    def test_like_predicate(self):
        pred = search._parse_predicate(
            {'tree.steward': {'LIKE': 'thisisatest'}})

        target = ('AND', {('tree__steward__icontains', 'thisisatest')})

        self.assertEqual(self.destructure_query_set(pred), target)
Exemplo n.º 6
0
    def test_like_predicate(self):
        pred = search._parse_predicate(
            {'tree.steward': {'LIKE': 'thisisatest'}},
            mapping=search.DEFAULT_MAPPING)

        target = ('AND', {('tree__steward__icontains', 'thisisatest')})

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

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

        self.assertEqual(self.destructure_query_set(pred), target)
Exemplo n.º 8
0
    def test_parse_species_predicate(self):
        pred = search._parse_predicate(
            {'species.id': 113,
             'species.flowering': True})

        target = ('AND', {('tree__species__id', 113),
                          ('tree__species__flowering', True)})

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

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

        self.assertEqual(self.destructure_query_set(pred), target)
Exemplo n.º 10
0
    def test_parse_species_predicate(self):
        pred = search._parse_predicate(
            {'species.id': 113,
             'species.flowering': True},
            mapping=search.DEFAULT_MAPPING)

        target = ('AND', {('tree__species__id', 113),
                          ('tree__species__flowering', True)})

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

        pred = search._parse_predicate(
            {'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(self.destructure_query_set(pred), target)
Exemplo n.º 12
0
    def test_parse_collection_udf_nested_pass_date_comparison(self):
        self._setup_tree_and_collection_udf()

        pred = search._parse_predicate(
            {'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(self.destructure_query_set(pred), target)
Exemplo n.º 13
0
    def test_parse_predicate_with_tree_map(self):
        pred = search._parse_predicate(
            {'plot.width':
             {'MIN': 5,
              'MAX': {'VALUE': 9,
                      'EXCLUSIVE': False}},
             'tree.height':
             9},
            mapping=search.TREE_MAPPING)

        p1 = ('AND', {('plot__width__lte', 9),
                      ('plot__width__gte', 5),
                      ('height', 9)})

        self.assertEqual(self.destructure_query_set(pred),
                         p1)
Exemplo n.º 14
0
    def test_parse_predicate_with_tree_map(self):
        pred = search._parse_predicate(
            {'plot.width':
             {'MIN': 5,
              'MAX': {'VALUE': 9,
                      'EXCLUSIVE': False}},
             'tree.height':
             9},
            mapping=search.TREE_MAPPING)

        p1 = ('AND', {('plot__width__lte', 9),
                      ('plot__width__gte', 5),
                      ('height', 9)})

        self.assertEqual(self.destructure_query_set(pred),
                         p1)
Exemplo n.º 15
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_predicate(
            {'udf:tree:%s.current' % agility.pk: {'MIN': 1}},
            mapping=search.DEFAULT_MAPPING)

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

        self.assertEqual(self.destructure_query_set(pred), target)
Exemplo n.º 16
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_predicate(
            {'udf:tree:%s.current' % agility.pk: {
                'MIN': 1
            }},
            mapping=search.DEFAULT_MAPPING)

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

        self.assertEqual(self.destructure_query_set(pred), target)