@@ -19,59 +19,58 @@ def setup_class(cls):
1919 'X-Watson-Learning-Opt-Out' : '1' ,
2020 'X-Watson-Test' : '1'
2121 })
22- cls .collection_id = 'a06f7036-0529-49ee-bdf6-82ddec276923'
2322
2423 def test_01_colllections (self ):
25- # collection = self.visual_recognition.create_collection(
26- # name='my_collection', description='just for fun').get_result()
27- # collection_id = collection.get('collection_id')
28- # assert collection_id is not None
24+ collection = self .visual_recognition .create_collection (
25+ name = 'my_collection' , description = 'just for fun' ).get_result ()
26+ collection_id = collection .get ('collection_id' )
27+ assert collection_id is not None
2928
3029 my_collection = self .visual_recognition .get_collection (
31- collection_id = self . collection_id ).get_result ()
30+ collection_id = collection . get ( ' collection_id' ) ).get_result ()
3231 assert my_collection is not None
33- assert my_collection .get ('name' ) == 'sdk-collection-do-not-delete '
32+ assert my_collection .get ('name' ) == 'my_collection '
3433
35- # updated_collection = self.visual_recognition.update_collection(
36- # collection_id=self. collection_id,
37- # description='new description').get_result()
38- # assert updated_collection is not None
34+ updated_collection = self .visual_recognition .update_collection (
35+ collection_id = collection_id ,
36+ description = 'new description' ).get_result ()
37+ assert updated_collection is not None
3938
4039 collections = self .visual_recognition .list_collections ().get_result (
4140 ).get ('collections' )
4241 assert collections is not None
4342
44- # self.visual_recognition.delete_collection(collection_id=collection_id)
43+ self .visual_recognition .delete_collection (collection_id = collection_id )
4544
4645 def test_02_images (self ):
47- # collection = self.visual_recognition.create_collection(
48- # name='my_collection', description='just for fun').get_result()
49- # collection_id = collection.get('collection_id')
46+ collection = self .visual_recognition .create_collection (
47+ name = 'my_collection' , description = 'just for fun' ).get_result ()
48+ collection_id = collection .get ('collection_id' )
5049
5150 add_images = self .visual_recognition .add_images (
52- self . collection_id ,
51+ collection_id ,
5352 image_url = [
53+ "https://upload.wikimedia.org/wikipedia/commons/3/33/KokoniPurebredDogsGreeceGreekCreamWhiteAdult.jpg" ,
5454 "https://upload.wikimedia.org/wikipedia/commons/0/07/K%C3%B6nigspudel_Apricot.JPG"
5555 ],
5656 ).get_result ()
5757 assert add_images is not None
5858 image_id = add_images .get ('images' )[0 ].get ('image_id' )
5959
6060 list_images = self .visual_recognition .list_images (
61- self .collection_id ).get_result ()
62- print (list_images )
61+ collection_id ).get_result ()
6362 assert list_images is not None
6463
6564 image_details = self .visual_recognition .get_image_details (
66- self . collection_id , image_id ).get_result ()
65+ collection_id , image_id ).get_result ()
6766 assert image_details is not None
6867
6968 response = self .visual_recognition .get_jpeg_image (
70- self . collection_id , image_id ).get_result ()
69+ collection_id , image_id ).get_result ()
7170 assert response .content is not None
7271
73- self .visual_recognition .delete_image (self . collection_id , image_id )
74- # self.visual_recognition.delete_collection(collection_id)
72+ self .visual_recognition .delete_image (collection_id , image_id )
73+ self .visual_recognition .delete_collection (collection_id )
7574
7675 def test_03_analyze (self ):
7776 dog_path = os .path .join (os .path .dirname (__file__ ),
@@ -82,7 +81,7 @@ def test_03_analyze(self):
8281 with open (dog_path , 'rb' ) as dog_file , open (giraffe_path ,
8382 'rb' ) as giraffe_files :
8483 analyze_images = self .visual_recognition .analyze (
85- collection_ids = [self . collection_id ],
84+ collection_ids = ['a06f7036-0529-49ee-bdf6-82ddec276923' ],
8685 features = [AnalyzeEnums .Features .OBJECTS .value ],
8786 images_file = [
8887 FileWithMetadata (dog_file ),
@@ -95,12 +94,12 @@ def test_03_analyze(self):
9594 print (json .dumps (analyze_images , indent = 2 ))
9695
9796 def test_04_objects_and_training (self ):
98- # create a collection
99- # my_collection = self.visual_recognition.create_collection(
100- # name='my_test_collection',
101- # description='testing for python').get_result()
102- # collection_id = my_collection.get('collection_id')
103- # assert collection_id is not None
97+ # create a classifier
98+ my_collection = self .visual_recognition .create_collection (
99+ name = 'my_test_collection' ,
100+ description = 'testing for python' ).get_result ()
101+ collection_id = my_collection .get ('collection_id' )
102+ assert collection_id is not None
104103
105104 # add images
106105 with open (
@@ -109,7 +108,7 @@ def test_04_objects_and_training(self):
109108 '../../resources/South_Africa_Luca_Galuzzi_2004.jpeg' ),
110109 'rb' ) as giraffe_info :
111110 add_images_result = self .visual_recognition .add_images (
112- self . collection_id ,
111+ collection_id ,
113112 images_file = [FileWithMetadata (giraffe_info )],
114113 ).get_result ()
115114 assert add_images_result is not None
@@ -118,7 +117,7 @@ def test_04_objects_and_training(self):
118117
119118 # add image training data
120119 training_data = self .visual_recognition .add_image_training_data (
121- self . collection_id ,
120+ collection_id ,
122121 image_id ,
123122 objects = [
124123 TrainingDataObject (object = 'giraffe training data' ,
@@ -128,40 +127,38 @@ def test_04_objects_and_training(self):
128127
129128 # list objects metadata
130129 object_metadata_list = self .visual_recognition .list_object_metadata (
131- collection_id = self . collection_id ).get_result ()
130+ collection_id = collection_id ).get_result ()
132131 assert object_metadata_list is not None
133132
134133 # update object metadata
135134 object_metadata = object_metadata_list .get ('objects' )[0 ]
136135 updated_object_metadata = self .visual_recognition .update_object_metadata (
137- collection_id = self . collection_id ,
136+ collection_id = collection_id ,
138137 object = object_metadata .get ('object' ),
139138 new_object = 'updated giraffe training data' ).get_result ()
140139 assert updated_object_metadata is not None
141140
142141 # get object metadata
143142 object_metadata = self .visual_recognition .get_object_metadata (
144- collection_id = self . collection_id ,
143+ collection_id = collection_id ,
145144 object = 'updated giraffe training data' ,
146145 ).get_result ()
147146 assert object_metadata is not None
148147 assert object_metadata .get ('object' ) == 'updated giraffe training data'
149148
150149 # train collection
151- train_result = self .visual_recognition .train (self . collection_id ).get_result ()
150+ train_result = self .visual_recognition .train (collection_id ).get_result ()
152151 assert train_result is not None
153152 assert train_result .get ('training_status' ) is not None
154153
155154 # training usage
156- # training_usage = self.visual_recognition.get_training_usage(
157- # start_time='2019-11-01', end_time='2019-11-27').get_result()
158- # assert training_usage is not None
155+ training_usage = self .visual_recognition .get_training_usage (
156+ start_time = '2019-11-01' , end_time = '2019-11-27' ).get_result ()
157+ assert training_usage is not None
159158
160159 # delete object
161160 self .visual_recognition .delete_object (
162- self .collection_id , object = 'updated giraffe training data' )
163-
164- self .visual_recognition .delete_image (self .collection_id , image_id )
161+ collection_id , object = 'updated giraffe training data' )
165162
166163 # delete collection
167- # self.visual_recognition.delete_collection(collection_id)
164+ self .visual_recognition .delete_collection (collection_id )
0 commit comments