Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
DuniterPy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
clients
python
DuniterPy
Commits
e045755a
Commit
e045755a
authored
6 years ago
by
Vincent Texier
Browse files
Options
Downloads
Patches
Plain Diff
issue
#56
WIP - Fix session mandatory in Endpoint.conn_handler() parameters
parent
b35ccec9
No related branches found
No related tags found
No related merge requests found
Pipeline
#2682
passed
6 years ago
Stage: github-sync
Stage: build
Stage: test
Stage: release
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
duniterpy/api/endpoint.py
+7
-9
7 additions, 9 deletions
duniterpy/api/endpoint.py
tests/api/bma/test_bma.py
+37
-10
37 additions, 10 deletions
tests/api/bma/test_bma.py
with
44 additions
and
19 deletions
duniterpy/api/endpoint.py
+
7
−
9
View file @
e045755a
...
...
@@ -42,7 +42,7 @@ class Endpoint:
def
inline
(
self
)
->
str
:
raise
NotImplementedError
(
"
inline() is not implemented
"
)
def
conn_handler
(
self
,
session
:
aiohttp
.
ClientSession
=
None
,
proxy
:
str
=
None
)
->
ConnectionHandler
:
def
conn_handler
(
self
,
session
:
aiohttp
.
ClientSession
,
proxy
:
str
=
None
)
->
ConnectionHandler
:
raise
NotImplementedError
(
"
conn_handler is not implemented
"
)
def
__str__
(
self
)
->
str
:
...
...
@@ -85,7 +85,7 @@ class UnknownEndpoint(Endpoint):
doc
+=
"
{0}
"
.
format
(
p
)
return
doc
def
conn_handler
(
self
,
session
:
aiohttp
.
ClientSession
=
None
,
proxy
:
str
=
None
)
->
ConnectionHandler
:
def
conn_handler
(
self
,
session
:
aiohttp
.
ClientSession
,
proxy
:
str
=
None
)
->
ConnectionHandler
:
return
ConnectionHandler
(
""
,
""
,
""
,
0
,
""
)
def
__str__
(
self
)
->
str
:
...
...
@@ -166,8 +166,7 @@ class BMAEndpoint(Endpoint):
IPv6
=
(
"
{0}
"
.
format
(
self
.
ipv6
)
if
self
.
ipv6
else
""
),
PORT
=
(
"
{0}
"
.
format
(
self
.
port
)
if
self
.
port
else
""
))
# fixme: session must be mandatory
def
conn_handler
(
self
,
session
:
aiohttp
.
ClientSession
=
None
,
proxy
:
str
=
None
)
->
ConnectionHandler
:
def
conn_handler
(
self
,
session
:
aiohttp
.
ClientSession
,
proxy
:
str
=
None
)
->
ConnectionHandler
:
"""
Return connection handler instance for the endpoint
...
...
@@ -247,8 +246,7 @@ class SecuredBMAEndpoint(BMAEndpoint):
inlined
=
[
str
(
info
)
for
info
in
(
self
.
server
,
self
.
ipv4
,
self
.
ipv6
,
self
.
port
,
self
.
path
)
if
info
]
return
SecuredBMAEndpoint
.
API
+
"
"
+
"
"
.
join
(
inlined
)
# fixme: session must be mandatory
def
conn_handler
(
self
,
session
:
aiohttp
.
ClientSession
=
None
,
proxy
:
str
=
None
)
->
ConnectionHandler
:
def
conn_handler
(
self
,
session
:
aiohttp
.
ClientSession
,
proxy
:
str
=
None
)
->
ConnectionHandler
:
"""
Return connection handler instance for the endpoint
...
...
@@ -297,7 +295,7 @@ class WS2PEndpoint(Endpoint):
inlined
=
[
str
(
info
)
for
info
in
(
self
.
ws2pid
,
self
.
server
,
self
.
port
,
self
.
path
)
if
info
]
return
WS2PEndpoint
.
API
+
"
"
+
"
"
.
join
(
inlined
)
def
conn_handler
(
self
,
session
:
aiohttp
.
ClientSession
=
None
,
proxy
:
str
=
None
)
->
ConnectionHandler
:
def
conn_handler
(
self
,
session
:
aiohttp
.
ClientSession
,
proxy
:
str
=
None
)
->
ConnectionHandler
:
"""
Return connection handler instance for the endpoint
...
...
@@ -345,7 +343,7 @@ class ESUserEndpoint(Endpoint):
inlined
=
[
str
(
info
)
for
info
in
(
self
.
server
,
self
.
port
)
if
info
]
return
ESUserEndpoint
.
API
+
"
"
+
"
"
.
join
(
inlined
)
def
conn_handler
(
self
,
session
:
aiohttp
.
ClientSession
=
None
,
proxy
:
str
=
None
)
->
ConnectionHandler
:
def
conn_handler
(
self
,
session
:
aiohttp
.
ClientSession
,
proxy
:
str
=
None
)
->
ConnectionHandler
:
"""
Return connection handler instance for the endpoint
...
...
@@ -392,7 +390,7 @@ class ESSubscribtionEndpoint(Endpoint):
inlined
=
[
str
(
info
)
for
info
in
(
self
.
server
,
self
.
port
)
if
info
]
return
ESSubscribtionEndpoint
.
API
+
"
"
+
"
"
.
join
(
inlined
)
def
conn_handler
(
self
,
session
:
aiohttp
.
ClientSession
=
None
,
proxy
:
str
=
None
)
->
ConnectionHandler
:
def
conn_handler
(
self
,
session
:
aiohttp
.
ClientSession
,
proxy
:
str
=
None
)
->
ConnectionHandler
:
"""
Return connection handler instance for the endpoint
...
...
This diff is collapsed.
Click to expand it.
tests/api/bma/test_bma.py
+
37
−
10
View file @
e045755a
import
asyncio
import
unittest
import
aiohttp
from
duniterpy.api.client
import
API
,
parse_error
from
duniterpy.api.endpoint
import
BMAEndpoint
class
TestBmaApi
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
loop
=
asyncio
.
new_event_loop
()
asyncio
.
set_event_loop
(
self
.
loop
)
def
tearDown
(
self
):
try
:
self
.
loop
.
stop
()
self
.
loop
.
close
()
finally
:
asyncio
.
set_event_loop
(
None
)
def
test_reverse_url_complete
(
self
):
async
def
go
():
endpoint
=
BMAEndpoint
(
"
test.com
"
,
"
124.2.2.1
"
,
"
2001:0db8:0000:85a3:0000:0000:ac1f:8001
"
,
9092
)
api
=
API
(
endpoint
.
conn_handler
(),
"
any
"
)
session
=
aiohttp
.
ClientSession
()
api
=
API
(
endpoint
.
conn_handler
(
session
),
"
any
"
)
self
.
assertEqual
(
api
.
reverse_url
(
"
http
"
,
"
/test/url
"
),
"
http://test.com:9092/any/test/url
"
)
await
session
.
close
()
self
.
loop
.
run_until_complete
(
go
())
def
test_reverse_url_only_ipv4
(
self
):
async
def
go
():
endpoint
=
BMAEndpoint
(
""
,
"
124.2.2.1
"
,
""
,
9092
)
api
=
API
(
endpoint
.
conn_handler
(),
"
any
"
)
session
=
aiohttp
.
ClientSession
()
api
=
API
(
endpoint
.
conn_handler
(
session
),
"
any
"
)
self
.
assertEqual
(
api
.
reverse_url
(
"
http
"
,
"
/test/url
"
),
"
http://124.2.2.1:9092/any/test/url
"
)
await
session
.
close
()
self
.
loop
.
run_until_complete
(
go
())
def
test_reverse_url_only_ipv6
(
self
):
async
def
go
():
endpoint
=
BMAEndpoint
(
""
,
""
,
"
2001:0db8:0000:85a3:0000:0000:ac1f:8001
"
,
9092
)
api
=
API
(
endpoint
.
conn_handler
(),
"
any
"
)
session
=
aiohttp
.
ClientSession
()
api
=
API
(
endpoint
.
conn_handler
(
session
),
"
any
"
)
self
.
assertEqual
(
api
.
reverse_url
(
"
http
"
,
"
/test/url
"
),
"
http://[2001:0db8:0000:85a3:0000:0000:ac1f:8001]:9092/any/test/url
"
)
await
session
.
close
()
self
.
loop
.
run_until_complete
(
go
())
def
test_parse_error
(
self
):
error
=
parse_error
(
"""
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment