Skip to content

Commit

Permalink
feat: add e2e-test for data + add .coveragerc
Browse files Browse the repository at this point in the history
  • Loading branch information
GuyKh committed Feb 21, 2024
1 parent 78df842 commit db68f3b
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[run]
omit = tests/*, example.py
5 changes: 1 addition & 4 deletions iec_api/iec_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
class IecClient:
"""IEC API Client."""

def __init__(self, session: ClientSession, user_id: str | int, automatically_login: bool = False):
def __init__(self, session: ClientSession, user_id: str | int):
"""
Initializes the class with the provided user ID and optionally logs in automatically.
Expand All @@ -50,9 +50,6 @@ def __init__(self, session: ClientSession, user_id: str | int, automatically_log
self._bp_number: Optional[str] = None # BP Number associated with the instance
self._contract_id: Optional[str] = None # Contract ID associated with the instance

if automatically_login:
self.login_with_id() # Attempt to log in automatically if specified

# -------------
# Data methods:
# -------------
Expand Down
57 changes: 57 additions & 0 deletions tests/e2e_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import unittest
from datetime import datetime, timedelta

import aiohttp

from iec_api.iec_client import IecClient
from iec_api.models.jwt import JWT


class CommonsTest(unittest.IsolatedAsyncioTestCase):
jwt_token = {
"access_token": "Fill",
"refresh_token": "this",
"token_type": "Bearer",
"expires_in": 3600,
"scope": "offline_access email openid profile",
"id_token": "yourself",
}

async def test_e2e_with_existing_token(self):
user_id = 123456782
session = aiohttp.ClientSession(
connector=aiohttp.TCPConnector(ssl=False), timeout=aiohttp.ClientTimeout(total=10)
)
client = IecClient(session, user_id)
await client.load_jwt_token(JWT.from_dict(self.jwt_token))
await client.check_token()
await client.refresh_token()
await client.save_token_to_file()

await client.get_customer()
await client.get_accounts()
await client.get_default_account()
await client.get_contracts()
await client.get_default_contract()

await client.get_device_type()
devices = await client.get_devices()
device = devices[0]
await client.get_device_by_device_id(device_id=device.device_number)

await client.get_billing_invoices()
await client.get_electric_bill()
await client.get_last_meter_reading()

selected_date: datetime = datetime.now() - timedelta(days=30)

await client.get_remote_reading(device.device_number, int(device.device_code), selected_date, selected_date)

await client.save_token_to_file()
await client.load_token_from_file()
await client.check_token()
await client.refresh_token()


if __name__ == "__main__":
unittest.main()

0 comments on commit db68f3b

Please sign in to comment.