コード例 #1
0
 def test_get_connection(self, mocked_get_connection):
     """
     Test and assert that objecstore.get_connection is called with the given
     config, and that the connection is returned.
     """
     mocked_get_connection.return_value = 'this is the connection'
     objstore = ObjectStore(config='this is the config')
     connection = objstore.get_connection()
     mocked_get_connection.assert_called_with('this is the config')
     self.assertEqual(connection, 'this is the connection')
コード例 #2
0
ファイル: views.py プロジェクト: Amsterdam/blackspots-backend
    def get_file(self, request, pk=None):
        document_model = self.get_object()
        container_path = ObjectStore.get_container_path(document_model.type)
        filename = document_model.filename

        objstore = ObjectStore(settings.OBJECTSTORE_CONNECTION_CONFIG)
        connection = objstore.get_connection()
        try:
            store_object = objstore.get_document(connection, container_path, filename)
        except ClientException as e:
            return handle_swift_exception(container_path, filename, e)

        content_type = store_object[0].get('content-type')
        obj_data = store_object[1]

        response = HttpResponse(content_type=content_type)
        response['Content-Disposition'] = f'attachment; filename="{filename}"'
        response.write(obj_data)

        return response
コード例 #3
0
def perform_import():
    log.info('Clearing models')
    clear_models()

    objstore = ObjectStore(config=settings.OBJECTSTORE_CONNECTION_CONFIG)

    log.info('Opening object store connection')
    connection = objstore.get_connection()

    log.info('Getting documents list')
    document_list = objstore.get_wba_documents_list(connection)
    log.info(f'document list size: {len(document_list)}')

    log.info('Fetching xls file')
    xls_path = objstore.fetch_spots(connection)
    log.info('Importing xls file')
    process_xls(xls_path, document_list)

    log.info(f'Spot count: {Spot.objects.all().count()}')
    log.info(f'Document count: {Document.objects.all().count()}')