Skip to content

Commit

Permalink
unit test fix #11 [test_localization_disable.py]
Browse files Browse the repository at this point in the history
  • Loading branch information
MothScientist committed Jan 11, 2025
1 parent d743597 commit bcb1af5
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 41 deletions.
13 changes: 0 additions & 13 deletions .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,6 @@ jobs:
pip install pytest
pip install pytest-asyncio
- name: Load conf.toml
run: |
cat conf.toml # log/debug
cd budget_graph || exit 1
python -c "import build_project; build_project.load_global_config(); build_project.create_directories();"
- name: Create .env file
env:
HASH_LOG_SALT_TEST: ${{ secrets.HASH_LOG_SALT_TEST }}
Expand All @@ -53,10 +47,6 @@ jobs:
- name: Run UnitTests
run: |
cat conf.toml # log/debug
cd budget_graph || exit 1
python -c "import build_project; build_project.load_global_config(); build_project.create_directories();"
cd .. || exit 1
cd tests || exit 1
python -m pytest \
test_sources.py \
Expand Down Expand Up @@ -234,9 +224,6 @@ jobs:
- name: Run UnitTests
run: |
cat conf.toml # log/debug
cd budget_graph || exit 1
python -c "import build_project; build_project.load_global_config(); build_project.create_directories();"
cd .. || exit 1
cd tests || exit 1
python -m pytest \
Expand Down
7 changes: 0 additions & 7 deletions budget_graph/build_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from sys import path as sys_path
sys_path.append('../')
from budget_graph.db_manager import connect_db, close_db
from budget_graph.global_config import GlobalConfig


def drop_tables_in_db() -> None:
Expand Down Expand Up @@ -56,13 +55,7 @@ def create_tables_in_db() -> None:
close_db(conn)


def load_global_config() -> None:
GlobalConfig.set_config()
GlobalConfig.print_config()


if __name__ == '__main__':
load_global_config()
create_directories()
drop_tables_in_db()
create_tables_in_db()
14 changes: 2 additions & 12 deletions budget_graph/global_config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import tomllib
from tomllib import load as tomllib_load


class GlobalConfig:
Expand All @@ -11,7 +11,7 @@ class GlobalConfig:
@staticmethod
def set_config():
with open('../conf.toml', 'rb') as toml_conf_file:
conf_data = tomllib.load(toml_conf_file)
conf_data = tomllib_load(toml_conf_file)

# vars are written only once when the application is launched and are then immutable

Expand Down Expand Up @@ -39,13 +39,3 @@ def set_config():
GlobalConfig.localization_enable = (
GlobalConfig.localization_enable or conf_data.get('localization').get('localization_enable')
)

@staticmethod
def print_config():
print(
f'global_cache_enable: {GlobalConfig.global_cache_enable}\n'
f'redis_enable: {GlobalConfig.redis_enable}\n'
f'timeit_enable: {GlobalConfig.timeit_enable}\n'
f'recaptcha_enable: {GlobalConfig.recaptcha_enable}\n'
f'localization_enable: {GlobalConfig.localization_enable}'
)
2 changes: 1 addition & 1 deletion tests/test_localization.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from budget_graph.global_config import GlobalConfig


# GlobalConfig.set_config()
GlobalConfig.set_config()


class TestLanguages(unittest.TestCase):
Expand Down
22 changes: 14 additions & 8 deletions tests/test_localization_disable.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,50 @@

import unittest
from budget_graph.dictionary import receive_translation
from budget_graph.global_config import GlobalConfig

GlobalConfig.set_config()


class TestConfigLanguages(unittest.TestCase):
"""
Testing application localization modules when the parameter in the .toml file localization_enable = false
"""
def test_languages_01(self):
def test_languages_001(self):
self.assertTrue(GlobalConfig.localization_enable)

def test_languages_002(self):
unknown_key: str = 'unknown_key_unknown_key'
res: str = receive_translation('en', unknown_key)
self.assertEqual(res, 'Error')

def test_languages_02(self):
def test_languages_003(self):
unknown_lang: str = 'vw'
res: str = receive_translation(unknown_lang, 'data_is_safe')
self.assertEqual(res, 'Error')

def test_languages_03(self):
def test_languages_004(self):
res: str = receive_translation('is', 'check_correct_username')
self.assertEqual(res, 'Check the correct spelling of the username.')

def test_languages_04(self):
def test_languages_005(self):
res: str = receive_translation('en', 'start_after_change_language')
self.assertEqual(res, 'To change the language correctly, '
'please restart the bot by clicking on the /start button.')

def test_languages_05(self):
def test_languages_006(self):
res: str = receive_translation('es', 'data_is_safe')
self.assertEqual(res, 'Your data will not be harmed!')

def test_languages_06(self):
def test_languages_007(self):
res: str = receive_translation('de', 'change_owner')
self.assertNotEqual(res, 'Besitzer wechseln')

def test_languages_07(self):
def test_languages_008(self):
res: str = receive_translation('kk', 'add_income')
self.assertNotEqual(res, 'Error')

def test_languages_08(self):
def test_languages_009(self):
res: str = receive_translation('pt', 'view_table')
self.assertNotEqual(res, 'Ver tabela')

Expand Down

0 comments on commit bcb1af5

Please sign in to comment.