示例#1
0
    def test_callback(self):
        def _on(_litem):
            return _litem['catalog']

        book_data = copy.deepcopy(books)
        catalog_books = join_one(book_data, catalogs_dict, on=_on, select_as='catalog_name')
        self.assertTrue(all(['catalog_name' in book for book in catalog_books]))
        self.assertEqual('Java', catalog_books[1]['catalog_name'])
示例#2
0
 def test_join_one_with_custom_default(self):
     book_data = copy.deepcopy(books)
     cur_catalogs_dict = {
         1: 'Python',
         2: 'Java'
     }
     catalog_books = join_one(book_data, cur_catalogs_dict, on='catalog', select_as='catalog_name',
                              default='[未知分类]')
     self.assertTrue(all(['catalog_name' in book for book in catalog_books]))
     self.assertEqual('[未知分类]', catalog_books[2]['catalog_name'])
示例#3
0
    def test_with_choices(self):
        book_data = copy.deepcopy(books)

        catalog_books = join_one(book_data, catalog_choices, on='catalog', select_as='catalog_name')
        self.assertTrue(all(['catalog_name' in book for book in catalog_books]))
        self.assertEqual('Java', catalog_books[1]['catalog_name'])