@@ -19,59 +19,58 @@ def setup_class(cls):
19
19
'X-Watson-Learning-Opt-Out' : '1' ,
20
20
'X-Watson-Test' : '1'
21
21
})
22
- cls .collection_id = 'a06f7036-0529-49ee-bdf6-82ddec276923'
23
22
24
23
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
29
28
30
29
my_collection = self .visual_recognition .get_collection (
31
- collection_id = self . collection_id ).get_result ()
30
+ collection_id = collection . get ( ' collection_id' ) ).get_result ()
32
31
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 '
34
33
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
39
38
40
39
collections = self .visual_recognition .list_collections ().get_result (
41
40
).get ('collections' )
42
41
assert collections is not None
43
42
44
- # self.visual_recognition.delete_collection(collection_id=collection_id)
43
+ self .visual_recognition .delete_collection (collection_id = collection_id )
45
44
46
45
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' )
50
49
51
50
add_images = self .visual_recognition .add_images (
52
- self . collection_id ,
51
+ collection_id ,
53
52
image_url = [
53
+ "https://upload.wikimedia.org/wikipedia/commons/3/33/KokoniPurebredDogsGreeceGreekCreamWhiteAdult.jpg" ,
54
54
"https://upload.wikimedia.org/wikipedia/commons/0/07/K%C3%B6nigspudel_Apricot.JPG"
55
55
],
56
56
).get_result ()
57
57
assert add_images is not None
58
58
image_id = add_images .get ('images' )[0 ].get ('image_id' )
59
59
60
60
list_images = self .visual_recognition .list_images (
61
- self .collection_id ).get_result ()
62
- print (list_images )
61
+ collection_id ).get_result ()
63
62
assert list_images is not None
64
63
65
64
image_details = self .visual_recognition .get_image_details (
66
- self . collection_id , image_id ).get_result ()
65
+ collection_id , image_id ).get_result ()
67
66
assert image_details is not None
68
67
69
68
response = self .visual_recognition .get_jpeg_image (
70
- self . collection_id , image_id ).get_result ()
69
+ collection_id , image_id ).get_result ()
71
70
assert response .content is not None
72
71
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 )
75
74
76
75
def test_03_analyze (self ):
77
76
dog_path = os .path .join (os .path .dirname (__file__ ),
@@ -82,7 +81,7 @@ def test_03_analyze(self):
82
81
with open (dog_path , 'rb' ) as dog_file , open (giraffe_path ,
83
82
'rb' ) as giraffe_files :
84
83
analyze_images = self .visual_recognition .analyze (
85
- collection_ids = [self . collection_id ],
84
+ collection_ids = ['a06f7036-0529-49ee-bdf6-82ddec276923' ],
86
85
features = [AnalyzeEnums .Features .OBJECTS .value ],
87
86
images_file = [
88
87
FileWithMetadata (dog_file ),
@@ -95,12 +94,12 @@ def test_03_analyze(self):
95
94
print (json .dumps (analyze_images , indent = 2 ))
96
95
97
96
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
104
103
105
104
# add images
106
105
with open (
@@ -109,7 +108,7 @@ def test_04_objects_and_training(self):
109
108
'../../resources/South_Africa_Luca_Galuzzi_2004.jpeg' ),
110
109
'rb' ) as giraffe_info :
111
110
add_images_result = self .visual_recognition .add_images (
112
- self . collection_id ,
111
+ collection_id ,
113
112
images_file = [FileWithMetadata (giraffe_info )],
114
113
).get_result ()
115
114
assert add_images_result is not None
@@ -118,7 +117,7 @@ def test_04_objects_and_training(self):
118
117
119
118
# add image training data
120
119
training_data = self .visual_recognition .add_image_training_data (
121
- self . collection_id ,
120
+ collection_id ,
122
121
image_id ,
123
122
objects = [
124
123
TrainingDataObject (object = 'giraffe training data' ,
@@ -128,40 +127,38 @@ def test_04_objects_and_training(self):
128
127
129
128
# list objects metadata
130
129
object_metadata_list = self .visual_recognition .list_object_metadata (
131
- collection_id = self . collection_id ).get_result ()
130
+ collection_id = collection_id ).get_result ()
132
131
assert object_metadata_list is not None
133
132
134
133
# update object metadata
135
134
object_metadata = object_metadata_list .get ('objects' )[0 ]
136
135
updated_object_metadata = self .visual_recognition .update_object_metadata (
137
- collection_id = self . collection_id ,
136
+ collection_id = collection_id ,
138
137
object = object_metadata .get ('object' ),
139
138
new_object = 'updated giraffe training data' ).get_result ()
140
139
assert updated_object_metadata is not None
141
140
142
141
# get object metadata
143
142
object_metadata = self .visual_recognition .get_object_metadata (
144
- collection_id = self . collection_id ,
143
+ collection_id = collection_id ,
145
144
object = 'updated giraffe training data' ,
146
145
).get_result ()
147
146
assert object_metadata is not None
148
147
assert object_metadata .get ('object' ) == 'updated giraffe training data'
149
148
150
149
# 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 ()
152
151
assert train_result is not None
153
152
assert train_result .get ('training_status' ) is not None
154
153
155
154
# 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
159
158
160
159
# delete object
161
160
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' )
165
162
166
163
# delete collection
167
- # self.visual_recognition.delete_collection(collection_id)
164
+ self .visual_recognition .delete_collection (collection_id )
0 commit comments