Skip to content

Commit 9c5078b

Browse files
committed
test(helpdesk): validate response types and add HTTP status assertions
1 parent 59d7853 commit 9c5078b

33 files changed

Lines changed: 224 additions & 86 deletions

e2e_config.test.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
"commerce.product.template.id": "TPL-1767-7355-0002",
5858
"commerce.user.id": "USR-4303-2348",
5959
"helpdesk.chat.id": "CHT-5064-0262-3671",
60+
"helpdesk.channel.id": "CHL-5064-0262-3671",
6061
"commerce.subscription.agreement.id": "AGR-2473-3299-1721",
6162
"commerce.subscription.id": "SUB-3678-1831-2188",
6263
"commerce.subscription.product.item.id": "ITM-1767-7355-0001",

tests/e2e/helpdesk/cases/test_async_cases.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
from http import HTTPStatus
2+
13
import pytest
24

35
from mpt_api_client.exceptions import MPTAPIError
6+
from mpt_api_client.resources.helpdesk.cases import Case
47

58
pytestmark = [pytest.mark.flaky]
69

@@ -12,13 +15,12 @@ async def test_get_case(async_mpt_ops, async_created_case):
1215
assert result.id == async_created_case.id
1316

1417

15-
@pytest.mark.skip(reason="Unskip after MPT-19124 completed")
1618
async def test_list_cases(async_mpt_ops):
1719
limit = 1
1820

1921
result = await async_mpt_ops.helpdesk.cases.fetch_page(limit=limit)
2022

21-
assert len(result) > 0
23+
assert all(isinstance(case, Case) for case in result)
2224

2325

2426
@pytest.mark.skip(reason="Unskip after MPT-19124 completed")
@@ -65,7 +67,7 @@ async def test_complete_case(async_mpt_ops, async_created_case):
6567
assert result is not None
6668

6769

68-
@pytest.mark.skip(reason="Unskip after MPT-19124 completed")
6970
async def test_not_found(async_mpt_ops, invalid_case_id):
70-
with pytest.raises(MPTAPIError):
71+
with pytest.raises(MPTAPIError) as error:
7172
await async_mpt_ops.helpdesk.cases.get(invalid_case_id)
73+
assert error.value.status_code == HTTPStatus.NOT_FOUND

tests/e2e/helpdesk/cases/test_sync_cases.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
from http import HTTPStatus
2+
13
import pytest
24

35
from mpt_api_client.exceptions import MPTAPIError
6+
from mpt_api_client.resources.helpdesk.cases import Case
47

58
pytestmark = [pytest.mark.flaky]
69

@@ -12,13 +15,12 @@ def test_get_case(mpt_ops, created_case):
1215
assert result.id == created_case.id
1316

1417

15-
@pytest.mark.skip(reason="Unskip after MPT-19124 completed")
1618
def test_list_cases(mpt_ops):
1719
limit = 1
1820

1921
result = mpt_ops.helpdesk.cases.fetch_page(limit=limit)
2022

21-
assert len(result) > 0
23+
assert all(isinstance(case, Case) for case in result)
2224

2325

2426
@pytest.mark.skip(reason="Unskip after MPT-19124 completed")
@@ -65,7 +67,8 @@ def test_complete_case(mpt_ops, created_case):
6567
assert result is not None
6668

6769

68-
@pytest.mark.skip(reason="Unskip after MPT-19124 completed")
6970
def test_not_found(mpt_ops, invalid_case_id):
70-
with pytest.raises(MPTAPIError):
71+
with pytest.raises(MPTAPIError) as error:
7172
mpt_ops.helpdesk.cases.get(invalid_case_id)
73+
74+
assert error.value.status_code == HTTPStatus.NOT_FOUND

tests/e2e/helpdesk/channels/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
@pytest.fixture
1010
def channel_id(e2e_config):
11-
return e2e_config["helpdesk.channel.id"]
11+
return e2e_config["helpdesk.channel.id"] # FIXME: seed data
1212

1313

1414
@pytest.fixture
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
from http import HTTPStatus
2+
13
import pytest
24

35
from mpt_api_client.exceptions import MPTAPIError
6+
from mpt_api_client.resources.helpdesk.chat_messages import ChatMessage
47

