def test_a_base64_param(): """ Verification of a mapped parameter as BASE64 """ result = map_param("[BASE64:toolium/test/resources/document.txt]") expected = "RG9jdW1lbnQgdXNlZCB0byB2ZXJpZnkgZnVuY3Rpb25hbGl0aWVzIGluIE1TUyA=" assert expected == result set_base64_path('toolium/test/resources/') result = map_param("[BASE64:document.txt]") assert expected == result
def test_a_file_param(): """ Verification of a mapped parameter as FILE """ result = map_param("[FILE:toolium/test/resources/document.txt]") expected = "Document used to verify functionalities in MSS " assert expected == result set_file_path('toolium/test/resources/') result = map_param("[FILE:document.txt]") assert expected == result
def test_a_poe_param_no_result_assertion(): """ Verification of a POE mapped parameter without result """ dataset.poeditor_terms = [ { "term": "Poniendo mute", "definition": "Ahora la tele está silenciada", "reference": "home:home.tv.mute", } ] with pytest.raises(Exception) as excinfo: map_param('[POE:home.tv.off]') assert "No translations found in POEditor for reference home.tv.off" in str(excinfo.value)
def test_a_context_param(): """ Verification of a mapped parameter as CONTEXT """ context = mock.MagicMock() context.attribute = "attribute value" context.storage = {"storage_key": "storage entry value"} dataset.behave_context = context result_att = map_param("[CONTEXT:attribute]") expected_att = "attribute value" assert expected_att == result_att result_st = map_param("[CONTEXT:storage_key]") expected_st = "storage entry value" assert expected_st == result_st
def test_a_text_param(): """ Verification of a text param """ result = map_param("just_text") expected = "just_text" assert expected == result
def test_a_poe_param_with_two_prefixes(): """ Verification of a POE mapped parameter with several results for a reference, filtered with two prefixes """ dataset.project_config = {'poeditor': {'prefixes': ['MH.', 'PRE.']}} dataset.poeditor_terms = [ { "term": "Hola, estoy aquí para ayudarte", "definition": "Hola, estoy aquí para ayudarte", "reference": "common:common.greetings.main", }, { "term": "Hola! En qué puedo ayudarte?", "definition": "Hola, buenas", "reference": "common:PRE.common.greetings.main", }, { "term": "Hola! En qué puedo ayudarte MH?", "definition": "Hola, buenas MH", "reference": "common:MH.common.greetings.main", } ] result = map_param('[POE:common.greetings.main]') expected = "Hola, buenas MH" assert result == expected
def test_a_poe_param_multiple_options_but_only_one_result(): """ Verification of a POE mapped parameter with a single result from several options for a key """ dataset.project_config = {'poeditor': {'key_field': 'term', 'search_type': 'exact'}} dataset.poeditor_terms = [ { "term": "loginSelectLine_text_subtitle", "definition": "Te damos la bienvenida_1", "context": "", "term_plural": "", "reference": "", "comment": "" }, { "term": "loginSelectLine_text_subtitle_2", "definition": "Te damos la bienvenida_2", "context": "", "term_plural": "", "reference": "", "comment": "" } ] result = map_param('[POE:loginSelectLine_text_subtitle]') expected = "Te damos la bienvenida_1" assert result == expected
def test_a_conf_param_with_special_characters(): """ Verification of a combination of text plus a config param with special characters """ dataset.project_config = {"user": "******", "password": "******"} result = map_param("[CONF:user]-an:d_![CONF:password]") expected = "user-1-an:d_!p4:ssw0_rd" assert expected == result
def test_a_combi_of_textplusconfig(): """ Verification of a combination of text plus a config param """ os.environ['MY_VAR'] = "some value" result = map_param("adding [ENV:MY_VAR]") expected = "adding some value" assert expected == result
def test_an_env_param(): """ Verification of a mapped parameter as ENV """ os.environ['MY_PASSWD'] = "admin123" result = map_param("[ENV:MY_PASSWD]") expected = "admin123" assert expected == result
def test_a_conf_param(): """ Verification of a mapped parameter as CONF """ dataset.project_config = {"service": {"port": 80}} result = map_param("[CONF:service.port]") expected = 80 assert expected == result
def test_a_combi_of_textplusconfig_integer(): """ Verification of a combination of text plus a config param """ dataset.project_config = {"service": {"port": 80}} result = map_param("use port [CONF:service.port]") expected = "use port 80" assert expected == result
def test_a_combi_of_config_plustext_plusconfig(): """ Verification of a combination of a config param plus text plus a config param """ os.environ['MY_VAR_1'] = "this is" os.environ['MY_VAR_2'] = "some value" result = map_param("[ENV:MY_VAR_1] some text and [ENV:MY_VAR_2]") expected = "this is some text and some value" assert expected == result
def test_a_lang_param(): """ Verification of a mapped parameter as LANG """ dataset.language_terms = {"home": {"button": {"send": {"es": "enviar", "en": "send"}}}} dataset.language = "es" result = map_param("[LANG:home.button.send]") expected = "enviar" assert expected == result
def test_a_toolium_param(): """ Verification of a mapped parameter as TOOLIUM """ config_file_path = os.path.join("toolium", "test", "resources", "toolium.cfg") dataset.toolium_config = ExtendedConfigParser.get_config_from_file(config_file_path) result = map_param("[TOOLIUM:TestExecution_environment]") expected = "QA" assert expected == result
def test_a_poe_param_single_result(): """ Verification of a POE mapped parameter with a single result for a reference """ dataset.poeditor_terms = [ { "term": "Poniendo mute", "definition": "Ahora la tele está silenciada", "reference": "home:home.tv.mute", } ] result = map_param('[POE:home.tv.mute]') expected = "Ahora la tele está silenciada" assert result == expected
def send_poeditor_request(context, endpoint, method, params, status_code): """ Send a request to the POEditor API :param context: behave context :param endpoint: endpoint path :param method: HTTP method to be used in the request :param params: parameters to be sent in the request :param code: expected status code :return: response """ url = "/".join([map_param('[CONF:poeditor.base_url]'), endpoint]) r = requests.request(method, url, data=params) assert r.status_code == status_code, f"{r.status_code} status code has been received instead of {status_code} \ in POEditor response. Response body: {r.json()}" return r
def get_poeditor_project_info_by_name(context, project_name=None): """ Get POEditor project info from project name from config or parameter :param context: behave context :param project_name: POEditor project name :return: N/A (saves it to context.poeditor_project) """ projects = get_poeditor_projects(context) project_name = project_name if project_name else map_param( '[CONF:poeditor.project_name]') projects_by_name = [ project for project in projects if project['name'] == project_name ] assert len(projects_by_name) == 1, "ERROR: Project name %s not found, available projects: %s" % \ (project_name, [project['name'] for project in projects]) context.poeditor_project = projects_by_name[0]
def test_a_poe_param_single_result_selecting_a_key_field(): """ Verification of a POE mapped parameter with a single result for a term """ dataset.project_config = {'poeditor': {'key_field': 'term'}} dataset.poeditor_terms = [ { "term": "loginSelectLine_text_subtitle", "definition": "Te damos la bienvenida", "context": "", "term_plural": "", "reference": "", "comment": "" } ] result = map_param('[POE:loginSelectLine_text_subtitle]') expected = "Te damos la bienvenida" assert result == expected
def test_a_poe_param_with_prefix(): """ Verification of a POE mapped parameter with several results for a reference, filtered with a prefix """ dataset.project_config = {'poeditor': {'key_field': 'reference', 'search_type': 'contains', 'prefixes': ['PRE.']}} dataset.poeditor_terms = [ { "term": "Hola, estoy aquí para ayudarte", "definition": "Hola, estoy aquí para ayudarte", "reference": "common:common.greetings.main", }, { "term": "Hola! En qué puedo ayudarte?", "definition": "Hola, buenas", "reference": "common:PRE.common.greetings.main", } ] result = map_param('[POE:common.greetings.main]') expected = "Hola, buenas" assert result == expected
def test_a_poe_param_with_prefix_and_exact_resource(): """ Verification of a POE mapped parameter that uses an exact resource name and has a prefix configured """ dataset.project_config = {'poeditor': {'prefixes': ['PRE.']}} dataset.poeditor_terms = [ { "term": "Hola, estoy aquí para ayudarte", "definition": "Hola, estoy aquí para ayudarte", "reference": "common:common.greetings.main", }, { "term": "Hola! En qué puedo ayudarte?", "definition": "Hola, buenas", "reference": "common:PRE.common.greetings.main", } ] result = map_param('[POE:common:common.greetings.main]') expected = "Hola, buenas" assert result == expected
def test_a_poe_param_multiple_results(): """ Verification of a POE mapped parameter with several results for a reference """ dataset.project_config = {'poeditor': {'key_field': 'reference'}} dataset.poeditor_terms = [ { "term": "Hola, estoy aquí para ayudarte", "definition": "Hola, estoy aquí para ayudarte", "reference": "common:common.greetings.main", }, { "term": "Hola! En qué puedo ayudarte?", "definition": "Hola, buenas", "reference": "common:common.greetings.main", } ] result = map_param('[POE:common.greetings.main]') first_expected = "Hola, estoy aquí para ayudarte" second_expected = "Hola, buenas" assert len(result) == 2 assert result[0] == first_expected assert result[1] == second_expected
def load_poeditor_texts(context): """ Download POEditor texts and save in output folder if the config exists or use previously downloaded texts :param context: behave context """ if get_poeditor_api_token(context): # Try to get poeditor mode param from toolium config first poeditor_mode = dataset.toolium_config.get_optional( 'TestExecution', 'poeditor_mode') if poeditor_mode: dataset.project_config['poeditor']['mode'] = poeditor_mode if 'mode' in dataset.project_config['poeditor'] and map_param( '[CONF:poeditor.mode]') == 'offline': file_path = get_poeditor_file_path(context) # With offline POEditor mode, file must exist if not os.path.exists(file_path): error_message = 'You are using offline POEditor mode but poeditor file has not been found in %s' % \ file_path context.logger.error(error_message) assert False, error_message with open(file_path, 'r') as f: dataset.poeditor_terms = json.load(f) # For backwards compatibility context.poeditor_export = dataset.poeditor_terms last_mod_time = time.strftime( '%d/%m/%Y %H:%M:%S', time.localtime(os.path.getmtime(file_path))) context.logger.info( 'Using local POEditor file "%s" with date: %s' % (file_path, last_mod_time)) else: # without mode configured or mode = 'online' download_poeditor_texts(context, 'json') else: context.logger.info("POEditor is not configured")