-
-
Notifications
You must be signed in to change notification settings - Fork 751
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2a8f387
commit 98e1fa9
Showing
20 changed files
with
424 additions
and
770 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# This file is part of OctoBot (https://github.com/Drakkar-Software/OctoBot) | ||
# Copyright (c) 2023 Drakkar-Software, All rights reserved. | ||
# | ||
# OctoBot is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU General Public License | ||
# as published by the Free Software Foundation; either | ||
# version 3.0 of the License, or (at your option) any later version. | ||
# | ||
# OctoBot is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
# General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public | ||
# License along with OctoBot. If not, see <https://www.gnu.org/licenses/>. | ||
import math | ||
import time | ||
import pytest | ||
|
||
import octobot_commons.enums as commons_enums | ||
from additional_tests.supabase_backend_tests import authenticated_client_1, anon_client | ||
|
||
|
||
# All test coroutines will be treated as marked. | ||
pytestmark = pytest.mark.asyncio | ||
|
||
|
||
async def test_fetch_candles_history_range_as_auth(authenticated_client_1): | ||
# locale db | ||
min_time, max_time = await authenticated_client_1.fetch_candles_history_range( | ||
"binance", "BTC/USDT", commons_enums.TimeFrames.FOUR_HOURS, False | ||
) | ||
assert 0 < min_time < max_time < time.time() | ||
|
||
# prod db | ||
prod_min_time, prod_max_time = await authenticated_client_1.fetch_candles_history_range( | ||
"binance", "BTC/USDT", commons_enums.TimeFrames.FOUR_HOURS, True | ||
) | ||
assert 0 < prod_min_time < prod_max_time < time.time() | ||
assert prod_min_time != min_time | ||
assert prod_max_time != max_time | ||
|
||
|
||
async def test_fetch_candles_history_range_as_anon(anon_client): | ||
# locale db | ||
min_time, max_time = await anon_client.fetch_candles_history_range( | ||
"binance", "BTC/USDT", commons_enums.TimeFrames.FOUR_HOURS, False | ||
) | ||
assert 0 < min_time < max_time < time.time() | ||
|
||
# prod db | ||
prod_min_time, prod_max_time = await anon_client.fetch_candles_history_range( | ||
"binance", "BTC/USDT", commons_enums.TimeFrames.FOUR_HOURS, True | ||
) | ||
assert 0 < prod_min_time < prod_max_time < time.time() | ||
assert prod_min_time != min_time | ||
assert prod_max_time != max_time | ||
|
||
|
||
async def test_fetch_candles_history(anon_client): | ||
start_time = 1718785679 | ||
end_time = 1721377495 | ||
candles_count = math.floor((end_time - start_time) / ( | ||
commons_enums.TimeFramesMinutes[commons_enums.TimeFrames.FIFTEEN_MINUTES] * 60 | ||
)) | ||
# requires multiple fetches | ||
assert candles_count == 2879 | ||
candles = await anon_client.fetch_candles_history( | ||
"binance", "BTC/USDT", commons_enums.TimeFrames.FIFTEEN_MINUTES, start_time, end_time | ||
) | ||
fetched_count = candles_count + 1 | ||
assert len(candles) == fetched_count | ||
# candles are unique | ||
assert len(set(c[0] for c in candles)) == fetched_count |
46 changes: 46 additions & 0 deletions
46
additional_tests/supabase_backend_tests/test_cryptocurrencies.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# This file is part of OctoBot (https://github.com/Drakkar-Software/OctoBot) | ||
# Copyright (c) 2023 Drakkar-Software, All rights reserved. | ||
# | ||
# OctoBot is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU General Public License | ||
# as published by the Free Software Foundation; either | ||
# version 3.0 of the License, or (at your option) any later version. | ||
# | ||
# OctoBot is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
# General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public | ||
# License along with OctoBot. If not, see <https://www.gnu.org/licenses/>. | ||
import postgrest | ||
import pytest | ||
|
||
from additional_tests.supabase_backend_tests import authenticated_client_1 | ||
|
||
|
||
# All test coroutines will be treated as marked. | ||
pytestmark = pytest.mark.asyncio | ||
|
||
|
||
async def test_paginated_fetch_cryptocurrencies(authenticated_client_1): | ||
pages = [] | ||
|
||
def cryptocurrencies_request_factory(table: postgrest.AsyncRequestBuilder, select_count): | ||
pages.append(1) | ||
return ( | ||
table.select( | ||
"symbol, last_price", | ||
count=select_count | ||
) | ||
) | ||
|
||
raw_currencies = await authenticated_client_1.paginated_fetch( | ||
authenticated_client_1, | ||
"cryptocurrencies", | ||
cryptocurrencies_request_factory | ||
) | ||
assert len(raw_currencies) > 1500 | ||
# ensure at least 2 calls have been performed | ||
assert 2 <= sum(pages) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# This file is part of OctoBot (https://github.com/Drakkar-Software/OctoBot) | ||
# Copyright (c) 2023 Drakkar-Software, All rights reserved. | ||
# | ||
# OctoBot is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU General Public License | ||
# as published by the Free Software Foundation; either | ||
# version 3.0 of the License, or (at your option) any later version. | ||
# | ||
# OctoBot is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
# General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public | ||
# License along with OctoBot. If not, see <https://www.gnu.org/licenses/>. | ||
import json | ||
import pytest | ||
|
||
from additional_tests.supabase_backend_tests import admin_client | ||
|
||
|
||
# All test coroutines will be treated as marked. | ||
pytestmark = pytest.mark.asyncio | ||
|
||
|
||
async def test_upload_asset(admin_client): | ||
asset_content = json.dumps({"test_upload_asset_content": 1}).encode() | ||
asset_name = "test_upload_asset" | ||
asset_bucket = "product-images" | ||
await admin_client.remove_asset(asset_bucket, asset_name) # remove asset if exists | ||
uploaded_asset_id = await admin_client.upload_asset(asset_bucket, asset_name, asset_content) | ||
|
||
assets = await admin_client.list_assets(asset_bucket) | ||
asset_by_id = { | ||
asset["id"]: asset | ||
for asset in assets | ||
} | ||
assert uploaded_asset_id in asset_by_id | ||
assert asset_by_id[uploaded_asset_id]["name"] == asset_name | ||
|
||
await admin_client.remove_asset(asset_bucket, asset_name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.