Example #1
0
    def test_integration(self):
        api.initialize_index(self.index_path)

        doc_set_info = {
            'id': 'test',
            'title': 'Test documentation',
            'path': get_data_path('upload', 'test'),
            'harvester': html_config()
        }
        api.index_document_set(self.index_path, doc_set_info)

        self.assertEqual(
            list(api.search(self.index_path, "ShouldNotBeIndexed")), [])
        hits = list(api.search(self.index_path, "ShouldBeIndexed"))
        self.assertEqual(len(hits), 1)
        self.assertEqual(hits[0]['path'], 'test1.html')
        self.assertEqual(hits[0]['title'], 'The title')
        self.assertEqual(hits[0]['set'], 'test')
        self.assertEqual(hits[0]['kind'], 'HTML')
        hits = list(api.search(self.index_path, "ShouldBeIndexed set:test"))
        self.assertEqual(len(hits), 1)
        self.assertEqual(
            list(api.search(self.index_path, "ShouldBeIndexed set:unknown")),
            [])

        api.clear_document_set(self.index_path, 'unknown')
        hits = list(api.search(self.index_path, "ShouldBeIndexed"))
        self.assertEqual(len(hits), 1)

        api.clear_document_set(self.index_path, doc_set_info['id'])
        self.assertEqual(list(api.search(self.index_path, "ShouldBeIndexed")),
                         [])
Example #2
0
    def test_integration(self):
        api.initialize_index(self.index_path)

        doc_set_info = {
            'id': 'test',
            'title': 'Test documentation',
            'path': get_data_path('upload', 'test'),
            'harvester': html_config()
        }
        api.index_document_set(self.index_path, doc_set_info)

        self.assertEqual(list(api.search(self.index_path, "ShouldNotBeIndexed")), [])
        hits = list(api.search(self.index_path, "ShouldBeIndexed"))
        self.assertEqual(len(hits), 1)
        self.assertEqual(hits[0]['path'], 'test1.html')
        self.assertEqual(hits[0]['title'], 'The title')
        self.assertEqual(hits[0]['set'], 'test')
        self.assertEqual(hits[0]['kind'], 'HTML')
        hits = list(api.search(self.index_path, "ShouldBeIndexed set:test"))
        self.assertEqual(len(hits), 1)
        self.assertEqual(list(api.search(self.index_path, "ShouldBeIndexed set:unknown")), [])

        api.clear_document_set(self.index_path, 'unknown')
        hits = list(api.search(self.index_path, "ShouldBeIndexed"))
        self.assertEqual(len(hits), 1)

        api.clear_document_set(self.index_path, doc_set_info['id'])
        self.assertEqual(list(api.search(self.index_path, "ShouldBeIndexed")), [])
Example #3
0
def index(settings, only_doc_set, force):
    index_path = settings['dokang.index_path']
    doc_sets = get_doc_sets(settings)
    for doc_set, info in doc_sets.items():
        if only_doc_set is not None and only_doc_set != doc_set:
            continue
        api.index_document_set(index_path, info, force)
Example #4
0
def index(settings, only_doc_set, force):
    index_path = settings['dokang.index_path']
    doc_sets = settings['dokang.doc_sets']
    for doc_set, info in doc_sets.items():
        if only_doc_set is not None and only_doc_set != doc_set:
            continue
        api.index_document_set(index_path, info, force)
Example #5
0
 def _prepare_index(cls):
     api.initialize_index(INDEX_PATH)
     doc_set_info = {
         'id': 'test',
         'title': 'Test documentation',
         'path': get_data_path('upload', 'test'),
         'harvester': html_config()
     }
     api.index_document_set(INDEX_PATH, doc_set_info)
Example #6
0
 def _prepare_index(cls):
     api.initialize_index(INDEX_PATH)
     doc_set_info = {
         'id': 'test',
         'title': 'Test documentation',
         'path': get_data_path('upload', 'test'),
         'harvester': html_config()
     }
     api.index_document_set(INDEX_PATH, doc_set_info)
Example #7
0
 def _prepare_index(cls):
     api.initialize_index(INDEX_PATH)
     doc_set_info = {
         'id': 'test',
         'title': 'Test documentation',
         'path': get_data_path('api'),
         'url': 'http://docs.exemple.com/',
         'harvester': html_config()
     }
     api.index_document_set(INDEX_PATH, doc_set_info)
Example #8
0
def doc_upload(
    request
):  # Route is not activated when dokang.uploaded_docs.dir is not set
    settings = request.registry.settings
    doc_dir = settings['dokang.uploaded_docs.dir']
    token = settings.get('dokang.uploaded_docs.token')

    bad_auth = (token is None or request.authorization is None
                or request.authorization[0] != 'Basic'
                or base64.b64decode(request.authorization[1]).decode('utf-8')
                != 'dokang:{0}'.format(token))
    if bad_auth:
        raise HTTPForbidden()

    if not request.POST:
        raise HTTPMethodNotAllowed()

    if request.POST.get(':action', '--no-action--') != 'doc_upload':
        raise HTTPBadRequest('Only doc_upload action is supported.')

    form = DocUploadForm(request.POST)
    if not form.validate():
        raise HTTPBadRequest(form.errors)

    project = form.data['name']
    project_dir = os.path.join(doc_dir, project)
    metadata = utils.doc_set(settings, project)

    zip_file = zipfile.ZipFile(form.data['content'].file)
    if os.path.exists(project_dir):
        shutil.rmtree(project_dir)
    zip_file.extractall(project_dir)

    with open(os.path.join(project_dir, '.dokang'), 'w') as fp:
        json.dump({'title': metadata['title']}, fp)

    # index new doc set
    index_path = settings['dokang.index_path']
    api.index_document_set(index_path,
                           utils.doc_set(settings, project),
                           force=False)

    return HTTPMovedPermanently(
        request.route_url('catch_all_doc_view', subpath=project))
Example #9
0
def doc_upload(request):  # Route is not activated when dokang.uploaded_docs.dir is not set
    settings = request.registry.settings
    doc_dir = settings['dokang.uploaded_docs.dir']
    token = settings.get('dokang.uploaded_docs.token')

    bad_auth = (
        token is None or
        request.authorization is None or
        request.authorization[0] != 'Basic' or
        base64.b64decode(request.authorization[1]) != 'dokang:{0}'.format(token)
    )
    if bad_auth:
        raise HTTPForbidden()

    if not request.POST:
        raise HTTPMethodNotAllowed()

    if request.POST.get(':action', '--no-action--') != 'doc_upload':
        raise HTTPBadRequest('Only doc_upload action is supported.')

    form = DocUploadForm(request.POST)
    if not form.validate():
        raise HTTPBadRequest(form.errors)

    project = form.data['name']
    project_dir = os.path.join(doc_dir, project)

    zip_file = zipfile.ZipFile(form.data['content'].file)
    if os.path.exists(project_dir):
        shutil.rmtree(project_dir)
    zip_file.extractall(project_dir)

    # update doc sets
    doc_set_info = settings['dokang.doc_sets'][project] = utils.doc_set(settings, project)

    # index new doc set
    index_path = settings['dokang.index_path']
    api.index_document_set(index_path, doc_set_info, force=False)

    return HTTPMovedPermanently(request.route_url('catch_all_doc_view', subpath=project))