Skip to content

Commit

Permalink
Merge pull request #591 from camptocamp/test-module-trasversal-dashboard
Browse files Browse the repository at this point in the history
Add serialization, deserialization function test in trivial cases
  • Loading branch information
sbrunner authored Nov 2, 2024
2 parents 8d540d8 + 68404f7 commit 3bd0fe5
Show file tree
Hide file tree
Showing 2 changed files with 171 additions and 0 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/failed.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Used to test the workflow dashboard
name: Failed workflow

on:
push:
branches:
- master

jobs:
main1:
name: Main 1
runs-on: ubuntu-24.04
timeout-minutes: 1

steps:
- run: 'false'

main2:
name: Main 2
runs-on: ubuntu-24.04
timeout-minutes: 1

steps:
- run: 'false'
147 changes: 147 additions & 0 deletions tests/test_module.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
from typing import Any

import pytest
from pydantic import BaseModel

from github_app_geo_project import module
from github_app_geo_project.module.modules import MODULES
from github_app_geo_project.module.tests import TestModule

Expand Down Expand Up @@ -28,3 +32,146 @@ def test_conversions() -> None:
def test_all_empty_status() -> None:
for module in MODULES.values():
module.transversal_status_to_json(module.transversal_status_from_json({}))


class ConfigDictModule(module.Module[dict[str, Any], None, None]):
pass


@pytest.mark.parametrize(
"data",
[
{},
{"type": "success"},
],
)
def test_json_configuration_from_json(data) -> None:
test_module = ConfigDictModule()

assert test_module.configuration_from_json(data) == data


class EventDataDictModule(module.Module[None, dict[str, Any], None]):
pass


@pytest.mark.parametrize(
"data",
[
{},
{"type": "success"},
],
)
def test_json_event_data_from_json(data) -> None:
test_module = EventDataDictModule()

assert test_module.event_data_from_json(data) == data


@pytest.mark.parametrize(
"data",
[
{},
{"type": "success"},
],
)
def test_json_envent_data_to_json(data) -> None:
test_module = EventDataDictModule()

assert test_module.event_data_to_json(data) == data


class TransversalStatusDictModule(module.Module[None, None, dict[str, Any]]):
pass


@pytest.mark.parametrize(
"data",
[
{},
{"type": "success"},
],
)
def test_json_transversal_status_from_json(data) -> None:
test_module = TransversalStatusDictModule()

assert test_module.transversal_status_from_json(data) == data


@pytest.mark.parametrize(
"data",
[
{},
{"type": "success"},
],
)
def test_json_transversal_status_to_json(data) -> None:
test_module = TransversalStatusDictModule()

assert test_module.transversal_status_to_json(data) == data


class Data(BaseModel):
value: str


class ConfigDataModule(module.Module[Data, None, None]):
pass


@pytest.mark.parametrize(
"data,expected",
[
[{"value": "test"}, Data(value="test")],
],
)
def test_data_configuration_from_json(data, expected) -> None:
test_module = ConfigDataModule()

assert test_module.configuration_from_json(data) == expected


class EventDataDataModule(module.Module[None, Data, None]):
pass


@pytest.mark.parametrize(
"data,expected",
[
[{"value": "test"}, Data(value="test")],
],
)
def test_data_event_data_from_json(data, expected) -> None:
test_module = EventDataDataModule()

assert test_module.event_data_from_json(data) == expected


@pytest.mark.parametrize("data,expected", [[Data(value="test"), {"value": "test"}]])
def test_data_event_data_to_json(data, expected) -> None:
test_module = EventDataDataModule()

assert test_module.event_data_to_json(data) == expected


class TransversalStatusDataModule(module.Module[None, None, Data]):
pass


@pytest.mark.parametrize(
"data,expected",
[
[{"value": "test"}, Data(value="test")],
],
)
def test_data_transversal_status_from_json(data, expected) -> None:
test_module = TransversalStatusDataModule()

assert test_module.transversal_status_from_json(data) == expected


@pytest.mark.parametrize("data,expected", [[Data(value="test"), {"value": "test"}]])
def test_data_transversal_status_to_json(data, expected) -> None:
test_module = TransversalStatusDataModule()

assert test_module.transversal_status_to_json(data) == expected

0 comments on commit 3bd0fe5

Please sign in to comment.