def test_iter(self):
     pkeys = {'query', 'normalized', 'to', 'from', 'pages',
              '1266004', 'ns', 'title', 'pageid'}
     bkeys = {'thumbnail_url', 'preview_url', 'bib_key',
              'info_url', 'ISBN:9780804720687', 'preview'}
     test_pelican = PelicanJson(self.pelecanus_occidentalis)
     test_book = PelicanJson(self.book)
     self.assertEqual(set(test_pelican.keys()), pkeys)
     self.assertEqual(set(test_book.keys()), bkeys)
 def test_searchkey(self):
     test_rickettsi = PelicanJson(self.ricketts)
     paths = [['query', 'pages', '1422396', 'extlinks'] + [n, '*']
              for n in range(10)]
     for item in test_rickettsi.search_key('*'):
         self.assertIn(item, paths)
     for key in test_rickettsi.keys():
         self.assertTrue(next(test_rickettsi.search_key(key)))
     pelican_item = PelicanJson(self.item)
     for key in pelican_item.keys():
         self.assertTrue(next(pelican_item.search_key(key)))
 def test_len(self):
     keys = {'query', 'normalized', 'to', 'from', 'pages',
             '1266004', 'ns', 'title', 'pageid'}
     length = len(keys)
     test_pelican = PelicanJson(self.pelecanus_occidentalis)
     self.assertEqual(len(test_pelican), length)
     self.assertEqual(set(test_pelican.keys()), keys)
     self.assertEqual(len(test_pelican), len(list(test_pelican.keys())),
                      len(keys))
     test_pelican['new'] = 'VALUE'
     self.assertEqual(len(test_pelican), length + 1)
 def test_items(self):
     answer_dict = {'ns': 0,
                    'title': 'Pelecanus occidentalis',
                    'pageid': 1266004,
                    'to': 'Pelecanus occidentalis',
                    'from': 'Pelecanus_occidentalis'}
     test_pelican = PelicanJson(self.pelecanus_occidentalis)
     test_book = PelicanJson(self.book)
     self.assertEqual(len(list(test_book.keys())),
                      len(list(test_book.items())))
     self.assertEqual(len(list(test_pelican.keys())),
                      len(list(test_pelican.items())))
     for key, value in test_pelican.items():
         if key in answer_dict:
             self.assertEqual(answer_dict[key], value)
 def test_contains(self):
     test_pelican = PelicanJson(self.book)
     self.assertIn('ISBN:9780804720687', test_pelican)
     self.assertIn('preview', test_pelican)
     self.assertIn('bib_key', test_pelican)
     test_pelican = PelicanJson(self.monterrey)
     for key in test_pelican.keys():
         self.assertIn(key, test_pelican)
     self.assertFalse(test_pelican.__contains__('NADA'))
 def test_keys_flat(self):
     test_book = PelicanJson(self.book)
     test_pelican = PelicanJson(self.pelecanus_occidentalis)
     assert set(test_book.keys(flat=True)) == {'ISBN:9780804720687'}
     assert set(test_pelican.keys(flat=True)) == {"query"}