Example #1
0
    def test_set_types(self):
        """
        Tests the _set_types method, making sure we set the correct types for each type.

        """
        base = Base()
        base.field_map = GENERIC_FIELDS
        base._create_total_map()
        base._set_defaults()
        base.field_three = 1
        base.field_five = '5'
        base.field_six = datetime(2020, 1, 1)
        base.field_seven = 0

        # check that ints and bools are converted where possible.
        base._set_types()
        assert base.field_three == True
        assert base.field_five == 5
        assert base.field_seven == False
        # assert type(base.field_six) == 'datetime'

        base.field_five = 'five'
        with pytest.raises(AttributeError):
            base._set_types()

        # reset field_five, set field_seven to string 0 to see if it converts to negative bool
        base.field_three = 'True'
        base.field_five = 5
        base.field_seven = 'false'
        base._set_types()
        assert base.field_three
        assert base.field_seven == False
Example #2
0
    def test_set_defaults(self):
        """
        Tests the _set_defaults method, making sure we set the default values for fields in the
        field map on the class.

        """
        base = Base()
        base.field_map = GENERIC_FIELDS
        base._create_total_map()
        assert base._set_defaults()
        assert base.field_three == False
        assert base.field_four == 'test'
        assert base.field_five == 7