コード例 #1
0
 def test_partial_query_search_by_title(self):
     book_collection_test = ({'author': 'Tzonis',
                              'title': 'Santiago Calatrava The Complete Works Expanded Edition',
                              'publisher': 'Rizzoli', 'shelf': '33',
                              'category': 'Architecture', 'subject': '20th Century'},
                             {'author': 'Ramen Noodles', 'title': 'Top Ramen',
                              'publisher': 'Nong Shim', 'shelf': 'Lego',
                              'category': 'Food', 'subject': 'Sustenance'},
                             {'author': 'Steven Jobs', 'title': 'Apple and Oranges',
                              'publisher': 'California', 'shelf': '12',
                              'category': 'Technology', 'subject': 'Biography'})
     key = "title"
     search_query = "e"
     expected_output = [{'author': 'Tzonis',
                         'title': 'Santiago Calatrava The Complete Works Expanded Edition',
                         'publisher': 'Rizzoli', 'shelf': '33',
                         'category': 'Architecture', 'subject': '20th Century'},
                        {'author': 'Ramen Noodles', 'title': 'Top Ramen',
                         'publisher': 'Nong Shim', 'shelf': 'Lego',
                         'category': 'Food', 'subject': 'Sustenance'},
                        {'author': 'Steven Jobs', 'title': 'Apple and Oranges',
                         'publisher': 'California', 'shelf': '12',
                         'category': 'Technology', 'subject': 'Biography'}]
     actual_value = search_engine(book_collection_test, key, search_query)
     self.assertEqual(expected_output, actual_value)
コード例 #2
0
 def test_full_query_search_by_subject(self):
     book_collection_test = [{'author': 'Mazda', 'title': "2008 Mazda MX-5 Owner's Manual",
                              'publisher': 'Mazda', 'shelf': '17', 'category': 'Science',
                              'subject': 'Automobile'},
                             {'author': 'Ramen Noodles', 'title': 'Top Ramen',
                              'publisher': 'Nong Shim', 'shelf': 'Lego',
                              'category': 'Food', 'subject': 'Sustenance'},
                             {'author': 'Steven Jobs', 'title': 'Apple and Oranges',
                              'publisher': 'California', 'shelf': '12',
                              'category': 'Technology', 'subject': 'Biography'}]
     key = "subject"
     search_query = "automobile"
     expected_output = [{'author': 'Mazda', 'title': "2008 Mazda MX-5 Owner's Manual",
                         'publisher': 'Mazda', 'shelf': '17', 'category': 'Science',
                         'subject': 'Automobile'}, ]
     actual_value = search_engine(book_collection_test, key, search_query)
     self.assertEqual(expected_output, actual_value)