Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Goblin OGM
AIO Gremlin
Commits
17878e5f
Commit
17878e5f
authored
Nov 18, 2015
by
davebshow
Browse files
fixed sasl tests, also fixed base64 encoding for auth string
parent
ca5c1e1b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
219 additions
and
40 deletions
+219
-40
aiogremlin/subprotocol.py
aiogremlin/subprotocol.py
+1
-2
setup.py
setup.py
+3
-3
tests/test_sasl.py
tests/test_sasl.py
+209
-9
tests/tests.py
tests/tests.py
+6
-26
No files found.
aiogremlin/subprotocol.py
View file @
17878e5f
...
...
@@ -69,7 +69,6 @@ class GremlinWriter:
if
binary
:
message
=
self
.
_set_message_header
(
message
,
mime_type
)
self
.
ws
.
send
(
message
,
binary
=
binary
)
print
(
message
)
return
self
.
ws
@
staticmethod
...
...
@@ -111,7 +110,7 @@ class GremlinWriter:
"op"
:
"authentication"
,
"processor"
:
processor
,
"args"
:
{
"sasl"
:
base64
.
b64encode
(
auth
)
"sasl"
:
base64
.
b64encode
(
auth
)
.
decode
()
}
}
if
session
is
None
:
...
...
setup.py
View file @
17878e5f
...
...
@@ -3,7 +3,7 @@ from setuptools import setup
setup
(
name
=
"aiogremlin"
,
version
=
"0.1.
1
"
,
version
=
"0.1.
2
"
,
url
=
""
,
license
=
"MIT"
,
author
=
"davebshow"
,
...
...
@@ -12,8 +12,8 @@ setup(
long_description
=
open
(
"README.txt"
).
read
(),
packages
=
[
"aiogremlin"
,
"tests"
],
install_requires
=
[
"aiohttp==0.1
6.5
"
,
"aiowebsocketclient==0.0.
3
"
"aiohttp==0.1
8.4
"
,
"aiowebsocketclient==0.0.
4
"
],
test_suite
=
"tests"
,
classifiers
=
[
...
...
tests/test_sasl.py
View file @
17878e5f
...
...
@@ -8,21 +8,64 @@ import aiohttp
from
aiogremlin
import
(
submit
,
GremlinConnector
,
GremlinClient
,
GremlinClientSession
,
GremlinServerError
,
GremlinClientWebSocketResponse
)
from
tests
import
SubmitTest
,
GremlinClientTest
,
GremlinClientSessionTest
class
Sasl
SubmitTest
(
SubmitTest
):
class
SubmitTest
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
uri
=
'https://localhost:8182/'
self
.
loop
=
asyncio
.
new_event_loop
()
asyncio
.
set_event_loop
(
None
)
def
tearDown
(
self
):
self
.
loop
.
close
()
class
SaslGremlinClientTest
(
GremlinClientTest
):
def
test_submit
(
self
):
@
asyncio
.
coroutine
def
go
():
resp
=
yield
from
submit
(
"x + x"
,
url
=
'https://localhost:8182/'
,
bindings
=
{
"x"
:
4
},
loop
=
self
.
loop
,
username
=
"stephen"
,
password
=
"password"
)
results
=
yield
from
resp
.
get
()
return
results
results
=
self
.
loop
.
run_until_complete
(
go
())
self
.
assertEqual
(
results
[
0
].
data
[
0
],
8
)
def
test_rebinding
(
self
):
@
asyncio
.
coroutine
def
go1
():
result
=
yield
from
submit
(
"graph2.addVertex()"
,
url
=
'https://localhost:8182/'
,
loop
=
self
.
loop
,
username
=
"stephen"
,
password
=
"password"
)
resp
=
yield
from
result
.
get
()
try
:
self
.
loop
.
run_until_complete
(
go1
())
error
=
False
except
GremlinServerError
:
error
=
True
self
.
assertTrue
(
error
)
@
asyncio
.
coroutine
def
go2
():
result
=
yield
from
submit
(
"graph2.addVertex()"
,
url
=
'https://localhost:8182/'
,
rebindings
=
{
"graph2"
:
"graph"
},
loop
=
self
.
loop
,
username
=
"stephen"
,
password
=
"password"
)
resp
=
yield
from
result
.
get
()
self
.
assertEqual
(
len
(
resp
),
1
)
try
:
self
.
loop
.
run_until_complete
(
go2
())
except
GremlinServerError
:
print
(
"RELEASE DOES NOT SUPPORT REBINDINGS"
)
class
GremlinClientTest
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
uri
=
'https://localhost:8182/'
self
.
loop
=
asyncio
.
new_event_loop
()
asyncio
.
set_event_loop
(
None
)
connector
=
aiohttp
.
TCPConnector
(
force_close
=
False
,
loop
=
self
.
loop
,
...
...
@@ -32,15 +75,92 @@ class SaslGremlinClientTest(GremlinClientTest):
connector
=
connector
,
loop
=
self
.
loop
,
ws_response_class
=
GremlinClientWebSocketResponse
)
self
.
gc
=
GremlinClient
(
url
=
self
.
uri
,
loop
=
self
.
loop
,
self
.
gc
=
GremlinClient
(
url
=
"https://localhost:8182/"
,
loop
=
self
.
loop
,
username
=
"stephen"
,
password
=
"password"
,
client_session
=
client_session
)
def
tearDown
(
self
):
self
.
loop
.
run_until_complete
(
self
.
gc
.
close
())
self
.
loop
.
close
()
def
test_connection
(
self
):
@
asyncio
.
coroutine
def
go
():
ws
=
yield
from
self
.
gc
.
_connector
.
ws_connect
(
self
.
gc
.
url
)
self
.
assertFalse
(
ws
.
closed
)
yield
from
ws
.
close
()
self
.
loop
.
run_until_complete
(
go
())
def
test_execute
(
self
):
@
asyncio
.
coroutine
def
go
():
resp
=
yield
from
self
.
gc
.
execute
(
"x + x"
,
bindings
=
{
"x"
:
4
})
return
resp
results
=
self
.
loop
.
run_until_complete
(
go
())
self
.
assertEqual
(
results
[
0
].
data
[
0
],
8
)
def
test_sub_waitfor
(
self
):
sub1
=
self
.
gc
.
execute
(
"x + x"
,
bindings
=
{
"x"
:
1
})
sub2
=
self
.
gc
.
execute
(
"x + x"
,
bindings
=
{
"x"
:
2
})
sub3
=
self
.
gc
.
execute
(
"x + x"
,
bindings
=
{
"x"
:
4
})
coro
=
asyncio
.
gather
(
*
[
asyncio
.
async
(
sub1
,
loop
=
self
.
loop
),
asyncio
.
async
(
sub2
,
loop
=
self
.
loop
),
asyncio
.
async
(
sub3
,
loop
=
self
.
loop
)],
loop
=
self
.
loop
)
# Here I am looking for resource warnings.
results
=
self
.
loop
.
run_until_complete
(
coro
)
self
.
assertIsNotNone
(
results
)
def
test_resp_stream
(
self
):
@
asyncio
.
coroutine
def
stream_coro
():
results
=
[]
resp
=
yield
from
self
.
gc
.
submit
(
"x + x"
,
bindings
=
{
"x"
:
4
})
while
True
:
f
=
yield
from
resp
.
stream
.
read
()
if
f
is
None
:
break
results
.
append
(
f
)
self
.
assertEqual
(
results
[
0
].
data
[
0
],
8
)
self
.
loop
.
run_until_complete
(
stream_coro
())
def
test_execute_error
(
self
):
execute
=
self
.
gc
.
execute
(
"x + x g.asdfas"
,
bindings
=
{
"x"
:
4
})
try
:
self
.
loop
.
run_until_complete
(
execute
)
error
=
False
except
:
error
=
True
self
.
assertTrue
(
error
)
class
SaslGremlinClientSessionTest
(
GremlinClientSessionTest
):
def
test_rebinding
(
self
):
execute
=
self
.
gc
.
execute
(
"graph2.addVertex()"
)
try
:
self
.
loop
.
run_until_complete
(
execute
)
error
=
False
except
GremlinServerError
:
error
=
True
self
.
assertTrue
(
error
)
@
asyncio
.
coroutine
def
go
():
result
=
yield
from
self
.
gc
.
execute
(
"graph2.addVertex()"
,
rebindings
=
{
"graph2"
:
"graph"
})
self
.
assertEqual
(
len
(
result
),
1
)
try
:
self
.
loop
.
run_until_complete
(
go
())
except
GremlinServerError
:
print
(
"RELEASE DOES NOT SUPPORT REBINDINGS"
)
class
GremlinClientSessionTest
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
uri
=
'https://localhost:8182/'
self
.
loop
=
asyncio
.
new_event_loop
()
asyncio
.
set_event_loop
(
None
)
connector
=
aiohttp
.
TCPConnector
(
force_close
=
False
,
loop
=
self
.
loop
,
...
...
@@ -50,7 +170,7 @@ class SaslGremlinClientSessionTest(GremlinClientSessionTest):
connector
=
connector
,
loop
=
self
.
loop
,
ws_response_class
=
GremlinClientWebSocketResponse
)
self
.
gc
=
GremlinClientSession
(
url
=
self
.
uri
,
self
.
gc
=
GremlinClientSession
(
url
=
"https://localhost:8182/"
,
loop
=
self
.
loop
,
username
=
"stephen"
,
password
=
"password"
,
client_session
=
client_session
)
...
...
@@ -59,6 +179,86 @@ class SaslGremlinClientSessionTest(GremlinClientSessionTest):
self
.
script2
=
"v.property('name')"
def
tearDown
(
self
):
self
.
loop
.
run_until_complete
(
self
.
gc
.
close
())
self
.
loop
.
close
()
def
test_session
(
self
):
@
asyncio
.
coroutine
def
go
():
yield
from
self
.
gc
.
execute
(
self
.
script1
)
results
=
yield
from
self
.
gc
.
execute
(
self
.
script2
)
return
results
results
=
self
.
loop
.
run_until_complete
(
go
())
self
.
assertEqual
(
results
[
0
].
data
[
0
][
'value'
],
'Dave'
)
def
test_session_reset
(
self
):
@
asyncio
.
coroutine
def
go
():
yield
from
self
.
gc
.
execute
(
self
.
script1
)
self
.
gc
.
reset_session
()
results
=
yield
from
self
.
gc
.
execute
(
self
.
script2
)
return
results
try
:
results
=
self
.
loop
.
run_until_complete
(
go
())
error
=
False
except
GremlinServerError
:
error
=
True
self
.
assertTrue
(
error
)
def
test_session_manual_reset
(
self
):
@
asyncio
.
coroutine
def
go
():
yield
from
self
.
gc
.
execute
(
self
.
script1
)
new_sess
=
str
(
uuid
.
uuid4
())
sess
=
self
.
gc
.
reset_session
(
session
=
new_sess
)
self
.
assertEqual
(
sess
,
new_sess
)
self
.
assertEqual
(
self
.
gc
.
session
,
new_sess
)
results
=
yield
from
self
.
gc
.
execute
(
self
.
script2
)
return
results
try
:
results
=
self
.
loop
.
run_until_complete
(
go
())
error
=
False
except
GremlinServerError
:
error
=
True
self
.
assertTrue
(
error
)
def
test_session_set
(
self
):
@
asyncio
.
coroutine
def
go
():
yield
from
self
.
gc
.
execute
(
self
.
script1
)
new_sess
=
str
(
uuid
.
uuid4
())
self
.
gc
.
session
=
new_sess
self
.
assertEqual
(
self
.
gc
.
session
,
new_sess
)
results
=
yield
from
self
.
gc
.
execute
(
self
.
script2
)
return
results
try
:
results
=
self
.
loop
.
run_until_complete
(
go
())
error
=
False
except
GremlinServerError
:
error
=
True
self
.
assertTrue
(
error
)
def
test_resp_session
(
self
):
@
asyncio
.
coroutine
def
go
():
session
=
str
(
uuid
.
uuid4
())
self
.
gc
.
session
=
session
resp
=
yield
from
self
.
gc
.
submit
(
"x + x"
,
bindings
=
{
"x"
:
4
})
while
True
:
f
=
yield
from
resp
.
stream
.
read
()
if
f
is
None
:
break
self
.
assertEqual
(
resp
.
session
,
session
)
self
.
loop
.
run_until_complete
(
go
())
if
__name__
==
"__main__"
:
unittest
.
main
()
tests/tests.py
View file @
17878e5f
...
...
@@ -13,7 +13,6 @@ from aiogremlin import (submit, GremlinConnector, GremlinClient,
class
SubmitTest
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
uri
=
'http://localhost:8182/'
self
.
loop
=
asyncio
.
new_event_loop
()
asyncio
.
set_event_loop
(
None
)
...
...
@@ -24,7 +23,7 @@ class SubmitTest(unittest.TestCase):
@
asyncio
.
coroutine
def
go
():
resp
=
yield
from
submit
(
"x + x"
,
url
=
self
.
uri
,
resp
=
yield
from
submit
(
"x + x"
,
url
=
'http://localhost:8182/'
,
bindings
=
{
"x"
:
4
},
loop
=
self
.
loop
,
username
=
"stephen"
,
password
=
"password"
)
results
=
yield
from
resp
.
get
()
...
...
@@ -37,7 +36,7 @@ class SubmitTest(unittest.TestCase):
@
asyncio
.
coroutine
def
go1
():
result
=
yield
from
submit
(
"graph2.addVertex()"
,
url
=
'http
s
://localhost:8182/'
,
url
=
'http://localhost:8182/'
,
loop
=
self
.
loop
,
username
=
"stephen"
,
password
=
"password"
)
resp
=
yield
from
result
.
get
()
...
...
@@ -52,7 +51,7 @@ class SubmitTest(unittest.TestCase):
@
asyncio
.
coroutine
def
go2
():
result
=
yield
from
submit
(
"graph2.addVertex()"
,
url
=
self
.
uri
,
"graph2.addVertex()"
,
url
=
'http://localhost:8182/'
,
rebindings
=
{
"graph2"
:
"graph"
},
loop
=
self
.
loop
,
username
=
"stephen"
,
password
=
"password"
)
resp
=
yield
from
result
.
get
()
...
...
@@ -67,19 +66,10 @@ class SubmitTest(unittest.TestCase):
class
GremlinClientTest
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
uri
=
'http://localhost:8182/'
self
.
loop
=
asyncio
.
new_event_loop
()
asyncio
.
set_event_loop
(
None
)
connector
=
aiohttp
.
TCPConnector
(
force_close
=
False
,
loop
=
self
.
loop
,
verify_ssl
=
False
)
client_session
=
aiohttp
.
ClientSession
(
connector
=
connector
,
loop
=
self
.
loop
,
ws_response_class
=
GremlinClientWebSocketResponse
)
self
.
gc
=
GremlinClient
(
url
=
self
.
uri
,
loop
=
self
.
loop
,
username
=
"stephen"
,
password
=
"password"
,
client_session
=
client_session
)
self
.
gc
=
GremlinClient
(
url
=
"http://localhost:8182/"
,
loop
=
self
.
loop
)
def
tearDown
(
self
):
self
.
loop
.
run_until_complete
(
self
.
gc
.
close
())
...
...
@@ -163,20 +153,10 @@ class GremlinClientTest(unittest.TestCase):
class
GremlinClientSessionTest
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
uri
=
'http://localhost:8182/'
self
.
loop
=
asyncio
.
new_event_loop
()
asyncio
.
set_event_loop
(
None
)
connector
=
aiohttp
.
TCPConnector
(
force_close
=
False
,
loop
=
self
.
loop
,
verify_ssl
=
False
)
client_session
=
aiohttp
.
ClientSession
(
connector
=
connector
,
loop
=
self
.
loop
,
ws_response_class
=
GremlinClientWebSocketResponse
)
self
.
gc
=
GremlinClientSession
(
url
=
self
.
uri
,
loop
=
self
.
loop
,
username
=
"stephen"
,
password
=
"password"
,
client_session
=
client_session
)
self
.
gc
=
GremlinClientSession
(
url
=
"http://localhost:8182/"
,
loop
=
self
.
loop
)
self
.
script1
=
"""v=graph.addVertex('name', 'Dave')"""
...
...
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