Exemple #1
0
    def test_custom(self):
        boolean_array = types.Array(element_template=types.Boolean(),
                                    description="boolean")
        self.assertEqual(boolean_array.description, "boolean")

        float_array = types.Array(element_template=types.Float(),
                                  description="float")
        self.assertEqual(float_array.description, "float")

        integer_array = types.Array(element_template=types.Integer(),
                                    description="integer")
        self.assertEqual(integer_array.description, "integer")

        string_array = types.Array(element_template=types.String(),
                                   description="string")
        self.assertEqual(string_array.description, "string")

        date_array = types.Array(element_template=types.Date(),
                                 description="date")
        self.assertEqual(date_array.description, "date")

        datetime_array = types.Array(element_template=types.DateTime(),
                                     description="datetime")
        self.assertEqual(datetime_array.description, "datetime")

        time_array = types.Array(element_template=types.Date(),
                                 description="time")
        self.assertEqual(time_array.description, "time")
Exemple #2
0
    def test_data_structure(self):
        from datetime import date
        array_empty = types.Array(element_template=types.Date())
        self.assertEqual(array_empty.as_serializable(), [])

        array_dates = types.Array(element_template=types.Date())
        array_dates.append(date(2018, 1, 1))
        array_dates.append("2018-01-02")
        self.assertEqual(array_dates.as_serializable(),
                         ["2018-01-01", "2018-01-02"])
Exemple #3
0
 def test_custom(self):
     self.assertEqual(
         types.Array(element_template=types.Boolean(),
                     max_length=1).max_length, 1)
     self.assertEqual(
         types.Array(element_template=types.Float(),
                     max_length=2).max_length, 2)
     self.assertEqual(
         types.Array(element_template=types.Integer(),
                     max_length=3).max_length, 3)
     self.assertEqual(
         types.Array(element_template=types.String(),
                     max_length=4).max_length, 4)
     self.assertEqual(
         types.Array(element_template=types.Date(),
                     max_length=5).max_length, 5)
     self.assertEqual(
         types.Array(element_template=types.DateTime(),
                     max_length=6).max_length, 6)
     self.assertEqual(
         types.Array(element_template=types.Time(),
                     max_length=7).max_length, 7)
     self.assertEqual(
         types.Array(element_template=types.Model(),
                     max_length=8).max_length, 8)
Exemple #4
0
 def test_data_structure(self):
     self.assertIsNone(
         types.Array(element_template=types.Date()).attribute_rewrite_map())
     self.assertIsNone(
         types.Array(
             element_template=types.DateTime()).attribute_rewrite_map())
     self.assertIsNone(
         types.Array(element_template=types.Time()).attribute_rewrite_map())
Exemple #5
0
 class MyModel(types.Model):
     boolean = types.Boolean()
     date = types.Date()
     datetime = types.DateTime()
     float = types.Float()
     integer = types.Integer()
     string = types.String()
     sub = SubModel()
     time = types.Time()
Exemple #6
0
    def test_date_default(self):
        datetime_type = types.Date()

        blueprint = datetime_type.blueprint()
        blueprint["map_name"] = "a_b"
        datetime_meta = AttributeMetaData("created_date", blueprint)
        self.assertEqual(datetime_meta.name, "created_date")
        self.assertEqual(datetime_meta.map_name, "a_b")
        self.assertEqual(datetime_meta.cc, "CreatedDate")
        self.assertEqual(datetime_meta.ccif, "createdDate")
        self.assertEqual(datetime_meta.blueprint_type, "date")
        self.assertEqual(datetime_meta.client_class_name, "Date")
        self.assertEqual(datetime_meta.required, "true")
        self.assertEqual(datetime_meta.default, "null")
Exemple #7
0
    def test_data_structure(self):
        date_array = types.Array(element_template=types.Date())
        self.assertFalse(date_array.get_attribute_filter())
        self.assertFalse(date_array.get_attribute_filter(False))
        self.assertTrue(date_array.get_attribute_filter(True))

        datetime_array = types.Array(element_template=types.DateTime())
        self.assertFalse(datetime_array.get_attribute_filter())
        self.assertFalse(datetime_array.get_attribute_filter(False))
        self.assertTrue(datetime_array.get_attribute_filter(True))

        time_array = types.Array(element_template=types.Time())
        self.assertFalse(time_array.get_attribute_filter())
        self.assertFalse(time_array.get_attribute_filter(False))
        self.assertTrue(time_array.get_attribute_filter(True))
Exemple #8
0
 def test_default(self):
     self.assertIsNone(
         types.Array(element_template=types.Boolean()).min_length)
     self.assertIsNone(
         types.Array(element_template=types.Float()).min_length)
     self.assertIsNone(
         types.Array(element_template=types.Integer()).min_length)
     self.assertIsNone(
         types.Array(element_template=types.String()).min_length)
     self.assertIsNone(
         types.Array(element_template=types.Date()).min_length)
     self.assertIsNone(
         types.Array(element_template=types.DateTime()).min_length)
     self.assertIsNone(
         types.Array(element_template=types.Time()).min_length)
     self.assertIsNone(
         types.Array(element_template=types.Model()).min_length)
Exemple #9
0
    def test_date_given_values(self):
        datetime_type = types.Date(
            required=False,
            default=types.Date.TODAY
        )

        blueprint = datetime_type.blueprint()
        blueprint["map_name"] = "a_b"
        datetime_meta = AttributeMetaData("created_date", blueprint)
        self.assertEqual(datetime_meta.name, "created_date")
        self.assertEqual(datetime_meta.map_name, "a_b")
        self.assertEqual(datetime_meta.cc, "CreatedDate")
        self.assertEqual(datetime_meta.ccif, "createdDate")
        self.assertEqual(datetime_meta.blueprint_type, "date")
        self.assertEqual(datetime_meta.client_class_name, "Date")
        self.assertEqual(datetime_meta.required, "false")
        self.assertEqual(datetime_meta.default, "prestans.types.Date.TODAY")
Exemple #10
0
 def test_data_structure(self):
     self.assertFalse(types.Array(element_template=types.Date()).is_scalar)
     self.assertFalse(
         types.Array(element_template=types.DateTime()).is_scalar)
     self.assertFalse(types.Array(element_template=types.Time()).is_scalar)
Exemple #11
0
 class MyModel(types.Model):
     name = types.String()
     birthday = types.Date()
     tags = types.Array(element_template=types.String())
     sub = SubModel()
     sub_array = types.Array(element_template=SubModel())