Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
SMART
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
3
Issues
3
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
UNI-KLU
SMART
Commits
4a566c1b
Commit
4a566c1b
authored
Sep 09, 2019
by
Alexander Lercher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rest Gateway: Tests + dummy version of message-sender
parent
443d3b35
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
44 additions
and
24 deletions
+44
-24
DummyMessageManager.py
modules/messaging/DummyMessageManager.py
+22
-0
ReconnectingMessageManager.py
modules/messaging/ReconnectingMessageManager.py
+6
-6
test_blockchain_trace.py
rest-gateway/tests/test_blockchain_trace.py
+12
-8
test_MessageHandler.py
...trace-retrieval-microservice/tests/test_MessageHandler.py
+4
-10
No files found.
modules/messaging/DummyMessageManager.py
0 → 100644
View file @
4a566c1b
from
messaging.ReconnectingMessageManager
import
ReconnectingMessageManager
class
DummyMessageManager
(
ReconnectingMessageManager
):
'''Dummy class to be used for testing - sets itself as singleton instance if called before ReconnectingMessageManager'''
@
staticmethod
def
get_instance
():
if
ReconnectingMessageManager
.
_instance
==
None
:
ReconnectingMessageManager
.
_instance
=
DummyMessageManager
()
assert
isinstance
(
ReconnectingMessageManager
.
_instance
,
DummyMessageManager
)
return
ReconnectingMessageManager
.
_instance
last_message
=
{}
def
_init_message_manager
(
self
):
pass
def
create_message_destination
(
self
,
exch
,
exch_type
):
pass
def
send_message
(
self
,
exch
,
key
,
mess
):
self
.
last_message
=
{
'ex'
:
exch
,
'key'
:
key
,
'msg'
:
mess
}
modules/messaging/ReconnectingMessageManager.py
View file @
4a566c1b
...
...
@@ -7,7 +7,7 @@ LOGGER = logging.getLogger(__name__)
class
ReconnectingMessageManager
:
'''The ReconnectingMessageManager Singleton handles connection errors by itself'''
_
_
instance
=
None
_instance
=
None
_message_manager
:
MessageManager
=
None
_consuming
=
False
...
...
@@ -16,15 +16,15 @@ class ReconnectingMessageManager:
@
staticmethod
def
getInstance
()
->
ReconnectingMessageManager
:
''' Static access method. '''
if
ReconnectingMessageManager
.
_
_
instance
==
None
:
ReconnectingMessageManager
.
_
_
instance
=
ReconnectingMessageManager
()
return
ReconnectingMessageManager
.
_
_
instance
if
ReconnectingMessageManager
.
_instance
==
None
:
ReconnectingMessageManager
.
_instance
=
ReconnectingMessageManager
()
return
ReconnectingMessageManager
.
_instance
def
__init__
(
self
):
if
ReconnectingMessageManager
.
_
_
instance
!=
None
:
if
ReconnectingMessageManager
.
_instance
!=
None
:
raise
Exception
(
"This class is a singleton!"
)
ReconnectingMessageManager
.
_
_
instance
=
self
ReconnectingMessageManager
.
_instance
=
self
self
.
_init_message_manager
()
def
_init_message_manager
(
self
):
...
...
rest-gateway/tests/test_blockchain_trace.py
View file @
4a566c1b
import
unittest
import
manage_sys_paths
from
messaging.DummyMessageManager
import
DummyMessageManager
# init dummy message manager so no connection to rabbitmq is established
_
=
DummyMessageManager
.
get_instance
()
import
rest.blockchain_trace
as
blockchain_trace
class
Test_BlockchainTrace
(
unittest
.
TestCase
):
...
...
@@ -25,15 +29,15 @@ class Test_BlockchainTrace(unittest.TestCase):
input
=
self
.
_get_valid_input
()
self
.
assertTrue
(
blockchain_trace
.
isBlockchainTraceValid
(
input
),
"Trace should be valid"
)
def
test_isBlockchainTraceValid_invalidMetadataInputType
(
self
):
input
=
self
.
_get_valid_input
()
input
[
"Metadata"
]
=
"string"
self
.
assertFalse
(
blockchain_trace
.
isBlockchainTraceValid
(
input
),
"Metadata type should be invalid"
)
#
def test_isBlockchainTraceValid_invalidMetadataInputType(self):
#
input = self._get_valid_input()
#
input["Metadata"] = "string"
#
self.assertFalse(blockchain_trace.isBlockchainTraceValid(input), "Metadata type should be invalid")
def
test_isBlockchainTraceValid_invalidTransactionFromLatLngInputType
(
self
):
input
=
self
.
_get_valid_input
()
input
[
"TransactionFromLatLng"
]
=
[
"55.1"
,
"44.1"
]
self
.
assertFalse
(
blockchain_trace
.
isBlockchainTraceValid
(
input
),
"TransactionFromLatLng type should be invalid"
)
#
def test_isBlockchainTraceValid_invalidTransactionFromLatLngInputType(self):
#
input = self._get_valid_input()
#
input["TransactionFromLatLng"] = ["55.1", "44.1"]
#
self.assertFalse(blockchain_trace.isBlockchainTraceValid(input), "TransactionFromLatLng type should be invalid")
def
test_isBlockchainTraceValid_emptyInput
(
self
):
input
=
{}
...
...
transaction-hub-in/trace-retrieval-microservice/tests/test_MessageHandler.py
View file @
4a566c1b
...
...
@@ -10,13 +10,7 @@ class DummyMongoRepo:
def
insert_trace
(
self
,
trace
):
self
.
last_trace
=
trace
class
DummyMessageSender
:
'''Dummy class to be used for testing the MessageHandler'''
last_message
=
{}
def
create_message_destination
(
self
,
exch
,
exch_type
):
pass
def
send_message
(
self
,
exch
,
key
,
mess
):
self
.
last_message
=
{
'ex'
:
exch
,
'key'
:
key
,
'msg'
:
mess
}
from
messaging.DummyMessageManager
import
DummyMessageManager
as
DummyMessageSender
class
Test_MessageHandler
(
unittest
.
TestCase
):
handler
=
None
...
...
@@ -25,7 +19,7 @@ class Test_MessageHandler(unittest.TestCase):
def
setUp
(
self
):
self
.
repo
=
DummyMongoRepo
()
self
.
msg_sender
=
DummyMessageSender
()
self
.
msg_sender
=
DummyMessageSender
.
get_instance
()
self
.
handler
=
MessageHandler
(
self
.
repo
,
self
.
msg_sender
)
def
test_handleGeneric_emptyMessage_NotJsonError
(
self
):
...
...
@@ -93,14 +87,14 @@ class Test_MessageHandler(unittest.TestCase):
def
test_handleGeneric_correctTraceContent_AddedToRepo
(
self
):
msg
=
self
.
_get_valid_message
()
res
=
self
.
handler
.
handle_generic
(
msg
)
_
=
self
.
handler
.
handle_generic
(
msg
)
trace
=
json
.
loads
(
msg
)[
'content'
]
self
.
assertEqual
(
trace
,
self
.
repo
.
last_trace
)
def
test_handleGeneric_correctTraceContent_NotificationSentCorrectly
(
self
):
msg
=
self
.
_get_valid_message
()
res
=
self
.
handler
.
handle_generic
(
msg
)
_
=
self
.
handler
.
handle_generic
(
msg
)
self
.
assertEqual
(
'datahub'
,
self
.
msg_sender
.
last_message
[
'ex'
])
self
.
assertEqual
(
'semantic-linking'
,
self
.
msg_sender
.
last_message
[
'key'
])
...
...
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