HTML parser unittests
This commit is contained in:
parent
3fbd283db1
commit
057acdfc8e
11 changed files with 3877 additions and 0 deletions
|
@ -3,6 +3,7 @@ from typing import List
|
||||||
|
|
||||||
abs_dir = Path(__file__).absolute().parent
|
abs_dir = Path(__file__).absolute().parent
|
||||||
samples = abs_dir / 'samples'
|
samples = abs_dir / 'samples'
|
||||||
|
htmls = samples / 'html'
|
||||||
|
|
||||||
|
|
||||||
def read_sample(name: str) -> List[str]:
|
def read_sample(name: str) -> List[str]:
|
||||||
|
@ -18,3 +19,14 @@ def read_sample(name: str) -> List[str]:
|
||||||
.strip() \
|
.strip() \
|
||||||
.replace('\r\n', '\n') \
|
.replace('\r\n', '\n') \
|
||||||
.split('\n')
|
.split('\n')
|
||||||
|
|
||||||
|
|
||||||
|
def read_html(name: str) -> bytes:
|
||||||
|
|
||||||
|
path = samples / 'html' / (name + '.html')
|
||||||
|
|
||||||
|
if not path.exists():
|
||||||
|
return b''
|
||||||
|
|
||||||
|
with path.open('rb') as file:
|
||||||
|
return file.read()
|
||||||
|
|
49
tests/mock.py
Normal file
49
tests/mock.py
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
from requests_mock import Mocker
|
||||||
|
from tests import files
|
||||||
|
|
||||||
|
mock = Mocker()
|
||||||
|
|
||||||
|
with mock:
|
||||||
|
|
||||||
|
mock.get(
|
||||||
|
'https://aternos.org/go/',
|
||||||
|
content=files.read_html('aternos_go'),
|
||||||
|
)
|
||||||
|
|
||||||
|
mock.get(
|
||||||
|
'https://aternos.org/servers/',
|
||||||
|
content=files.read_html('aternos_servers'),
|
||||||
|
)
|
||||||
|
|
||||||
|
mock.get(
|
||||||
|
'https://aternos.org/server/',
|
||||||
|
content=files.read_html('aternos_server1'),
|
||||||
|
)
|
||||||
|
|
||||||
|
mock.get(
|
||||||
|
'https://aternos.org/panel/ajax/status.php',
|
||||||
|
content=files.read_html('aternos_status'),
|
||||||
|
)
|
||||||
|
|
||||||
|
mock.post(
|
||||||
|
'https://aternos.org/panel/ajax/account/login.php',
|
||||||
|
json={
|
||||||
|
'success': True,
|
||||||
|
'error': None,
|
||||||
|
'message': None,
|
||||||
|
'show2FA': False,
|
||||||
|
},
|
||||||
|
cookies={
|
||||||
|
'ATERNOS_SESSION': '0123abcd',
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
mock.get(
|
||||||
|
'https://aternos.org/players/',
|
||||||
|
content=files.read_html('aternos_players'),
|
||||||
|
)
|
||||||
|
|
||||||
|
mock.get(
|
||||||
|
'https://aternos.org/files/',
|
||||||
|
content=files.read_html('aternos_file_root'),
|
||||||
|
)
|
1
tests/requirements.txt
Normal file
1
tests/requirements.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
requests-mock>=1.10.0
|
1410
tests/samples/html/aternos_config.html
Normal file
1410
tests/samples/html/aternos_config.html
Normal file
File diff suppressed because one or more lines are too long
576
tests/samples/html/aternos_files_root.html
Normal file
576
tests/samples/html/aternos_files_root.html
Normal file
File diff suppressed because one or more lines are too long
120
tests/samples/html/aternos_go.html
Normal file
120
tests/samples/html/aternos_go.html
Normal file
File diff suppressed because one or more lines are too long
539
tests/samples/html/aternos_players.html
Normal file
539
tests/samples/html/aternos_players.html
Normal file
File diff suppressed because one or more lines are too long
708
tests/samples/html/aternos_server1.html
Normal file
708
tests/samples/html/aternos_server1.html
Normal file
File diff suppressed because one or more lines are too long
424
tests/samples/html/aternos_servers.html
Normal file
424
tests/samples/html/aternos_servers.html
Normal file
File diff suppressed because one or more lines are too long
1
tests/samples/html/aternos_status.html
Normal file
1
tests/samples/html/aternos_status.html
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{"brand":"aternos","status":0,"change":1667483582,"slots":20,"problems":0,"players":0,"playerlist":[],"message":{"text":"","class":"blue"},"dynip":null,"bedrock":false,"host":"","port":18713,"headstarts":null,"ram":0,"lang":"offline","label":"Offline","class":"offline","countdown":null,"queue":null,"id":"S0m3DGvTlbv8FfIM","name":"world35v","software":"Vanilla","softwareId":"NJcwtD9vj2X7udfa","type":"vanilla","version":"1.19.3","deprecated":false,"ip":"world35v.aternos.me","displayAddress":"world35v.aternos.me","motd":"\u00a77\u0414\u043e\u0431\u0440\u043e \u043f\u043e\u0436\u0430\u043b\u043e\u0432\u0430\u0442\u044c \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440 \u0438\u0433\u0440\u043e\u043a\u0430 \u00a79world35v\u00a77!","onlineMode":true,"icon":"fa-stop-circle","dns":{"type":"DEFAULT","domains":["world35v.aternos.me"],"host":null,"port":null}}
|
37
tests/test_http.py
Executable file
37
tests/test_http.py
Executable file
|
@ -0,0 +1,37 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
from python_aternos import Client
|
||||||
|
from tests import mock
|
||||||
|
|
||||||
|
|
||||||
|
class TestHttp(unittest.TestCase):
|
||||||
|
|
||||||
|
def test_basic(self) -> None:
|
||||||
|
with mock.mock:
|
||||||
|
at = Client.from_credentials('test', '')
|
||||||
|
# no exception = ok
|
||||||
|
|
||||||
|
def test_servers(self) -> None:
|
||||||
|
with mock.mock:
|
||||||
|
at = Client.from_credentials('test', '')
|
||||||
|
srvs = at.list_servers(cache=False)
|
||||||
|
self.assertTrue(srvs)
|
||||||
|
|
||||||
|
def test_status(self) -> None:
|
||||||
|
with mock.mock:
|
||||||
|
at = Client.from_credentials('test', '')
|
||||||
|
srv = at.list_servers(cache=False)[0]
|
||||||
|
self.assertEqual(
|
||||||
|
srv.subdomain,
|
||||||
|
'world35v',
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
srv.is_java,
|
||||||
|
True,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
Reference in a new issue