How to use print_response method in Playwright Python

Best Python code snippet using playwright-python

Run Playwright Python automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

BTeeBot.py

Source: BTeeBot.py Github

copy
1#!/usr/bin/env python3
2
3# Name: BTeeBot.py
4# Description: moredullboyjack.
5# Author: Bajron
6
7import sys, os
8MDIR = os.path.dirname(sys.argv[0])
9
10sys.path.append(MDIR + "/../../TUSPythonInterface")
11sys.path.append(MDIR + "/../Moderator")
12
13from TUSUserInterface import *
14from TUSDictionary import *
15
16from time import sleep
17
18def remove_whitespace_nodes(dom):
19    from xml.dom.minidom import Node
20    if dom.hasChildNodes() :
21        for ch in dom.childNodes:
22            remove_whitespace_nodes(ch)
23    elif dom.nodeType == Node.TEXT_NODE and dom.data.strip(" \t\n\r") == '' :
24        dom.data = ''
25
26def clean_up_reply(dom):
27    remove_whitespace_nodes(dom)
28    dom.normalize();
29    return dom
30
31def print_response( ret, full = False ):
32    # get status and message
33    st = int(ret.getElementsByTagName('status')[0].getAttribute('value') );
34
35    msgs = ret.getElementsByTagName('message');
36    msg = "" if not msgs else msgs[0].getAttribute('value');
37
38    print ( "Reply is: " + REPLY_STATUSES[st] + " / " + msg)
39    # print the whole message
40    if(full or st != 10):
41        remove_whitespace_nodes(ret)
42        ret.normalize();
43        print(ret.toprettyxml(indent="    ", newl="\n"));
44
45def extract_items(aItemTagName, aReply):
46    clean_up_reply(aReply)
47    ret = []
48    for obj in aReply.getElementsByTagName(aItemTagName):
49        item = {}
50        for ch in obj.childNodes:
51            # 'value' attribute variant
52            item[ch._get_localName()] = ch.getAttribute('value')
53            # Tag contents variant below
54            #item[ch._get_localName()]  = ch.firstChild.nodeValue
55
56        ret.append(item)
57    return ret
58
59LAND = ['login','world_name','land_name','granted']
60SITE = ['land_name', 'settlement_name']
61BUILDING =['buildingclass','buildingname','volume']
62HUMAN = ['humanclass','humanname','experience','volume']
63RESOURCE =['resourcename','volume']
64
65def extract(tags, elements):
66    ret = []
67    for obj in elements:
68        item = {}
69        for tag in tags:
70            item[tag] = obj.getElementsByTagName(tag)[0].getAttribute('value')
71        ret.append(item)
72    return ret
73
74################################################################################
75
76B,H,R = {},{},{}
77set_up_consts(MDIR + '/../../TUSCore/GameServer/Configuration/Data/Test',R,B,H)
78#
79# now use short name to get the object map
80# B['farm'] == {'name':'farm', 'class':'regular', ... }
81#
82
83# synchronize with modbot, TODO better way
84NUMBER_OF_EPOCHS = 1
85NUMBER_OF_TICKS = 20
86SLEEP_BETWEEN_TICKS = 3
87
88# Define bot specific "constants".
89LOGIN = "btee"
90PASSWORD = "bteepasswd"
91MODERATED = True
92interface = TUSUserInterface(LOGIN, PASSWORD, MODERATED)
93
94# Define names.
95WORLD_NAME = "World"
96LAND_NAME = "BTee Land"
97TICK_LEN = 3
98SETTLEMENT_NAME = "BTee Settlement"
99ID_HOLDER_CLASS_SETTLEMENT = "1" # ????
100
101print ("Creating user")
102
103ret = interface.createUser()
104print_response(ret)
105
106print ("Creating land" )
107ret = interface.createLand(WORLD_NAME, LAND_NAME)
108print_response(ret)
109
110print ("Creating settlement")
111ret = interface.createSettlement(LAND_NAME, SETTLEMENT_NAME)
112print_response(ret)
113
114print( "Building...")
115interface.setCurrentHolder(ID_HOLDER_CLASS_SETTLEMENT, SETTLEMENT_NAME)
116
117ret = interface.build(B['farm'], 2)
118print_response(ret)
119
120ret = interface.build(B["sawmill"], 1)
121print_response(ret)
122
123ret = interface.build(B["marketplace"], 1)
124print_response(ret)
125
126ret = interface.build(B["mine"], 1)
127print_response(ret)
128
129ret = interface.build(B["quarry"], 1)
130print_response(ret)
131
132ret = interface.build(B["steelworks"], 1)
133print_response(ret)
134
135print ("Engaging human")
136
137ret = interface.engage(H["farmer"] , 10)
138print_response(ret)
139
140ret = interface.engage(H["lumberjack"] , 5)
141print_response(ret)
142
143ret = interface.engage(H["merchant"], 5)
144print_response(ret)
145
146ret = interface.engage(H["miner"], 5)
147print_response(ret)
148
149ret = interface.engage(H["stone mason"], 5)
150print_response(ret)
151
152ret = interface.engage(H["breeder"], 5)
153print_response(ret)
154
155ret = interface.engage(H["steelworker"], 1)
156print_response(ret)
157
158ret = interface.engage(H["fisherman"], 3)
159print_response(ret)
160
161print ("Dismissing jobless")
162ret = interface.dismiss( {'key':'workerjoblessnovice'}, 750)
163print_response(ret)
164
165# Take a look around
166
167print ("Getting epoch")
168ret = interface.getEpoch(WORLD_NAME)
169print_response(ret, True)
170
171print ("Getting lands")
172ret = interface.getLands()
173print_response(ret)
174
175lands = extract(LAND, ret.getElementsByTagName('object'));
176
177for land in lands:
178    ret = interface.getLand(land['land_name']);
179    print_response(ret)
180
181    ret = interface.getSettlements(land['land_name']);
182    print_response(ret)
183    sites = extract(SITE, ret.getElementsByTagName('object'))
184
185    land['_sites'] = sites
186
187    for site in sites:
188        ret = interface.getSettlement( site['settlement_name'] )
189        print_response(ret)
190
191        interface.setCurrentHolder( ID_HOLDER_CLASS_SETTLEMENT, site['settlement_name'])
192
193        ret = interface.listHumans()
194        print_response(ret,True);
195        humans = extract_items('object', ret)
196
197        site['_humans'] = humans
198
199        for h in humans:
200            ret = interface.humanDetails(h)
201            print_response(ret)
202
203        ret = interface.listBuildings()
204        print_response(ret)
205        buildings = extract_items('object', ret);
206
207        site['_buildings'] = buildings
208
209        for b in buildings:
210            ret = interface.buildingDetails(b)
211            print_response(ret)
212
213        ret = interface.listResources()
214        print_response(ret, True)
215        resources = extract_items('object',ret)
216
217        site['_resources'] = resources
218
219        for r in resources:
220            ret = interface.resourceDetails(r)
221            print_response(ret)
222
223
224from pprint import pprint
225
226pprint( lands, indent=4)
227
228print( "What now?")
229
230def pRVec(aList,aName):
231    s = ""
232    s += aName + " <- c("
233    first = True
234    for el in aList:
235        if not first:
236            s += ", "
237        else :
238            first = False
239        s += str(el)
240    s += ")"
241    return s
242
243print( pRVec([1,2,3],"test"))
244
245rDict = {}
246for i,r in R.items():
247    rDict[r['name']] = []
248
249hDict = {}
250
251interface.setCurrentHolder( ID_HOLDER_CLASS_SETTLEMENT, SETTLEMENT_NAME)
252
253for iEpoch in range(NUMBER_OF_EPOCHS):
254    for iTick in range(NUMBER_OF_TICKS):
255        print(iTick)
256        ret = interface.listResources()
257        res = extract_items('object', ret);
258        for r in res:
259            rDict[r['resourcename']].append( int(r['volume']) )
260        print( res)
261
262        ret = interface.listHumans()
263        hum = extract_items('object', ret)
264        for h in hum:
265            assert_human_key(h)
266            if not h['key'] in hDict :
267                hDict[h['key']] = iEpoch * [0]
268            hDict[h['key']].append( int(h['volume']) )
269
270            #hVol.append( int( hum[0]['volume']) )
271            #hExp.append( int( hum[0]['experience']) )
272        if MODERATED:
273            interface.waitForNextRound()
274            #print ("BTee: next round")
275        else:
276            sleep(SLEEP_BETWEEN_TICKS)
277
278for i,r in rDict.items():
279    print( pRVec( r, "res_"+str(i)) + ";")
280for i,h in hDict.items():
281    print( pRVec( h, "hum_"+str(i)) + ";")
282#print(pRVec( hExp, "hExp") + ";")
283#print(pRVec( hVol, "hVol") + ";")
284
285del interface
286
Full Screen

test_show.py

Source: test_show.py Github

copy
1# -*- coding: utf-8 -*-
2# Copyright (c) 2018-2019 Linh Pham
3# wwdtm is relased under the terms of the Apache License 2.0
4"""Testing module for wwdtm.show"""
5
6import json
7import mysql.connector
8from wwdtm.show import details, info, utility
9
10def test_id_exists(show_id: int,
11                   database_connection: mysql.connector.connect,
12                   print_response: bool = False):
13    """Testing repsonse from utility.id_exists"""
14    response = utility.id_exists(show_id, database_connection)
15    assert response
16    if print_response:
17        print(json.dumps(response, indent=2))
18
19def test_id_not_exists(show_id: int,
20                       database_connection: mysql.connector.connect,
21                       print_response: bool = False):
22    """Testing repsonse from utility.id_exists with an invalid ID"""
23    response = utility.id_exists(show_id, database_connection)
24    assert not response
25    if print_response:
26        print(json.dumps(response, indent=2))
27
28def test_date_exists(show_year: int,
29                     show_month: int,
30                     show_day: int,
31                     database_connection: mysql.connector.connect,
32                     print_response: bool = False):
33    """Testing response from utility.date_exists"""
34    response = utility.date_exists(show_year,
35                                   show_month,
36                                   show_day,
37                                   database_connection)
38    assert response
39    if print_response:
40        print(json.dumps(response, indent=2))
41
42def test_date_not_exists(show_year: int,
43                         show_month: int,
44                         show_day: int,
45                         database_connection: mysql.connector.connect,
46                         print_response: bool = False):
47    """Testing response from utility.date_exists with an incorrect date"""
48    response = utility.date_exists(show_year,
49                                   show_month,
50                                   show_day,
51                                   database_connection)
52    assert not response
53    if print_response:
54        print(json.dumps(response, indent=2))
55
56def test_retrieve_by_id(show_id: int,
57                        database_connection: mysql.connector.connect,
58                        print_response: bool = False):
59    """Testing response from info.retrieve_by_id"""
60    show_info = info.retrieve_by_id(show_id, database_connection)
61    assert show_info is not None
62    assert "best_of" in show_info
63    assert "repeat_show" in show_info
64    if print_response:
65        print(json.dumps(show_info, indent=2))
66
67def test_retrieve_by_invalid_id(show_id: int,
68                                database_connection: mysql.connector.connect,
69                                print_response: bool = False):
70    """Testing response from info.retrieve_by_id with an invalid ID"""
71    show_info = info.retrieve_by_id(show_id, database_connection)
72    assert show_info is None
73    if print_response:
74        print(json.dumps(show_info, indent=2))
75
76def test_retrieve_by_date(show_year: int,
77                          show_month: int,
78                          show_day: int,
79                          database_connection: mysql.connector.connect,
80                          print_response: bool = False):
81    """Testing response from info.retrieve_by_date"""
82    show_info = info.retrieve_by_date(show_year,
83                                      show_month,
84                                      show_day,
85                                      database_connection)
86    assert show_info is not None
87    assert "best_of" in show_info
88    assert "repeat_show" in show_info
89    if print_response:
90        print(json.dumps(show_info, indent=2))
91
92def test_retrieve_by_invalid_date(show_year: int,
93                                  show_month: int,
94                                  show_day: int,
95                                  database_connection: mysql.connector.connect,
96                                  print_response: bool = False):
97    """Testing response from info.retrieve_by_date with incorrect date"""
98    try:
99        show_info = info.retrieve_by_date(show_year,
100                                          show_month,
101                                          show_day,
102                                          database_connection)
103        assert show_info is None
104        if print_response:
105            print(json.dumps(show_info, indent=2))
106    except ValueError:
107        assert True
108
109def test_retrieve_by_date_string(show_date: str,
110                                 database_connection: mysql.connector.connect,
111                                 print_response: bool = False):
112    """Testing response from info.retrieve_by_date_string"""
113    show_info = info.retrieve_by_date_string(show_date, database_connection)
114    assert show_info is not None
115    if print_response:
116        print(json.dumps(show_info, indent=2))
117
118def test_retrieve_by_invalid_date_string(show_date: str,
119                                         database_connection: mysql.connector.connect,
120                                         print_response: bool = False):
121    """Testing response from info.retrieve_by_date_string with an
122    incorrect date"""
123    try:
124        show_info = info.retrieve_by_date_string(show_date, database_connection)
125        assert show_info is None
126        if print_response:
127            print(json.dumps(show_info, indent=2))
128    except ValueError:
129        assert True
130
131def test_retrieve_months_by_year(show_year: int,
132                                 database_connection: mysql.connector.connect,
133                                 print_response: bool = False):
134    """Testing response from info.retrieve_months_by_year"""
135    show_months = info.retrieve_months_by_year(show_year,
136                                               database_connection)
137    assert show_months is not None
138    if print_response:
139        print(json.dumps(show_months, indent=2))
140
141def test_retrieve_years(database_connection: mysql.connector.connect,
142                        print_response: bool = False):
143    """Testing response from info.retrieve_years"""
144    show_years = info.retrieve_years(database_connection)
145    assert show_years is not None
146    if print_response:
147        print(json.dumps(show_years, indent=2))
148
149def test_retrieve_by_year(show_year: int,
150                          database_connection: mysql.connector.connect,
151                          print_response: bool = False):
152    """Testing response form info.retrieve_by_year"""
153    show_info = info.retrieve_by_year(show_year, database_connection)
154    assert show_info is not None
155    if print_response:
156        print(json.dumps(show_info, indent=2))
157
158def test_retrieve_by_year_month(show_year: int,
159                                show_month: int,
160                                database_connection: mysql.connector.connect,
161                                print_response: bool = False):
162    """Testing response form info.retrieve_by_year_month"""
163    show_info = info.retrieve_by_year_month(show_year,
164                                            show_month,
165                                            database_connection)
166    assert show_info is not None
167    if print_response:
168        print(json.dumps(show_info, indent=2))
169
170def test_retrieve_all(database_connection: mysql.connector.connect,
171                      print_response: bool = False):
172    """Testing response from info.retrieve_all"""
173    show_info = info.retrieve_all(database_connection)
174    assert show_info is not None
175    if print_response:
176        print(json.dumps(show_info, indent=2))
177
178def test_retrieve_all_ids(database_connection: mysql.connector.connect,
179                          print_response: bool = False):
180    """Testing response from info.retrieve_all_ids"""
181    show_ids = info.retrieve_all_ids(database_connection)
182    assert show_ids is not None
183    if print_response:
184        print(json.dumps(show_ids, indent=2))
185
186def test_retrieve_all_dates(database_connection: mysql.connector.connect,
187                            print_response: bool = False):
188    """Testing response from info.retrieve_all_dates"""
189    show_dates = info.retrieve_all_dates(database_connection)
190    assert show_dates is not None
191    if print_response:
192        print(json.dumps(show_dates, indent=2))
193
194def test_retrieve_all_dates_tuple(database_connection: mysql.connector.connect,
195                                  print_response: bool = False):
196    """Testing response from info.retrieve_all_dates_tuple"""
197    show_dates = info.retrieve_all_dates_tuple(database_connection)
198    assert show_dates is not None
199    if print_response:
200        print(json.dumps(show_dates, indent=2))
201
202def test_retrieve_scores_by_year(show_year: int,
203                                 database_connection: mysql.connector.connect,
204                                 print_response: bool = False):
205    """Testing response from info.retrieve_scores_by_year"""
206    show_scores = info.retrieve_scores_by_year(show_year, database_connection)
207    assert show_scores is not None
208    if print_response:
209        print(json.dumps(show_scores, indent=2))
210
211def test_retrieve_all_years_months(database_connection: mysql.connector.connect,
212                                   print_response: bool = False):
213    """Testing response from info.retrieve_all_show_years_months"""
214    show_years_months = info.retrieve_all_show_years_months(database_connection)
215    assert show_years_months is not None
216    if print_response:
217        print(json.dumps(show_years_months, indent=2))
218
219def test_retrieve_all_years_months_tuple(database_connection: mysql.connector.connect,
220                                         print_response: bool = False):
221    """Testing response from info.retrieve_all_show_years_months_tuple"""
222    show_years_months = info.retrieve_all_show_years_months_tuple(database_connection)
223    assert show_years_months is not None
224    if print_response:
225        print(json.dumps(show_years_months, indent=2))
226
227def test_retrieve_recent(database_connection: mysql.connector.connect,
228                         print_response: bool = False):
229    """Testing response from info.retrieve_recent"""
230    show_info = info.retrieve_recent(database_connection)
231    assert show_info is not None
232    if print_response:
233        print(json.dumps(show_info, indent=2))
234
235def test_retrieve_details_by_id(show_id: int,
236                                database_connection: mysql.connector.connect,
237                                print_response: bool = False):
238    """Testing response from details.retrieve_by_id"""
239    show_details = details.retrieve_by_id(show_id, database_connection)
240    assert show_details is not None
241    assert "host" in show_details
242    assert "scorekeeper" in show_details
243    assert "panelists" in show_details
244    assert "bluff" in show_details
245    assert "guests" in show_details
246    assert "description" in show_details
247    assert "notes" in show_details
248    if print_response:
249        print(json.dumps(show_details, indent=2))
250
251def test_retrieve_details_by_invalid_id(show_id: int,
252                                        database_connection: mysql.connector.connect,
253                                        print_response: bool = False):
254    """Testing response from details.retrieve_by_id with an
255    invalid ID"""
256    show_details = details.retrieve_by_id(show_id, database_connection)
257    assert show_details is None
258    if print_response:
259        print(json.dumps(show_details, indent=2))
260
261def test_retrieve_details_by_date(show_year: int,
262                                  show_month: int,
263                                  show_day: int,
264                                  database_connection: mysql.connector.connect,
265                                  print_response: bool = False):
266    """Testing response from details.retrieve_by_date"""
267    show_details = details.retrieve_by_date(show_year,
268                                            show_month,
269                                            show_day,
270                                            database_connection)
271    assert show_details is not None
272    assert "host" in show_details
273    assert "scorekeeper" in show_details
274    assert "panelists" in show_details
275    assert "bluff" in show_details
276    assert "guests" in show_details
277    assert "description" in show_details
278    assert "notes" in show_details
279    if print_response:
280        print(json.dumps(show_details, indent=2))
281
282def test_retrieve_details_by_invalid_date(show_year: int,
283                                          show_month: int,
284                                          show_day: int,
285                                          database_connection: mysql.connector.connect,
286                                          print_response: bool = False):
287    """Testing repsonse from details.retrieve_by_date with an incorrect
288    date"""
289    show_details = details.retrieve_by_date(show_year,
290                                            show_month,
291                                            show_day,
292                                            database_connection)
293    assert show_details is None
294    if print_response:
295        print(json.dumps(show_details, indent=2))
296
297def test_retrieve_details_by_date_string(show_date: str,
298                                         database_connection: mysql.connector.connect,
299                                         print_response: bool = False):
300    """Testing repsonse from details.retrieve_by_date_string"""
301    show_details = details.retrieve_by_date_string(show_date,
302                                                   database_connection)
303    assert show_details is not None
304    assert "host" in show_details
305    assert "scorekeeper" in show_details
306    assert "panelists" in show_details
307    assert "bluff" in show_details
308    assert "guests" in show_details
309    assert "description" in show_details
310    assert "notes" in show_details
311    if print_response:
312        print(json.dumps(show_details, indent=2))
313
314def test_retrieve_details_by_invalid_date_string(show_date: str,
315                                                 database_connection: mysql.connector.connect,
316                                                 print_response: bool = False):
317    """Testing response from details.retrieve_by_date_string with
318    invalud date string"""
319    show_details = details.retrieve_by_date_string(show_date,
320                                                   database_connection)
321    assert show_details is None
322    if print_response:
323        print(json.dumps(show_details, indent=2))
324
325def test_retrieve_details_by_year(show_year: int,
326                                  database_connection: mysql.connector.connect,
327                                  print_response: bool = False):
328    """Testing response from details.retrieve_by_year"""
329    show_details = details.retrieve_by_year(show_year,
330                                            database_connection)
331    assert show_details is not None
332    if print_response:
333        print(json.dumps(show_details, indent=2))
334
335def test_retrieve_details_by_year_month(show_year: int,
336                                        show_month: int,
337                                        database_connection: mysql.connector.connect,
338                                        print_response: bool = False):
339    """Testing response from details.retrieve_by_year_month"""
340    show_details = details.retrieve_by_year_month(show_year,
341                                                  show_month,
342                                                  database_connection)
343    assert show_details is not None
344    if print_response:
345        print(json.dumps(show_details, indent=2))
346
347def test_retrieve_all_details(database_connection: mysql.connector.connect,
348                              print_response: bool = False):
349    """Testing response from details.retrieve_all"""
350    show_details = details.retrieve_all(database_connection)
351    assert show_details is not None
352    if print_response:
353        print(json.dumps(show_details, indent=2))
354
355def test_retrieve_recent_details(database_connection: mysql.connector.connect,
356                                 print_response: bool = False):
357    """Testing response from details.retrieve_recent"""
358    show_details = details.retrieve_recent(database_connection)
359    assert show_details is not None
360    if print_response:
361        print(json.dumps(show_details, indent=2))
362
Full Screen

