-
Notifications
You must be signed in to change notification settings - Fork 7
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
Carlos Wu Fei
authored and
Carlos Wu Fei
committed
Jan 2, 2024
1 parent
5ce5db3
commit 778e5c2
Showing
6 changed files
with
117 additions
and
108 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 was deleted.
Oops, something went wrong.
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,72 @@ | ||
from account.assets import Assets | ||
from main import app | ||
from db import setup_db | ||
|
||
import mongomock | ||
|
||
test_client = mongomock.MongoClient() | ||
|
||
async def get_test_client(): | ||
return test_client | ||
|
||
app.dependency_overrides[setup_db] = get_test_client | ||
|
||
class TestAccount: | ||
|
||
def __init__(self) -> None: | ||
self.db = test_client["bots"]["market_domination"] | ||
pass | ||
|
||
def test_get_market_domination(self): | ||
# Mock the database and its find method | ||
data = [ | ||
{ | ||
"data": [ | ||
{"priceChangePercent": "0.5"}, | ||
{"priceChangePercent": "-0.3"}, | ||
{"priceChangePercent": "0.2"}, | ||
{"priceChangePercent": "-0.1"}, | ||
], | ||
"time": "2022-01-01", | ||
}, | ||
{ | ||
"data": [ | ||
{"priceChangePercent": "0.1"}, | ||
{"priceChangePercent": "-0.2"}, | ||
{"priceChangePercent": "0.3"}, | ||
{"priceChangePercent": "-0.4"}, | ||
], | ||
"time": "2022-01-02", | ||
}, | ||
{ | ||
"data": [ | ||
{"priceChangePercent": "0.4"}, | ||
{"priceChangePercent": "-0.5"}, | ||
{"priceChangePercent": "0.6"}, | ||
{"priceChangePercent": "-0.7"}, | ||
], | ||
"time": "2022-01-03", | ||
}, | ||
] | ||
|
||
self.db.insert_one(data) | ||
|
||
# Create an instance of AccountAssets and set the mock database | ||
assets = Assets() | ||
|
||
# Call the get_market_domination method | ||
result = assets.get_market_domination() | ||
|
||
# Assert the expected result | ||
expected_result = { | ||
"data": { | ||
"dates": ["2022-01-01", "2022-01-02", "2022-01-03"], | ||
"gainers_percent": [0.5, 0.1, 0.4], | ||
"losers_percent": [0.3, 0.2, 0.5], | ||
"gainers_count": 3, | ||
"losers_count": 3, | ||
}, | ||
"message": "Successfully retrieved market domination data.", | ||
"error": 0, | ||
} | ||
assert result == expected_result |
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