MCPcopy
hub / github.com/redis/redis-py / test_alias

Method test_alias

tests/test_search.py:760–818  ·  view source on GitHub ↗
(self, client)

Source from the content-addressed store, hash-verified

758 @pytest.mark.redismod
759 @skip_ifmodversion_lt("2.0.0", "search")
760 def test_alias(self, client):
761 index1 = self.getClient(client)
762 index2 = self.getClient(client)
763
764 def1 = IndexDefinition(prefix=["index1:"])
765 def2 = IndexDefinition(prefix=["index2:"])
766
767 ftindex1 = index1.ft("testAlias")
768 ftindex2 = index2.ft("testAlias2")
769 ftindex1.create_index((TextField("name"),), definition=def1)
770 ftindex2.create_index((TextField("name"),), definition=def2)
771
772 index1.hset("index1:lonestar", mapping={"name": "lonestar"})
773 index2.hset("index2:yogurt", mapping={"name": "yogurt"})
774
775 if expects_resp2_shape(client) or expects_unified_shape(client):
776 res = ftindex1.search("*").docs[0]
777 assert "index1:lonestar" == res.id
778
779 # create alias and check for results
780 ftindex1.aliasadd("spaceballs")
781 alias_client = self.getClient(client).ft("spaceballs")
782 res = alias_client.search("*").docs[0]
783 assert "index1:lonestar" == res.id
784
785 # Throw an exception when trying to add an alias that already exists
786 with pytest.raises(Exception):
787 ftindex2.aliasadd("spaceballs")
788
789 # update alias and ensure new results
790 ftindex2.aliasupdate("spaceballs")
791 alias_client2 = self.getClient(client).ft("spaceballs")
792
793 res = alias_client2.search("*").docs[0]
794 assert "index2:yogurt" == res.id
795 elif expects_resp3_shape(client):
796 res = ftindex1.search("*")["results"][0]
797 assert "index1:lonestar" == res["id"]
798
799 # create alias and check for results
800 ftindex1.aliasadd("spaceballs")
801 alias_client = self.getClient(client).ft("spaceballs")
802 res = alias_client.search("*")["results"][0]
803 assert "index1:lonestar" == res["id"]
804
805 # Throw an exception when trying to add an alias that already exists
806 with pytest.raises(Exception):
807 ftindex2.aliasadd("spaceballs")
808
809 # update alias and ensure new results
810 ftindex2.aliasupdate("spaceballs")
811 alias_client2 = self.getClient(client).ft("spaceballs")
812
813 res = alias_client2.search("*")["results"][0]
814 assert "index2:yogurt" == res["id"]
815
816 ftindex2.aliasdel("spaceballs")
817 with pytest.raises(Exception):

Callers

nothing calls this directly

Calls 13

IndexDefinitionClass · 0.90
TextFieldClass · 0.90
expects_resp2_shapeFunction · 0.85
expects_unified_shapeFunction · 0.85
expects_resp3_shapeFunction · 0.85
create_indexMethod · 0.80
hsetMethod · 0.80
aliasaddMethod · 0.80
aliasupdateMethod · 0.80
aliasdelMethod · 0.80
getClientMethod · 0.45
ftMethod · 0.45

Tested by

no test coverage detected