Ejemplo n.º 1
0
 def test_find_value(self):
     expected = ['query', 'normalized', 0, 'from']
     seek_value = 'Pelecanus_occidentalis'
     value_gen = find_value(self.pelecanus_occidentalis, seek_value)
     self.assertEqual(next(value_gen), expected)
     with self.assertRaises(StopIteration):
         next(value_gen)
     answer_template = ['query', 'pages', '1422396', 'images']
     answers = [answer_template + [n, 'ns'] for n in range(7)]
     for path in find_value(self.ricketts, 6):
         self.assertIn(path, answers)
Ejemplo n.º 2
0
    def test_validate_fail_incorrect_value_type(self):
        profile = new_profile()
        for path in find_value(profile, 'REQUIRED_VALUE'):
            set_nested_value(profile, path, 'Fixed!')

        # Clobber list with new dictionary
        test_copy = copy.deepcopy(profile)
        test_copy['links']['alternate'] = {'WRONG': 'Bad Value'}
        self.assertFalse(validate(test_copy)[0])

        # Clobber list with string
        test_copy = copy.deepcopy(profile)
        set_nested_value(test_copy, ['links', 'item'], 'Bad Value')
        self.assertFalse(validate(test_copy)[0])

        # Clobber string with new dictionary
        test_copy = copy.deepcopy(profile)
        test_copy['attributes']['guid'] = [{'new Key': 'Bad Value'}]
        self.assertFalse(validate(test_copy)[0])
Ejemplo n.º 3
0
 def test_find_value_inside_lists(self):
     paths = [['links', 'enclosure', 0, 'meta', 'program_guid'],
              ['attributes', 'tags', 0],
              ['attributes', 'guid']]
     for path in find_value(self.item, 'someGUID'):
         self.assertIn(path, paths)
Ejemplo n.º 4
0
 def test_validate_pass(self):
     profile = new_profile()
     for path in find_value(profile, 'REQUIRED_VALUE'):
         set_nested_value(profile, path, 'Fixed!')
     self.assertTrue(validate(profile))