Skip to content

Commit

Permalink
fix: making event groups events publishable should not clear event group
Browse files Browse the repository at this point in the history
KK-1211
  • Loading branch information
nikomakela committed Aug 30, 2024
1 parent 28374c9 commit e00f931
Show file tree
Hide file tree
Showing 11 changed files with 357 additions and 277 deletions.
3 changes: 3 additions & 0 deletions common/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ def setup_test_environment(settings):
settings.KUKKUU_REMINDER_DAYS_IN_ADVANCE = 7
settings.KUKKUU_DEFAULT_EVENT_DURATION = 120
settings.KUKKUU_ENROLLED_OCCURRENCE_IN_PAST_LEEWAY = 30
settings.OIDC_BROWSER_TEST_API_TOKEN_AUTH = {
"ENABLED": False,
}
with translation.override("fi"), freeze_time("2020-12-12"):
yield
shutil.rmtree("test_media", ignore_errors=True)
Expand Down
5 changes: 3 additions & 2 deletions events/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -853,9 +853,10 @@ def mutate_and_get_payload(cls, root, info, **kwargs):
info, project_global_id, Project
).pk

if "event_group_id" in kwargs and kwargs["event_group_id"]:
event_group_global_id = kwargs.pop("event_group_id", None)
if event_group_global_id:
kwargs["event_group_id"] = get_obj_if_user_can_administer(
info, kwargs["event_group_id"], EventGroup
info, event_group_global_id, EventGroup
).pk

