Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_serializable_with_embedded_models_and_list():
class Question(Model):
id = LongType()
class QuestionPack(Model):
id = LongType()
questions = ListType(ModelType(Question))
class Game(Model):
id = StringType()
question_pack = ModelType(QuestionPack)
q1 = Question({"id": 1})
q2 = Question({"id": 2})
game = Game({
"id": "1",
"question_pack": {
"id": 2,
"questions": [q1, q2]
}
})
assert game.question_pack.questions[0] == q1
assert game.question_pack.questions[1] == q2
d = game.serialize()
def test_doesnt_fail_if_role_isnt_found_on_embedded_models():
class ExperienceLevel(Model):
level = IntType()
title = StringType()
class Options:
roles = {
"public": wholelist(),
}
class Player(Model):
id = StringType()
secret = StringType()
xp_level = ModelType(ExperienceLevel)
class Options:
roles = {
"public": blacklist("secret")
}
p = Player(dict(
id="1",
secret="super_secret",
xp_level={
"level": 1,
"title": "Starter"
}
))
d = p.serialize(role="public")
def test_model_type():
class C1(ResourceCollection):
foo = types.StringType(required=True)
def create_resources(self):
pass
class C2(ResourceCollection):
c1 = compound.ModelType(C1, required=True)
def create_resources(self):
pass
c1 = C1(foo="foo")
c2 = C2(c1=c1)
assert c2.c1.foo == "foo"
legalName_ru = StringType()
uri = URLType() # A URI to identify the organization.
class Organization(Model):
"""An organization."""
class Options:
roles = organization_roles
name = StringType(required=True)
name_en = StringType()
name_ru = StringType()
identifier = ModelType(BaseIdentifier, required=True)
additionalIdentifiers = ListType(ModelType(BaseIdentifier))
address = ModelType(Address, required=True)
contactPoint = ModelType(ContactPoint, required=True)
class BaseUnit(Model):
"""
Description of the unit which the good comes in e.g. hours, kilograms.
Made up of a unit name of a single unit.
"""
name = StringType()
name_en = StringType()
name_ru = StringType()
code = StringType(required=True)
class BasicValue(Model):
amount = DecimalType(required=True, min_value=0, precision=-2) # Amount as a number.
from schematics.types import StringType, BooleanType, DateType
from schematics.types.compound import ListType, ModelType
from mingus.service.models import BaseModel
class Todolist(BaseModel):
title = StringType(max_length=60, required=True)
tag = StringType(max_length=40)
checked = BooleanType(default=False)
created = DateType()
class User(BaseModel):
name = StringType(max_length=40, required=True)
todolist = ListType(ModelType(Todolist))
is_market_data_delayed = BooleanType(required=True)
status = EnumType(constants.MarketStatus)
bet_delay = IntType()
bsp_reconciled = BooleanType()
complete = BooleanType()
inplay = BooleanType()
number_of_winners = IntType()
number_of_runners = IntType()
number_of_active_runners = IntType()
last_match_time = DateTimeType()
total_matched = FloatType()
total_available = FloatType()
cross_matching = BooleanType()
runners_voidable = BooleanType()
version = FloatType()
runners = ListType(ModelType(Runner))
class RunnerProfitAndLoss(BetfairModel):
selection_id = IntType()
if_win = FloatType()
if_lose = FloatType()
class MarketProfitAndLoss(BetfairModel):
market_id = StringType()
commission_applied = FloatType()
profit_and_losses = ListType(ModelType(RunnerProfitAndLoss))
class ExBestOffersOverrides(BetfairModel):
best_prices_depth = IntType()
""" Describes a user who has participated in a project """
username = StringType()
project_id = LongType(serialized_name="projectId")
is_participant = BooleanType(serialized_name="isParticipant")
class UserSearchDTO(Model):
""" Paginated list of TM users """
def __init__(self):
super().__init__()
self.users = []
pagination = ModelType(Pagination)
users = ListType(ModelType(ListedUser))
class UserFilterDTO(Model):
""" DTO to hold all Tasking Manager users """
def __init__(self):
super().__init__()
self.usernames = []
self.users = []
pagination = ModelType(Pagination)
usernames = ListType(StringType)
users = ListType(ModelType(ProjectParticipantUser))
league = types.StringType()
roles = types.compound.ListType(types.StringType())
hands = types.compound.ModelType(PlayerHands)
class ProjectionLine(models.Model):
player = types.compound.ModelType(Player)
# enforce that "components" exists,
# but not its contents
components = types.compound.DictType(types.StringType)
class ProjectionSchematic(models.Model):
system = types.StringType()
season = types.IntType()
batting = types.compound.ModelType(ProjectionLine)
pitching = types.compound.ModelType(ProjectionLine)