def test_cross_app_copy_index(self):
        rule = F.rule(object_id='one')
        synonym = F.synonym(object_id='one')
        responses = [
            self.index.save_object({'objectID': 'one'}),
            self.index.save_rule(rule),
            self.index.save_synonym(synonym),
            self.index.set_settings({'searchableAttributes': ['objectID']})
        ]

        MultipleResponse(responses).wait()

        AccountClient.copy_index(self.index, self.index2).wait()

        # Assert objects got copied
        res = self.index2.search('')

        self.assertEqual(len(res['hits']), 1)
        self.assertEqual(res['hits'][0], {'objectID': 'one'})

        # Assert settings got copied
        settings = self.index2.get_settings()
        self.assertEqual(settings['searchableAttributes'], ['objectID'])

        # Assert synonyms got copied
        self.assertEqual(self.index2.get_rule('one'), rule)

        # Assert synonyms got copied
        self.assertEqual(self.index2.get_synonym('one'), synonym)

        # Assert that copying again fails because index already exists
        with self.assertRaises(AlgoliaException) as _:
            AccountClient.copy_index(self.index, self.index2)
    def test_cross_app_copy_index(self):
        rule = F.rule(object_id='one')
        synonym = F.synonym(object_id='one')
        responses = [
            self.index.save_object({'objectID': 'one'}),
            self.index.save_rule(rule),
            self.index.save_synonym(synonym),
            self.index.set_settings({'searchableAttributes': ['objectID']})
        ]

        MultipleResponse(responses).wait()

        AccountClient.copy_index(self.index, self.index2).wait()

        # Assert objects got copied
        res = self.index2.search('')

        self.assertEqual(len(res['hits']), 1)
        self.assertEqual(res['hits'][0], {'objectID': 'one'})

        # Assert settings got copied
        settings = self.index2.get_settings()
        self.assertEqual(settings['searchableAttributes'], ['objectID'])

        # Assert synonyms got copied
        self.assertEqual(self.index2.get_rule('one'), rule)

        # Assert synonyms got copied
        self.assertEqual(self.index2.get_synonym('one'), synonym)

        # Assert that copying again fails because index already exists
        with self.assertRaises(AlgoliaException) as _:
            AccountClient.copy_index(self.index, self.index2)
Example #3
0
    def test_replacing(self):
        responses = MultipleResponse()
        responses.push(self.index.save_object({"objectID": "one"}))
        responses.push(self.index.save_rule(F.rule(object_id="one")))

        responses.push(self.index.save_synonym(
            {"objectID": "one", "type": "synonym", "synonyms": ["one", "two"]}
        ))

        responses.wait()

        responses.push(self.index.replace_all_objects([{"objectID": "two"}]))
        responses.push(self.index.replace_all_rules([{
            "objectID": "two",
            "condition": {"anchoring": "is", "pattern": "pattern"},
            "consequence": {
                "params": {
                    "query": {
                        "edits": [
                            {"type": "remove", "delete": "pattern"}
                        ]
                    }
                }
            }
        }
        ]))

        responses.push(self.index.replace_all_synonyms([
            {"objectID": "two", "type": "synonym", "synonyms": ["one", "two"]}
        ]))

        responses.wait()

        # Check that record with objectID=`one` does not exist
        with self.assertRaises(RequestException) as _:
            self.index.get_object('one')

        # Check that record with objectID=`two` does exist
        self.assertEqual(self.index.get_object('two')['objectID'], 'two')

        # Check that rule with objectID=`one` does not exist
        with self.assertRaises(RequestException) as _:
            self.index.get_rule('one')

        # Check that rule with objectID=`two` does exist
        self.assertEqual(self.index.get_rule('two')['objectID'], 'two')

        # Check that synonym with objectID=`one` does not exist
        with self.assertRaises(RequestException) as _:
            self.index.get_synonym('one')

        # Check that synonym with objectID="two" does exist using getSynonym
        self.assertEqual(self.index.get_synonym('two')['objectID'], 'two')
    def test_replacing(self):
        responses = MultipleResponse()
        responses.push(self.index.save_object({"objectID": "one"}))
        responses.push(self.index.save_rule(F.rule(object_id="one")))

        responses.push(self.index.save_synonym(
            {"objectID": "one", "type": "synonym", "synonyms": ["one", "two"]}
        ))

        responses.wait()

        responses.push(self.index.replace_all_objects([{"objectID": "two"}]))
        responses.push(self.index.replace_all_rules([{
            "objectID": "two",
            "condition": {"anchoring": "is", "pattern": "pattern"},
            "consequence": {
                "params": {
                    "query": {
                        "edits": [
                            {"type": "remove", "delete": "pattern"}
                        ]
                    }
                }
            }
        }
        ]))

        responses.push(self.index.replace_all_synonyms([
            {"objectID": "two", "type": "synonym", "synonyms": ["one", "two"]}
        ]))

        responses.wait()

        # Check that record with objectID=`one` does not exist
        with self.assertRaises(RequestException) as _:
            self.index.get_object('one')

        # Check that record with objectID=`two` does exist
        self.assertEqual(self.index.get_object('two')['objectID'], 'two')

        # Check that rule with objectID=`one` does not exist
        with self.assertRaises(RequestException) as _:
            self.index.get_rule('one')

        # Check that rule with objectID=`two` does exist
        self.assertEqual(self.index.get_rule('two')['objectID'], 'two')

        # Check that synonym with objectID=`one` does not exist
        with self.assertRaises(RequestException) as _:
            self.index.get_synonym('one')

        # Check that synonym with objectID="two" does exist using getSynonym
        self.assertEqual(self.index.get_synonym('two')['objectID'], 'two')
Example #5
0
    def test_cross_app_copy_index(self):
        rule = F.rule(object_id="one")
        synonym = F.synonym(object_id="one")
        responses = [
            self.index.save_object({"objectID": "one"}),
            self.index.save_rule(rule),
            self.index.save_synonym(synonym),
            self.index.set_settings({"searchableAttributes": ["objectID"]}),
        ]

        MultipleResponse(responses).wait()

        AccountClient.copy_index(self.index, self.index2).wait()

        # Assert objects got copied
        res = self.index2.search("")

        self.assertEqual(len(res["hits"]), 1)
        self.assertEqual(res["hits"][0], {"objectID": "one"})

        # Assert settings got copied
        settings = self.index2.get_settings()
        self.assertEqual(settings["searchableAttributes"], ["objectID"])

        # Assert rules got copied
        self.assertEqual(rule_without_metadata(self.index2.get_rule("one")),
                         rule)

        # Assert synonyms got copied
        list_synonyms1 = [synonym for synonym in self.index.browse_synonyms()]
        list_synonyms2 = [synonym for synonym in self.index2.browse_synonyms()]

        self.assertEqual(list_synonyms1, list_synonyms2)

        # Assert synomys are the same
        self.assertEqual(self.index2.get_synonym("one"), synonym)

        # Assert that copying again fails because index already exists
        with self.assertRaises(AlgoliaException) as _:
            AccountClient.copy_index(self.index, self.index2)