def test_init(self): """Test successful DateTime Field initialization""" created_at = DateTime() assert created_at is not None value = datetime.now() assert value == created_at._load(value)
class Recalled(BaseEvent): email = String() sent_at = DateTime() class Meta: aggregate_cls = Email stream_name = "recalls"
class CommentViaWithReference(BaseEntity): content = Text() added_on = DateTime() posting = Reference("tests.aggregate.elements.PostVia") class Meta: aggregate_cls = PostViaWithReference
class CommentVia(BaseEntity): content = Text() added_on = DateTime() posting_id = String() class Meta: aggregate_cls = PostVia
class Post(BaseAggregate): title = String(required=True, max_length=1000) slug = String(required=True, max_length=1024) content = Text(required=True) posted_at = DateTime(required=True, default=datetime.now()) post_meta = HasOne("tests.repository.child_entities.PostMeta") comments = HasMany("tests.repository.child_entities.Comment")
class Comment(BaseEntity): content = Text() added_on = DateTime() post = Reference("Post") class Meta: aggregate_cls = Post
class Post(BaseAggregate): title = String(required=True, max_length=1000) slug = String(required=True, max_length=1024) content = Text(required=True) posted_at = DateTime(required=True, default=datetime.now()) meta = HasOne("tests.unit_of_work.aggregate_elements.PostMeta") comments = HasMany("tests.unit_of_work.aggregate_elements.Comment")
class Comment(BaseEntity): content = Text(required=True) commented_at = DateTime(required=True, default=datetime.now()) post = Reference(Post) class Meta: aggregate_cls = Post
def test_type_casting(self): """Test type casting and validation for the Field""" created_at = DateTime() today = datetime.now() # Test date being passed as value assert created_at._load(today.date()) == datetime( today.year, today.month, today.day) # Test string dates being passed as value assert created_at._load("2018-03-16") == datetime(2018, 3, 16) assert created_at._load("2018-03-16 10:23:32") == datetime( 2018, 3, 16, 10, 23, 32) # Test for invalid datetime with pytest.raises(ValidationError): assert created_at._load("2018-03-16 10 23 32")
class Sent(BaseEvent): email = String() sent_at = DateTime()
class Activated(BaseEvent): id = Identifier() activated_at = DateTime()
class Email(BaseEventSourcedAggregate): email = String() sent_at = DateTime()
class Post(BaseAggregate): title = String(required=True, max_length=1000) slug = String(required=True, max_length=1024) content = Text(required=True) posted_at = DateTime(required=True, default=datetime.utcnow)
class Login(BaseCommand): id = Identifier() activated_at = DateTime() class Meta: aggregate_cls = User
class LoggedIn(BaseEvent): id = Identifier() activated_at = DateTime() class Meta: aggregate_cls = User
class TimeStamped: created_at = DateTime(default=datetime.utcnow) updated_at = DateTime(default=datetime.utcnow) class Meta: abstract = True
def test_null_values(self): created_at = DateTime() assert created_at._load(None) is None assert created_at._load("") is None
class Person(BaseAggregate): first_name = String(max_length=50, required=True) last_name = String(max_length=50, required=True) age = Integer(default=21) created_at = DateTime(default=datetime.now())
class Role(BaseAggregate): name = String(max_length=15, required=True) created_on = DateTime(default=datetime.today())
class Event(BaseAggregate): name = String(max_length=255) created_at = DateTime(default=datetime.utcnow()) payload = Dict()
class Send(BaseCommand): email = String() sent_at = DateTime()
class Published(BaseEvent): id = Identifier(required=True) published_time = DateTime(default=datetime.utcnow) class Meta: aggregate_cls = Post
class Published(BaseEvent): id = Identifier(required=True) published_time = DateTime(default=datetime.utcnow)
class Activate(BaseCommand): id = Identifier() activated_at = DateTime()