forked from openedx-unsupported/ecommerce
-
Notifications
You must be signed in to change notification settings - Fork 0
/
conftest.py
320 lines (283 loc) · 10.4 KB
/
conftest.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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
import pytest
from django.core.management import call_command
from oscar.core.loading import get_model
from oscar.core.utils import slugify
from ecommerce.core.constants import (
COUPON_PRODUCT_CLASS_NAME,
COURSE_ENTITLEMENT_PRODUCT_CLASS_NAME,
ENROLLMENT_CODE_PRODUCT_CLASS_NAME,
SEAT_PRODUCT_CLASS_NAME
)
from ecommerce.extensions.basket.constants import EMAIL_OPT_IN_ATTRIBUTE, PURCHASER_BEHALF_ATTRIBUTE
from ecommerce.extensions.catalogue.utils import create_subcategories
from ecommerce.extensions.checkout.signals import BUNDLE
from ecommerce.core.constants import ORDER_MANAGER_ROLE
from ecommerce.core.constants import DONATIONS_FROM_CHECKOUT_TESTS_PRODUCT_TYPE_NAME
from ecommerce.core.constants import ENTERPRISE_COUPON_ADMIN_ROLE
COUPON_CATEGORY_NAME = 'Coupons'
DEFAULT_CATEGORIES = [
'Affiliate Promotion', 'Bulk Enrollment', 'ConnectEd', 'Course Promotion',
'Customer Service', 'Financial Assistance', 'Geography Promotion',
'Marketing Partner Promotion', 'Marketing-Other', 'Paid Cohort', 'Other',
'Retention Promotion', 'Services-Other', 'Support-Other', 'Upsell Promotion',
'Bulk Enrollment - Prepay',
'Bulk Enrollment - Upon Redemption',
'Bulk Enrollment - Integration',
'On-Campus Learners',
'Partner No Rev - Prepay',
'Partner No Rev - Upon Redemption',
'Security Disclosure Reward',
'Partner No Rev - RAP',
'Partner No Rev - ORAP',
'B2B Affiliate Promotion',
'Scholarship',
'edX Employee Request',
]
@pytest.fixture(scope='session')
def django_db_setup(django_db_setup, django_db_blocker, django_db_use_migrations):
if django_db_use_migrations:
return
with django_db_blocker.unblock():
BasketAttributeType = get_model('basket', 'BasketAttributeType')
Category = get_model("catalogue", "Category")
ProductAttribute = get_model("catalogue", "ProductAttribute")
ProductClass = get_model("catalogue", "ProductClass")
Option = get_model("catalogue", "Option")
EcommerceFeatureRole = get_model('core', 'EcommerceFeatureRole')
Condition = get_model('offer', 'Condition')
Benefit = get_model('offer', 'Benefit')
ConditionalOffer = get_model('offer', 'ConditionalOffer')
BasketAttributeType.objects.get_or_create(name=EMAIL_OPT_IN_ATTRIBUTE)
BasketAttributeType.objects.get_or_create(name=PURCHASER_BEHALF_ATTRIBUTE)
BasketAttributeType.objects.get_or_create(name=BUNDLE)
for klass in (Category, ProductAttribute, ProductClass, Option):
klass.skip_history_when_saving = True
# Create a new product class for course seats
seat, _ = ProductClass.objects.get_or_create(
track_stock=False,
requires_shipping=False,
name=SEAT_PRODUCT_CLASS_NAME,
slug=slugify(SEAT_PRODUCT_CLASS_NAME)
)
# Create product attributes for course seat products
ProductAttribute.objects.get_or_create(
product_class=seat,
name="course_key",
code="course_key",
type="text",
required=True
)
ProductAttribute.objects.get_or_create(
product_class=seat,
name="id_verification_required",
code="id_verification_required",
type="boolean",
required=False
)
ProductAttribute.objects.get_or_create(
product_class=seat,
name="certificate_type",
code="certificate_type",
type="text",
required=False
)
# Create a category for course seats
Category.objects.get_or_create(
description="All course seats",
numchild=1,
slug="seats",
depth=1,
path="0001",
image="",
name="Seats"
)
ProductAttribute.objects.get_or_create(
product_class=seat,
name='credit_provider',
code='credit_provider',
type='text',
required=False
)
ProductAttribute.objects.get_or_create(
product_class=seat,
name='credit_hours',
code='credit_hours',
type='integer',
required=False
)
Option.objects.get_or_create(
name='Course Entitlement',
code='course_entitlement',
type=Option.OPTIONAL,
)
coupon, _ = ProductClass.objects.get_or_create(
track_stock=False,
requires_shipping=False,
name=COUPON_PRODUCT_CLASS_NAME,
slug=slugify(COUPON_PRODUCT_CLASS_NAME),
)
ProductAttribute.objects.get_or_create(
product_class=coupon,
name='Coupon vouchers',
code='coupon_vouchers',
type='entity',
required=False
)
# Create a category for coupons.
Category.objects.get_or_create(
description='All Coupons',
slug='coupons',
depth=1,
path='0002',
image='',
name='Coupons'
)
ProductAttribute.objects.create(
product_class=coupon,
name='Note',
code='note',
type='text',
required=False
)
ProductAttribute.objects.create(
product_class=coupon,
name='Notification Email',
code='notify_email',
type='text',
required=False
)
ProductAttribute.objects.create(
product_class=coupon,
name='Enterprise Customer UUID',
code='enterprise_customer_uuid',
type='text',
required=False
)
ProductAttribute.objects.create(
product_class=coupon,
name='Enterprise Contract Metadata',
code='enterprise_contract_metadata',
type='entity',
required=False
)
ProductAttribute.objects.create(
product_class=coupon,
name='Inactive',
code='inactive',
type=ProductAttribute.BOOLEAN,
required=False
)
ProductAttribute.objects.create(
product_class=coupon,
name='Sales Force ID',
code='sales_force_id',
type='text',
required=False
)
ProductAttribute.objects.create(
product_class=coupon,
name='Is Public Code?',
code='is_public_code',
type='boolean',
required=False
)
# Create a new product class for course entitlement
course_entitlement, _ = ProductClass.objects.get_or_create(
track_stock=False,
requires_shipping=False,
name=COURSE_ENTITLEMENT_PRODUCT_CLASS_NAME,
slug=slugify(COURSE_ENTITLEMENT_PRODUCT_CLASS_NAME)
)
# Create product attributes for course entitlement products
ProductAttribute.objects.get_or_create(
product_class=course_entitlement,
name="UUID",
code="UUID",
type="text",
required=True
)
ProductAttribute.objects.get_or_create(
product_class=course_entitlement,
name="certificate_type",
code="certificate_type",
type="text",
required=False
)
ProductAttribute.objects.get_or_create(
product_class=course_entitlement,
name='id_verification_required',
code='id_verification_required',
type='boolean',
required=False
)
try:
Category.objects.get(name="Course Entitlements")
except Category.DoesNotExist:
# Create a category for course entitlements
Category.add_root(
description="All course entitlements",
slug="course_entitlements",
image="",
name="Course Entitlements"
)
enrollment_code, _ = ProductClass.objects.get_or_create(
track_stock=False,
requires_shipping=False,
name=ENROLLMENT_CODE_PRODUCT_CLASS_NAME,
slug=slugify(ENROLLMENT_CODE_PRODUCT_CLASS_NAME),
)
ProductAttribute.objects.get_or_create(
product_class=enrollment_code,
name='Course Key',
code='course_key',
type='text',
required=True
)
ProductAttribute.objects.get_or_create(
product_class=enrollment_code,
name='Seat Type',
code='seat_type',
type='text',
required=True
)
ProductAttribute.objects.get_or_create(
product_class=enrollment_code,
name='id_verification_required',
code='id_verification_required',
type='boolean',
required=False
)
EcommerceFeatureRole.objects.get_or_create(name=ORDER_MANAGER_ROLE)
new_dynamic_condition, _ = Condition.objects.get_or_create(
proxy_class='ecommerce.extensions.offer.dynamic_conditional_offer.DynamicDiscountCondition'
)
# The value doesn't matter, because it's dynamic, but oscar will complain without one.
new_dynamic_benefit, _ = Benefit.objects.get_or_create(
value=1,
proxy_class='ecommerce.extensions.offer.dynamic_conditional_offer.DynamicPercentageDiscountBenefit'
)
ConditionalOffer.objects.get_or_create(
name='dynamic_conditional_offer',
benefit=new_dynamic_benefit,
condition=new_dynamic_condition,
max_basket_applications=1,
priority=-10
)
# Create a new product class for donations for the donations from checkout tests
ProductClass.objects.get_or_create(
track_stock=False,
requires_shipping=False,
name=DONATIONS_FROM_CHECKOUT_TESTS_PRODUCT_TYPE_NAME,
slug=slugify(DONATIONS_FROM_CHECKOUT_TESTS_PRODUCT_TYPE_NAME)
)
try:
Category.objects.get(name="Donations")
except Category.DoesNotExist:
Category.add_root(
description="All donations",
slug="donations",
image="",
name="Donations"
)
EcommerceFeatureRole.objects.get_or_create(name=ENTERPRISE_COUPON_ADMIN_ROLE)
create_subcategories(Category, COUPON_CATEGORY_NAME, DEFAULT_CATEGORIES)