Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
senpy
senpy
Commits
c939b095
Commit
c939b095
authored
Oct 30, 2018
by
J. Fernando Sánchez
Browse files
Fix POST. Closes
#56
parent
6dd4a449
Changes
5
Hide whitespace changes
Inline
Side-by-side
senpy/blueprints.py
View file @
c939b095
...
@@ -69,7 +69,7 @@ def encoded_url(url=None, base=None):
...
@@ -69,7 +69,7 @@ def encoded_url(url=None, base=None):
if
request
.
method
==
'GET'
:
if
request
.
method
==
'GET'
:
url
=
request
.
full_path
[
1
:]
# Remove the first slash
url
=
request
.
full_path
[
1
:]
# Remove the first slash
else
:
else
:
hash
(
frozenset
(
request
.
form
.
params
()
.
items
()))
hash
(
frozenset
(
request
.
parameters
.
items
()))
code
=
'hash:{}'
.
format
(
hash
)
code
=
'hash:{}'
.
format
(
hash
)
code
=
code
or
base64
.
urlsafe_b64encode
(
url
.
encode
()).
decode
()
code
=
code
or
base64
.
urlsafe_b64encode
(
url
.
encode
()).
decode
()
...
...
senpy/gsitk_compat.py
View file @
c939b095
...
@@ -15,9 +15,12 @@ try:
...
@@ -15,9 +15,12 @@ try:
from
gsitk.datasets.datasets
import
DatasetManager
from
gsitk.datasets.datasets
import
DatasetManager
from
gsitk.evaluation.evaluation
import
Evaluation
as
Eval
from
gsitk.evaluation.evaluation
import
Evaluation
as
Eval
from
sklearn.pipeline
import
Pipeline
from
sklearn.pipeline
import
Pipeline
GSITK_AVAILABLE
=
True
import
pkg_resources
GSITK_VERSION
=
pkg_resources
.
get_distribution
(
"gsitk"
).
version
.
split
()
GSITK_AVAILABLE
=
GSITK_VERSION
>
(
0
,
1
,
9
,
1
)
# Earlier versions have a bug
modules
=
locals
()
modules
=
locals
()
except
ImportError
:
except
ImportError
:
logger
.
warn
(
IMPORTMSG
)
logger
.
warn
ing
(
IMPORTMSG
)
GSITK_AVAILABLE
=
False
GSITK_AVAILABLE
=
False
GSITK_VERSION
=
()
DatasetManager
=
Eval
=
Pipeline
=
raise_exception
DatasetManager
=
Eval
=
Pipeline
=
raise_exception
tests/test_blueprints.py
View file @
c939b095
...
@@ -67,6 +67,20 @@ class BlueprintsTest(TestCase):
...
@@ -67,6 +67,20 @@ class BlueprintsTest(TestCase):
logging
.
debug
(
"Got response: %s"
,
js
)
logging
.
debug
(
"Got response: %s"
,
js
)
assert
"@context"
in
js
assert
"@context"
in
js
assert
"entries"
in
js
assert
"entries"
in
js
assert
len
(
js
[
'analysis'
])
==
1
def
test_analysis_post
(
self
):
"""
The results for a POST request should be the same as for a GET request.
"""
resp
=
self
.
client
.
post
(
"/api/"
,
data
=
{
'i'
:
'My aloha mohame'
,
'with_parameters'
:
True
})
self
.
assertCode
(
resp
,
200
)
js
=
parse_resp
(
resp
)
logging
.
debug
(
"Got response: %s"
,
js
)
assert
"@context"
in
js
assert
"entries"
in
js
assert
len
(
js
[
'analysis'
])
==
1
def
test_analysis_extra
(
self
):
def
test_analysis_extra
(
self
):
"""
"""
...
...
tests/test_client.py
View file @
c939b095
...
@@ -24,6 +24,19 @@ class ModelsTest(TestCase):
...
@@ -24,6 +24,19 @@ class ModelsTest(TestCase):
except
Error
:
except
Error
:
pass
pass
def
test_client_post
(
self
):
endpoint
=
'http://dummy/'
client
=
Client
(
endpoint
)
with
patch_requests
(
'http://dummy/'
,
Results
()):
resp
=
client
.
analyse
(
'hello'
)
assert
isinstance
(
resp
,
Results
)
with
patch_requests
(
'http://dummy/'
,
Error
(
'Nothing'
),
method
=
'POST'
):
try
:
client
.
analyse
(
input
=
'hello'
,
method
=
'POST'
,
algorithm
=
'NONEXISTENT'
)
raise
Exception
(
'Exceptions should be raised. This is not golang'
)
except
Error
:
pass
def
test_plugins
(
self
):
def
test_plugins
(
self
):
endpoint
=
'http://dummy/'
endpoint
=
'http://dummy/'
client
=
Client
(
endpoint
)
client
=
Client
(
endpoint
)
...
...
tests/test_plugins.py
View file @
c939b095
#!/bin/env python
#!/bin/env python
import
os
import
os
import
sys
import
pickle
import
pickle
import
shutil
import
shutil
import
tempfile
import
tempfile
from
unittest
import
TestCase
from
unittest
import
TestCase
,
skipIf
from
senpy.models
import
Results
,
Entry
,
EmotionSet
,
Emotion
,
Plugins
from
senpy.models
import
Results
,
Entry
,
EmotionSet
,
Emotion
,
Plugins
from
senpy
import
plugins
from
senpy
import
plugins
from
senpy.plugins.conversion.emotion.centroids
import
CentroidConversion
from
senpy.plugins.conversion.emotion.centroids
import
CentroidConversion
from
senpy.gsitk_compat
import
GSITK_AVAILABLE
import
pandas
as
pd
import
pandas
as
pd
...
@@ -346,13 +346,15 @@ class PluginsTest(TestCase):
...
@@ -346,13 +346,15 @@ class PluginsTest(TestCase):
smart_metrics
=
results
[
0
].
metrics
[
0
]
smart_metrics
=
results
[
0
].
metrics
[
0
]
assert
abs
(
smart_metrics
[
'accuracy'
]
-
1
)
<
0.01
assert
abs
(
smart_metrics
[
'accuracy'
]
-
1
)
<
0.01
@
skipIf
(
not
GSITK_AVAILABLE
,
"GSITK is not available"
)
def
test_evaluation
(
self
):
def
test_evaluation
(
self
):
if
sys
.
version_info
<
(
3
,
0
):
self
.
_test_evaluation
()
with
self
.
assertRaises
(
Exception
)
as
context
:
self
.
_test_evaluation
(
)
@
skipIf
(
GSITK_AVAILABLE
,
"GSITK is available"
)
self
.
assertTrue
(
'GSITK '
in
str
(
context
.
exception
))
def
test_evaluation_unavailable
(
self
):
else
:
with
self
.
assertRaises
(
Exception
)
as
context
:
self
.
_test_evaluation
()
self
.
_test_evaluation
()
self
.
assertTrue
(
'GSITK '
in
str
(
context
.
exception
))
def
make_mini_test
(
fpath
):
def
make_mini_test
(
fpath
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment