66
77from posit .connect .metrics import shiny_usage
88from posit .connect .resources import ResourceParameters
9+ from posit .connect .urls import Url
910
10- from ..api import load_mock
11+ from ..api import load_mock , load_mock_dict
1112
1213
1314class TestShinyUsageEventAttributes :
15+ @classmethod
1416 def setup_class (cls ):
17+ results = load_mock_dict ("v1/instrumentation/shiny/usage?limit=500.json" )["results" ]
18+ assert isinstance (results , list )
1519 cls .event = shiny_usage .ShinyUsageEvent (
1620 mock .Mock (),
17- ** load_mock ( "v1/instrumentation/shiny/usage?limit=500.json" )[ " results" ] [0 ],
21+ ** results [0 ],
1822 )
1923
2024 def test_content_guid (self ):
@@ -37,34 +41,34 @@ class TestShinyUsageFind:
3741 @responses .activate
3842 def test (self ):
3943 # behavior
40- mock_get = [None ] * 2
41- mock_get [ 0 ] = responses .get (
42- "https://connect.example/__api__/v1/instrumentation/shiny/usage" ,
43- json = load_mock ("v1/instrumentation/shiny/usage?limit=500.json" ),
44- match = [
45- matchers .query_param_matcher (
46- {
47- "limit" : 500 ,
48- },
49- ),
50- ],
51- )
52-
53- mock_get [ 1 ] = responses . get (
54- "https://connect.example/__api__/ v1/instrumentation/shiny/usage" ,
55- json = load_mock ( "v1/instrumentation/shiny/usage?limit=500&next=23948901087.json" ),
56- match = [
57- matchers . query_param_matcher (
58- {
59- "next " : "23948901087" ,
60- "limit" : 500 ,
61- } ,
62- ) ,
63- ] ,
64- )
44+ mock_get = [
45+ responses .get (
46+ "https://connect.example/__api__/v1/instrumentation/shiny/usage" ,
47+ json = load_mock ("v1/instrumentation/shiny/usage?limit=500.json" ),
48+ match = [
49+ matchers .query_param_matcher (
50+ {
51+ "limit" : 500 ,
52+ },
53+ ),
54+ ],
55+ ),
56+ responses . get (
57+ "https://connect.example/__api__/v1/instrumentation/shiny/usage" ,
58+ json = load_mock ( " v1/instrumentation/shiny/usage?limit=500&next=23948901087.json" ) ,
59+ match = [
60+ matchers . query_param_matcher (
61+ {
62+ "next" : "23948901087" ,
63+ "limit " : 500 ,
64+ } ,
65+ ) ,
66+ ] ,
67+ ) ,
68+ ]
6569
6670 # setup
67- params = ResourceParameters (requests .Session (), "https://connect.example/__api__" )
71+ params = ResourceParameters (requests .Session (), Url ( "https://connect.example/__api__" ) )
6872
6973 # invoke
7074 events = shiny_usage .ShinyUsage (params ).find ()
@@ -79,34 +83,34 @@ class TestShinyUsageFindOne:
7983 @responses .activate
8084 def test (self ):
8185 # behavior
82- mock_get = [None ] * 2
83- mock_get [ 0 ] = responses .get (
84- "https://connect.example/__api__/v1/instrumentation/shiny/usage" ,
85- json = load_mock ("v1/instrumentation/shiny/usage?limit=500.json" ),
86- match = [
87- matchers .query_param_matcher (
88- {
89- "limit" : 500 ,
90- },
91- ),
92- ],
93- )
94-
95- mock_get [ 1 ] = responses . get (
96- "https://connect.example/__api__/ v1/instrumentation/shiny/usage" ,
97- json = load_mock ( "v1/instrumentation/shiny/usage?limit=500&next=23948901087.json" ),
98- match = [
99- matchers . query_param_matcher (
100- {
101- "next " : "23948901087" ,
102- "limit" : 500 ,
103- } ,
104- ) ,
105- ] ,
106- )
86+ mock_get = [
87+ responses .get (
88+ "https://connect.example/__api__/v1/instrumentation/shiny/usage" ,
89+ json = load_mock ("v1/instrumentation/shiny/usage?limit=500.json" ),
90+ match = [
91+ matchers .query_param_matcher (
92+ {
93+ "limit" : 500 ,
94+ },
95+ ),
96+ ],
97+ ),
98+ responses . get (
99+ "https://connect.example/__api__/v1/instrumentation/shiny/usage" ,
100+ json = load_mock ( " v1/instrumentation/shiny/usage?limit=500&next=23948901087.json" ) ,
101+ match = [
102+ matchers . query_param_matcher (
103+ {
104+ "next" : "23948901087" ,
105+ "limit " : 500 ,
106+ } ,
107+ ) ,
108+ ] ,
109+ ) ,
110+ ]
107111
108112 # setup
109- params = ResourceParameters (requests .Session (), "https://connect.example/__api__" )
113+ params = ResourceParameters (requests .Session (), Url ( "https://connect.example/__api__" ) )
110114
111115 # invoke
112116 event = shiny_usage .ShinyUsage (params ).find_one ()
0 commit comments