Changeset View
Changeset View
Standalone View
Standalone View
swh/model/tests/generate_testdata.py
Show First 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | ctime = datetime.fromtimestamp( | ||||
random() * MAX_DATE, timezone(choice(all_timezones))) | random() * MAX_DATE, timezone(choice(all_timezones))) | ||||
content = {'data': data, | content = {'data': data, | ||||
'status': status, | 'status': status, | ||||
'length': size, | 'length': size, | ||||
'ctime': ctime, | 'ctime': ctime, | ||||
**h.digest()} | **h.digest()} | ||||
if status == 'absent': | if status == 'absent': | ||||
content['reason'] = 'why not' | content['reason'] = 'why not' | ||||
content['data'] = b'' | content['data'] = None | ||||
return content | return content | ||||
def gen_contents(n=20) -> List[Dict]: | def gen_contents(n=20) -> List[Dict]: | ||||
"""Returns a list of n randomly generated content objects (as dict) suitable | """Returns a list of n randomly generated content objects (as dict) suitable | ||||
for using as Storage.content_add() argument. | for using as Storage.content_add() argument. | ||||
""" | """ | ||||
return [gen_content() for i in range(n)] | return [gen_content() for i in range(n)] |