Added logic to run build code to cpl run #124

This commit is contained in:
2022-12-02 18:41:58 +01:00
parent 3c20ab296a
commit d0877a4ea6
3 changed files with 71 additions and 11 deletions

View File

@@ -15,10 +15,10 @@ class RunTestCase(CommandTestCase):
CommandTestCase.__init__(self, method_name)
self._source = 'run-test'
self._project_file = f'src/{String.convert_to_snake_case(self._source)}/{self._source}.json'
self._appsettings = f'src/{String.convert_to_snake_case(self._source)}/appsettings.json'
self._application = f'src/{String.convert_to_snake_case(self._source)}/application.py'
self._test_code = f"""
import json
import os
settings = dict()
with open('appsettings.json', 'r', encoding='utf-8') as cfg:
# load json
@@ -26,14 +26,19 @@ class RunTestCase(CommandTestCase):
cfg.close()
settings['RunTest']['WasStarted'] = 'True'
settings['RunTest']['Path'] = os.path.dirname(os.path.realpath(__file__))
with open('appsettings.json', 'w', encoding='utf-8') as project_file:
project_file.write(json.dumps(settings, indent=2))
project_file.close()
"""
def _get_appsettings(self):
with open(os.path.join(os.getcwd(), self._appsettings), 'r', encoding='utf-8') as cfg:
def _get_appsettings(self, is_dev=False):
appsettings = f'dist/{self._source}/build/{String.convert_to_snake_case(self._source)}/appsettings.json'
if is_dev:
appsettings = f'src/{String.convert_to_snake_case(self._source)}/appsettings.json'
with open(os.path.join(os.getcwd(), appsettings), 'r', encoding='utf-8') as cfg:
# load json
project_json = json.load(cfg)
cfg.close()
@@ -41,7 +46,7 @@ class RunTestCase(CommandTestCase):
return project_json
def _save_appsettings(self, settings: dict):
with open(os.path.join(os.getcwd(), self._appsettings), 'w', encoding='utf-8') as project_file:
with open(os.path.join(os.getcwd(), f'src/{String.convert_to_snake_case(self._source)}/appsettings.json'), 'w', encoding='utf-8') as project_file:
project_file.write(json.dumps(settings, indent=2))
project_file.close()
@@ -57,7 +62,7 @@ class RunTestCase(CommandTestCase):
file.close()
def test_run(self):
CLICommands.run(is_dev=True, output=True)
CLICommands.run()
settings = self._get_appsettings()
self.assertNotEqual(settings, {})
self.assertIn('RunTest', settings)
@@ -66,10 +71,17 @@ class RunTestCase(CommandTestCase):
'True',
settings['RunTest']['WasStarted']
)
self.assertNotEqual(
os.path.join(os.getcwd(), f'src/{String.convert_to_snake_case(self._source)}'),
settings['RunTest']['Path']
)
self.assertEqual(
os.path.join(os.getcwd(), f'dist/{self._source}/build/{String.convert_to_snake_case(self._source)}'),
settings['RunTest']['Path']
)
def test_run_by_project(self):
os.chdir(os.path.join(os.getcwd()))
CLICommands.run(self._source, is_dev=True)
CLICommands.run(self._source)
settings = self._get_appsettings()
self.assertNotEqual(settings, {})
self.assertIn('RunTest', settings)
@@ -78,3 +90,41 @@ class RunTestCase(CommandTestCase):
'True',
settings['RunTest']['WasStarted']
)
self.assertNotEqual(
os.path.join(os.getcwd(), f'src/{String.convert_to_snake_case(self._source)}'),
settings['RunTest']['Path']
)
self.assertEqual(
os.path.join(os.getcwd(), f'dist/{self._source}/build/{String.convert_to_snake_case(self._source)}'),
settings['RunTest']['Path']
)
def test_run_dev(self):
CLICommands.run(is_dev=True)
settings = self._get_appsettings(is_dev=True)
self.assertNotEqual(settings, {})
self.assertIn('RunTest', settings)
self.assertIn('WasStarted', settings['RunTest'])
self.assertEqual(
'True',
settings['RunTest']['WasStarted']
)
self.assertEqual(
os.path.join(os.getcwd(), f'src/{String.convert_to_snake_case(self._source)}'),
settings['RunTest']['Path']
)
def test_run_dev_by_project(self):
CLICommands.run(self._source, is_dev=True)
settings = self._get_appsettings(is_dev=True)
self.assertNotEqual(settings, {})
self.assertIn('RunTest', settings)
self.assertIn('WasStarted', settings['RunTest'])
self.assertEqual(
'True',
settings['RunTest']['WasStarted']
)
self.assertEqual(
os.path.join(os.getcwd(), f'src/{String.convert_to_snake_case(self._source)}'),
settings['RunTest']['Path']
)