Skip to content

Add tests for Api methods#1

Open
spazyCZ wants to merge 4 commits intomainfrom
add-tests-1
Open

Add tests for Api methods#1
spazyCZ wants to merge 4 commits intomainfrom
add-tests-1

Conversation

@spazyCZ
Copy link
Owner

@spazyCZ spazyCZ commented Dec 20, 2024

Add tests for pyxtb project

  • tests/test_api.py

    • Import pytest and pytest-asyncio
    • Import Api from pyxtb.api
    • Add fixture api to set up and tear down Api instance
    • Add test function test_login to test the login method of Api
    • Add test function test_get_all_symbols to test the get_all_symbols method of Api
    • Add test function test_get_calendar to test the get_calendar method of Api
  • README.md

    • Add a section "## Running Tests" with instructions on how to run the tests using pytest

Add tests for `pyxtb` project

* **tests/test_api.py**
  - Import `pytest` and `pytest-asyncio`
  - Import `Api` from `pyxtb.api`
  - Add fixture `api` to set up and tear down `Api` instance
  - Add test function `test_login` to test the `login` method of `Api`
  - Add test function `test_get_all_symbols` to test the `get_all_symbols` method of `Api`
  - Add test function `test_get_calendar` to test the `get_calendar` method of `Api`

* **README.md**
  - Add a section "## Running Tests" with instructions on how to run the tests using `pytest`
* Import necessary modules and classes
* Add test functions for:
  - `get_chart_last_request`
  - `get_chart_range_request`
  - `get_commission_def`
  - `get_current_user_data`
  - `get_ibs_history`
  - `get_margin_level`
  - `get_margin_trade`
  - `get_news`
  - `get_profit_calculation`
  - `get_server_time`
  - `get_step_rules`
  - `get_symbol`
  - `get_tick_prices`
  - `get_trade_records`
  - `get_trades`
  - `get_trades_history`
  - `get_trading_hours`
  - `get_version`
  - `ping`
  - `trade_transaction`
  - `trade_transaction_status`
* Write `fetch_and_store_data` function to fetch data for various methods and store it in JSON files in `mock_data` directory
* Add main block to run `fetch_and_store_data` function

Update `tests/test_api.py` to use mocked data

* Add `mock_data` fixture to load mocked data from `mock_data` directory
* Modify test functions to use mocked data instead of making actual API calls
@spazyCZ spazyCZ requested a review from Copilot April 9, 2025 22:24
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

pyxtb/api.py:255

  • Fix the nested double quotes in the f-string; consider using single quotes for the key (e.g., parsed_data['data']).
f"Received command: {command} with data: {parsed_data["data"]}"

data['get_chart_last_request'] = await api.get_chart_last_request(
ChartLastInfoRecord(
period=Period.PERIOD_M5,
start=int((datetime.datetime.now() - datetime.timedelta(days=1)).timestamp() * 1000),
Copy link

Copilot AI Apr 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing import for datetime; please add 'import datetime' at the top of the file.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments