Skip to content

Commit

Permalink
matomo: default date=yesterday
Browse files Browse the repository at this point in the history
  • Loading branch information
MJedr committed Oct 5, 2023
1 parent 94d79f1 commit d63f692
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 6 deletions.
4 changes: 2 additions & 2 deletions matomo-api/docker-compose-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
POSTGRES_DB: matomo
1 change: 0 additions & 1 deletion matomo-api/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,3 @@ urllib3 = "1.26.7"
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

11 changes: 9 additions & 2 deletions matomo-api/src/cli.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
2 changes: 1 addition & 1 deletion matomo-api/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
10 changes: 10 additions & 0 deletions matomo-api/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit d63f692

Please sign in to comment.