示例#1
0
    def test_disabled_index(self):
        """
        Make sure that searchengine operations are shut down when mock engine has a filename, but file does
        not exist - this is helpful for test scenarios where we essentially want to not slow anything down
        """
        this_moment = datetime.utcnow()
        test_object = {
            "id":
            "FAKE_ID",
            "content": {
                "name": "How did 11 of 12 balls get deflated during the game"
            },
            "my_date_value":
            this_moment,
            "my_integer_value":
            172,
            "my_float_value":
            57.654,
            "my_string_value":
            "If the officials just blew it, would they come out and admit it?"
        }

        self.searcher.index("test_doc", [test_object])
        response = self.searcher.search(query_string="deflated")
        self.assertEqual(response["total"], 1)

        # copy content, and then erase file so that backed file is not present and work is disabled
        initial_file_content = None
        with open("testfile.pkl", "r") as dict_file:
            initial_file_content = json.load(dict_file)
        os.remove("testfile.pkl")

        response = self.searcher.search(query_string="ABC")
        self.assertEqual(response["total"], 0)

        self.searcher.index("test_doc", [{"content": {"name": "ABC"}}])
        # now search should be unsuccessful because file does not exist
        response = self.searcher.search(query_string="ABC")
        self.assertEqual(response["total"], 0)

        # remove it, and then we'll reload file and it still should be there
        self.searcher.remove("test_doc", ["FAKE_ID"])

        MockSearchEngine.create_test_file("fakefile.pkl", initial_file_content)

        # now search should be successful because file did exist in file
        response = self.searcher.search(query_string="deflated")
        self.assertEqual(response["total"], 1)

        self.searcher.remove("not_a_test_doc", ["FAKE_ID"])
        response = self.searcher.search(query_string="deflated")
        self.assertEqual(response["total"], 1)

        self.searcher.remove("test_doc", ["FAKE_ID"])
        response = self.searcher.search(query_string="deflated")
        self.assertEqual(response["total"], 0)
示例#2
0
    def test_disabled_index(self):
        """
        Make sure that searchengine operations are shut down when mock engine has a filename, but file does
        not exist - this is helpful for test scenarios where we essentially want to not slow anything down
        """
        this_moment = datetime.utcnow()
        test_object = {
            "id": "FAKE_ID",
            "content": {
                "name": "How did 11 of 12 balls get deflated during the game"
            },
            "my_date_value": this_moment,
            "my_integer_value": 172,
            "my_float_value": 57.654,
            "my_string_value": "If the officials just blew it, would they come out and admit it?"
        }

        self.searcher.index("test_doc", [test_object])
        response = self.searcher.search(query_string="deflated")
        self.assertEqual(response["total"], 1)

        # copy content, and then erase file so that backed file is not present and work is disabled
        initial_file_content = None
        with open("testfile.pkl", "r") as dict_file:
            initial_file_content = json.load(dict_file)
        os.remove("testfile.pkl")

        response = self.searcher.search(query_string="ABC")
        self.assertEqual(response["total"], 0)

        self.searcher.index("test_doc", [{"content": {"name": "ABC"}}])
        # now search should be unsuccessful because file does not exist
        response = self.searcher.search(query_string="ABC")
        self.assertEqual(response["total"], 0)

        # remove it, and then we'll reload file and it still should be there
        self.searcher.remove("test_doc", ["FAKE_ID"])

        MockSearchEngine.create_test_file("fakefile.pkl", initial_file_content)

        # now search should be successful because file did exist in file
        response = self.searcher.search(query_string="deflated")
        self.assertEqual(response["total"], 1)

        self.searcher.remove("not_a_test_doc", ["FAKE_ID"])
        response = self.searcher.search(query_string="deflated")
        self.assertEqual(response["total"], 1)

        self.searcher.remove("test_doc", ["FAKE_ID"])
        response = self.searcher.search(query_string="deflated")
        self.assertEqual(response["total"], 0)
示例#3
0
 def setUp(self):
     super(FileBackedMockSearchTests, self).setUp()
     MockSearchEngine.create_test_file()
     self._searcher = None
示例#4
0
 def setUp(self):
     super().setUp()
     MockSearchEngine.create_test_file()
     self._searcher = None
示例#5
0
 def setUp(self):
     super(FileBackedMockSearchTests, self).setUp()
     MockSearchEngine.create_test_file()
     self._searcher = None