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)
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') )
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') )
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)
class OneItemFilterTestCase(BaseQueryTestCase): def setUp(self): self.testee = ResultFilter(ONE_LEVEL) def test_where_equals_name(self): result = self.testee.filter_on(filter_path='contests.name', target='contest1') self._assert_type_str(result) expected = ('{"contests": [{"entry_count": 23, ' '"name": "contest1", "rosters": ["blah", "blah2"]}]}') self.assertEquals(expected, result) def test_where_equals_two_elements(self): result = self.testee.filter_on(filter_path='contests.entry_count', target=24) self._assert_type_str(result) expected = ('{"contests": [{"entry_count": 24, ' '"name": "contest2", "rosters": ["bleeb", ' '"blop"]}, {"entry_count": 24, "name": ' '"contest4", "rosters": ["bleeb", "blop"]}]}') self.assertEquals(expected, result)
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)
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)
class TwoItemFilterTestCase(BaseQueryTestCase): def setUp(self): self.testee = ResultFilter(TWO_LEVEL) def test_where_equals(self): result = self.testee.filter_on( filter_path='contests.bloopers.main_bloop', target="256") self._assert_type_str(result) expected = ('{"contests": [{"bloopers": {"second_bloop":' ' "blamo", "main_bloop": "256"}, "entry_count":' ' 23, "name": "contest1", "rosters": ["blah", "blah2"]}]}') self.assertEquals(expected, result) def test_where_equals_matches_two(self): result = self.testee.filter_on(filter_path='contests.entry_count', target=24) self._assert_type_str(result) expected = ('{"contests": [{"bloopers": {"second_bloop": ' '"slamo", "main_bloop": "255"}, "entry_count": 24, ' '"name": "contest2", "rosters": ["bleeb", "blop"]}, ' '{"bloopers": {"second_bloop": "rilamo", "main_bloop": ' '"254"}, "entry_count": 24, "name": "contest4", ' '"rosters": ["bleeb", "blop"]}]}') self.assertEquals(expected, result)
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)
def setUp(self): self.testee = ResultFilter(TWO_LEVEL)
def setUp(self): self.testee = ResultFilter(SIMPLE)
def setUp(self): self.testee = ResultFilter(BAD_KEYS)
def setUp(self): self.testee = ResultFilter(ONE_LEVEL_REPEATS_WITH_LIST)