def test_rendering_graph_js(self): if os.path.exists(self.graph_file): namespace = self.namespace + 'mermaid_js' file_path = path + '/' + self.valid_yml load_yaml(file_path, namespace) ussd_screens = staticconf.config.get_namespace(namespace). \ get_config_values() actual_graph_js = render_journey_as_graph(ussd_screens) expected_graph_js = json.loads(self.read_file_content(self.graph_file)) for key, value in expected_graph_js["vertices"].items(): if value.get('id') == 'test_explicit_dict_loop': for i in ( "a for apple\n", "b for boy\n", "c for cat\n" ): self.assertRegex(value.get('text'), i) else: self.assertDictEqual(value, actual_graph_js.vertices[key]) # self.assertDictEqual(expected_graph_js["vertices"], actual_graph_js.vertices) for index, value in enumerate(expected_graph_js['edges']): self.assertDictEqual(value, actual_graph_js.get_edges()[index]) self.assertEqual(expected_graph_js["edges"], actual_graph_js.get_edges())
def handle(self): if isinstance(self.screen_content, dict): if self.screen_content.get('variables'): variable_conf = self.screen_content['variables'] file_path = variable_conf['file'] namespace = variable_conf['namespace'] # check if it has been loaded if not namespace in \ staticconf.config.configuration_namespaces: load_yaml(file_path, namespace) self.ussd_request.session['template_namespace'] = namespace # create ussd variables defined int the yaml for key, value in \ self.screen_content.get('create_ussd_variables', {}).\ items(): self.ussd_request.session[key] = \ self.evaluate_jija_expression(value, lazy_evaluating=True) # set default language self.ussd_request.session['default_language'] = \ self.screen_content.get('default_language', 'en') return self.ussd_request.forward( self.screen_content['next_screen'] ) else: return self.ussd_request.forward(self.screen_content)
def load_variable_files(self): variable_conf = self.screen_content['variables'] file_path = variable_conf['file'] namespace = variable_conf['namespace'] # check if it has been loaded if not namespace in \ staticconf.config.configuration_namespaces: load_yaml(file_path, namespace) self.ussd_request.session.update( staticconf.config.configuration_namespaces[namespace]. configuration_values)
def load_variable_files(self): variable_conf = self.screen_content['variables'] file_path = variable_conf['file'] namespace = variable_conf['namespace'] # check if it has been loaded if not namespace in \ staticconf.config.configuration_namespaces: load_yaml(file_path, namespace) self.ussd_request.session.update( staticconf.config.configuration_namespaces[namespace]. configuration_values )
def _test_ussd_validation(self, yaml_to_validate, expected_validation, expected_errors): if self.validate_ussd: namespace = self.namespace + str(expected_validation) file_path = path + '/' + yaml_to_validate load_yaml(file_path, namespace) ussd_screens = staticconf.config. \ get_namespace(namespace). \ get_config_values() is_valid, error_message = UssdView.validate_ussd_journey( ussd_screens) self.assertEqual(is_valid, expected_validation, error_message) self.assertDictEqual(error_message, expected_errors)
def test_rendering_mermaid_js(self): if os.path.exists(self.mermaid_file): namespace = self.namespace + 'mermaid_js' file_path = path + '/' + self.valid_yml load_yaml(file_path, namespace) ussd_screens = staticconf.config.get_namespace(namespace). \ get_config_values() mermaid_text_format = render_journey_as_mermaid_text(ussd_screens) file_content = self.read_file_content(self.mermaid_file) expected_text_lines = file_content.split('\n') actual_text_lines = mermaid_text_format.split('\n') for index, line in enumerate(expected_text_lines): self.assertEqual(line, actual_text_lines[index]) self.assertEqual(mermaid_text_format, file_content)
def handle(self, *args, **options): error_message = {} for ussd_config in options["ussd_configs"]: if not os.path.isfile(ussd_config): raise CommandError( "The file path {} does not exist".format(ussd_config)) namespace = 'validation' load_yaml(ussd_config, namespace) ussd_screens = staticconf.config. \ get_namespace(namespace). \ get_config_values() is_valid, error_ussd_config_message = UssdView.validate_ussd_journey( ussd_screens) error_message[ussd_config] = dict( valid=is_valid, error_message=error_ussd_config_message) if not is_valid: raise CommandError(json.dumps(error_message)) self.stdout.write(json.dumps(error_message))
def handle(self, *args, **options): error_message = {} for ussd_config in options["ussd_configs"]: if not os.path.isfile(ussd_config): raise CommandError("This file path {} does not exist".format(ussd_config)) namespace = 'validation' load_yaml(ussd_config, namespace) ussd_screens = staticconf.config. \ get_namespace(namespace). \ get_config_values() is_valid, error_ussd_config_message = UssdView.validate_ussd_journey( ussd_screens) error_message[ussd_config] = dict( valid=is_valid, error_message=error_ussd_config_message ) if not is_valid: raise CommandError(json.dumps(error_message)) self.stdout.write(json.dumps(error_message))