Fix e2e tests (allow BetaLogin endpoint, add licenses)
This commit is contained in:
parent
a2df6ff7bd
commit
050ca414a8
|
|
@ -12,7 +12,6 @@ from wagtail.core.models import Page
|
|||
from books.factories import BookFactory, TopicFactory, ModuleFactory, ChapterFactory, ContentBlockFactory
|
||||
from core.factories import UserFactory
|
||||
from objectives.factories import ObjectiveGroupFactory, ObjectiveFactory
|
||||
from users.models import Role
|
||||
from users.services import create_users, create_student
|
||||
|
||||
from .data.module_data import data
|
||||
|
|
|
|||
|
|
@ -39,9 +39,7 @@ def is_private_api_call_allowed(user, body):
|
|||
except AttributeError:
|
||||
return False
|
||||
|
||||
# logout, me and coupon resources are always allowed. Even if the user has no valid license
|
||||
if re.search(r"mutation\s*.*\s*logout\s*{", body_unicode) or re.search(r"query\s*.*\s*me\s*{", body_unicode) \
|
||||
or re.search(r"mutation\s*Coupon", body_unicode):
|
||||
if is_endpoint_allowed(body_unicode):
|
||||
return True
|
||||
|
||||
license_expiry = user.license_expiry_date
|
||||
|
|
@ -53,6 +51,12 @@ def is_private_api_call_allowed(user, body):
|
|||
return True
|
||||
|
||||
|
||||
# logout, betalogin, me and coupon resources are always allowed. Even if the user has no valid license
|
||||
def is_endpoint_allowed(body):
|
||||
return re.search(r"mutation\s*.*\s*logout\s*{", body) or re.search(r"query\s*.*\s*me\s*{", body) \
|
||||
or re.search(r"mutation\s*Coupon", body) or re.search(r"mutation\s*BetaLogin", body)
|
||||
|
||||
|
||||
def sync_hidden_for(model, school_class_template, school_class_to_sync):
|
||||
if model.hidden_for.filter(id=school_class_template.id).exists() and not model.hidden_for.filter(
|
||||
id=school_class_to_sync.id).exists():
|
||||
|
|
|
|||
|
|
@ -1,8 +1,11 @@
|
|||
import random
|
||||
from datetime import timedelta
|
||||
|
||||
import factory
|
||||
|
||||
from users.models import SchoolClass, SchoolClassMember, License, Team
|
||||
from django.utils.timezone import now
|
||||
|
||||
|
||||
class_types = ['DA', 'KV', 'INF', 'EE']
|
||||
class_suffix = ['A', 'B', 'C', 'D', 'E']
|
||||
|
|
@ -44,3 +47,6 @@ class TeamFactory(factory.django.DjangoModelFactory):
|
|||
class LicenseFactory(factory.django.DjangoModelFactory):
|
||||
class Meta:
|
||||
model = License
|
||||
|
||||
expire_date = now() + timedelta(days=7)
|
||||
order_id = factory.Sequence(lambda n: n)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,10 @@
|
|||
from datetime import timedelta
|
||||
|
||||
from django.utils.timezone import now
|
||||
|
||||
from core.factories import UserFactory
|
||||
from users.factories import SchoolClassFactory
|
||||
from users.factories import SchoolClassFactory, LicenseFactory
|
||||
from users.licenses import MYSKILLBOX_LICENSES
|
||||
from users.models import Role, UserRole, DEFAULT_SCHOOL_ID
|
||||
|
||||
|
||||
|
|
@ -47,6 +52,9 @@ def create_users(data=None):
|
|||
)
|
||||
|
||||
else:
|
||||
in_a_week = now() + timedelta(days=7)
|
||||
hep_id = 1
|
||||
|
||||
for school_class in data:
|
||||
first, last = school_class.get('teacher')
|
||||
teacher = UserFactory(
|
||||
|
|
@ -54,19 +62,26 @@ def create_users(data=None):
|
|||
first_name=first,
|
||||
last_name=last,
|
||||
email='{}.{}@skillbox.example'.format(first, last).lower(),
|
||||
onboarding_visited=True
|
||||
onboarding_visited=True,
|
||||
license_expiry_date=in_a_week,
|
||||
hep_id=hep_id
|
||||
)
|
||||
UserRole.objects.create(user=teacher, role=teacher_role)
|
||||
|
||||
students = []
|
||||
|
||||
for first, last in school_class.get('students'):
|
||||
hep_id += 1
|
||||
student = create_student(
|
||||
username='{}.{}'.format(first, last).lower(),
|
||||
first_name=first,
|
||||
last_name=last,
|
||||
email='{}.{}@skillbox.example'.format(first, last).lower(),
|
||||
onboarding_visited=True
|
||||
onboarding_visited=True,
|
||||
license_expiry_date=in_a_week,
|
||||
hep_id=hep_id
|
||||
)
|
||||
|
||||
students.append(student)
|
||||
|
||||
SchoolClassFactory(
|
||||
|
|
|
|||
Loading…
Reference in New Issue