Example #1
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()}')
Example #2
0
    def test_get_wba_documents_list(self, mocked_get_full_container_list):
        """
        Test and assert that the correct list of documents is returned
        """
        mocked_get_full_container_list.return_value = [
            {
                'hash': 'hash1',
                'last_modified': '2019-08-26T09:08:55.150810',
                'bytes': 1,
                'name': 'ontwerp/filename1.pdf',
                'content_type': 'application/pdf'
            },
            {
                'hash': 'hash2',
                'last_modified': '2019-08-26T09:08:55.150810',
                'bytes': 1,
                'name': 'rapport/filename2.pdf',
                'content_type': 'application/pdf'
            },
            {
                'hash': 'hash3',
                'last_modified': '2019-08-26T09:08:55.150810',
                'bytes': 1,
                'name': 'ontwerp/filename3.pdf',
                'content_type': 'application/pdf'
            },
        ]

        objstore = ObjectStore(config='this is the config')
        return_value = objstore.get_wba_documents_list(connection=None)

        self.assertEqual(return_value, [
            ('ontwerp', 'filename1.pdf'),
            ('rapport', 'filename2.pdf'),
            ('ontwerp', 'filename3.pdf'),
        ])