test_panelist.py

Source: test_panelist.py Github

copy
1# -*- coding: utf-8 -*-
2# Copyright (c) 2018-2019 Linh Pham
3# wwdtm is relased under the terms of the Apache License 2.0
4"""Testing module for wwdtm.panelist"""
5
6import json
7import mysql.connector
8from wwdtm.panelist import details, info, utility
9
10def test_id_exists(panelist_id: int,
11                   database_connection: mysql.connector.connect,
12                   print_response: bool = False):
13    """Testing response from utility.id_exists"""
14    response = utility.id_exists(panelist_id, database_connection)
15    assert response
16    if print_response:
17        print(json.dumps(response, indent=2))
18
19def test_id_not_exists(panelist_id: int,
20                       database_connection: mysql.connector.connect,
21                       print_response: bool = False):
22    """Testing response from utility.id_exists"""
23    response = utility.id_exists(panelist_id, database_connection)
24    assert not response
25    if print_response:
26        print(json.dumps(response, indent=2))
27
28def test_slug_exists(panelist_slug: str,
29                     database_connection: mysql.connector.connect,
30                     print_response: bool = False):
31    """Testing response from utility.slug_exists"""
32    response = utility.slug_exists(panelist_slug, database_connection)
33    assert response
34    if print_response:
35        print(json.dumps(response, indent=2))
36
37def test_slug_not_exists(panelist_slug: str,
38                         database_connection: mysql.connector.connect,
39                         print_response: bool = False):
40    """Testing response from utility.slug_exists"""
41    response = utility.slug_exists(panelist_slug, database_connection)
42    assert not response
43    if print_response:
44        print(json.dumps(response, indent=2))
45
46def test_retrieve_all(database_connection: mysql.connector.connect,
47                      print_response: bool = False):
48    """Testing response from info.retrieve_all"""
49    panelists = info.retrieve_all(database_connection)
50    assert panelists is not None
51    if print_response:
52        print(json.dumps(panelists, indent=2))
53
54def test_retrieve_all_ids(database_connection: mysql.connector.connect,
55                          print_response: bool = False):
56    """Testing response from info.retrieve_all_ids"""
57    panelist_ids = info.retrieve_all_ids(database_connection)
58    assert panelist_ids is not None
59    if print_response:
60        print(json.dumps(panelist_ids, indent=2))
61
62def test_retrieve_by_id(panelist_id: int,
63                        database_connection: mysql.connector.connect,
64                        print_response: bool = False):
65    """Testing response from info.retrieve_by_id"""
66    panelist_dict = info.retrieve_by_id(panelist_id, database_connection)
67    assert panelist_dict is not None
68    assert "id" in panelist_dict
69    if print_response:
70        print(json.dumps(panelist_dict, indent=2))
71
72def test_retrieve_by_slug(panelist_slug: str,
73                          database_connection: mysql.connector.connect,
74                          print_response: bool = False):
75    """Testing response from info.retrieve_by_slug"""
76    panelist_dict = info.retrieve_by_slug(panelist_slug,
77                                          database_connection)
78    assert panelist_dict is not None
79    assert "id" in panelist_dict
80    if print_response:
81        print(json.dumps(panelist_dict, indent=2))
82
83def test_retrieve_details_by_id(panelist_id: int,
84                                database_connection: mysql.connector.connect,
85                                print_response: bool = False):
86    """Testing response from details.retrieve_by_id"""
87    panelist_dict = details.retrieve_by_id(panelist_id,
88                                           database_connection)
89    assert panelist_dict is not None
90    assert "statistics" in panelist_dict
91    assert "bluffs" in panelist_dict
92    assert "appearances" in panelist_dict
93    if print_response:
94        print(json.dumps(panelist_dict, indent=2))
95
96def test_retrieve_details_by_slug(panelist_slug: str,
97                                  database_connection: mysql.connector.connect,
98                                  print_response: bool = False):
99    """Testing response from details.retrieve_by_slug"""
100    panelist_dict = details.retrieve_by_slug(panelist_slug,
101                                             database_connection)
102    assert panelist_dict is not None
103    assert "statistics" in panelist_dict
104    assert "bluffs" in panelist_dict
105    assert "appearances" in panelist_dict
106    if print_response:
107        print(json.dumps(panelist_dict, indent=2))
108
109def test_retrieve_all_details(database_connection: mysql.connector.connect,
110                              print_response: bool = False):
111    """Testing response from details.retrieve_all"""
112    panelists_dict = details.retrieve_all(database_connection)
113    assert panelists_dict is not None
114    if print_response:
115        print(json.dumps(panelists_dict, indent=2))
116
117def test_retrieve_scores_grouped_list_by_id(panelist_id: int,
118                                            database_connection: mysql.connector.connect,
119                                            print_response: bool = False):
120    """Testing response from info.retrieve_scores_grouped_list_by_id"""
121    score_list = info.retrieve_scores_grouped_list_by_id(panelist_id,
122                                                         database_connection)
123    assert score_list is not None
124    assert "score" in score_list
125    assert "count" in score_list
126    assert len(score_list["score"]) == len(score_list["count"])
127    if print_response:
128        print(json.dumps(score_list, indent=2))
129
130def test_retrieve_scores_grouped_list_by_slug(panelist_slug: str,
131                                              database_connection: mysql.connector.connect,
132                                              print_response: bool = False):
133    """Testing response from info.retrieve_scores_grouped_list_by_slug"""
134    score_list = info.retrieve_scores_grouped_list_by_slug(panelist_slug,
135                                                           database_connection)
136    assert score_list is not None
137    assert "score" in score_list
138    assert "count" in score_list
139    assert len(score_list["score"]) == len(score_list["count"])
140    if print_response:
141        print(json.dumps(score_list, indent=2))
142
143def test_retrieve_scores_grouped_ordered_pair_by_id(panelist_id: int,
144                                                    database_connection: mysql.connector.connect,
145                                                    print_response: bool = False):
146    """Testing response from info.retrieve_scores_grouped_ordered_pair_by_id"""
147    score_list = info.retrieve_scores_grouped_ordered_pair_by_id(panelist_id,
148                                                                 database_connection)
149    assert score_list is not None
150    if print_response:
151        print(json.dumps(score_list, indent=2))
152
153def test_retrieve_scores_grouped_ordered_pair_by_slug(panelist_slug: str,
154                                                      database_connection: mysql.connector.connect,
155                                                      print_response: bool = False):
156    """Testing response from info.retrieve_scores_grouped_ordered_pair_by_slug"""
157    score_list = info.retrieve_scores_grouped_ordered_pair_by_slug(panelist_slug,
158                                                                   database_connection)
159    assert score_list is not None
160    if print_response:
161        print(json.dumps(score_list, indent=2))
162
163def test_retrieve_scores_list_by_id(panelist_id: int,
164                                    database_connection: mysql.connector.connect,
165                                    print_response: bool = False):
166    """Testing response from info.retrieve_scores_list_by_id"""
167    score_list = info.retrieve_scores_list_by_id(panelist_id,
168                                                 database_connection)
169    assert score_list is not None
170    assert "shows" in score_list
171    assert "scores" in score_list
172    assert len(score_list["shows"]) == len(score_list["scores"])
173    if print_response:
174        print(json.dumps(score_list, indent=2))
175
176def test_retrieve_scores_list_by_slug(panelist_slug: str,
177                                      database_connection: mysql.connector.connect,
178                                      print_response: bool = False):
179    """Testing response from info.retrieve_scores_list_by_slug"""
180    score_list = info.retrieve_scores_list_by_slug(panelist_slug,
181                                                   database_connection)
182    assert score_list is not None
183    assert "shows" in score_list
184    assert "scores" in score_list
185    assert len(score_list["shows"]) == len(score_list["scores"])
186    if print_response:
187        print(json.dumps(score_list, indent=2))
188
189def test_retrieve_scores_ordered_pair_by_id(panelist_id: int,
190                                            database_connection: mysql.connector.connect,
191                                            print_response: bool = False):
192    """Testing response from info.retrieve_scores_ordered_pair_by_id"""
193    score_list = info.retrieve_scores_ordered_pair_by_id(panelist_id,
194                                                         database_connection)
195    assert score_list is not None
196    if print_response:
197        print(json.dumps(score_list, indent=2))
198
199def test_retrieve_scores_ordered_pair_by_slug(panelist_slug: str,
200                                              database_connection: mysql.connector.connect,
201                                              print_response: bool = False):
202    """Testing response from info.retrieve_scores_ordered_pair_by_slug"""
203    score_list = info.retrieve_scores_ordered_pair_by_slug(panelist_slug,
204                                                           database_connection)
205    assert score_list is not None
206    if print_response:
207        print(json.dumps(score_list, indent=2))
208
209def test_retrieve_yearly_appearances_by_id(panelist_id: int,
210                                           database_connection: mysql.connector.connect,
211                                           print_response: bool = False):
212    """Testing response from info.retrieve_yearly_appearances_by_id"""
213    appearances = info.retrieve_yearly_appearances_by_id(panelist_id,
214                                                         database_connection)
215
216    assert appearances is not None
217    if print_response:
218        print(json.dumps(appearances, indent=2))
219
220def test_retrieve_yearly_appearances_by_slug(panelist_slug: str,
221                                             database_connection: mysql.connector.connect,
222                                             print_response: bool = False):
223    """Testing response from info.retrieve_yearly_appearances_by_slug"""
224    appearances = info.retrieve_yearly_appearances_by_slug(panelist_slug,
225                                                           database_connection)
226
227    assert appearances is not None
228    if print_response:
229        print(json.dumps(appearances, indent=2))
230
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Run Python Tests on LambdaTest Cloud Grid

Execute automation tests with Playwright Python on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)