Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(tests): use built-in typing #953

Merged
merged 1 commit into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions api/desecapi/tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from contextlib import nullcontext
from functools import partial, reduce
from json import JSONDecodeError
from typing import Union, List, Dict, Set
from unittest import mock

from django.conf import settings
Expand Down Expand Up @@ -422,7 +421,7 @@ def request_pdns_zone_update(cls, name=None):
}

def request_pdns_zone_update_assert_body(
self, name: str = None, updated_rr_sets: Union[List[RRset], Dict] = None
self, name: str = None, updated_rr_sets: list[RRset] | dict = None
):
if updated_rr_sets is None:
updated_rr_sets = []
Expand Down Expand Up @@ -1119,7 +1118,7 @@ def assertRRsetDB(
subname: str,
type_: str,
ttl: int = None,
rr_contents: Set[str] = None,
rr_contents: set[str] = None,
):
if rr_contents is not None:
try:
Expand Down
14 changes: 7 additions & 7 deletions test/e2e2/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import warnings
from datetime import datetime
from json import JSONDecodeError
from typing import Optional, Tuple, Iterable
from collections.abc import Iterable

import dns
import dns.name
Expand Down Expand Up @@ -143,7 +143,7 @@ def _do_request(self, *args, **kwargs):
tsprint(f'API <<< SSL could not be verified against any verification method')
raise exc

def _request(self, method: str, *, path: str, data: Optional[dict] = None, headers: Optional[dict] = None, **kwargs) -> requests.Response:
def _request(self, method: str, *, path: str, data: dict | None = None, headers: dict | None = None, **kwargs) -> requests.Response:
if data is not None:
data = json.dumps(data)

Expand Down Expand Up @@ -183,16 +183,16 @@ def get(self, path: str, **kwargs) -> requests.Response:
def options(self, path: str, **kwargs) -> requests.Response:
return self._request("OPTIONS", path=path, **kwargs)

def post(self, path: str, data: Optional[dict] = None, **kwargs) -> requests.Response:
def post(self, path: str, data: dict | None = None, **kwargs) -> requests.Response:
return self._request("POST", path=path, data=data, **kwargs)

def patch(self, path: str, data: Optional[dict] = None, **kwargs) -> requests.Response:
def patch(self, path: str, data: dict | None = None, **kwargs) -> requests.Response:
return self._request("PATCH", path=path, data=data, **kwargs)

def delete(self, path: str, **kwargs) -> requests.Response:
return self._request("DELETE", path=path, **kwargs)

def register(self, email: str, password: str) -> Tuple[requests.Response, requests.Response]:
def register(self, email: str, password: str) -> tuple[requests.Response, requests.Response]:
self.email = email
self.password = password
captcha = self.post("/captcha/")
Expand Down Expand Up @@ -458,7 +458,7 @@ class SecondaryNSClient(NSClient):


def return_eventually(expression: callable, min_pause: float = .1, max_pause: float = 2, timeout: float = 5,
retry_on: Tuple[type] = (Exception,)):
retry_on: tuple[type] = (Exception,)):
if not callable(expression):
raise ValueError('Expression given not callable. Did you forget "lambda:"?')

Expand All @@ -479,7 +479,7 @@ def return_eventually(expression: callable, min_pause: float = .1, max_pause: fl


def assert_eventually(assertion: callable, min_pause: float = .1, max_pause: float = 2, timeout: float = 5,
retry_on: Tuple[type] = (AssertionError,), assertion_kwargs=None) -> None:
retry_on: tuple[type] = (AssertionError,), assertion_kwargs=None) -> None:
def _assert():
assert assertion(**(assertion_kwargs or dict()))
return_eventually(_assert, min_pause, max_pause, timeout, retry_on=retry_on)
Expand Down
4 changes: 1 addition & 3 deletions test/e2e2/spec/test_api_rr.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
from typing import List, Tuple

import pytest

from conftest import DeSECAPIV1Client, assert_all_ns


def generate_params(dict_value_lists_by_type: dict) -> List[Tuple[str, str]]:
def generate_params(dict_value_lists_by_type: dict) -> list[tuple[str, str]]:
return [
(rr_type, value)
for rr_type in dict_value_lists_by_type.keys()
Expand Down
Loading