mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2025-02-02 14:16:38 +00:00
fix(graphql): backup quotas field typing
This commit is contained in:
parent
9fdc536f9f
commit
ad9384c850
|
@ -24,5 +24,6 @@ def same_month(a: datetime, b: datetime) -> bool:
|
|||
def same_year(a: datetime, b: datetime) -> bool:
|
||||
return a.year == b.year
|
||||
|
||||
|
||||
def same_lifetime_of_the_universe(a: datetime, b: datetime) -> bool:
|
||||
return True
|
||||
|
|
|
@ -29,3 +29,8 @@ class _AutobackupQuotas(BaseModel):
|
|||
@strawberry.experimental.pydantic.type(model=_AutobackupQuotas, all_fields=True)
|
||||
class AutobackupQuotas:
|
||||
pass
|
||||
|
||||
|
||||
@strawberry.experimental.pydantic.input(model=_AutobackupQuotas, all_fields=True)
|
||||
class AutobackupQuotasInput:
|
||||
pass
|
||||
|
|
|
@ -12,8 +12,8 @@ from selfprivacy_api.graphql.queries.backup import Backup
|
|||
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.backup import (
|
||||
AutobackupQuotasInput,
|
||||
RestoreStrategy,
|
||||
AutobackupQuotas,
|
||||
)
|
||||
|
||||
from selfprivacy_api.backup import Backups
|
||||
|
@ -36,13 +36,6 @@ class InitializeRepositoryInput:
|
|||
password: str
|
||||
|
||||
|
||||
@strawberry.input
|
||||
class SetAutobackupQuotasInput:
|
||||
"""A single field input to reuse AutobackupQuotas"""
|
||||
|
||||
quotas: AutobackupQuotas
|
||||
|
||||
|
||||
@strawberry.type
|
||||
class GenericBackupConfigReturn(MutationReturnInterface):
|
||||
"""Generic backup config return"""
|
||||
|
@ -102,7 +95,7 @@ class BackupMutations:
|
|||
|
||||
@strawberry.mutation(permission_classes=[IsAuthenticated])
|
||||
def set_autobackup_quotas(
|
||||
self, quotas: SetAutobackupQuotasInput
|
||||
self, quotas: AutobackupQuotasInput
|
||||
) -> GenericBackupConfigReturn:
|
||||
"""
|
||||
Set autobackup quotas.
|
||||
|
|
|
@ -28,7 +28,7 @@ class BackupConfiguration:
|
|||
# If none, autobackups are disabled
|
||||
autobackup_period: typing.Optional[int]
|
||||
# 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
|
||||
location_name: typing.Optional[str]
|
||||
location_id: typing.Optional[str]
|
||||
|
|
|
@ -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.backup import AutobackupQuotas
|
||||
from selfprivacy_api.graphql.common_types.backup import (
|
||||
_AutobackupQuotas,
|
||||
AutobackupQuotas,
|
||||
)
|
||||
from selfprivacy_api.jobs import Jobs, JobStatus
|
||||
|
||||
API_RELOAD_SNAPSHOTS = """
|
||||
|
@ -41,7 +44,7 @@ mutation TestAutobackupPeriod($period: Int) {
|
|||
|
||||
|
||||
API_SET_AUTOBACKUP_QUOTAS_MUTATION = """
|
||||
mutation TestAutobackupQuotas($input: SetAutobackupQuotasInput!) {
|
||||
mutation TestAutobackupQuotas($input: AutobackupQuotasInput!) {
|
||||
backup {
|
||||
setAutobackupQuotas(quotas: $input) {
|
||||
success
|
||||
|
@ -54,7 +57,13 @@ mutation TestAutobackupQuotas($input: SetAutobackupQuotasInput!) {
|
|||
autobackupPeriod
|
||||
locationName
|
||||
locationId
|
||||
autobackupQuotas
|
||||
autobackupQuotas {
|
||||
daily
|
||||
weekly
|
||||
monthly
|
||||
yearly
|
||||
total
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -200,12 +209,12 @@ def api_set_period(authorized_client, period):
|
|||
return response
|
||||
|
||||
|
||||
def api_set_quotas(authorized_client, quotas):
|
||||
def api_set_quotas(authorized_client, quotas: _AutobackupQuotas):
|
||||
response = authorized_client.post(
|
||||
"/graphql",
|
||||
json={
|
||||
"query": API_SET_AUTOBACKUP_QUOTAS_MUTATION,
|
||||
"variables": {"input": {"quotas": quotas}},
|
||||
"variables": {"input": quotas.dict()},
|
||||
},
|
||||
)
|
||||
return response
|
||||
|
@ -358,7 +367,7 @@ def test_remove(authorized_client, generic_userdata):
|
|||
|
||||
|
||||
def test_autobackup_quotas_nonzero(authorized_client):
|
||||
quotas = AutobackupQuotas(
|
||||
quotas = _AutobackupQuotas(
|
||||
daily=2,
|
||||
weekly=4,
|
||||
monthly=13,
|
||||
|
|
Loading…
Reference in a new issue