Skip to content

test_project#

project_json#

Source code in tests/unit/apps/core/models/test_project.py
@pytest.fixture
def project_json():
    return {
        "participating_organizations": [{"pref_label": {"fi": "testi"}}],
        "funding": [
            {
                "funding_identifier": "rahoitustunniste",
                "funder": {"organization": {"pref_label": {"fi": "rahoittajataho"}}},
            }
        ],
    }

test_serialize_project#

Source code in tests/unit/apps/core/models/test_project.py
def test_serialize_project(project_json):
    serializer = ProjectModelSerializer(
        data=project_json,
        context={"dataset": None},
    )
    serializer.is_valid(raise_exception=True)
    project = serializer.save()
    assert project.participating_organizations.first().pref_label["fi"] == "testi"
    assert project.funding.first().funding_identifier == "rahoitustunniste"
    assert project.funding.first().funder.organization.pref_label["fi"] == "rahoittajataho"

test_serialize_project_no_org#

Source code in tests/unit/apps/core/models/test_project.py
def test_serialize_project_no_org(project_json):
    project_json["participating_organizations"] = []
    serializer = ProjectModelSerializer(
        data=project_json,
        context={"dataset": None},
    )
    with pytest.raises(serializers.ValidationError):
        serializer.is_valid(raise_exception=True)

test_serialize_project_no_org_migrating#

Source code in tests/unit/apps/core/models/test_project.py
def test_serialize_project_no_org_migrating(project_json):
    project_json["participating_organizations"] = []
    serializer = ProjectModelSerializer(
        data=project_json,
        context={"dataset": None, "migrating": True},
    )
    serializer.is_valid(raise_exception=True)
    project = serializer.save()
    assert project.participating_organizations.count() == 0