Ejemplo n.º 1
0
class SimpleQueryTestCase(BaseQueryTestCase):

    def setUp(self):
        self.testee = ResultFilter(SIMPLE)

    def _assert_type_str(self, result):
        self.assertEquals(str, type(result))

    def test_query_level1(self):
        result = self.testee.apply('level1')
        self._assert_type_str(result)
        self.assertEquals('item_level1', result)

    def test_query_level2_first_key(self):
        result = self.testee.apply('level2.level3')
        self._assert_type_str(result)
        self.assertEquals('item_level3', result)

    def test_query_level2_all(self):
        result = self.testee.apply('level2')
        self._assert_type_str(result)
        self.assertEquals(
            '{"level3": "item_level3", "level35": "item_level35"}',
            self.testee.apply('level2')
        )
Ejemplo n.º 2
0
 def test_ok_with_different_delimiter(self):
     testee = ResultFilter(
         BAD_KEYS, criteria_delim='^'
     )
     result = testee.apply('level2.5^level35')
     self._assert_type_str(result)
     self.assertEquals('item_level35', result)
Ejemplo n.º 3
0
class BadParametersTestCase(BaseQueryTestCase):

    def setUp(self):
        self.testee = ResultFilter(SIMPLE)

    def test_bad_key_one_level(self):
        self.assertEquals(
            'Unable to filter using level11',
            self.testee.apply('level11')
        )

    def test_bad_key_part(self):
        self.assertEquals(
            'Unable to filter using level2.level23',
            self.testee.apply('level2.level23')
        )
Ejemplo n.º 4
0
class OneLevelRepeatedKeysTestCase(BaseQueryTestCase):

    def setUp(self):
        self.testee = ResultFilter(ONE_LEVEL_REPEATS_WITH_LIST)

    def test_same_keys(self):
        result = self.testee.apply('level2.level25')
        self._assert_type_str(result)
        expected = ('[{"level252": "item_level252", "level251": '
                    '"item_level251"}, {"level262": "item_level262", '
                    '"level261": "item_level261"}]')
        self.assertEquals(expected, result)

    def test_same_keys_root(self):
        result = self.testee.apply('level2')
        self._assert_type_str(result)
        expected = ('[{"level25": {"level252": "item_level252", "level251": '
                    '"item_level251"}}, {"level25": {"level262": "item_level262", '
                    '"level261": "item_level261"}}]')
        self.assertEquals(expected, result)
Ejemplo n.º 5
0
class OneLevelRepeatedKeysNoList(BaseQueryTestCase):

    def setUp(self):
        self.testee = ResultFilter(ONE_LEVEL_REPEATS)

    def test_same_keys_no_list(self):
        result = self.testee.apply('level2.level25')
        self._assert_type_str(result)
        expected = ''
        expected = ('{"level262": "item_level262", '
                    '"level261": "item_level261"}')
        self.assertEquals(expected, result)
Ejemplo n.º 6
0
class OneLevelNestedQueryTestCase(BaseQueryTestCase):

    def setUp(self):
        self.testee = ResultFilter(ONE_LEVEL)

    def test_two_subdicts(self):
        result = self.testee.apply('level2')
        self._assert_type_str(result)
        expected = ('{"level26": {"level262": "item_level262", "level261":'
                    ' "item_level261"}, "level25": {"level252": "item_level252",'
                    ' "level251": "item_level251"}}')
        self.assertEquals(expected, result)
Ejemplo n.º 7
0
class JsonKeysClashWithCriteriaTestCase(BaseQueryTestCase):

    def setUp(self):
        self.testee = ResultFilter(BAD_KEYS)

    def test_clashing_key_with_period(self):
        result = self.testee.apply('level2.5.level35')
        self._assert_type_str(result)
        self.assertEquals(
            'Criteria delimiter [.] is a key in document',
            result
        )

    def test_ok_with_different_delimiter(self):
        testee = ResultFilter(
            BAD_KEYS, criteria_delim='^'
        )
        result = testee.apply('level2.5^level35')
        self._assert_type_str(result)
        self.assertEquals('item_level35', result)