Unverified Commit 511ad440 authored by Dylan Jones's avatar Dylan Jones
Browse files

what is this, some kind of real project with docstrings???

parent 5930bcc4
......@@ -9,11 +9,25 @@ class FieldType(enum.Enum):
RATING = {'num_reviews': int, 'average_rating': float}
def validate(self, data):
Given an instance of a value, verfiy that the instance satisfies the
schema for this primitive type. e.g. if FieldType.STRING.validate was
called, it would make sure that the `data` parameter looked like
"value": "some string"
This method throws a ValueError if the passed value doesn't conform to the
:param data: the instance of this primitive to validate.
:raises ValueError: if the passed data is incorrect
if type(data) is not dict:
raise ValueError("YA DONE GOOFED. NEED A DICT.")
for field in self.value:
if field not in data:
raise ValueError(f"Fields of type {self.name} need a {field} field")
self.value[field](data[field]) # This will throw ValueError if it fails to validate
if type(data[field]) is not self.value[field]:
raise ValueError(f"Expecting field of type {self.value[field]}, got {type(data[field])}")
if len(data) != len(self.value):
raise ValueError(f"Too many fields for field of type {self.name}")
......@@ -29,7 +29,7 @@ class Base(object):
class Point(Base):
TODO docstring
Represents actual instances of any and all points on the map.
__tablename__ = 'point'
name = Column(String, nullable=True)
......@@ -62,7 +62,7 @@ class Point(Base):
class Category(Base):
Represent a schema for a single category of objects (e.g. water fountain)
Represent a schema for a single category of objects (e.g. water fountain or bathroom)
__tablename__ = 'category'
......@@ -74,7 +74,7 @@ class Category(Base):
class Field(Base):
Represent a field that can be on an ObjectType schema
Represents a single field in the Category schema.
__tablename__ = 'field'
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment