From a5c8ca58f71ceac057918dff8d9dbe9b2daa7c1c Mon Sep 17 00:00:00 2001 From: shekhar-cis Date: Thu, 18 Aug 2022 22:11:09 +0530 Subject: [PATCH] Update json load function and Add test for loading json --- src/bitmessagekivy/mpybit.py | 14 +++++----- .../tests/test_load_screen_data_file.py | 26 +++++++++++++++++++ 2 files changed, 34 insertions(+), 6 deletions(-) create mode 100644 src/bitmessagekivy/tests/test_load_screen_data_file.py diff --git a/src/bitmessagekivy/mpybit.py b/src/bitmessagekivy/mpybit.py index 75d50804..072b1fb7 100644 --- a/src/bitmessagekivy/mpybit.py +++ b/src/bitmessagekivy/mpybit.py @@ -1,5 +1,5 @@ # pylint: disable=no-name-in-module, too-few-public-methods, import-error, unused-argument -# pylint: disable=attribute-defined-outside-init, global-variable-not-assigned +# pylint: disable=attribute-defined-outside-init, global-variable-not-assigned, unused-variable """ Bitmessage android(mobile) interface @@ -40,22 +40,20 @@ logger = logging.getLogger('default') data_screen_dict = {} -def load_screen_json(): +def load_screen_json(data_file="screens_data.json"): """Load screens data from json""" - data_file = "screens_data.json" with open(os.path.join(os.path.dirname(__file__), data_file)) as read_file: all_data = json.load(read_file) data_screens = list(all_data.keys()) - global data_screen_dict for key in all_data: if all_data[key]['Import']: import_data = all_data.get(key)['Import'] import_to = import_data.split("import")[1].strip() import_from = import_data.split("import")[0].split('from')[1].strip() data_screen_dict[import_to] = importlib.import_module(import_from, import_to) - return data_screens, all_data + return data_screens, all_data, 'success' def get_identity_list(): @@ -158,7 +156,7 @@ class NavigateApp(MDApp): def __init__(self): super(NavigateApp, self).__init__() - self.data_screens, self.all_data = load_screen_json() + self.data_screens, self.all_data, response = load_screen_json() self.kivy_state_obj = KivyStateVariables() title = "PyBitmessage" @@ -213,3 +211,7 @@ class NavigateApp(MDApp): class PaymentMethodLayout(BoxLayout): """PaymentMethodLayout class for kivy Ui""" + + +if __name__ == '__main__': + NavigateApp().run() diff --git a/src/bitmessagekivy/tests/test_load_screen_data_file.py b/src/bitmessagekivy/tests/test_load_screen_data_file.py new file mode 100644 index 00000000..4148c05f --- /dev/null +++ b/src/bitmessagekivy/tests/test_load_screen_data_file.py @@ -0,0 +1,26 @@ + +import unittest +from pybitmessage.bitmessagekivy.mpybit import load_screen_json +from .common import skip_screen_checks +from .common import ordered + + + +class TestLoadScreenData(unittest.TestCase): + """Screen Data Json test""" + + @skip_screen_checks + @ordered + def test_load_json(self): + """Test to load a valid json""" + file_name = 'screens_data.json' + loaded_screen_names = load_screen_json(file_name) + self.assertEqual(loaded_screen_names[2], 'success') + + @skip_screen_checks + @ordered + def test_load_invalid_file(self): + """Test to load an invalid json""" + file_name = 'invalid_screens_data.json' + loaded_screen_names = load_screen_json(file_name) + self.assertEqual(loaded_screen_names[2], 'File not found')