diff --git a/matomo-api/docker-compose-tests.yaml b/matomo-api/docker-compose-tests.yaml index 227836a..f5e4070 100644 --- a/matomo-api/docker-compose-tests.yaml +++ b/matomo-api/docker-compose-tests.yaml @@ -2,11 +2,11 @@ version: '3.1' services: db: - ports: + ports: - "5432:5432" image: postgres:14 restart: always environment: POSTGRES_PASSWORD: matomo POSTGRES_USER: matomo - POSTGRES_DB: matomo \ No newline at end of file + POSTGRES_DB: matomo diff --git a/matomo-api/pyproject.toml b/matomo-api/pyproject.toml index 4621db1..d5ef456 100644 --- a/matomo-api/pyproject.toml +++ b/matomo-api/pyproject.toml @@ -22,4 +22,3 @@ urllib3 = "1.26.7" [build-system] requires = ["poetry-core>=1.0.0"] build-backend = "poetry.core.masonry.api" - diff --git a/matomo-api/src/cli.py b/matomo-api/src/cli.py index a8c24bb..41ade64 100644 --- a/matomo-api/src/cli.py +++ b/matomo-api/src/cli.py @@ -1,11 +1,18 @@ -from datetime import date, datetime +from datetime import date, datetime, timedelta import click from api import MatomoAPI +def _get_yesterday_date_string(): + today = datetime.now() + yesterday = today - timedelta(days=1) + formatted_yesterday = yesterday.strftime("%Y-%m-%d") + return formatted_yesterday + + @click.command() -@click.option("--date", "-d", default=date.today()) +@click.option("--date", "-d", default=_get_yesterday_date_string()) def fetch_matomo_inspire_data(date: str): click.echo(f"Fetching data for date {date}") if isinstance(date, str): diff --git a/matomo-api/tests/conftest.py b/matomo-api/tests/conftest.py index f0eaa8b..a3df2c4 100644 --- a/matomo-api/tests/conftest.py +++ b/matomo-api/tests/conftest.py @@ -48,6 +48,6 @@ def updated_env(monkeypatch): monkeypatch.setenv(env_name, env_value) -@pytest.fixture(scope='function') +@pytest.fixture(scope="function") def matomo_api(): yield MatomoAPI() diff --git a/matomo-api/tests/test_cli.py b/matomo-api/tests/test_cli.py index 2ffcd3d..726d443 100644 --- a/matomo-api/tests/test_cli.py +++ b/matomo-api/tests/test_cli.py @@ -11,3 +11,13 @@ def test_cli(db): runner = CliRunner() result = runner.invoke(fetch_matomo_inspire_data, ["--date", "2022-01-02"]) assert result.exit_code == 0 + + +@pytest.mark.vcr( + filter_headers=["authorization", "Set-Cookie"], + filter_query_parameters=["token_auth", "idSite"], +) +def test_cli_default_arguments(db): + runner = CliRunner() + result = runner.invoke(fetch_matomo_inspire_data, []) + assert result.exit_code == 0 \ No newline at end of file