Exemplo n.º 1
0
    def test_multi_object(self, connection):
        obj = mro.test_type(varchar = 'init')
        obj2 = mro.test_type(varchar = 'init')

        obj.varchar = '1'
        obj.varchar2 = '2'

        assert obj.varchar != obj.varchar2

        obj.varchar = '1'
        obj2.varchar = '2'

        assert obj.varchar != obj2.varchar
Exemplo n.º 2
0
    def test_not_null(self, connection):
        obj = mro.test_type(varchar = 'init')

        obj.varchar = '1'
        assert obj.varchar == '1'
        with pytest.raises(ValueError) as excinfo:
            obj.varchar_not_null = None
        assert excinfo.value.args[0] == 'The value of [{}] cannot be null.'.format('varchar_not_null')
Exemplo n.º 3
0
    def test_real(self, connection):
        obj = mro.test_type(varchar = 'init')

        obj.real = 2.0
        assert obj.real == 2.0
        with pytest.raises(TypeError) as excinfo:
            obj.real = '1'
        assert excinfo.value.args[0] == 'Value should be of type [float] not [{}]'.format(str.__name__)
Exemplo n.º 4
0
    def test_text(self, connection):
        obj = mro.test_type(varchar = 'init')

        obj.text = '1'
        assert obj.text == '1'
        with pytest.raises(TypeError) as excinfo:
            obj.text = 1
        assert excinfo.value.args[0] == 'Value should be of type [str] not [{}]'.format(int.__name__)
Exemplo n.º 5
0
    def test_datetime(self, connection):
        obj = mro.test_type(varchar = 'init')

        obj.timestamp = datetime(2015, 12, 21, 17, 20)
        assert obj.timestamp == datetime(2015, 12, 21, 17, 20)
        with pytest.raises(TypeError) as excinfo:
            obj.timestamp = date(2015, 12, 21)
        assert excinfo.value.args[0] == 'Value should be of type [datetime] not [{}]'.format(date.__name__)
Exemplo n.º 6
0
    def test_boolean(self, connection):
        obj = mro.test_type(varchar = 'init')

        obj.boolean = True
        assert obj.boolean == True
        with pytest.raises(TypeError) as excinfo:
            obj.boolean = 1
        assert excinfo.value.args[0] == 'Value should be of type [bool] not [{}]'.format(int.__name__)
Exemplo n.º 7
0
    def test_integer(self, connection):
        obj = mro.test_type(varchar = 'init')

        obj.integer = 1
        assert obj.integer == 1
        with pytest.raises(TypeError) as excinfo:
            obj.integer = '1'
        assert excinfo.value.args[0] == 'Value should be of type [int] not [{}]'.format(str.__name__)
Exemplo n.º 8
0
    def test_not_updateable(self, connection):
        raise Exception("Not implemented")
        obj = mro.test_type(varchar = 'init')

        obj.varchar = '1'
        assert obj.varchar == '1'
        with pytest.raises(PermissionError) as excinfo:
            obj.varchar_not_updateble = '2'
        assert excinfo.value.args[0] == 'The value of [{}] is not updateable.'.format('varchar_not_updateble')
Exemplo n.º 9
0
    def test_jsonb(self, connection):
        obj = mro.test_type(varchar = 'init')

        obj.jsonb = '{"key": "value"}'
        assert obj.jsonb == '{"key": "value"}'
        with pytest.raises(psycopg2.DataError) as excinfo:
            obj.jsonb = 'this is just text'
        assert excinfo.value.args[0].startswith('invalid input syntax for type json')
        connection.rollback()
Exemplo n.º 10
0
    def test_varchar(self, connection):
        obj = mro.test_type(varchar = 'init')

        message = 'sldkhfaskjf ashdkfjahs dfkjashd'

        with pytest.raises(ValueError) as excinfo:
            obj.varchar = message
            message = 'Hey'
        assert excinfo.value.args[0] == 'Value length [{}] should not exceed [{}]'.format(len(message), 15)

        message = mro.test_type(varchar = 'init')

        with pytest.raises(TypeError) as excinfo:
            obj.varchar = message
        assert excinfo.value.args[0] == 'Value should be of type [str] not [{}]'.format(message.__class__ .__name__)

        message = 'Hello World!'

        obj.varchar = message

        assert obj.varchar == message