-
Notifications
You must be signed in to change notification settings - Fork 572
Added api.py methods testcases #1864
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9a194f0
Added statusBar, getAllInboxMessages, getAllInboxMessageIds, getInbox…
kdcis 21cb4e5
Added testmode check for HandleclearUISignalQueue & HandleGetStatusBa…
kdcis 56ec5b8
Created testmode decorator & routed command decorator through it
kdcis 62ffe96
Added anouncement addr comment, replaces assertTrue with assertEqual …
kdcis 21d5a6c
Instead of print added getAllInboxMessages values in assertEqual mess…
kdcis 1617527
Merged inbox & trash functions related testcases into single testcase…
kdcis 5771f21
Added undeleteMessage function in helper_inbox & respective method in…
kdcis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import time | ||
|
kdcis marked this conversation as resolved.
|
||
| import uuid | ||
|
|
||
| import helper_inbox | ||
| import helper_sql | ||
|
|
||
| # from .tests.samples import sample_inbox_msg_ids, sample_deterministic_addr4 | ||
| sample_deterministic_addr4 = 'BM-2cWzSnwjJ7yRP3nLEWUV5LisTZyREWSzUK' | ||
| sample_inbox_msg_ids = ['27e644765a3e4b2e973ee7ccf958ea20', '51fc5531-3989-4d69-bbb5-68d64b756f5b', | ||
| '2c975c515f8b414db5eea60ba57ba455', 'bc1f2d8a-681c-4cc0-9a12-6067c7e1ac24'] | ||
|
|
||
|
|
||
| def populate_api_test_data(): | ||
| '''Adding test records in inbox table''' | ||
| helper_sql.sql_ready.wait() | ||
|
|
||
| test1 = ( | ||
|
kdcis marked this conversation as resolved.
|
||
| sample_inbox_msg_ids[0], sample_deterministic_addr4, | ||
| sample_deterministic_addr4, 'Test1 subject', int(time.time()), | ||
| 'Test1 body', 'inbox', 2, 0, uuid.uuid4().bytes | ||
| ) | ||
| test2 = ( | ||
| sample_inbox_msg_ids[1], sample_deterministic_addr4, | ||
| sample_deterministic_addr4, 'Test2 subject', int(time.time()), | ||
| 'Test2 body', 'inbox', 2, 0, uuid.uuid4().bytes | ||
| ) | ||
| test3 = ( | ||
| sample_inbox_msg_ids[2], sample_deterministic_addr4, | ||
| sample_deterministic_addr4, 'Test3 subject', int(time.time()), | ||
| 'Test3 body', 'inbox', 2, 0, uuid.uuid4().bytes | ||
| ) | ||
| test4 = ( | ||
| sample_inbox_msg_ids[3], sample_deterministic_addr4, | ||
| sample_deterministic_addr4, 'Test4 subject', int(time.time()), | ||
| 'Test4 body', 'inbox', 2, 0, uuid.uuid4().bytes | ||
| ) | ||
| helper_inbox.insert(test1) | ||
| helper_inbox.insert(test2) | ||
| helper_inbox.insert(test3) | ||
| helper_inbox.insert(test4) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,12 +6,14 @@ | |
| import json | ||
| import time | ||
|
|
||
| from binascii import hexlify | ||
| from six.moves import xmlrpc_client # nosec | ||
|
|
||
| import psutil | ||
|
|
||
| from .samples import ( | ||
| sample_seed, sample_deterministic_addr3, sample_deterministic_addr4) | ||
| sample_seed, sample_deterministic_addr3, sample_deterministic_addr4, sample_statusbar_msg, | ||
| sample_inbox_msg_ids, sample_test_subscription_address, sample_subscription_name) | ||
|
|
||
| from .test_process import TestProcessProto | ||
|
|
||
|
|
@@ -46,17 +48,9 @@ def test_shutdown(self): | |
|
|
||
|
|
||
| # TODO: uncovered API commands | ||
| # getAllInboxMessages | ||
| # getAllInboxMessageIds | ||
| # getInboxMessageById | ||
| # getInboxMessagesByReceiver | ||
| # trashMessage | ||
| # trashInboxMessage | ||
| # addSubscription | ||
| # disseminatePreEncryptedMsg | ||
| # disseminatePubkey | ||
| # getMessageDataByDestinationHash | ||
| # statusBar | ||
|
|
||
|
|
||
| class TestAPI(TestAPIProto): | ||
|
|
@@ -91,6 +85,71 @@ def test_invalid_method(self): | |
| 'API Error 0020: Invalid method: test' | ||
| ) | ||
|
|
||
| def test_statusbar_method(self): | ||
| """Test statusbar method""" | ||
| self.api.clearUISignalQueue() | ||
| self.assertEqual( | ||
|
kdcis marked this conversation as resolved.
|
||
| self.api.statusBar(sample_statusbar_msg), | ||
| 'null' | ||
| ) | ||
|
kdcis marked this conversation as resolved.
|
||
| self.assertEqual( | ||
| self.api.getStatusBar(), | ||
| sample_statusbar_msg | ||
| ) | ||
|
|
||
| def test_message_inbox(self): | ||
| """Test message inbox methods""" | ||
| self.assertEqual( | ||
| len(json.loads( | ||
|
kdcis marked this conversation as resolved.
|
||
| self.api.getAllInboxMessages())["inboxMessages"]), | ||
| 4, | ||
| json.loads(self.api.getAllInboxMessages())["inboxMessages"] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe add a comment explaining this is the custom error message to aid in debugging. |
||
| ) | ||
| self.assertEqual( | ||
| len(json.loads( | ||
|
kdcis marked this conversation as resolved.
|
||
| self.api.getAllInboxMessageIds())["inboxMessageIds"]), | ||
| 4 | ||
| ) | ||
| self.assertEqual( | ||
| len(json.loads( | ||
| self.api.getInboxMessageById(hexlify(sample_inbox_msg_ids[2])))["inboxMessage"]), | ||
| 1 | ||
| ) | ||
| self.assertEqual( | ||
| len(json.loads( | ||
|
kdcis marked this conversation as resolved.
|
||
| self.api.getInboxMessagesByReceiver(sample_deterministic_addr4))["inboxMessages"]), | ||
| 4 | ||
| ) | ||
|
|
||
| def test_message_trash(self): | ||
| """Test message inbox methods""" | ||
|
|
||
| messages_before_delete = len(json.loads(self.api.getAllInboxMessageIds())["inboxMessageIds"]) | ||
| self.assertEqual( | ||
| self.api.trashMessage(hexlify(sample_inbox_msg_ids[0])), | ||
| 'Trashed message (assuming message existed).' | ||
| ) | ||
| self.assertEqual( | ||
| self.api.trashInboxMessage(hexlify(sample_inbox_msg_ids[1])), | ||
| 'Trashed inbox message (assuming message existed).' | ||
| ) | ||
| self.assertEqual( | ||
| len(json.loads(self.api.getAllInboxMessageIds())["inboxMessageIds"]), | ||
| messages_before_delete - 2 | ||
| ) | ||
| self.assertEqual( | ||
| self.api.undeleteMessage(hexlify(sample_inbox_msg_ids[0])), | ||
| 'Undeleted message' | ||
| ) | ||
| self.assertEqual( | ||
| self.api.undeleteMessage(hexlify(sample_inbox_msg_ids[1])), | ||
| 'Undeleted message' | ||
| ) | ||
| self.assertEqual( | ||
| len(json.loads(self.api.getAllInboxMessageIds())["inboxMessageIds"]), | ||
| messages_before_delete | ||
| ) | ||
|
|
||
|
PeterSurda marked this conversation as resolved.
|
||
| def test_clientstatus_consistency(self): | ||
| """If networkStatus is notConnected networkConnections should be 0""" | ||
| status = json.loads(self.api.clientStatus()) | ||
|
|
@@ -193,9 +252,28 @@ def test_addressbook(self): | |
|
|
||
| def test_subscriptions(self): | ||
| """Testing the API commands related to subscriptions""" | ||
|
|
||
|
kdcis marked this conversation as resolved.
|
||
| self.assertEqual( | ||
| self.api.addSubscription(sample_test_subscription_address[0], sample_subscription_name.encode('base64')), | ||
| 'Added subscription.' | ||
| ) | ||
|
|
||
| added_subscription = {'label': None, 'enabled': False} | ||
| # check_address | ||
| for sub in json.loads(self.api.listSubscriptions())['subscriptions']: | ||
| # special address, added when sqlThread starts | ||
| if sub['address'] == sample_test_subscription_address[0]: | ||
| added_subscription = sub | ||
| break | ||
|
|
||
| self.assertEqual( | ||
| base64.decodestring(added_subscription['label']) if added_subscription['label'] else None, | ||
| sample_subscription_name) | ||
| self.assertTrue(added_subscription['enabled']) | ||
|
|
||
| for s in json.loads(self.api.listSubscriptions())['subscriptions']: | ||
| # special address, added when sqlThread starts | ||
| if s['address'] == 'BM-GtovgYdgs7qXPkoYaRgrLFuFKz1SFpsw': | ||
| if s['address'] == sample_test_subscription_address[1]: | ||
| self.assertEqual( | ||
| base64.decodestring(s['label']), | ||
| 'Bitmessage new releases/announcements') | ||
|
|
@@ -206,7 +284,10 @@ def test_subscriptions(self): | |
| 'Could not find Bitmessage new releases/announcements' | ||
| ' in subscriptions') | ||
| self.assertEqual( | ||
| self.api.deleteSubscription('BM-GtovgYdgs7qXPkoYaRgrLFuFKz1SFpsw'), | ||
| self.api.deleteSubscription(sample_test_subscription_address[0]), | ||
| 'Deleted subscription if it existed.') | ||
| self.assertEqual( | ||
| self.api.deleteSubscription(sample_test_subscription_address[1]), | ||
| 'Deleted subscription if it existed.') | ||
| self.assertEqual( | ||
| json.loads(self.api.listSubscriptions())['subscriptions'], []) | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why space?