-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_utils.py
207 lines (159 loc) · 6.08 KB
/
test_utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
from django.utils import timezone
from datetime import date
from organization.models import Organization, Channel, Plan, Bill
from hub_auth.models import Account, APIKey
from video.models import Media, LiveVideo, LiveVideoCut, Tag
def create_organizations(name, org_quantity, bucket_name='', contact_email='', cf_id='',
cf_domain='', plan=None, config=None):
organizations = []
for number in range(1, org_quantity + 1):
org = Organization.objects.create(
name=f'{name} {number}',
bucket_name=bucket_name,
contact_email=contact_email,
cf_id=cf_id,
cf_domain=cf_domain,
plan=plan,
config=config if config else {}
)
organizations.append(org)
return organizations
def create_user(username, password, organization):
user = Account.objects.create_user(
username=username,
password=password,
organization=organization,
email=f'{username}@admin.com'
)
return user
def create_superuser(username, password, organization):
su = Account.objects.create_superuser(
username=username,
password=password,
organization=organization,
email='admin@admin.com'
)
return su
def create_key(name, user):
key = APIKey.objects.create(
name=f'{name}',
account=user,
)
return key
def create_channels(name, organization, quantity, allowed_domains=[],
ads_vast_url=None, detect_adblock=False, autoplay=False,
cf_domain='domain.cloudfront.com'):
channels = []
for number in range(1, quantity + 1):
channel = Channel.objects.create(
name=f'{name} {number}',
organization=organization,
allowed_domains=allowed_domains,
ads_vast_url=ads_vast_url,
detect_adblock=detect_adblock,
autoplay=autoplay,
cf_domain=f'{number}.{cf_domain}',
cf_id=f'my_cf_id_{number}'
)
channels.append(channel)
return channels
def create_videos(name, created_by, organization, quantity, state=Media.State.WAITING_FILE,
metadata=None, ads_vast_url=None, enable_ads=True, autoplay='c',
created_at=None, media_type='video'):
videos = []
for number in range(1, quantity + 1):
video = create_video(name, created_by, organization, number, state, metadata, ads_vast_url,
enable_ads, autoplay, created_at, media_type)
videos.append(video)
return videos
def create_live_videos(name, created_by, organization, quantity, state=LiveVideo.State.OFF,
metadata=None, ads_vast_url=None, enable_ads=True, autoplay='c',
created_at=None, ml_channel_arn='', input_state=[]):
lives = []
for number in range(1, quantity + 1):
live = create_live_video(name, created_by, organization, number, state, metadata,
ads_vast_url,
enable_ads, autoplay, created_at, ml_channel_arn, input_state)
lives.append(live)
return lives
def create_tags(name, organization, quantity):
tags = []
for number in range(1, quantity + 1):
tag = Tag.objects.create(
name=f'{name} {number}',
organization=organization
)
tags.append(tag)
return tags
def create_live_cut(live, initial_time, final_time, description='',
state=LiveVideoCut.State.SCHEDULED):
return LiveVideoCut.objects.create(
live=live,
initial_time=initial_time,
final_time=final_time,
description=description,
state=state
)
def add_channel_to_video(channel, video):
video.channel = channel
video.save()
def add_channel_to_live_video(channel, live):
live.channel = channel
live.save()
def create_video(name, created_by, organization, number, state=Media.State.WAITING_FILE,
metadata=None, ads_vast_url=None, enable_ads=True, autoplay='c',
created_at=None, media_type='video'):
video = Media.objects.create(
name=f'{name} {number}',
created_by=created_by,
organization=organization,
state=state,
metadata=metadata if metadata else {},
ads_vast_url=ads_vast_url,
enable_ads=enable_ads,
autoplay=autoplay,
created_at=created_at if created_at else timezone.now(),
media_type=media_type
)
return video
def create_live_video(name, created_by, organization, number, state=LiveVideo.State.OFF,
metadata=None, ads_vast_url=None, enable_ads=True, autoplay='c',
created_at=None, ml_channel_arn='', input_state=[]):
live = LiveVideo.objects.create(
name=f'{name} {number}',
created_by=created_by,
organization=organization,
state=state,
metadata=metadata if metadata else {},
ads_vast_url=ads_vast_url,
enable_ads=enable_ads,
autoplay=autoplay,
created_at=created_at if created_at else timezone.now(),
ml_channel_arn=ml_channel_arn,
input_state=input_state
)
return live
def create_plans(name, quantity, description='', storage=0, video_transcoding=0, audio_transcoding=0, data_transfer=0):
plans = []
for number in range(1, quantity + 1):
plan = Plan.objects.create(
name=f'{name} {number}',
description=description,
storage=storage,
video_transcoding=video_transcoding,
audio_transcoding=audio_transcoding,
data_transfer=data_transfer
)
plans.append(plan)
return plans
def create_bill(organization, plan, month=date.today().replace(day=1), storage=0, video_transcoding=0,
data_transfer=0):
bill = Bill.objects.create(
organization=organization,
plan=plan,
date=month,
storage=storage,
video_transcoding=video_transcoding,
data_transfer=data_transfer
)
return bill