58
pytestmark = [pytest.mark.flaky]
69

@@ -9,10 +12,11 @@
912
async def test_list_channel_messages(async_channel_messages_service):
1013
result = await async_channel_messages_service.fetch_page(limit=1)
1114

12-
assert len(result) > 0
15+
assert all(isinstance(message, ChatMessage) for message in result)
1316

1417

1518
@pytest.mark.skip(reason="Unskip after MPT-19124 completed")
1619
async def test_list_channel_messages_not_found(async_mpt_ops, invalid_channel_id):
17-
with pytest.raises(MPTAPIError, match=r"404 Not Found"):
20+
with pytest.raises(MPTAPIError) as error:
1821
await async_mpt_ops.helpdesk.channels.messages(invalid_channel_id).fetch_page(limit=1)
22+
assert error.value.status_code == HTTPStatus.NOT_FOUND
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
from http import HTTPStatus
2+
13
import pytest
24

35
from mpt_api_client.exceptions import MPTAPIError
6+
from mpt_api_client.resources.helpdesk.chat_messages import ChatMessage
47

58
pytestmark = [pytest.mark.flaky]
69

@@ -9,10 +12,12 @@
912
def test_list_channel_messages(channel_messages_service):
1013
result = channel_messages_service.fetch_page(limit=1)
1114

12-
assert len(result) > 0
15+
assert all(isinstance(message, ChatMessage) for message in result)
1316

1417

1518
@pytest.mark.skip(reason="Unskip after MPT-19124 completed")
1619
def test_list_channel_messages_not_found(mpt_ops, invalid_channel_id):
17-
with pytest.raises(MPTAPIError, match=r"404 Not Found"):
20+
with pytest.raises(MPTAPIError) as error:
1821
mpt_ops.helpdesk.channels.messages(invalid_channel_id).fetch_page(limit=1)
22+
23+
assert error.value.status_code == HTTPStatus.NOT_FOUND
Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1+
from http import HTTPStatus
2+
13
import pytest
24

35
from mpt_api_client.exceptions import MPTAPIError
6+
from mpt_api_client.resources.helpdesk.channels import Channel
47

5-
pytestmark = [pytest.mark.flaky]
8+
pytestmark = [pytest.mark.flaky, pytest.mark.skip(reason="Unskip after MPT-19124 completed")]
69

710

8-
@pytest.mark.skip(reason="Unskip after MPT-19124 completed")
911
async def test_get_channel(async_mpt_ops, channel_id):
1012
service = async_mpt_ops.helpdesk.channels
1113

@@ -14,23 +16,20 @@ async def test_get_channel(async_mpt_ops, channel_id):
1416
assert result.id == channel_id
1517

1618

17-
@pytest.mark.skip(reason="Unskip after MPT-19124 completed")
1819
async def test_list_channels(async_mpt_ops):
1920
service = async_mpt_ops.helpdesk.channels
2021

2122
result = await service.fetch_page(limit=1)
2223

23-
assert len(result) > 0
24+
assert all(isinstance(channel, Channel) for channel in result)
2425

2526

26-
@pytest.mark.skip(reason="Unskip after MPT-19124 completed")
2727
def test_create_channel(async_created_channel):
2828
result = async_created_channel
2929

3030
assert result.id is not None
3131

3232

33-
@pytest.mark.skip(reason="Unskip after MPT-19124 completed")
3433
async def test_update_channel(async_mpt_ops, async_created_channel, short_uuid):
3534
service = async_mpt_ops.helpdesk.channels
3635
new_name = f"E2E Updated Channel {short_uuid}"
@@ -41,7 +40,6 @@ async def test_update_channel(async_mpt_ops, async_created_channel, short_uuid):
4140
assert result.to_dict().get("name") == new_name
4241

4342

44-
@pytest.mark.skip(reason="Unskip after MPT-19124 completed")
4543
async def test_delete_channel(async_mpt_ops, async_created_channel):
4644
result = async_created_channel
4745

@@ -51,5 +49,6 @@ async def test_delete_channel(async_mpt_ops, async_created_channel):
5149
async def test_not_found(async_mpt_ops, invalid_channel_id):
5250
service = async_mpt_ops.helpdesk.channels
5351

