fix(graphql): backup quotas field typing

This commit is contained in:
Inex Code 2023-08-30 12:03:19 +03:00
parent 9fdc536f9f
commit ad9384c850
5 changed files with 24 additions and 16 deletions

View file

@ -24,5 +24,6 @@ def same_month(a: datetime, b: datetime) -> bool:
def same_year(a: datetime, b: datetime) -> bool: def same_year(a: datetime, b: datetime) -> bool:
return a.year == b.year return a.year == b.year
def same_lifetime_of_the_universe(a: datetime, b: datetime) -> bool: def same_lifetime_of_the_universe(a: datetime, b: datetime) -> bool:
return True return True

View file

@ -29,3 +29,8 @@ class _AutobackupQuotas(BaseModel):
@strawberry.experimental.pydantic.type(model=_AutobackupQuotas, all_fields=True) @strawberry.experimental.pydantic.type(model=_AutobackupQuotas, all_fields=True)
class AutobackupQuotas: class AutobackupQuotas:
pass pass
@strawberry.experimental.pydantic.input(model=_AutobackupQuotas, all_fields=True)
class AutobackupQuotasInput:
pass

View file

@ -12,8 +12,8 @@ from selfprivacy_api.graphql.queries.backup import Backup
from selfprivacy_api.graphql.queries.providers import BackupProvider from selfprivacy_api.graphql.queries.providers import BackupProvider
from selfprivacy_api.graphql.common_types.jobs import job_to_api_job from selfprivacy_api.graphql.common_types.jobs import job_to_api_job
from selfprivacy_api.graphql.common_types.backup import ( from selfprivacy_api.graphql.common_types.backup import (
AutobackupQuotasInput,
RestoreStrategy, RestoreStrategy,
AutobackupQuotas,
) )
from selfprivacy_api.backup import Backups from selfprivacy_api.backup import Backups
@ -36,13 +36,6 @@ class InitializeRepositoryInput:
password: str password: str
@strawberry.input
class SetAutobackupQuotasInput:
"""A single field input to reuse AutobackupQuotas"""
quotas: AutobackupQuotas
@strawberry.type @strawberry.type
class GenericBackupConfigReturn(MutationReturnInterface): class GenericBackupConfigReturn(MutationReturnInterface):
"""Generic backup config return""" """Generic backup config return"""
@ -102,7 +95,7 @@ class BackupMutations:
@strawberry.mutation(permission_classes=[IsAuthenticated]) @strawberry.mutation(permission_classes=[IsAuthenticated])
def set_autobackup_quotas( def set_autobackup_quotas(
self, quotas: SetAutobackupQuotasInput self, quotas: AutobackupQuotasInput
) -> GenericBackupConfigReturn: ) -> GenericBackupConfigReturn:
""" """
Set autobackup quotas. Set autobackup quotas.

View file

@ -28,7 +28,7 @@ class BackupConfiguration:
# If none, autobackups are disabled # If none, autobackups are disabled
autobackup_period: typing.Optional[int] autobackup_period: typing.Optional[int]
# None is equal to all quotas being unlimited (-1). Optional for compatibility reasons. # None is equal to all quotas being unlimited (-1). Optional for compatibility reasons.
autobackup_quotas: typing.Optional[AutobackupQuotas] autobackup_quotas: AutobackupQuotas
# Bucket name for Backblaze, path for some other providers # Bucket name for Backblaze, path for some other providers
location_name: typing.Optional[str] location_name: typing.Optional[str]
location_id: typing.Optional[str] location_id: typing.Optional[str]

View file

@ -4,7 +4,10 @@ from tests.common import generate_backup_query
from selfprivacy_api.graphql.common_types.service import service_to_graphql_service from selfprivacy_api.graphql.common_types.service import service_to_graphql_service
from selfprivacy_api.graphql.common_types.backup import AutobackupQuotas from selfprivacy_api.graphql.common_types.backup import (
_AutobackupQuotas,
AutobackupQuotas,
)
from selfprivacy_api.jobs import Jobs, JobStatus from selfprivacy_api.jobs import Jobs, JobStatus
API_RELOAD_SNAPSHOTS = """ API_RELOAD_SNAPSHOTS = """
@ -41,7 +44,7 @@ mutation TestAutobackupPeriod($period: Int) {
API_SET_AUTOBACKUP_QUOTAS_MUTATION = """ API_SET_AUTOBACKUP_QUOTAS_MUTATION = """
mutation TestAutobackupQuotas($input: SetAutobackupQuotasInput!) { mutation TestAutobackupQuotas($input: AutobackupQuotasInput!) {
backup { backup {
setAutobackupQuotas(quotas: $input) { setAutobackupQuotas(quotas: $input) {
success success
@ -54,7 +57,13 @@ mutation TestAutobackupQuotas($input: SetAutobackupQuotasInput!) {
autobackupPeriod autobackupPeriod
locationName locationName
locationId locationId
autobackupQuotas autobackupQuotas {
daily
weekly
monthly
yearly
total
}
} }
} }
} }
@ -200,12 +209,12 @@ def api_set_period(authorized_client, period):
return response return response
def api_set_quotas(authorized_client, quotas): def api_set_quotas(authorized_client, quotas: _AutobackupQuotas):
response = authorized_client.post( response = authorized_client.post(
"/graphql", "/graphql",
json={ json={
"query": API_SET_AUTOBACKUP_QUOTAS_MUTATION, "query": API_SET_AUTOBACKUP_QUOTAS_MUTATION,
"variables": {"input": {"quotas": quotas}}, "variables": {"input": quotas.dict()},
}, },
) )
return response return response
@ -358,7 +367,7 @@ def test_remove(authorized_client, generic_userdata):
def test_autobackup_quotas_nonzero(authorized_client): def test_autobackup_quotas_nonzero(authorized_client):
quotas = AutobackupQuotas( quotas = _AutobackupQuotas(
daily=2, daily=2,
weekly=4, weekly=4,
monthly=13, monthly=13,