event = get_obj_if_user_can_administer(info, kwargs.pop("id"), Event)
Expand Down
8 changes: 8 additions & 0 deletions events/tests/mutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
mutation AddEvent($input: AddEventMutationInput!) {
addEvent(input: $input) {
event {
id
eventGroup {
id
}
translations{
languageCode
name
Expand Down Expand Up @@ -43,6 +47,10 @@
mutation UpdateEvent($input: UpdateEventMutationInput!) {
updateEvent(input: $input) {
event {
id
eventGroup {
id
}
translations{
name
shortDescription
Expand Down
9 changes: 9 additions & 0 deletions events/tests/snapshots/snap_test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from snapshottest import Snapshot


snapshots = Snapshot()

snapshots["test_add_event_group[model_perm] 1"] = {
Expand Down Expand Up @@ -56,6 +57,8 @@
"event": {
"capacityPerOccurrence": 30,
"duration": 1000,
"eventGroup": {"id": "RXZlbnRHcm91cE5vZGU6MjE="},
"id": "RXZlbnROb2RlOjE2NQ==",
"image": "",
"imageAltText": "Image alt text",
"participantsPerInvite": "FAMILY",
Expand Down Expand Up @@ -1290,6 +1293,8 @@
"event": {
"capacityPerOccurrence": 30,
"duration": 1000,
"eventGroup": None,
"id": "RXZlbnROb2RlOjI1OA==",
"image": "",
"imageAltText": "Image alt text",
"participantsPerInvite": "FAMILY",
Expand Down Expand Up @@ -1386,6 +1391,8 @@
"event": {
"capacityPerOccurrence": 30,
"duration": 1000,
"eventGroup": {"id": "RXZlbnRHcm91cE5vZGU6MjI="},
"id": "RXZlbnROb2RlOjE4Mg==",
"image": "http://testserver/media/teacher.jpg",
"imageAltText": "Image alt text",
"occurrences": {"edges": []},
Expand Down Expand Up @@ -1419,6 +1426,8 @@
"event": {
"capacityPerOccurrence": 35,
"duration": 181,
"eventGroup": {"id": "RXZlbnRHcm91cE5vZGU6MjM="},
"id": "RXZlbnROb2RlOjE4Mw==",
"image": "http://testserver/media/teacher.jpg",
"imageAltText": "",
"occurrences": {"edges": []},
Expand Down
20 changes: 16 additions & 4 deletions events/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,26 +543,38 @@ def test_update_event_project_user(
snapshot, project_user_api_client, event, event_group
):
event_variables = deepcopy(UPDATE_EVENT_VARIABLES)
event_variables["input"]["id"] = to_global_id("EventNode", event.id)
event_variables["input"]["eventGroupId"] = to_global_id(
"EventGroupNode", event_group.id
)
event_node_id = to_global_id("EventNode", event.id)
event_group_node_id = to_global_id("EventGroupNode", event_group.id)
event_variables["input"]["id"] = event_node_id
event_variables["input"]["eventGroupId"] = event_group_node_id
executed = project_user_api_client.execute(
UPDATE_EVENT_MUTATION, variables=event_variables
)
assert executed["data"]["updateEvent"]["event"]["id"] == event_node_id
assert executed["data"]["updateEvent"]["event"]["eventGroup"]["id"] == (
event_group_node_id
)
snapshot.assert_match(executed)


def test_update_event_ready_for_event_group_publishing(
snapshot, project_user_api_client, event, event_group
):
event.event_group = event_group
event.save()
assert event.event_group.id == event_group.id

variables = {
"input": {"id": get_global_id(event), "readyForEventGroupPublishing": True},
}
executed = project_user_api_client.execute(
UPDATE_EVENT_MUTATION, variables=variables
)
assert executed["data"]["updateEvent"]["event"]["readyForEventGroupPublishing"]
snapshot.assert_match(executed)
# the event group id should be still set
event.refresh_from_db()
assert event.event_group.id == event_group.id


def test_update_ticketmaster_event(snapshot, project_user_api_client):
Expand Down
16 changes: 4 additions & 12 deletions languages/tests/snapshots/snap_test_add_languages_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@

snapshots = Snapshot()

snapshots[
"test_add_default_languages 1"
] = """Created special language "Other"
snapshots["test_add_default_languages 1"] = """Created special language "Other"
Created Arabic (ara)
Created Bengali (ben)
Created German (deu)
Expand Down Expand Up @@ -76,9 +74,7 @@
"zho": {"en": "Chinese", "fi": "kiina", "sv": "Kinesiska"},
}

snapshots[
"test_add_languages 1"
] = """Created Manide (abd)
snapshots["test_add_languages 1"] = """Created Manide (abd)
Created Ngelima (agh)
All done!
"""
Expand All @@ -88,9 +84,7 @@
"agh": {"en": "Ngelima", "fi": "Ngelima", "sv": "Ngelima"},
}

snapshots[
"test_add_languages_and_flush 1"
] = """Flushed existing languages
snapshots["test_add_languages_and_flush 1"] = """Flushed existing languages
Created Manide (abd)
Created Ngelima (agh)
All done!
Expand All @@ -101,7 +95,5 @@
"agh": {"en": "Ngelima", "fi": "Ngelima", "sv": "Ngelima"},
}

snapshots[
"test_no_arguments 1"
] = """Nothing to do. Hint: try --help.
snapshots["test_no_arguments 1"] = """Nothing to do. Hint: try --help.
"""
51 changes: 30 additions & 21 deletions projects/tests/snapshots/snap_test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,44 @@

from snapshottest import Snapshot


snapshots = Snapshot()

snapshots["test_project_query_normal_user 1"] = {
"data": {
"project": {
"enrolmentLimit": 2,
"id": "UHJvamVjdE5vZGU6MQ==",
"name": "Testiprojekti",
"singleEventsAllowed": True,
"translations": [{"languageCode": "FI", "name": "Testiprojekti"}],
"year": 2020,
snapshots['test_project_query_normal_user 1'] = {
'data': {
'project': {
'enrolmentLimit': 2,
'id': 'UHJvamVjdE5vZGU6MQ==',
'name': 'Testiprojekti',
'singleEventsAllowed': True,
'translations': [
{
'languageCode': 'FI',
'name': 'Testiprojekti'
}
],
'year': 2020
}
}
}

snapshots["test_projects_query_normal_user 1"] = {
"data": {
"projects": {
"edges": [
snapshots['test_projects_query_normal_user 1'] = {
'data': {
'projects': {
'edges': [
{
"node": {
"enrolmentLimit": 2,
"id": "UHJvamVjdE5vZGU6MQ==",
"name": "Testiprojekti",
"singleEventsAllowed": True,
"translations": [
{"languageCode": "FI", "name": "Testiprojekti"}
'node': {
'enrolmentLimit': 2,
'id': 'UHJvamVjdE5vZGU6MQ==',
'name': 'Testiprojekti',
'singleEventsAllowed': True,
'translations': [
{
'languageCode': 'FI',
'name': 'Testiprojekti'
}
],
"year": 2020,
'year': 2020
}
}
]
Expand Down
3 changes: 1 addition & 2 deletions projects/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,12 @@ def test_project_query_unauthenticated(snapshot, api_client, project):

def test_projects_query_normal_user(snapshot, guardian_api_client, project):
executed = guardian_api_client.execute(PROJECTS_QUERY)

assert len(executed["data"]["projects"]["edges"]) == 1
snapshot.assert_match(executed)


def test_project_query_normal_user(snapshot, guardian_api_client, project):
variables = {"id": to_global_id("ProjectNode", project.id)}

executed = guardian_api_client.execute(PROJECT_QUERY, variables=variables)

snapshot.assert_match(executed)
24 changes: 14 additions & 10 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,29 @@ extend-exclude = ["migrations", "snapshots"]
[tool.ruff.lint]
# See https://docs.astral.sh/ruff/rules/ for documentation of rules
extend-select = [
"C90", # Enable mccabe (C90) rules
"I", # Enable isort (I) rules
"E", # Enable pycodestyle error (E) rules
"W", # Enable pycodestyle warning (W) rules
"C90", # Enable mccabe (C90) rules
"I", # Enable isort (I) rules
"E", # Enable pycodestyle error (E) rules
"W", # Enable pycodestyle warning (W) rules
]
# Ignore conflicting lint rules:
# https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules
#
# If left enabled, these could cause conflicts between the linter
# (i.e. "ruff check --fix") and formatter (i.e. "ruff format").
ignore = [
"E111", # "Indentation is not a multiple of four"
"E114", # "Indentation is not a multiple of four (comment)"
"E117", # "Over-indented"
"E111", # "Indentation is not a multiple of four"
"E114", # "Indentation is not a multiple of four (comment)"
"E117", # "Over-indented"
]

[tool.ruff.lint.isort]
# isort options for ruff:
# https://docs.astral.sh/ruff/settings/#lintisort
order-by-type = false # Don't use type (i.e. case) to sort imports
order-by-type = false # Don't use type (i.e. case) to sort imports

[tool.ruff.format]
docstring-code-format = true # Format code in docstrings
docstring-code-format = true # Format code in docstrings

[tool.coverage.run]
# Coverage run options:
Expand All @@ -45,4 +45,8 @@ DJANGO_SETTINGS_MODULE = "kukkuu.settings"
# pytest options:
# https://docs.pytest.org/en/stable/reference/reference.html#configuration-options
norecursedirs = ["node_modules", ".git", "venv*"]
doctest_optionflags = ["NORMALIZE_WHITESPACE", "IGNORE_EXCEPTION_DETAIL", "ALLOW_UNICODE"]
doctest_optionflags = [
"NORMALIZE_WHITESPACE",
"IGNORE_EXCEPTION_DETAIL",
"ALLOW_UNICODE",
]
Loading

0 comments on commit e00f931

Please sign in to comment.