Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
seller = db.EmbeddedDocumentField(Seller)
@classmethod
def generate_test_data(cls, additional_suffix=""):
"""Generate test data."""
return cls(
seller=Seller.generate_test_data(additional_suffix),
price=1000000
)
class Article(Dictable, gj.Document):
"""Test schema."""
user = db.ReferenceField(User)
addition = db.EmbeddedDocumentField(ArticleMetaData)
title = db.StringField()
date = db.DateTimeField()
body = db.BinaryField()
uuid = db.UUIDField()
@classmethod
def generate_test_data(cls, user=None, additional_suffix=""):
"""Generate test data."""
return cls(
pk=ObjectId(),
user=user or User.generate_test_data(additional_suffix),
title=("Test Tile{}").format(
(" {}").format(additional_suffix) if additional_suffix else ""
),
date=now - timedelta(microseconds=now.microsecond % 1000),
body=Binary(b"\x00\x01\x02\x03\x04"),
def test_embedded_document_field_only_allow_subclasses_of_embedded_document(self):
# Relates to #1661
class MyDoc(Document):
name = StringField()
with self.assertRaises(ValidationError):
class MyFailingDoc(Document):
emb = EmbeddedDocumentField(MyDoc)
with self.assertRaises(ValidationError):
class MyFailingdoc2(Document):
emb = EmbeddedDocumentField("MyDoc")
# department_id = me.StringField()
# eg. Byron Weber
first_name = me.StringField(required=True)
# eg. Becker
last_name = me.StringField(required=True)
# eg. ['MATH', 'CS']
departments_taught = me.ListField(me.StringField())
clarity = me.EmbeddedDocumentField(_rating.AggregateRating,
default=_rating.AggregateRating())
easiness = me.EmbeddedDocumentField(_rating.AggregateRating,
default=_rating.AggregateRating())
passion = me.EmbeddedDocumentField(_rating.AggregateRating,
default=_rating.AggregateRating())
@classmethod
def get_id_from_name(cls, first_name, last_name=None):
if not last_name:
return re.sub(r'\s+', '_', first_name.lower())
first_name = first_name.lower()
last_name = last_name.lower()
return re.sub(r'\s+', '_', '%s %s' % (first_name, last_name))
@staticmethod
def guess_names(combined_name):
"""Returns first, last name given a string."""
names = re.split(r'\s+', combined_name)
return (' '.join(names[:-1]), names[-1])
desc = me.StringField(required=True)
class BannerCourse(me.DynamicDocument):
creation_date = me.DateTimeField()
semester = me.StringField(required=True)
number = me.StringField(required=True)
full_number = me.StringField(required=True)
crn = me.StringField(required=True)
dept = me.EmbeddedDocumentField(BannerDepartment, required=True)
title = me.StringField(required=True)
seats_available = me.IntField()
seats_total = me.IntField()
meeting = me.ListField(me.EmbeddedDocumentField(CourseMeeting))
description = me.StringField(required=True)
instructors = me.ListField(me.EmbeddedDocumentField(CourseInstructor))
prerequisites = me.StringField()
exam_time = me.StringField()
exam_date = me.StringField()
exam_location = me.StringField()
exam_group = me.StringField()
critical_review_website = me.StringField()
class NonconflictEntry(me.DynamicDocument):
course_id = me.ObjectIdField(required=True)
non_conflicting = me.ListField(me.ObjectIdField())
score = db.IntField(required=False, default=80)
class Fuzzy(db.Document):
value = db.StringField(required=True, unique=True)
likelihood = db.IntField(required=True)
score = db.IntField(required=False, default=80)
class Matching(db.EmbeddedDocument):
name = db.StringField(required=True, choices=matching_types)
value = db.StringField(required=True, max_length=500)
data = db.DictField()
class Matches(db.Document):
timestamp = db.DateTimeField(required=False, default=datetime.datetime.now)
datasource = db.StringField(max_length=50, required=True, choices=source_options)
matching = db.EmbeddedDocumentField(Matching)
url = db.StringField(max_length=1000, required=True)
frequency = db.IntField(required=False, default=900)
enabled = db.BooleanField(required=False, default=False)
meta = {
'ordering': ['-timestamp'],
}
"id"],
'hidden_fields': [],
'linked_fields': ["source", "campaign"],
'details_link': 'details',
'no_sort': ['details']
}
}
disassembly_type = StringField()
description = StringField()
filedata = getFileField(collection_name=settings.COL_DISASSEMBLY)
filename = StringField()
link_id = UUIDField(binary=True, required=True, default=uuid.uuid4)
md5 = StringField()
filename = StringField()
tool = EmbeddedDocumentField(EmbeddedTool)
version = IntField(default=0)
def migrate(self):
"""
Migrate to the latest schema version.
"""
pass
def add_file_data(self, file_data):
"""
Add filedata to Disassembly.
:param file_data: The disassembly data to add.
:type file_data: str
"""
# TLOs
Actor = EmbeddedDocumentField(ActorAccess, required=True,
default=ActorAccess())
ActorIdentifier = EmbeddedDocumentField(ActorIdentifierAccess,
required=True,
default=ActorIdentifierAccess())
Backdoor = EmbeddedDocumentField(BackdoorAccess, required=True,
default=BackdoorAccess())
Campaign = EmbeddedDocumentField(CampaignAccess, required=True,
default=CampaignAccess())
Certificate = EmbeddedDocumentField(CertificateAccess, required=True,
default=CertificateAccess())
Domain = EmbeddedDocumentField(DomainAccess, required=True,
default=DomainAccess())
Email = EmbeddedDocumentField(EmailAccess, required=True,
default=EmailAccess())
Event = EmbeddedDocumentField(EventAccess, required=True,
default=EventAccess())
Exploit = EmbeddedDocumentField(ExploitAccess, required=True,
default=ExploitAccess())
Indicator = EmbeddedDocumentField(IndicatorAccess, required=True,
default=IndicatorAccess())
IP = EmbeddedDocumentField(IPAccess, required=True,
default=IPAccess())
PCAP = EmbeddedDocumentField(PCAPAccess, required=True,
default=PCAPAccess())
RawData = EmbeddedDocumentField(RawDataAccess, required=True,
default=RawDataAccess())
Sample = EmbeddedDocumentField(SampleAccess, required=True,
default=SampleAccess())
Signature = EmbeddedDocumentField(SignatureAccess, required=True,
class Storage(EmbeddedDocument):
free = IntField(default=0)
usage = IntField(default=0)
total = IntField(default=0)
class Network(EmbeddedDocument):
inbound = IntField(default=0)
outbound = IntField(default=0)
class Datas(Document):
timestamp = DateTimeField(default=datetime.utcnow)
mac_addr = StringField()
cpu = EmbeddedDocumentField(CPU)
memory = EmbeddedDocumentField(Memory)
storage = EmbeddedDocumentField(Storage)
network = EmbeddedDocumentField(Network)
class Devices(Document):
mac_addr = StringField()
start = DateTimeField()
end = DateTimeField()
count = IntField()
def spread_data(data):
result = dict()
result.update(spread_cpu(data.cpu))
result.update(spread_storage(data.storage))
department_id = me.StringField(required=True)
# eg. 121l
number = me.StringField(required=True)
# eg. Introductory Earth Sciences Laboratory 1
name = me.StringField(required=True)
# Description about the course
description = me.StringField(required=True)
easiness = me.EmbeddedDocumentField(rating.AggregateRating, default=rating.AggregateRating())
interest = me.EmbeddedDocumentField(rating.AggregateRating, default=rating.AggregateRating())
usefulness = me.EmbeddedDocumentField(rating.AggregateRating, default=rating.AggregateRating())
# TODO(mack): deprecate overall rating
overall = me.EmbeddedDocumentField(rating.AggregateRating, default=rating.AggregateRating())
professor_ids = me.ListField(me.StringField())
antireqs = me.StringField()
coreqs = me.StringField()
prereqs = me.StringField()
# NOTE: The word term is overloaded based on where it's used. Here, it mean
# which terms of the year is the course being offered?
# e.g. ['01', '05', '09']
terms_offered = me.ListField(me.StringField())
# eg. ['earth', '121l', 'earth121l', 'Introductory', 'Earth' 'Sciences', 'Laboratory', '1']
_keywords = me.ListField(me.StringField(), required=True)
@property
# eg. byron_weber_becker
id = me.StringField(primary_key=True)
# TODO(mack): available in menlo data
# department_id = me.StringField()
# eg. Byron Weber
first_name = me.StringField(required=True)
# eg. Becker
last_name = me.StringField(required=True)
# eg. ['MATH', 'CS']
departments_taught = me.ListField(me.StringField())
clarity = me.EmbeddedDocumentField(_rating.AggregateRating,
default=_rating.AggregateRating())
easiness = me.EmbeddedDocumentField(_rating.AggregateRating,
default=_rating.AggregateRating())
passion = me.EmbeddedDocumentField(_rating.AggregateRating,
default=_rating.AggregateRating())
@classmethod
def get_id_from_name(cls, first_name, last_name=None):
if not last_name:
return re.sub(r'\s+', '_', first_name.lower())
first_name = first_name.lower()
last_name = last_name.lower()
return re.sub(r'\s+', '_', '%s %s' % (first_name, last_name))
@staticmethod