Skip to content

Commit 86fa2a5

Browse files
author
Marcel Odya
committed
Removed private models dependencies
1 parent 7578d68 commit 86fa2a5

3 files changed

Lines changed: 10 additions & 106 deletions

File tree

mlapi/app.py

Lines changed: 6 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,7 @@ def root():
120120
text = {
121121
'available_routes': [
122122
"api.mlapi.io/v2/token - Check current token balance status [POST]",
123-
"api.mlapi.io/v2/cars - Car recognition NN[GET, POST]",
124-
"api.mlapi.io/v2/sentiment - Text Sentiment Analysis [GET, POST]",
123+
"api.mlapi.io/v2/test1 - Car recognition NN[GET, POST]",
125124
]
126125
}
127126
return text
@@ -168,21 +167,21 @@ def user():
168167
pass
169168

170169
## Needed for unathorized pre-requests
171-
@app.route('/v2/cars', methods=['OPTIONS'])
172-
def cars_opt():
170+
@app.route('/v2/test1', methods=['OPTIONS'])
171+
def test1_opt():
173172
return ""
174173

175-
@app.route('/v2/cars', methods=['GET', 'POST'])
174+
@app.route('/v2/test1', methods=['GET', 'POST'])
176175
@jwt_required()
177176
@set_parsers(JSONParser, JpegImageParser, PngImageParser, MultiPartParser)
178177
@reduce_uses
179-
def cars(errors=None):
178+
def test1(errors=None):
180179
'''Responds with predictions on the sent image on POST. Returns description on GET request.
181180
Accepted formats: image/jpeg, image/png, application/json with an image in Base64 format.
182181
'''
183182
if errors:
184183
return {"result":errors_handler(errors)}
185-
model_name = 'cars'
184+
model_name = 'test1'
186185
logging.debug("REQUEST: {}".format(repr(request)))
187186
if request.method == 'GET':
188187
return {
@@ -223,45 +222,6 @@ def cars(errors=None):
223222
"result":"You provided no data"
224223
}
225224

226-
## Needed for unathorized pre-requests
227-
@app.route('/v2/sentiment', methods=['OPTIONS'])
228-
def sentiment_opt():
229-
return ""
230-
231-
@app.route('/v2/sentiment', methods=['GET', 'POST'])
232-
@jwt_required()
233-
@reduce_uses
234-
def sentiment(errors=None):
235-
'''Responds with predictions on the sent text on POST. Returns description on GET request.
236-
Accepted formats: application/json
237-
'''
238-
if errors:
239-
return {"result":errors_handler(errors)}
240-
241-
model_name = 'sentiment'
242-
if request.method == 'GET':
243-
return {
244-
"description" : "Make an authenticated POST request for predicting the text. { 'text' : 'Text to predict' }",
245-
"accepted_content_type" : [
246-
"application/json"
247-
]
248-
}
249-
elif request.method == 'POST':
250-
if request.data:
251-
response = {
252-
"result": models_holder_instance.sendRequest(model_name, request.data)
253-
}
254-
save_request(
255-
response = str(response['result']),
256-
data_type = "T",
257-
data = request.data['text'])
258-
259-
return response
260-
else:
261-
return {
262-
"result":"You provided no data"
263-
}
264-
265225
return app, bcrypt, database, image_storage, jwt
266226

267227

mlapi/mlapi_db_tests.db

0 Bytes
Binary file not shown.

tests/test__app.py

Lines changed: 4 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -72,31 +72,6 @@ def test_not_getting_token_providing_no_credentails(self):
7272
############################################################
7373
######################## GET TESTS #########################
7474
############################################################
75-
@mock.patch("flask_jwt._jwt_required")
76-
def test_app_is_responding_on_get_cars(self, monkeypatch):
77-
monkeypatch = jwt_mock
78-
response = self.client.get("/v2/cars")
79-
valid_response = {
80-
"description" : "Make an authenticated POST request for predicting the image. POST binary file with proper header or { 'image' : 'BASE64 image' }",
81-
"accepted_content_type" : [
82-
"image/jpeg",
83-
"image/png",
84-
"application/json"
85-
]
86-
}
87-
self.assertEquals(response.json, valid_response)
88-
89-
@mock.patch("flask_jwt._jwt_required")
90-
def test_app_is_responding_on_get_sentiment(self, monkeypatch):
91-
monkeypatch = jwt_mock
92-
response = self.client.get("/v2/sentiment")
93-
valid_response = {
94-
"description" : "Make an authenticated POST request for predicting the text. { 'text' : 'Text to predict' }",
95-
"accepted_content_type" : [
96-
"application/json"
97-
]
98-
}
99-
self.assertEquals(response.json, valid_response)
10075

