Commit dfeb54e7 authored by Cresson Remi's avatar Cresson Remi
Browse files

Add tests in the CI

1 merge request!4Add tests in the CI
Showing with 28 additions and 21 deletions
+28 -21
......@@ -71,12 +71,12 @@ pages:
# -------------------------------- Tests ---------------------------------------
#tests:
# stage: Test
# allow_failure: false
# script:
# - pip install .
# - python tests/download_test.py
tests:
stage: Test
allow_failure: false
script:
- pip install .
- python test/download_test.py
# --------------------------------- Ship ---------------------------------------
......
......@@ -22,6 +22,8 @@ The credentials must be stored in a JSON file. It should look like this:
}
```
Or, you can also write the credentials in your python code inside a `dict`.
## Searching products
The `TheiaCatalog` class is the top level API to access the products. It uses
......
......@@ -7,15 +7,11 @@ import theia_picker
username = os.environ["THEIA_IDENT"]
password = os.environ["THEIA_PASS"]
with tempfile.NamedTemporaryFile("w+") as credentials_file, \
tempfile.TemporaryDirectory() as output_dir:
# Save credentials to JSON file
data = {"ident": username, "pass": password}
json.dump(data, credentials_file)
credentials_file.flush()
with tempfile.TemporaryDirectory() as output_dir:
# Login
cat = theia_picker.TheiaCatalog(credentials_file.name)
cat = theia_picker.TheiaCatalog(
credentials={"ident": username, "pass": password}
)
print("Login OK")
# Search
......
......@@ -717,10 +717,16 @@ class TheiaCatalog: # pylint: disable = too-few-public-methods
atdistrib_url = "https://theia.cnes.fr/atdistrib"
def __init__(self, config_file_json: str, max_records: int = 500):
def __init__(
self,
config_file_json: str = None,
max_records: int = 500,
credentials: Dict[str, str] = None
):
"""
Args:
config_file_json: JSON configuration file. Should look like this:
config_file_json: file containing the configuration, as JSON file.
Should look like this:
```json
{
......@@ -730,13 +736,16 @@ class TheiaCatalog: # pylint: disable = too-few-public-methods
```
max_records: Maximum number of records
credentials: configuration, provided as dict
"""
# Read THEIA credentials
with open(config_file_json, encoding='UTF-8') as json_file:
credentials = json.load(json_file)
self._requests_mgr = RequestsManager(credentials=credentials)
assert config_file_json or credentials, \
"config_file_json or credentials must be provided"
if config_file_json:
# Read THEIA credentials
with open(config_file_json, encoding='UTF-8') as json_file:
credentials = json.load(json_file)
self._requests_mgr = RequestsManager(credentials=credentials)
self.max_records = max_records
def _query(self, dict_query: dict) -> List[Feature]:
......
Supports Markdown
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