Skip to content

Commit f8f2959

Browse files
phanak-sapfilak-sap
authored andcommitted
tests: add few new tests for ODataHttpRequest.custom()
Cover uncertainities exposed by questions in issue #216.
1 parent 8e088cb commit f8f2959

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

tests/test_service_v2.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2632,3 +2632,57 @@ def test_custom_with_get_entity(service):
26322632

26332633
entity = service.entity_sets.MasterEntities.get_entity('12345').custom("foo", "bar").execute()
26342634
assert entity.Key == '12345'
2635+
2636+
@responses.activate
2637+
def test_custom_with_get_entity_url_params(service):
2638+
""" Test that `custom` after `get_entity` is setting up correctly URL parts """
2639+
2640+
responses.add(
2641+
responses.GET,
2642+
f"{service.url}/MasterEntities('12345')?foo=bar",
2643+
headers={'Content-type': 'application/json'},
2644+
json={'d': {'Key': '12345'}},
2645+
status=200)
2646+
2647+
oDataHttpRequest = service.entity_sets.MasterEntities.get_entity('12345').custom("foo", "bar")
2648+
assert oDataHttpRequest.get_query_params() == {'foo': 'bar'}
2649+
assert oDataHttpRequest.get_path() == "MasterEntities('12345')"
2650+
2651+
entity = oDataHttpRequest.execute()
2652+
assert entity.Key == '12345'
2653+
2654+
@responses.activate
2655+
def test_multiple_custom_with_get_entity_url_params(service):
2656+
""" Test that `custom` after `get_entity` called several times is setting up correctly URL parts """
2657+
2658+
responses.add(
2659+
responses.GET,
2660+
f"{service.url}/MasterEntities('12345')?foo=bar&$fizz=buzz",
2661+
headers={'Content-type': 'application/json'},
2662+
json={'d': {'Key': '12345'}},
2663+
status=200)
2664+
2665+
oDataHttpRequest = service.entity_sets.MasterEntities.get_entity('12345').custom("foo", "bar").custom("$fizz", "buzz")
2666+
assert oDataHttpRequest.get_query_params() == {'foo': 'bar', '$fizz': 'buzz'}
2667+
assert oDataHttpRequest.get_path() == "MasterEntities('12345')"
2668+
2669+
entity = oDataHttpRequest.execute()
2670+
assert entity.Key == '12345'
2671+
2672+
2673+
@responses.activate
2674+
def test_custom_with_get_entities_and_chained_filters_url_params(service):
2675+
""" Test that `custom` after `get_entities` works with complex query (count, filter) """
2676+
# pylint: disable=redefined-outer-name
2677+
2678+
responses.add(
2679+
responses.GET,
2680+
f"{service.url}/Employees/$count?foo=bar&$fizz=buzz&$filter=ID%20gte%2020%20and%20ID%20lte%2050%20and%20NickName%20eq%20%27Tim%27",
2681+
json=3,
2682+
status=200)
2683+
2684+
employees = service.entity_sets.Employees.get_entities().custom("foo", "bar").custom("$fizz", "buzz")
2685+
request = employees.filter(ID__range=(20, 50)).filter(NickName="Tim").count()
2686+
2687+
assert request.get_query_params() == {'foo': 'bar', '$fizz': 'buzz', '$filter': "ID gte 20 and ID lte 50 and NickName eq 'Tim'"}
2688+
assert request.get_path() == 'Employees/$count'

0 commit comments

Comments
 (0)