|
1 | | -import unittest |
| 1 | +from pathlib import Path |
2 | 2 |
|
| 3 | +import pytest |
3 | 4 | import requests_mock |
4 | 5 |
|
5 | 6 | import tableauserverclient as TSC |
6 | | -from ._utils import read_xml_asset |
7 | 7 |
|
8 | | -GET_XML = "data_acceleration_report.xml" |
| 8 | +TEST_ASSETS_DIR = Path(__file__).parent / "assets" |
9 | 9 |
|
| 10 | +GET_XML = TEST_ASSETS_DIR / "data_acceleration_report.xml" |
10 | 11 |
|
11 | | -class DataAccelerationReportTests(unittest.TestCase): |
12 | | - def setUp(self): |
13 | | - self.server = TSC.Server("http://test", False) |
14 | 12 |
|
15 | | - # Fake signin |
16 | | - self.server._site_id = "dad65087-b08b-4603-af4e-2887b8aafc67" |
17 | | - self.server._auth_token = "j80k54ll2lfMZ0tv97mlPvvSCRyD0DOM" |
18 | | - self.server.version = "3.8" |
| 13 | +@pytest.fixture(scope="function") |
| 14 | +def server(): |
| 15 | + server = TSC.Server("http://test", False) |
19 | 16 |
|
20 | | - self.baseurl = self.server.data_acceleration_report.baseurl |
| 17 | + # Fake signin |
| 18 | + server._site_id = "dad65087-b08b-4603-af4e-2887b8aafc67" |
| 19 | + server._auth_token = "j80k54ll2lfMZ0tv97mlPvvSCRyD0DOM" |
| 20 | + server.version = "3.8" |
21 | 21 |
|
22 | | - def test_get(self): |
23 | | - response_xml = read_xml_asset(GET_XML) |
24 | | - with requests_mock.mock() as m: |
25 | | - m.get(self.baseurl, text=response_xml) |
26 | | - data_acceleration_report = self.server.data_acceleration_report.get() |
| 22 | + return server |
27 | 23 |
|
28 | | - self.assertEqual(2, len(data_acceleration_report.comparison_records)) |
29 | 24 |
|
30 | | - self.assertEqual("site-1", data_acceleration_report.comparison_records[0].site) |
31 | | - self.assertEqual("sheet-1", data_acceleration_report.comparison_records[0].sheet_uri) |
32 | | - self.assertEqual("0", data_acceleration_report.comparison_records[0].unaccelerated_session_count) |
33 | | - self.assertEqual("0.0", data_acceleration_report.comparison_records[0].avg_non_accelerated_plt) |
34 | | - self.assertEqual("1", data_acceleration_report.comparison_records[0].accelerated_session_count) |
35 | | - self.assertEqual("0.166", data_acceleration_report.comparison_records[0].avg_accelerated_plt) |
| 25 | +def test_get_data_acceleration_report(server): |
| 26 | + response_xml = GET_XML.read_text() |
| 27 | + with requests_mock.mock() as m: |
| 28 | + m.get(server.data_acceleration_report.baseurl, text=response_xml) |
| 29 | + data_acceleration_report = server.data_acceleration_report.get() |
36 | 30 |
|
37 | | - self.assertEqual("site-2", data_acceleration_report.comparison_records[1].site) |
38 | | - self.assertEqual("sheet-2", data_acceleration_report.comparison_records[1].sheet_uri) |
39 | | - self.assertEqual("2", data_acceleration_report.comparison_records[1].unaccelerated_session_count) |
40 | | - self.assertEqual("1.29", data_acceleration_report.comparison_records[1].avg_non_accelerated_plt) |
41 | | - self.assertEqual("3", data_acceleration_report.comparison_records[1].accelerated_session_count) |
42 | | - self.assertEqual("0.372", data_acceleration_report.comparison_records[1].avg_accelerated_plt) |
| 31 | + assert 2 == len(data_acceleration_report.comparison_records) |
| 32 | + |
| 33 | + assert "site-1" == data_acceleration_report.comparison_records[0].site |
| 34 | + assert "sheet-1" == data_acceleration_report.comparison_records[0].sheet_uri |
| 35 | + assert "0" == data_acceleration_report.comparison_records[0].unaccelerated_session_count |
| 36 | + assert "0.0" == data_acceleration_report.comparison_records[0].avg_non_accelerated_plt |
| 37 | + assert "1" == data_acceleration_report.comparison_records[0].accelerated_session_count |
| 38 | + assert "0.166" == data_acceleration_report.comparison_records[0].avg_accelerated_plt |
| 39 | + |
| 40 | + assert "site-2" == data_acceleration_report.comparison_records[1].site |
| 41 | + assert "sheet-2" == data_acceleration_report.comparison_records[1].sheet_uri |
| 42 | + assert "2" == data_acceleration_report.comparison_records[1].unaccelerated_session_count |
| 43 | + assert "1.29" == data_acceleration_report.comparison_records[1].avg_non_accelerated_plt |
| 44 | + assert "3" == data_acceleration_report.comparison_records[1].accelerated_session_count |
| 45 | + assert "0.372" == data_acceleration_report.comparison_records[1].avg_accelerated_plt |
0 commit comments