Commit c89d3247 authored by Pauline Maury Laribière's avatar Pauline Maury Laribière
Browse files

Merge branch 'unittest' into 'master'

adding unit test

See merge request pauline.maury-laribiere/meatadata-auto!3
parents 6f99cdbe c3fce7e9
Pipeline #289765 passed with stage
in 6 minutes and 5 seconds
......@@ -253,6 +253,8 @@ target/
# Jupyter Notebook
.ipynb_checkpoints
experiments.ipynb
unittest.ipynb
# IPython
profile_default/
......@@ -335,4 +337,4 @@ tags
# Renku
.renku.lock
.renku/tmp
.renku/cache
\ No newline at end of file
.renku/cache
......@@ -61,7 +61,7 @@ def get_data_structure(identifier: str, language: str = "fr") -> dict:
def get_nomenclature_one_level(
identifier: str,
level_number: int,
filters: dict,
filters: dict = {},
language: str = "fr",
annotations: bool = False,
) -> pd.DataFrame:
......@@ -97,7 +97,7 @@ def get_nomenclature_multiple_levels(
identifier: str,
level_from: int,
level_to: int,
filters: dict,
filters: dict = {},
language: str = "fr",
annotations: bool = False,
post_processing: bool = False
......
......@@ -43,6 +43,7 @@ class Api:
self.api_url = self.get_url(
api_type, _id, version_format, language
)
def get_response(self) -> Union[dict, pd.DataFrame]:
"""
......
......@@ -5,7 +5,7 @@ import pandas as pd
import pandasdmx as sdmx
def sdmx_request(api_url: str, params: str) -> pd.Series:
def sdmx_request(api_url: str, params: str = {}) -> pd.Series:
"""
API query for SDMX output
Parameters:
......@@ -20,7 +20,7 @@ def sdmx_request(api_url: str, params: str) -> pd.Series:
return sdmx.to_pandas(response)
def json_request(api_url: str, params: str) -> dict:
def json_request(api_url: str, params: str = {}) -> dict:
"""
API query for JSON output
Parameters:
......
#!/bin/bash
# Check all tests pass
python -m unittest discover -v
# Remove previous release
rm -rf dist
rm -rf fso_metadata.egg-info
......
import fso_metadata
\ No newline at end of file
import unittest
import pandas as pd
from fso_metadata.api_call import (
get_codelist,
get_data_structure,
get_nomenclature_one_level,
get_nomenclature_multiple_levels
)
from test.test_constants import TEST_CODELIST_ID, TEST_DATASTRUCTURE_ID, TEST_NOMENCLATURE_ID
class TestGetCodelist(unittest.TestCase):
def test_get_codelist(self):
res = get_codelist(identifier=TEST_CODELIST_ID, export_format="SDMX-ML")
assert type(res) == pd.core.series.Series, 'Wrong codelist output type'
class TestGetDataStructure(unittest.TestCase):
def test_get_data_structure(self):
res = get_data_structure(identifier=TEST_DATASTRUCTURE_ID, language="fr")
assert type(res) == dict, 'Wrong data structure output type'
class TestNomOneLevel(unittest.TestCase):
def test_get_nomenclature_one_level(self):
res = get_nomenclature_one_level(
identifier=TEST_NOMENCLATURE_ID,
level_number=2,
language='en'
)
assert type(res) == pd.core.frame.DataFrame, 'Wrong data structure output type'
self.assertListEqual(list(res.columns), [
'Code',
'Parent',
'Name_en'
])
class TestNomMultipleLevels(unittest.TestCase):
def test_get_nomenclature_multiple_levels(self):
res = get_nomenclature_multiple_levels(
identifier=TEST_NOMENCLATURE_ID,
level_from=1,
level_to=6,
language='en'
)
assert type(res) == pd.core.frame.DataFrame, 'Wrong data structure output type'
self.assertListEqual(list(res.columns), [
'Major_groups',
'Sub-major_groups',
'Minor_groups',
'Unit_groups',
'Type',
'Occupations',
'Code',
'Name_en'
])
TEST_CODELIST_ID = 'CL_NOGA_SECTION'
TEST_DATASTRUCTURE_ID = 'HCL_CH_ISCO_19_PROF'
TEST_NOMENCLATURE_ID = 'HCL_CH_ISCO_19_PROF'
\ No newline at end of file
import unittest
import pandasdmx
import pandas as pd
from fso_metadata.constants import BASE_URL
from fso_metadata.format_request import sdmx_request, dict_to_string
from test.test_constants import TEST_CODELIST_ID
class TestSdmxRequest(unittest.TestCase):
def test_sdmx_request(self):
url = f'{BASE_URL}/api/Codelists/{TEST_CODELIST_ID}/exports/SDMX-ML/2.1'
params_possible = ['true', 'false']
for params in params_possible:
params_string = f'annotations={params}'
res = sdmx_request(url, params_string)
assert type(res) == pandasdmx.util.DictLike, 'Wrong output type'
class TestDictToString(unittest.TestCase):
def test_dict_to_string(self):
self.assertEqual(dict_to_string(
{'a': [1, 2], 'b': [3]}
), 'a=1&a=2&b=3')
self.assertEqual(dict_to_string(
{'a': ['testing'], 'b': ['the'], 'c': [], 'd': ['code']}
), 'a=testing&b=the&d=code')
self.assertEqual(dict_to_string(
{'AF_ACTIVE': [1], 'AF_AVAM': [1]}
), 'AF_ACTIVE=1&AF_AVAM=1')
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment