From 37519ec344e51e2f377e348da399620687ecce20 Mon Sep 17 00:00:00 2001 From: Ernesto Rico Schmidt <ernesto@helsinki.at> Date: Tue, 29 Oct 2024 12:04:58 -0400 Subject: [PATCH] test: add tests for categories, funding categories, languages, licenses, link types, music focus, topics and types --- program/tests/test_categories.py | 100 ++++++++++++++++++++++ program/tests/test_funding_categories.py | 88 +++++++++++++++++++ program/tests/test_languages.py | 65 +++++++++++++++ program/tests/test_licenses.py | 102 +++++++++++++++++++++++ program/tests/test_link_types.py | 66 +++++++++++++++ program/tests/test_music_focus.py | 75 +++++++++++++++++ program/tests/test_topics.py | 75 +++++++++++++++++ program/tests/test_types.py | 75 +++++++++++++++++ 8 files changed, 646 insertions(+) create mode 100644 program/tests/test_categories.py create mode 100644 program/tests/test_funding_categories.py create mode 100644 program/tests/test_languages.py create mode 100644 program/tests/test_licenses.py create mode 100644 program/tests/test_link_types.py create mode 100644 program/tests/test_music_focus.py create mode 100644 program/tests/test_topics.py create mode 100644 program/tests/test_types.py diff --git a/program/tests/test_categories.py b/program/tests/test_categories.py new file mode 100644 index 00000000..deba67dd --- /dev/null +++ b/program/tests/test_categories.py @@ -0,0 +1,100 @@ +import pytest + +from program.tests.factories import CategoryFactory + +pytestmark = pytest.mark.django_db + + +def url(category=None): + return f"/api/v1/categories/{category.id}/" if category else "/api/v1/categories/" + + +def test_create_category(admin_api_client): + data = { + "description": "DESCRIPTION", + "is_active": True, + "name": "NAME", + "slug": "category", + "subtitle": "SUBTITLE", + } + + response = admin_api_client.post(url(), data) + + assert response.status_code == 201 + + assert response.data["description"] == data["description"] + assert response.data["name"] == data["name"] + assert response.data["slug"] == data["slug"] + assert response.data["subtitle"] == data["subtitle"] + + +def test_retrieve_category(common_api_client1, category): + response = common_api_client1.get(url(category=category)) + + assert response.status_code == 200 + + assert response.data["description"] == category.description + assert response.data["name"] == category.name + assert response.data["slug"] == category.slug + assert response.data["subtitle"] == category.subtitle + + +def test_delete_category(admin_api_client, category): + response = admin_api_client.delete(url(category=category)) + + assert response.status_code == 204 + + +def test_list_categories(common_api_client1): + CATEGORIES = 3 + CategoryFactory.create_batch(size=CATEGORIES) + + response = common_api_client1.get(url()) + + assert response.status_code == 200 + assert len(response.data) == CATEGORIES + + +def test_update_description(admin_api_client, category): + update = {"description": "DESCRIPTION"} + + response = admin_api_client.patch(url(category=category), update) + + assert response.status_code == 200 + assert response.data["description"] == update["description"] + + +def test_update_is_active(admin_api_client, category): + update = {"is_active": False} + + response = admin_api_client.patch(url(category=category), update) + + assert response.status_code == 200 + assert response.data["is_active"] == update["is_active"] + + +def test_update_name(admin_api_client, category): + update = {"name": "NAME"} + + response = admin_api_client.patch(url(category=category), update) + + assert response.status_code == 200 + assert response.data["name"] == update["name"] + + +def test_update_slug(admin_api_client, category): + update = {"slug": "category"} + + response = admin_api_client.patch(url(category=category), update) + + assert response.status_code == 200 + assert response.data["slug"] == update["slug"] + + +def test_update_subtitle(admin_api_client, category): + update = {"subtitle": "SUBTITLE"} + + response = admin_api_client.patch(url(category=category), update) + + assert response.status_code == 200 + assert response.data["subtitle"] == update["subtitle"] diff --git a/program/tests/test_funding_categories.py b/program/tests/test_funding_categories.py new file mode 100644 index 00000000..bda1840a --- /dev/null +++ b/program/tests/test_funding_categories.py @@ -0,0 +1,88 @@ +import pytest + +from program.tests.factories import FundingCategoryFactory + +pytestmark = pytest.mark.django_db + + +def url(funding_category=None): + return ( + f"/api/v1/funding-categories/{funding_category.id}/" + if funding_category + else "/api/v1/funding-categories/" + ) + + +def test_create_funding_category(admin_api_client): + data = { + "name": "NAME", + "is_active": True, + "slug": "funding-category", + } + + response = admin_api_client.post(url(), data, format="json") + + assert response.status_code == 201 + + assert response.data["is_active"] == data["is_active"] + assert response.data["name"] == data["name"] + assert response.data["slug"] == data["slug"] + + +def test_retrieve_funding_category(common_api_client1, funding_category): + response = common_api_client1.get(url(funding_category=funding_category)) + + assert response.status_code == 200 + + assert response.data["is_active"] == funding_category.is_active + assert response.data["name"] == funding_category.name + assert response.data["slug"] == funding_category.slug + + +def test_delete_funding_category(admin_api_client, funding_category): + response = admin_api_client.delete(url(funding_category=funding_category)) + + assert response.status_code == 204 + + +def test_list_funding_categories(common_api_client1): + FUNDING_CATEGORIES = 3 + FundingCategoryFactory.create_batch(size=FUNDING_CATEGORIES) + + response = common_api_client1.get(url()) + + assert response.status_code == 200 + assert len(response.data) == FUNDING_CATEGORIES + + +def test_update_is_active(admin_api_client, funding_category): + update = { + "is_active": False, + } + + response = admin_api_client.patch(url(funding_category=funding_category), update) + + assert response.status_code == 200 + assert response.data["is_active"] == update["is_active"] + + +def test_update_name(admin_api_client, funding_category): + update = { + "name": "NAME", + } + + response = admin_api_client.patch(url(funding_category=funding_category), update) + + assert response.status_code == 200 + assert response.data["name"] == update["name"] + + +def test_update_slug(admin_api_client, funding_category): + update = { + "slug": "funding-category", + } + + response = admin_api_client.patch(url(funding_category=funding_category), update) + + assert response.status_code == 200 + assert response.data["slug"] == update["slug"] diff --git a/program/tests/test_languages.py b/program/tests/test_languages.py new file mode 100644 index 00000000..7e3a0b55 --- /dev/null +++ b/program/tests/test_languages.py @@ -0,0 +1,65 @@ +import pytest + +from program.tests.factories import LanguageFactory + +pytestmark = pytest.mark.django_db + + +def url(language=None): + return f"/api/v1/languages/{language.id}/" if language else "/api/v1/languages/" + + +def test_create_language(admin_api_client): + data = {"is_active": True, "name": "NAME"} + + response = admin_api_client.post(url(), data, format="json") + + assert response.status_code == 201 + + assert response.data["is_active"] == data["is_active"] + assert response.data["name"] == data["name"] + + +def test_retrieve_langauge(common_api_client1, language): + response = common_api_client1.get(url(language=language)) + + assert response.status_code == 200 + + assert response.data["is_active"] == language.is_active + assert response.data["name"] == language.name + + +def test_delete_langauge(admin_api_client, language): + response = admin_api_client.delete(url(language=language)) + + assert response.status_code == 204 + + +def test_list_langauges(common_api_client1): + LANGUAGES = 3 + LanguageFactory.create_batch(size=LANGUAGES) + + response = common_api_client1.get(url()) + + print(response.data) + + assert response.status_code == 200 + assert len(response.data) == LANGUAGES + + +def test_update_is_active(admin_api_client, language): + update = {"is_active": False} + + response = admin_api_client.patch(url(language=language), update, format="json") + + assert response.status_code == 200 + assert response.data["is_active"] == update["is_active"] + + +def test_update_name(admin_api_client, language): + update = {"name": "NAME"} + + response = admin_api_client.patch(url(language=language), update) + + assert response.status_code == 200 + assert response.data["name"] == update["name"] diff --git a/program/tests/test_licenses.py b/program/tests/test_licenses.py new file mode 100644 index 00000000..0aaa6613 --- /dev/null +++ b/program/tests/test_licenses.py @@ -0,0 +1,102 @@ +import pytest + +from program.tests.factories import LicenseFactory + +pytestmark = pytest.mark.django_db + + +def url(license=None): + return f"/api/v1/licenses/{license.id}/" if license else "/api/v1/licenses/" + + +def test_create_license(admin_api_client): + data = {"identifier": "IDENTIFIER", "name": "NAME"} + + response = admin_api_client.post(url(), data) + + assert response.status_code == 201 + + assert response.data["identifier"] == data["identifier"] + assert response.data["name"] == data["name"] + + +def test_retrieve_license(common_api_client1, license_): + response = common_api_client1.get(url(license=license_)) + + assert response.status_code == 200 + + assert response.data["identifier"] == license_.identifier + assert response.data["name"] == license_.name + + +def test_delete_license(admin_api_client, license_): + response = admin_api_client.delete(url(license=license_)) + + assert response.status_code == 204 + + +def test_list_licenses(common_api_client1): + LICENSES = 3 + LicenseFactory.create_batch(size=LICENSES) + + response = common_api_client1.get(url()) + + assert response.status_code == 200 + assert len(response.data) == LICENSES + + +def test_update_identifier(admin_api_client, license_): + update = { + "identifier": "IDENTIFIER", + } + + response = admin_api_client.patch(url(license=license_), update) + + assert response.status_code == 200 + + assert response.data["identifier"] == update["identifier"] + + +def test_update_name(admin_api_client, license_): + update = { + "name": "NAME", + } + + response = admin_api_client.patch(url(license=license_), update) + + assert response.status_code == 200 + + assert response.data["name"] == update["name"] + + +def test_update_needs_autor(admin_api_client, license_): + update = {"needs_author": False} + + response = admin_api_client.patch(url(license=license_), update) + + assert response.status_code == 200 + + assert response.data["needs_author"] == update["needs_author"] + + +def test_update_requires_express_permission_for_publication(admin_api_client, license_): + update = {"requires_express_permission_for_publication": False} + + response = admin_api_client.patch(url(license=license_), update) + + assert response.status_code == 200 + + assert ( + response.data["requires_express_permission_for_publication"] + == update["requires_express_permission_for_publication"] + ) + + +def test_update_url(admin_api_client, license_): + update = {"url": "https://aura.radio/"} + + response = admin_api_client.patch(url(license=license_), update) + + assert response.status_code == 200 + + assert response.data["url"] == update["url"] diff --git a/program/tests/test_link_types.py b/program/tests/test_link_types.py new file mode 100644 index 00000000..fd6a48bb --- /dev/null +++ b/program/tests/test_link_types.py @@ -0,0 +1,66 @@ +import pytest + +from program.tests.factories import LinkTypeFactory + +pytestmark = pytest.mark.django_db + + +def url(link_type=None): + return f"/api/v1/link-types/{link_type.id}/" if link_type else "/api/v1/link-types/" + + +def test_create_link_type(admin_api_client): + data = { + "is_active": True, + "name": "NAME", + } + + response = admin_api_client.post(url(), data) + + assert response.status_code == 201 + + assert response.data["is_active"] == data["is_active"] + assert response.data["name"] == data["name"] + + +def test_retrieve_link_type(common_api_client1, link_type): + response = common_api_client1.get(url(link_type=link_type)) + + assert response.status_code == 200 + + assert response.data["is_active"] == link_type.is_active + assert response.data["name"] == link_type.name + + +def test_delete_link_type(admin_api_client, link_type): + response = admin_api_client.delete(url(link_type=link_type)) + + assert response.status_code == 204 + + +def test_list_link_types(common_api_client1): + LINK_TYPES = 3 + LinkTypeFactory.create_batch(size=LINK_TYPES) + + response = common_api_client1.get(url()) + + assert response.status_code == 200 + assert len(response.data) == LINK_TYPES + + +def test_update_is_active(admin_api_client, link_type): + update = {"is_active": False} + + response = admin_api_client.patch(url(link_type=link_type), update) + + assert response.status_code == 200 + assert response.data["is_active"] == update["is_active"] + + +def test_update_name(admin_api_client, link_type): + update = {"name": "NAME"} + + response = admin_api_client.patch(url(link_type=link_type), update) + + assert response.status_code == 200 + assert response.data["name"] == update["name"] diff --git a/program/tests/test_music_focus.py b/program/tests/test_music_focus.py new file mode 100644 index 00000000..50572889 --- /dev/null +++ b/program/tests/test_music_focus.py @@ -0,0 +1,75 @@ +import pytest + +from program.tests.factories import MusicFocusFactory + +pytestmark = pytest.mark.django_db + + +def url(music_focus=None): + return f"/api/v1/music-focus/{music_focus.id}/" if music_focus else "/api/v1/music-focus/" + + +def test_create(admin_api_client): + data = { + "name": "NAME", + "slug": "music-focus", + } + + response = admin_api_client.post(url(), data) + + assert response.status_code == 201 + + assert response.data["name"] == data["name"] + assert response.data["slug"] == data["slug"] + + +def test_retrieve_music_focus(common_api_client1, music_focus): + response = common_api_client1.get(url(music_focus=music_focus)) + + assert response.status_code == 200 + + assert response.data["name"] == music_focus.name + assert response.data["slug"] == music_focus.slug + + +def test_delete(admin_api_client, music_focus): + response = admin_api_client.delete(url(music_focus=music_focus)) + + assert response.status_code == 204 + + +def test_list(common_api_client1): + MUSIC_FOCUS = 3 + MusicFocusFactory.create_batch(size=MUSIC_FOCUS) + + response = common_api_client1.get(url()) + + assert response.status_code == 200 + assert len(response.data) == MUSIC_FOCUS + + +def test_update_is_active(admin_api_client, music_focus): + update = {"is_active": False} + + response = admin_api_client.patch(url(music_focus=music_focus), update) + + assert response.status_code == 200 + assert response.data["is_active"] is update["is_active"] + + +def test_update_name(admin_api_client, music_focus): + update = {"name": "NAME"} + + response = admin_api_client.patch(url(music_focus=music_focus), update) + + assert response.status_code == 200 + assert response.data["name"] == update["name"] + + +def test_update_slug(admin_api_client, music_focus): + update = {"slug": "music-focus"} + + response = admin_api_client.patch(url(music_focus=music_focus), update) + + assert response.status_code == 200 + assert response.data["slug"] == update["slug"] diff --git a/program/tests/test_topics.py b/program/tests/test_topics.py new file mode 100644 index 00000000..d03c4b3d --- /dev/null +++ b/program/tests/test_topics.py @@ -0,0 +1,75 @@ +import pytest + +from program.tests.factories import TopicFactory + +pytestmark = pytest.mark.django_db + + +def url(topic=None): + return f"/api/v1/topics/{topic.id}/" if topic else "/api/v1/topics/" + + +def test_create_topic(admin_api_client): + data = { + "name": "NAME", + "slug": "topic", + } + + response = admin_api_client.post(url(), data) + + assert response.status_code == 201 + + assert response.data["name"] == data["name"] + assert response.data["slug"] == data["slug"] + + +def test_retrieve(common_api_client1, topic): + response = common_api_client1.get(url(topic=topic)) + + assert response.status_code == 200 + + assert response.data["name"] == topic.name + assert response.data["slug"] == topic.slug + + +def test_delete(admin_api_client, topic): + response = admin_api_client.delete(url(topic=topic)) + + assert response.status_code == 204 + + +def test_list(common_api_client1): + TOPICS = 3 + TopicFactory.create_batch(size=TOPICS) + + response = common_api_client1.get(url()) + + assert response.status_code == 200 + assert len(response.data) == TOPICS + + +def test_update_is_active(admin_api_client, topic): + update = {"is_active": False} + + response = admin_api_client.patch(url(topic=topic), update) + + assert response.status_code == 200 + assert response.data["is_active"] is update["is_active"] + + +def test_update_name(admin_api_client, topic): + update = {"name": "NAME"} + + response = admin_api_client.patch(url(topic=topic), update) + + assert response.status_code == 200 + assert response.data["name"] == update["name"] + + +def test_update_slug(admin_api_client, topic): + update = {"slug": "topic"} + + response = admin_api_client.patch(url(topic=topic), update) + + assert response.status_code == 200 + assert response.data["slug"] == update["slug"] diff --git a/program/tests/test_types.py b/program/tests/test_types.py new file mode 100644 index 00000000..d00bfd30 --- /dev/null +++ b/program/tests/test_types.py @@ -0,0 +1,75 @@ +import pytest + +from program.tests.factories import TypeFactory + +pytestmark = pytest.mark.django_db + + +def url(type=None): + return f"/api/v1/types/{type.id}/" if type else "/api/v1/types/" + + +def test_create(admin_api_client): + data = { + "name": "NAME", + "slug": "type", + } + + response = admin_api_client.post(url(), data) + + assert response.status_code == 201 + + assert response.data["name"] == data["name"] + assert response.data["slug"] == data["slug"] + + +def test_retrieve(common_api_client1, type_): + response = common_api_client1.get(url(type_)) + + assert response.status_code == 200 + + assert response.data["name"] == type_.name + assert response.data["slug"] == type_.slug + + +def test_delete(admin_api_client, type_): + response = admin_api_client.delete(url(type=type_)) + + assert response.status_code == 204 + + +def test_list(common_api_client1): + TYPES = 3 + TypeFactory.create_batch(size=TYPES) + + response = common_api_client1.get(url()) + + assert response.status_code == 200 + assert len(response.data) == TYPES + + +def test_update_is_active(admin_api_client, type_): + update = {"is_active": False} + + response = admin_api_client.patch(url(type=type_), update) + + assert response.status_code == 200 + assert response.data["is_active"] is update["is_active"] + + +def test_update_name(admin_api_client, type_): + update = {"name": "NAME"} + + response = admin_api_client.patch(url(type=type_), update) + + assert response.status_code == 200 + assert response.data["name"] == update["name"] + + +def test_update_slug(admin_api_client, type_): + update = {"slug": "topic"} + + response = admin_api_client.patch(url(type=type_), update) + + assert response.status_code == 200 + assert response.data["slug"] == update["slug"] -- GitLab