Skip to content

Commit

Permalink
feat(tests): use built-in typing
Browse files Browse the repository at this point in the history
  • Loading branch information
Rotzbua committed Jul 22, 2024
1 parent 41ee90e commit aef2962
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
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

0 comments on commit aef2962

Please sign in to comment.