From 49e0a31b8ff22d25574435567e25a9681d09e041 Mon Sep 17 00:00:00 2001 From: shekhar-cis Date: Mon, 19 Sep 2022 21:34:34 +0530 Subject: [PATCH] Add kivy network UI and test --- src/bitmessagekivy/baseclass/network.py | 11 ++++++-- src/bitmessagekivy/kv/network.kv | 4 +-- src/bitmessagekivy/main.kv | 2 ++ src/bitmessagekivy/screens_data.json | 5 ++++ src/bitmessagekivy/tests/telenium_process.py | 4 +-- .../tests/test_network_screen.py | 27 ++++++------------- src/mock/kivy_main.py | 21 ++++++++------- src/mock/network.py | 8 ++++-- 8 files changed, 46 insertions(+), 36 deletions(-) diff --git a/src/bitmessagekivy/baseclass/network.py b/src/bitmessagekivy/baseclass/network.py index 16b995a6..18c417aa 100644 --- a/src/bitmessagekivy/baseclass/network.py +++ b/src/bitmessagekivy/baseclass/network.py @@ -5,14 +5,21 @@ Network status """ +import os + from kivy.clock import Clock from kivy.properties import StringProperty from kivy.uix.screenmanager import Screen -from pybitmessage.network import objectracker, stats - from pybitmessage import state +if os.environ.get('INSTALL_TESTS', False): + from pybitmessage.mock import kivy_main + stats = kivy_main.network.stats + objectracker = kivy_main.network.objectracker +else: + from pybitmessage.network import stats, objectracker + class NetworkStat(Screen): """NetworkStat class for kivy Ui""" diff --git a/src/bitmessagekivy/kv/network.kv b/src/bitmessagekivy/kv/network.kv index b77dea26..17211e98 100644 --- a/src/bitmessagekivy/kv/network.kv +++ b/src/bitmessagekivy/kv/network.kv @@ -5,7 +5,7 @@ tab_display_mode:'text' Tab: - text: app.tr._("Total connections") + title: app.tr._("Total connections") ScrollView: do_scroll_x: False MDList: @@ -34,7 +34,7 @@ # color: (1,1,1,1) # halign: 'center' Tab: - text: app.tr._('Processes') + title: app.tr._('Processes') ScrollView: do_scroll_x: False MDList: diff --git a/src/bitmessagekivy/main.kv b/src/bitmessagekivy/main.kv index 4f5de8cf..4901d943 100644 --- a/src/bitmessagekivy/main.kv +++ b/src/bitmessagekivy/main.kv @@ -220,6 +220,8 @@ MDNavigationLayout: id:id_payment Create: id:id_create + NetworkStat: + id:id_networkstat MDNavigationDrawer: id: nav_drawer diff --git a/src/bitmessagekivy/screens_data.json b/src/bitmessagekivy/screens_data.json index 81a3ce70..cfb3c76c 100644 --- a/src/bitmessagekivy/screens_data.json +++ b/src/bitmessagekivy/screens_data.json @@ -21,5 +21,10 @@ "kv_string": "msg_composer", "name_screen": "create", "Import": "from pybitmessage.bitmessagekivy.baseclass.msg_composer import Create" + }, + "Network status": { + "kv_string": "network", + "name_screen": "networkstat", + "Import": "from pybitmessage.bitmessagekivy.baseclass.network import NetworkStat" } } diff --git a/src/bitmessagekivy/tests/telenium_process.py b/src/bitmessagekivy/tests/telenium_process.py index 98c2198f..c1ca10fa 100644 --- a/src/bitmessagekivy/tests/telenium_process.py +++ b/src/bitmessagekivy/tests/telenium_process.py @@ -121,8 +121,8 @@ class TeleniumTestProcess(TeleniumTestCase): # Checking the drawer is in 'closed' state self.assertExists('//MDNavigationDrawer[@status~=\"closed\"]', timeout=5) # This is for checking the menu button is appeared - self.assertExists('//MDActionTopAppBarButton[@icon~=\"menu\"]', timeout=5) + self.assertExists('//ActionTopAppBarButton[@icon~=\"menu\"]', timeout=5) # this is for opening Nav drawer - self.cli.wait_click('//MDActionTopAppBarButton[@icon=\"menu\"]', timeout=5) + self.cli.wait_click('//ActionTopAppBarButton[@icon=\"menu\"]', timeout=5) # checking state of Nav drawer self.assertExists("//MDNavigationDrawer[@state~=\"open\"]", timeout=5) diff --git a/src/bitmessagekivy/tests/test_network_screen.py b/src/bitmessagekivy/tests/test_network_screen.py index 6e073be0..8da6a7d9 100644 --- a/src/bitmessagekivy/tests/test_network_screen.py +++ b/src/bitmessagekivy/tests/test_network_screen.py @@ -1,35 +1,24 @@ # pylint: disable=too-few-public-methods +""" + Kivy Networkstat UI test +""" +from time import sleep from .telenium_process import TeleniumTestProcess -from .common import skip_screen_checks class NetworkStatusScreen(TeleniumTestProcess): """NetworkStatus Screen Functionality Testing""" - @skip_screen_checks def test_network_status(self): """Show NetworkStatus""" # This is for checking Current screen - self.assert_wait_no_except('//ScreenManager[@current]', timeout=15, value='inbox') + self.assert_wait_no_except('//ScreenManager[@current]', timeout=15, value='login') # Method to open side navbar - self.open_side_navbar() + if self.cli.wait('//ActionTopAppBarButton[@icon~=\"menu\"]', timeout=5): + sleep(0.2) # due to rapid transition effect, it doesn't click on menu-bar + self.open_side_navbar() # this is for scrolling Nav drawer self.drag("//NavigationItem[@text=\"Sent\"]", "//NavigationItem[@text=\"Inbox\"]") # assert for checking scroll function self.assertCheckScrollDown('//ContentNavigationDrawer//ScrollView[0]', timeout=5) - # Clicking on Network Status tab - self.cli.wait_click('//NavigationItem[@text=\"Network status\"]', timeout=5) - # checking current screen - self.assertExists("//ScreenManager[@current=\"networkstat\"]", timeout=5) - # Checking the state of "Total Connection" tab - self.assertExists( - '//NetworkStat/MDTabs[0]//MDTabsLabel[@text=\"Total connections\"][@state=\"down\"]', timeout=3) - # Checking the state of "Processes" tab - self.assertExists('//NetworkStat/MDTabs[0]//MDTabsLabel[@text=\"Processes\"][@state=\"normal\"]', timeout=3) - # Checking the "Tab" is rendered - self.assertExists('//NetworkStat/MDTabs[0]//MDTabsLabel[@text=\"Processes\"]', timeout=4) - # Clicking on Processes Tab - self.cli.wait_click('//NetworkStat/MDTabs[0]//MDTabsLabel[@text=\"Processes\"]', timeout=4) - # Checking the state of "Processes" tab - self.assertExists('//NetworkStat/MDTabs[0]//MDTabsLabel[@text=\"Processes\"][@state=\"normal\"]', timeout=3) diff --git a/src/mock/kivy_main.py b/src/mock/kivy_main.py index e0bf587d..4f630109 100644 --- a/src/mock/kivy_main.py +++ b/src/mock/kivy_main.py @@ -5,20 +5,23 @@ import os from kivy.config import Config -import multiqueue +from pybitmessage.mock import multiqueue from pybitmessage import state -if os.environ.get('INSTALL_TESTS', False): - Config.set('graphics', 'height', 1280) - Config.set('graphics', 'width', 720) - Config.set('graphics', 'position', 'custom') - Config.set('graphics', 'top', 0) - Config.set('graphics', 'left', 0) +if os.environ.get("INSTALL_TESTS", False): + Config.set("graphics", "height", 1280) + Config.set("graphics", "width", 720) + Config.set("graphics", "position", "custom") + Config.set("graphics", "top", 0) + Config.set("graphics", "left", 0) from pybitmessage.mock.class_addressGenerator import FakeAddressGenerator # noqa:E402 from pybitmessage.bitmessagekivy.mpybit import NavigateApp # noqa:E402 -from pybitmessage.mock.network import stats, objectracker # noqa:E402 +from pybitmessage.mock import network # noqa:E402 + +stats = network.stats +objectracker = network.objectracker def main(): @@ -33,5 +36,5 @@ def main(): state.kivyapp.run() -if __name__ == '__main__': +if __name__ == "__main__": main() diff --git a/src/mock/network.py b/src/mock/network.py index 7380387a..1fb56c30 100644 --- a/src/mock/network.py +++ b/src/mock/network.py @@ -7,12 +7,16 @@ class objectracker(object): """Mock object tracker""" + missingObjects = {} class stats(object): """Mock network statics""" + @staticmethod def connectedHostsList(): - """List of all the connected hosts""" - return () + """List of all the mock connected hosts""" + return [ + "conn1", "conn2", "conn3", "conn4" + ]