Exemplo n.º 1
0
 def test_serialize_with_model_appends(self):
     User.__appends__ = ["meta"]
     user = User.hydrate({"name": "Joe", "id": 1})
     serialized = user.serialize()
     self.assertEqual(serialized["id"], 1)
     self.assertEqual(serialized["name"], "Joe")
     self.assertEqual(serialized["meta"]["is_subscribed"], True)
 def test_can_get_accessor(self):
     user = User.hydrate(
         {"name": "joe", "email": "*****@*****.**", "is_admin": 1}
     )
     self.assertEqual(user.email, "*****@*****.**")
     self.assertEqual(user.name, "Hello, joe")
     self.assertTrue(user.is_admin is True, f"{user.is_admin} is not True")
Exemplo n.º 3
0
        def test_set_as_date(self):
            user = User.hydrate({
                "name": "Joe",
                "created_at": "2020-11-28 11:42:07"
            })

            self.assertTrue(user.created_at)
            self.assertTrue(user.created_at.is_future())
Exemplo n.º 4
0
        def test_serialize_with_on_the_fly_appends(self):
            user = User.hydrate({"name": "Joe", "id": 1})

            user.set_appends(["meta"])

            serialized = user.serialize()
            self.assertEqual(serialized["id"], 1)
            self.assertEqual(serialized["name"], "Joe")
            self.assertEqual(serialized["meta"]["is_subscribed"], True)
Exemplo n.º 5
0
        def test_access_as_date(self):
            user = User.hydrate({
                "name":
                "Joe",
                "created_at":
                datetime.datetime.now() + datetime.timedelta(days=1),
            })

            self.assertTrue(user.created_at)
            self.assertTrue(user.created_at.is_future())
Exemplo n.º 6
0
        def test_set_as_date(self):
            user = User.hydrate({
                "name":
                "Joe",
                "created_at":
                pendulum.now().add(days=10).to_datetime_string(),
            })

            self.assertTrue(user.created_at)
            self.assertTrue(user.created_at.is_future())
Exemplo n.º 7
0
        def test_serialize_with_date(self):
            user = User.hydrate({"name": "Joe", "created_at": pendulum.now()})

            self.assertTrue(json.dumps(user.serialize()))