Skip to content

Commit

Permalink
feat: added new tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Lash-L committed Feb 8, 2023
1 parent ae2010b commit 501ba1a
Show file tree
Hide file tree
Showing 7 changed files with 195 additions and 76 deletions.
5 changes: 4 additions & 1 deletion .idea/southern_company_api.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

139 changes: 69 additions & 70 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ aiohttp = "^3.8.1"
pytest = "^7.0"
pytest-cov = "^3.0"
pytest-asyncio = "^0.20.0"
isort = "^5.12.0"
flake8 = "^6.0.0"

[tool.semantic_release]
branch = "main"
Expand Down
4 changes: 4 additions & 0 deletions src/southern_company_api/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ class CantReachSouthernCompany(Exception):
pass


class NoRequestTokenFound(Exception):
pass


class NoJwtTokenFound(Exception):
pass

Expand Down
7 changes: 5 additions & 2 deletions src/southern_company_api/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
CantReachSouthernCompany,
InvalidLogin,
NoJwtTokenFound,
NoRequestTokenFound,
NoScTokenFound,
)

Expand All @@ -30,6 +31,8 @@ async def get_request_verification_token() -> str:
matches = re.findall(r'data-aft="(\S+)"', login_page)
except Exception as error:
raise CantReachSouthernCompany() from error
if len(matches) < 1:
raise NoRequestTokenFound()
return matches[0]


Expand Down Expand Up @@ -60,7 +63,7 @@ async def authenticate(self) -> bool:
async def _get_sc_web_token(self) -> str:
"""Gets a sc_web_token which we get from a successful log in"""
if self.request_token is None:
await get_request_verification_token()
self.request_token = await get_request_verification_token()
headers = {
"Content-Type": "application/json; charset=utf-8",
"RequestVerificationToken": self.request_token,
Expand Down Expand Up @@ -92,7 +95,7 @@ async def _get_sc_web_token(self) -> str:

async def _get_southern_jwt_cookie(self) -> str:
if self.sc is None:
await self._get_sc_web_token()
self.sc = await self._get_sc_web_token()
data = {"ScWebToken": self.sc}
async with aiohttp.ClientSession() as session:
async with session.post(
Expand Down
47 changes: 47 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,50 @@
# "Strict-Transport-Security": "max-age=15552000",
# "X-Content-Type-Options": "nosniff",
# }


ga_power_sample_account_response = {
"StatusCode": 200,
"Message": "Success",
"MessageType": 0,
"Data": [
{
"UserSid": "sample-user",
"AccountNumber": 1,
"Company": 2,
"AccountType": 0,
"Description": "Home Energy",
"PrimaryAccount": "Y",
"IsCurrentViewAccount": False,
"IsNicknameChanged": False,
"IsPrimaryAccountChanged": False,
"DataPresentmentPilotParticipant": "",
"BillStatus": 0,
"IsLocked": False,
"AccountLockedUntil": None,
"IsPinRequired": False,
"IsPinValidated": False,
"LocalAddress": {
"Number": "0000",
"Structure": "",
"Note": "",
"PreDirection": "",
"StreetName": "RANDOM_STREET",
"PostDirection": "",
"StreetType": "LANE",
"AddressLine1": "0000 RANDOM_STREET LANE ",
"AddressLine2": "",
"City": "SOMEWHERE",
"State": "GA",
"Zip": "00000",
"Country": None,
},
"PremiseNumber": None,
"IsPrePayAccount": False,
"IsInGulfDivestiturePilot": False,
"EixLinkedClients": [],
"IsEixConsented": False,
}
],
"IsScApiResult": True,
}
Loading

0 comments on commit 501ba1a

Please sign in to comment.