54-
with pytest.raises(MPTAPIError):
52+
with pytest.raises(MPTAPIError) as error:
5553
await service.get(invalid_channel_id)
54+
assert error.value.status_code == HTTPStatus.NOT_FOUND
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1+
from http import HTTPStatus
2+
13
import pytest
24

35
from mpt_api_client.exceptions import MPTAPIError
6+
from mpt_api_client.resources.helpdesk.channels import Channel
47

5-
pytestmark = [pytest.mark.flaky]
8+
pytestmark = [pytest.mark.flaky, pytest.mark.skip(reason="Unskip after MPT-19124 completed")]
69

710

8-
@pytest.mark.skip(reason="Unskip after MPT-19124 completed")
911
def test_get_channel(mpt_ops, channel_id):
1012
service = mpt_ops.helpdesk.channels
1113

@@ -14,23 +16,20 @@ def test_get_channel(mpt_ops, channel_id):
1416
assert result.id == channel_id
1517

1618

17-
@pytest.mark.skip(reason="Unskip after MPT-19124 completed")
1819
def test_list_channels(mpt_ops):
1920
service = mpt_ops.helpdesk.channels
2021

2122
result = service.fetch_page(limit=1)
2223

23-
assert len(result) > 0
24+
assert all(isinstance(channel, Channel) for channel in result)
2425

2526

26-
@pytest.mark.skip(reason="Unskip after MPT-19124 completed")
2727
def test_create_channel(created_channel):
2828
result = created_channel
2929

3030
assert result.id is not None
3131

3232

33-
@pytest.mark.skip(reason="Unskip after MPT-19124 completed")
3433
def test_update_channel(mpt_ops, created_channel, short_uuid):
3534
service = mpt_ops.helpdesk.channels
3635
new_name = f"E2E Updated Channel {short_uuid}"
@@ -41,7 +40,6 @@ def test_update_channel(mpt_ops, created_channel, short_uuid):
4140
assert result.to_dict().get("name") == new_name
4241

4342

44-
@pytest.mark.skip(reason="Unskip after MPT-19124 completed")
4543
def test_delete_channel(mpt_ops, created_channel):
4644
result = created_channel
4745

@@ -51,5 +49,7 @@ def test_delete_channel(mpt_ops, created_channel):
5149
def test_not_found(mpt_ops, invalid_channel_id):
5250
service = mpt_ops.helpdesk.channels
5351

54-
with pytest.raises(MPTAPIError):
52+
with pytest.raises(MPTAPIError) as error:
5553
service.get(invalid_channel_id)
54+
55+
assert error.value.status_code == HTTPStatus.NOT_FOUND

tests/e2e/helpdesk/chats/answers/parameters/test_async_parameters.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
from http import HTTPStatus
2+
13
import pytest
24

35
from mpt_api_client.exceptions import MPTAPIError
6+
from mpt_api_client.resources.helpdesk.chat_answer_parameters import ChatAnswerParameter
47

58
pytestmark = [
69
pytest.mark.flaky,
@@ -11,7 +14,7 @@
1114
async def test_list_chat_answer_parameters(async_chat_answer_parameters_service):
1215
result = await async_chat_answer_parameters_service.fetch_page(limit=20)
1316

14-
assert len(result) >= 0
17+
assert all(isinstance(parameter, ChatAnswerParameter) for parameter in result)
1518

1619

1720
async def test_iterate_chat_answer_parameters(async_chat_answer_parameters_service):
@@ -24,5 +27,6 @@ async def test_iterate_chat_answer_parameters(async_chat_answer_parameters_servi
2427
async def test_not_found(async_mpt_ops, chat_id):
2528
service = async_mpt_ops.helpdesk.chats.answers(chat_id).parameters("ANS-0000-0000")
2629

27-
with pytest.raises(MPTAPIError):
30+
with pytest.raises(MPTAPIError) as error:
2831
await service.fetch_page(limit=20)
32+
assert error.value.status_code == HTTPStatus.NOT_FOUND

0 commit comments

Comments
 (0)