10176
@mock.patch("flask_jwt._jwt_required")
10277
def test_app_is_responding_on_get_root(self, monkeypatch):
@@ -105,8 +80,7 @@ def test_app_is_responding_on_get_root(self, monkeypatch):
10580
valid_response = {
10681
'available_routes': [
10782
"api.mlapi.io/v2/token - Check current token balance status [POST]",
108-
"api.mlapi.io/v2/cars - Car recognition NN[GET, POST]",
109-
"api.mlapi.io/v2/sentiment - Text Sentiment Analysis [GET, POST]",
83+
"api.mlapi.io/v2/test1 - Car recognition NN[GET, POST]",
11084
]
11185
}
11286
self.assertEquals(response.json, valid_response)
@@ -119,40 +93,10 @@ def test_app_is_redirecting_from_slash(self, identity_mock, monkeypatch):
11993

12094
response = self.client.get("/")
12195
self.assertRedirects(response, '/v2/')
122-
# @mock.patch("flask_jwt._jwt_required")
123-
# @mock.patch("flask_jwt.current_identity")
124-
# def test_app_is_redirecting_from_get_cars_with_trailing_slash(self, identity_mock, monkeypatch):
125-
# monkeypatch = jwt_mock
126-
# identity_mock = { 'user_id' : 1 }
127-
128-
# response = self.client.get("/v2/cars/")
129-
# self.assertRedirects(response, '/v2/cars')
130-
131-
# @mock.patch("flask_jwt._jwt_required")
132-
# @mock.patch("flask_jwt.current_identity")
133-
# def test_app_is_redirecting_from_get_sentiment_with_trailing_slash(self, identity_mock, monkeypatch):
134-
# monkeypatch = jwt_mock
135-
# identity_mock = { 'user_id' : 1 }
136-
137-
# response = self.client.get("/v2/sentiment/")
138-
# self.assertRedirects(response, '/v2/sentiment')
13996

14097
############################################################
14198
######################## POST TESTS ########################
14299
############################################################
143-
@mock.patch("flask_jwt._jwt_required")
144-
@mock.patch("flask_jwt.current_identity")
145-
def test_app_is_responding_on_post_sentiment(self, identity_mock, monkeypatch):
146-
monkeypatch = jwt_mock
147-
identity_mock = { 'user_id' : 1 }
148-
149-
response = self.client.post("/v2/sentiment",
150-
data='{"text":"polecam"}',
151-
headers={'content-type': 'application/json'}
152-
)
153-
valid_response = "{'prediction': ['Neutral: 0.11%', 'Positive: 99.52%', 'Negative: 0.34%']}".split(":")[1::2]
154-
self.assert_200(response, "Not returned 200 code.")
155-
self.assertEquals(str(response.json).split(":")[1::2], valid_response)
156100

157101
@mock.patch("flask_jwt._jwt_required")
158102
@mock.patch("flask_jwt.current_identity")
@@ -170,7 +114,7 @@ def test_posted_binary_image_gets_saved(self, patch_uuid, identity_mock, patch_j
170114

171115
image_name = "{}.{}".format(fake_uuid, "jpg")
172116
response = self.client.post(
173-
'/v2/cars',
117+
'/v2/test1',
174118
data=fake_image_bytes,
175119
headers={'content-type': 'image/jpeg'}
176120
)
@@ -183,7 +127,7 @@ def test_posted_binary_image_gets_saved(self, patch_uuid, identity_mock, patch_j
183127

184128
image_name = "{}.{}".format(fake_uuid, "png")
185129
response = self.client.post(
186-
'/v2/cars',
130+
'/v2/test1',
187131
data=fake_image_bytes,
188132
headers={'content-type': 'image/png'}
189133
)
@@ -210,7 +154,7 @@ def test_posted_base64_image_gets_saved(self, patch_uuid, identity_mock, patch_j
210154
b = base64.b64decode(fake_image_json['image'].split(",")[1])
211155
image_name = "{}.{}".format(fake_uuid, "png")
212156
response = self.client.post(
213-
'/v2/cars',
157+
'/v2/test1',
214158
data=json.dumps(fake_image_json),
215159
headers={'content-type': 'application/json'}
216160
)

0 commit comments

Comments
 (0)