From e5405dfc6bf7943bd3c6d73d521e575ef9f1ca55 Mon Sep 17 00:00:00 2001 From: Inex Code Date: Tue, 5 Jul 2022 15:54:21 +0300 Subject: [PATCH] linting --- tests/conftest.py | 11 ++++++ tests/test_graphql/test_api_devices.py | 2 - tests/test_graphql/test_system.py | 53 +++++++++++++++----------- 3 files changed, 41 insertions(+), 25 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 7a6fdea..9acdd24 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,3 +1,6 @@ +"""Tests configuration.""" +# pylint: disable=redefined-outer-name +# pylint: disable=unused-argument import pytest from flask import testing from selfprivacy_api.app import create_app @@ -5,6 +8,7 @@ from selfprivacy_api.app import create_app @pytest.fixture def tokens_file(mocker, shared_datadir): + """Mock tokens file.""" mock = mocker.patch( "selfprivacy_api.utils.TOKENS_FILE", shared_datadir / "tokens.json" ) @@ -13,6 +17,7 @@ def tokens_file(mocker, shared_datadir): @pytest.fixture def app(): + """Flask application.""" app = create_app( { "ENABLE_SWAGGER": "1", @@ -24,10 +29,12 @@ def app(): @pytest.fixture def client(app, tokens_file): + """Flask unauthorized test client.""" return app.test_client() class AuthorizedClient(testing.FlaskClient): + """Flask authorized test client.""" def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.token = "TEST_TOKEN" @@ -40,6 +47,7 @@ class AuthorizedClient(testing.FlaskClient): class WrongAuthClient(testing.FlaskClient): + """Flask client with wrong token""" def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.token = "WRONG_TOKEN" @@ -53,16 +61,19 @@ class WrongAuthClient(testing.FlaskClient): @pytest.fixture def authorized_client(app, tokens_file): + """Authorized test client fixture.""" app.test_client_class = AuthorizedClient return app.test_client() @pytest.fixture def wrong_auth_client(app, tokens_file): + """Wrong token test client fixture.""" app.test_client_class = WrongAuthClient return app.test_client() @pytest.fixture def runner(app, tokens_file): + """Flask test runner.""" return app.test_cli_runner() diff --git a/tests/test_graphql/test_api_devices.py b/tests/test_graphql/test_api_devices.py index e5bf7ad..37cb2d2 100644 --- a/tests/test_graphql/test_api_devices.py +++ b/tests/test_graphql/test_api_devices.py @@ -2,8 +2,6 @@ # pylint: disable=unused-argument # pylint: disable=missing-function-docstring import datetime -import json -import pytest from mnemonic import Mnemonic from tests.common import generate_api_query, read_json, write_json diff --git a/tests/test_graphql/test_system.py b/tests/test_graphql/test_system.py index 308c981..b7d6862 100644 --- a/tests/test_graphql/test_system.py +++ b/tests/test_graphql/test_system.py @@ -127,7 +127,7 @@ def test_graphql_wrong_auth(wrong_auth_client): assert response.json.get("data") is None API_GET_DOMAIN_INFO = """ -domainInfo { +domainInfo() { domain hostname provider @@ -155,6 +155,12 @@ def dns_record(type="A", name="test.tld", content=None, ttl=3600, priority=None) "priority": priority, } +def is_dns_record_in_array(records, dns_record) -> bool: + for record in records: + if record["type"] == dns_record["type"] and record["name"] == dns_record["name"] and record["content"] == dns_record["content"] and record["ttl"] == dns_record["ttl"] and record["priority"] == dns_record["priority"]: + return True + return False + def test_graphql_get_domain(authorized_client, domain_file, mock_get_ip4, mock_get_ip6, turned_on): """Test get domain""" response = authorized_client.get( @@ -168,28 +174,29 @@ def test_graphql_get_domain(authorized_client, domain_file, mock_get_ip4, mock_g assert response.json["data"]["system"]["domainInfo"]["domain"] == "test.tld" assert response.json["data"]["system"]["domainInfo"]["hostname"] == "test-instance" assert response.json["data"]["system"]["domainInfo"]["provider"] == "HETZNER" - assert response.json["data"]["system"]["domainInfo"]["requiredDnsRecords"] == [ - dns_record(), - dns_record(type="AAAA"), - dns_record(name="api.test.tld"), - dns_record(name="api.test.tld", type="AAAA"), - dns_record(name="cloud.test.tld"), - dns_record(name="cloud.test.tld", type="AAAA"), - dns_record(name="git.test.tld"), - dns_record(name="git.test.tld", type="AAAA"), - dns_record(name="meet.test.tld"), - dns_record(name="meet.test.tld", type="AAAA"), - dns_record(name="password.test.tld"), - dns_record(name="password.test.tld", type="AAAA"), - dns_record(name="social.test.tld"), - dns_record(name="social.test.tld", type="AAAA"), - dns_record(name="vpn.test.tld"), - dns_record(name="vpn.test.tld", type="AAAA"), - dns_record(name="test.tld", type="MX", content="test.tld", priority=10), - dns_record(name="_dmarc.test.tld", type="TXT", content="v=DMARC1; p=none", ttl=18000), - dns_record(name="test.tld", type="TXT", content="v=spf1 a mx ip4:157.90.247.192 -all", ttl=18000), - dns_record(name="selector._domainkey.test.tld", type="TXT", content="I am a DKIM key", ttl=18000), - ] + dns_records = response.json["data"]["system"]["domainInfo"]["requiredDnsRecords"] + assert is_dns_record_in_array(dns_records, dns_record()) + assert is_dns_record_in_array(dns_records, dns_record(type="AAAA")) + assert is_dns_record_in_array(dns_records, dns_record(name="api.test.tld")) + assert is_dns_record_in_array(dns_records, dns_record(name="api.test.tld", type="AAAA")) + assert is_dns_record_in_array(dns_records, dns_record(name="cloud.test.tld")) + assert is_dns_record_in_array(dns_records, dns_record(name="cloud.test.tld", type="AAAA")) + assert is_dns_record_in_array(dns_records, dns_record(name="git.test.tld")) + assert is_dns_record_in_array(dns_records, dns_record(name="git.test.tld", type="AAAA")) + assert is_dns_record_in_array(dns_records, dns_record(name="meet.test.tld")) + assert is_dns_record_in_array(dns_records, dns_record(name="meet.test.tld", type="AAAA")) + assert is_dns_record_in_array(dns_records, dns_record(name="password.test.tld")) + assert is_dns_record_in_array(dns_records, dns_record(name="password.test.tld", type="AAAA")) + assert is_dns_record_in_array(dns_records, dns_record(name="social.test.tld")) + assert is_dns_record_in_array(dns_records, dns_record(name="social.test.tld", type="AAAA")) + assert is_dns_record_in_array(dns_records, dns_record(name="vpn.test.tld")) + assert is_dns_record_in_array(dns_records, dns_record(name="vpn.test.tld", type="AAAA")) + assert is_dns_record_in_array(dns_records, dns_record(name="test.tld", type="MX", content="test.tld", priority=10)) + assert is_dns_record_in_array(dns_records, dns_record(name="_dmarc.test.tld", type="TXT", content="v=DMARC1; p=none", ttl=18000)) + assert is_dns_record_in_array(dns_records, dns_record(name="test.tld", type="TXT", content="v=spf1 a mx ip4:157.90.247.192 -all", ttl=18000)) + assert is_dns_record_in_array(dns_records, dns_record(name="selector._domainkey.test.tld", type="TXT", content="I am a DKIM key", ttl=18000)) + +def test_graphql API_GET_TIMEZONE = """ settings {