Пример #1
0
    def test_loads_exported_array_data(self, open_mock):
        documents = [
            {
                '_id': 1,
                'msg': 'my test string'
            },
            {
                '_id': 2,
                'message': 'my other string'
            },
            {
                '_id': 3,
                'foo': 'bar',
                'greeting': 'hi there'
            },
        ]
        file_contents = dumps(documents)
        self.mock_open(open_mock, file_contents)

        with self.real_app.app_context():
            db = get_db()

            load_data_from_mongoexport('myresid.', 'my/file/location',
                                       'mycoll')

            open_mock.assert_called_with('my/file/location')
            collection_contents = list(db['myresid.mycoll'].find())
            self.assertItemsEqual(collection_contents, documents)

            db['myresid.mycoll'].drop()
Пример #2
0
    def test_loads_exported_data(self, open_mock):
        documents = [
            {'_id': 1, 'msg': 'my test string'},
            {'_id': 2, 'message': 'my other string'},
            {'_id': 3, 'foo': 'bar', 'greeting': 'hi there'},
        ]
        file_contents = '\n'.join([dumps(doc) for doc in documents])
        self.mock_open(open_mock, file_contents)

        with self.real_app.app_context():
            db = get_db()

            # Test normally (keeping the _id)
            load_data_from_mongoexport('myresid.', 'my/file/location',
                                       'mycoll')
            open_mock.assert_called_with('my/file/location')
            collection_contents = list(db['myresid.mycoll'].find())
            self.assertItemsEqual(collection_contents, documents)

            db['myresid.mycoll'].drop()

            # Test removing the _id
            load_data_from_mongoexport('myresid.', 'my/file/location',
                                       'mycoll', True)
            collection_contents = list(db['myresid.mycoll'].find())
            for doc in collection_contents:
                # Should not be any of the given _id's
                self.assertNotIn(doc['_id'], (1, 2, 3))
            db['myresid.mycoll'].drop()
Пример #3
0
    def test_loads_exported_array_data(self, open_mock):
        documents = [
            {'_id': 1, 'msg': 'my test string'},
            {'_id': 2, 'message': 'my other string'},
            {'_id': 3, 'foo': 'bar', 'greeting': 'hi there'},
        ]
        file_contents = dumps(documents)
        self.mock_open(open_mock, file_contents)

        with self.real_app.app_context():
            db = get_db()

            load_data_from_mongoexport('myresid.',
                                       'my/file/location', 'mycoll')

            open_mock.assert_called_with('my/file/location')
            collection_contents = list(db['myresid.mycoll'].find())
            self.assertItemsEqual(collection_contents, documents)

            db['myresid.mycoll'].drop()
Пример #4
0
    def test_loads_exported_data(self, open_mock):
        documents = [
            {
                '_id': 1,
                'msg': 'my test string'
            },
            {
                '_id': 2,
                'message': 'my other string'
            },
            {
                '_id': 3,
                'foo': 'bar',
                'greeting': 'hi there'
            },
        ]
        file_contents = '\n'.join([dumps(doc) for doc in documents])
        self.mock_open(open_mock, file_contents)

        with self.real_app.app_context():
            db = get_db()

            # Test normally (keeping the _id)
            load_data_from_mongoexport('myresid.', 'my/file/location',
                                       'mycoll')
            open_mock.assert_called_with('my/file/location')
            collection_contents = list(db['myresid.mycoll'].find())
            self.assertItemsEqual(collection_contents, documents)

            db['myresid.mycoll'].drop()

            # Test removing the _id
            load_data_from_mongoexport('myresid.', 'my/file/location',
                                       'mycoll', True)
            collection_contents = list(db['myresid.mycoll'].find())
            for doc in collection_contents:
                # Should not be any of the given _id's
                self.assertNotIn(doc['_id'], (1, 2, 3))
            db['myresid.mycoll'].drop()