@@ -10,6 +10,7 @@ class TestIndex:
10
10
index_uid = 'indexUID'
11
11
index_uid2 = 'indexUID2'
12
12
index_uid3 = 'indexUID3'
13
+ index_uid4 = 'indexUID4'
13
14
14
15
def setup_class (self ):
15
16
clear_all_indexes (self .client )
@@ -58,12 +59,13 @@ def test_get_index_with_none_uid(self):
58
59
59
60
def test_get_or_create_index (self ):
60
61
"""Test get_or_create_index method"""
61
- index_1 = self .client .get_or_create_index ('book_id' )
62
- index_2 = self .client .get_or_create_index ('book_id' )
63
- index_3 = self .client .get_or_create_index ('book_id' )
64
- assert index_1 .uid == index_2 .uid == index_3 .uid == 'book_id'
62
+ # self.client.create_index(self.index_uid3)
63
+ index_1 = self .client .get_or_create_index (self .index_uid4 )
64
+ index_2 = self .client .get_or_create_index (self .index_uid4 )
65
+ index_3 = self .client .get_or_create_index (self .index_uid4 )
66
+ assert index_1 .uid == index_2 .uid == index_3 .uid == self .index_uid4
65
67
update = index_1 .add_documents ([{
66
- 'id ' : 1 ,
68
+ 'book_id ' : 1 ,
67
69
'name' : "Some book"
68
70
}])
69
71
index_1 .wait_for_pending_update (update ['updateId' ])
@@ -73,6 +75,14 @@ def test_get_or_create_index(self):
73
75
with pytest .raises (Exception ):
74
76
self .client .get_index (index_3 ).info ()
75
77
78
+ def test_get_or_create_index_with_primary_key (self ):
79
+ """Test get_or_create_index method with primary key"""
80
+ index_1 = self .client .get_or_create_index ('books' , {'primaryKey' : self .index_uid4 })
81
+ index_2 = self .client .get_or_create_index ('books' , {'primaryKey' : 'some_wrong_key' })
82
+ assert index_1 .get_primary_key () == self .index_uid4
83
+ assert index_2 .get_primary_key () == self .index_uid4
84
+ index_1 .delete ()
85
+
76
86
def test_index_info (self ):
77
87
"""Tests getting an index's info"""
78
88
index = self .client .get_index (uid = self .index_uid )
0 commit comments