From 41689beaeeceb49c70d04e15fa1993549803ec37 Mon Sep 17 00:00:00 2001 From: Giacomo Licari Date: Sat, 9 Mar 2024 00:33:50 +0100 Subject: [PATCH] Cleanup --- api/api/services/database.py | 5 ++--- api/api/services/validator.py | 5 ++--- api/api/settings.py | 1 - api/tests/conftest.py | 4 ++-- api/tests/test_api.py | 5 ++--- api/tests/test_api_claim_rate_limit.py | 5 ++--- api/tests/test_api_cli.py | 7 +++---- api/tests/test_database.py | 8 +++----- 8 files changed, 16 insertions(+), 24 deletions(-) diff --git a/api/api/services/database.py b/api/api/services/database.py index 5f1cf1e..7d07761 100644 --- a/api/api/services/database.py +++ b/api/api/services/database.py @@ -1,10 +1,9 @@ import sqlite3 from datetime import datetime -from flask_sqlalchemy import SQLAlchemy - from api.const import (DEFAULT_ERC20_MAX_AMOUNT_PER_DAY, DEFAULT_NATIVE_MAX_AMOUNT_PER_DAY, FaucetRequestType) +from flask_sqlalchemy import SQLAlchemy db = SQLAlchemy() @@ -165,7 +164,7 @@ def last_by_ip_or_recipient(cls, ip, recipient): @classmethod def get_by_hash(cls, hash): return cls.query.filter_by(hash=hash).first() - + @classmethod def get_amount_sum_by_access_key_and_token(cls, access_key_id, diff --git a/api/api/services/validator.py b/api/api/services/validator.py index 3d84b5a..a47fb68 100644 --- a/api/api/services/validator.py +++ b/api/api/services/validator.py @@ -1,10 +1,9 @@ import datetime +from api.const import TokenType from flask import current_app, request from web3 import Web3 -from api.const import TokenType - from .captcha import captcha_verify from .database import AccessKeyConfig, Token, Transaction from .rate_limit import Strategy @@ -144,7 +143,7 @@ def web_request_limit_validation(self): else: raise NotImplementedError - # Check if the recipient can claim funds, they must not have claimed any tokens + # Check if the recipient can claim funds, they must not have claimed any tokens # in the period of time defined by FAUCET_RATE_LIMIT_TIME_LIMIT_SECONDS if transaction: time_diff_seconds = (datetime.datetime.utcnow() - transaction.created).total_seconds() diff --git a/api/api/settings.py b/api/api/settings.py index 45d0bd5..69468c2 100644 --- a/api/api/settings.py +++ b/api/api/settings.py @@ -1,4 +1,3 @@ -import json import os from dotenv import load_dotenv diff --git a/api/tests/conftest.py b/api/tests/conftest.py index e3b1fa8..2b19928 100644 --- a/api/tests/conftest.py +++ b/api/tests/conftest.py @@ -1,11 +1,11 @@ import os from unittest import TestCase, mock +from api.services import Strategy +from api.services.database import Token, db from temp_env_var import FAUCET_ENABLED_TOKENS, TEMP_ENV_VARS from api import create_app -from api.services import Strategy -from api.services.database import Token, db api_prefix = '/api/v1' diff --git a/api/tests/test_api.py b/api/tests/test_api.py index 468f9b4..de552dc 100644 --- a/api/tests/test_api.py +++ b/api/tests/test_api.py @@ -1,3 +1,5 @@ +from api.const import ZERO_ADDRESS +from api.services.database import Transaction from conftest import BaseTest, api_prefix # from mock import patch from temp_env_var import (CAPTCHA_TEST_RESPONSE_TOKEN, @@ -7,9 +9,6 @@ NATIVE_TOKEN_ADDRESS, NATIVE_TRANSFER_TX_HASH, TOKEN_TRANSFER_TX_HASH) -from api.const import ZERO_ADDRESS -from api.services.database import Transaction - class TestAPI(BaseTest): diff --git a/api/tests/test_api_claim_rate_limit.py b/api/tests/test_api_claim_rate_limit.py index 1a5b9bc..4157927 100644 --- a/api/tests/test_api_claim_rate_limit.py +++ b/api/tests/test_api_claim_rate_limit.py @@ -1,3 +1,5 @@ +from api.const import ZERO_ADDRESS +from api.services.database import Transaction from conftest import (RateLimitIPBaseTest, RateLimitIPorAddressBaseTest, api_prefix) # from mock import patch @@ -5,9 +7,6 @@ DEFAULT_ERC20_MAX_AMOUNT_PER_DAY, ERC20_TOKEN_ADDRESS, FAUCET_CHAIN_ID) -from api.const import ZERO_ADDRESS -from api.services.database import Transaction - class TestAPIWithIPLimitStrategy(RateLimitIPBaseTest): diff --git a/api/tests/test_api_cli.py b/api/tests/test_api_cli.py index 759b238..397ef6d 100644 --- a/api/tests/test_api_cli.py +++ b/api/tests/test_api_cli.py @@ -1,12 +1,11 @@ +from api.const import ZERO_ADDRESS +from api.services.database import AccessKey, AccessKeyConfig +from api.utils import generate_access_key from conftest import BaseTest, api_prefix # from mock import patch from temp_env_var import (DEFAULT_ERC20_MAX_AMOUNT_PER_DAY, ERC20_TOKEN_ADDRESS, FAUCET_CHAIN_ID) -from api.const import ZERO_ADDRESS -from api.services.database import AccessKey, AccessKeyConfig -from api.utils import generate_access_key - class TestAPICli(BaseTest): def test_ask_route_parameters(self): diff --git a/api/tests/test_database.py b/api/tests/test_database.py index a1a21a6..e18ea96 100644 --- a/api/tests/test_database.py +++ b/api/tests/test_database.py @@ -1,13 +1,11 @@ import pytest -from sqlalchemy.exc import IntegrityError - -from conftest import BaseTest -from temp_env_var import NATIVE_TOKEN_ADDRESS, NATIVE_TRANSFER_TX_HASH - from api.const import ZERO_ADDRESS from api.services.database import (AccessKey, AccessKeyConfig, Token, Transaction) from api.utils import generate_access_key +from conftest import BaseTest +from sqlalchemy.exc import IntegrityError +from temp_env_var import NATIVE_TOKEN_ADDRESS, NATIVE_TRANSFER_TX_HASH class TestDatabase(BaseTest):