Esempio n. 1
0
    def test_add_object(self):
        """
        Test storing object into the database.
        :return:
        """
        with patch("os.path.exists", MagicMock(return_value=False)), patch(
                "os.listdir", MagicMock(return_value=["some_table"])):
            writable = Writable()
            with patch("gzip.open",
                       MagicMock(return_value=writable)) as gzip_mock_open:
                obj = FoobarEntity()
                obj.foo = 123
                obj.bar = "test entity"
                obj.spam = 0.123

                csvdb = CsvDB("/foobar")
                csvdb.open()
                csvdb._tables = {
                    "some_table":
                    OrderedDict([
                        tuple(elm.split(":"))
                        for elm in ["foo:int", "bar:str", "spam:float"]
                    ])
                }
                csvdb.store(obj)

                # test the second call to gzip.open, the first is in the list_tables function
                assert gzip_mock_open.call_args_list[1][0][1] == "at"

                assert writable.data[0].strip() == "123,test entity,0.123"
Esempio n. 2
0
    def test_add_object(self):
        '''
        Test storing object into the database.
        :return:
        '''
        with patch("os.path.exists", MagicMock(return_value=False)), \
                patch("os.listdir", MagicMock(return_value=['some_table'])):
            writable = Writable()
            with patch("gzip.open", MagicMock(return_value=writable)):
                obj = FoobarEntity()
                obj.foo = 123
                obj.bar = 'test entity'
                obj.spam = 0.123

                csvdb = CsvDB('/foobar')
                csvdb.open()
                csvdb._tables = {
                    'some_table':
                    OrderedDict([
                        tuple(elm.split(':'))
                        for elm in ["foo:int", "bar:str", "spam:float"]
                    ])
                }
                csvdb.store(obj)
                assert writable.data[0].strip() == '123,test entity,0.123'
    def test_obj_validation(self):
        '''
        Test object validation.

        :return:
        '''
        obj = FoobarEntity()
        obj.foo = 123
        obj.bar = 'test entity'
        obj.spam = 0.123

        csvdb = CsvDB('/foobar')
        csvdb._tables = {'some_table': OrderedDict([tuple(elm.split(':'))
                                                    for elm in ["foo:int", "bar:str", "spam:float"]])}
        assert csvdb._validate_object(obj) == [123, 'test entity', 0.123]
Esempio n. 4
0
    def test_obj_validation(self):
        '''
        Test object validation.

        :return:
        '''
        with patch("os.path.exists", MagicMock(return_value=False)), \
                patch("os.listdir", MagicMock(return_value=['some_table'])):
            obj = FoobarEntity()
            obj.foo = 123
            obj.bar = 'test entity'
            obj.spam = 0.123

            csvdb = CsvDB('/foobar')
            csvdb._tables = {'some_table': OrderedDict([tuple(elm.split(':'))
                                                        for elm in ["foo:int", "bar:str", "spam:float"]])}
            assert csvdb._validate_object(obj) == [123, 'test entity', 0.123]
Esempio n. 5
0
    def test_add_object(self):
        '''
        Test storing object into the database.
        :return:
        '''
        writable = Writable()
        with patch("gzip.open", MagicMock(return_value=writable)):
            obj = FoobarEntity()
            obj.foo = 123
            obj.bar = 'test entity'
            obj.spam = 0.123

            csvdb = CsvDB('/foobar')
            csvdb.open()
            csvdb._tables = {'some_table': OrderedDict([tuple(elm.split(':'))
                                                        for elm in ["foo:int", "bar:str", "spam:float"]])}
            csvdb.store(obj)
            assert writable.data[0].strip() == '123,test entity,0.123'
Esempio n. 6
0
    def test_obj_validation(self):
        """
        Test object validation.

        :return:
        """
        with patch("os.path.exists", MagicMock(return_value=False)), patch(
                "os.listdir", MagicMock(return_value=["some_table"])):
            obj = FoobarEntity()
            obj.foo = 123
            obj.bar = "test entity"
            obj.spam = 0.123

            csvdb = CsvDB("/foobar")
            csvdb._tables = {
                "some_table":
                OrderedDict([
                    tuple(elm.split(":"))
                    for elm in ["foo:int", "bar:str", "spam:float"]
                ])
            }
            assert csvdb._validate_object(obj) == [123, "test entity", 0.123]