Пример #1
0
def test_taxonomy_delete(app, db, taxonomy_tree, test_record):
    taxonomies = current_flask_taxonomies.list_taxonomies(session=None).all()
    assert len(taxonomies) == 1
    with pytest.raises(DeleteAbortedError):
        current_flask_taxonomies.delete_taxonomy(taxonomies[0])
    taxonomies = current_flask_taxonomies.list_taxonomies(session=None).all()
    assert len(taxonomies) == 1
Пример #2
0
def test_api(app, db):
    taxonomy = current_flask_taxonomies.create_taxonomy("root",
                                                        extra_data={},
                                                        session=db.session)
    db.session.commit()

    identification = TermIdentification(taxonomy=taxonomy, slug="a")
    term = current_flask_taxonomies.create_term(identification,
                                                extra_data={"a": 1})
    assert term.slug == "a"
    db.session.commit()

    identification2 = TermIdentification(parent=term, slug="b")
    term2 = current_flask_taxonomies.create_term(identification2,
                                                 extra_data={"b": 2})
    assert term2.slug == "a/b"
    db.session.commit()

    res = current_flask_taxonomies.list_taxonomies().all()
    print(res)

    # filter
    term_identification = TermIdentification(taxonomy=taxonomy, slug=term.slug)
    assert list(
        current_flask_taxonomies.filter_term(term_identification)) == [term]

    assert list(
        current_flask_taxonomies.filter_term(
            TermIdentification(taxonomy=taxonomy,
                               slug=term2.slug))) == [term2]

    res_term = current_flask_taxonomies.filter_term(
        term_identification).one_or_none()
    assert isinstance(res_term, TaxonomyTerm)
Пример #3
0
def test_import_taxonomy(app, db):
    file_path = pathlib.Path(__file__).parent.absolute()
    data_path = file_path / "data" / "licenses_v2.xlsx"
    import_taxonomy(str(data_path))
    taxonomy = current_flask_taxonomies.list_taxonomies(session=None).all()[0]
    taxonomy_list = current_flask_taxonomies.list_taxonomy(taxonomy).all()
    assert len(taxonomy_list) > 0
    assert isinstance(taxonomy_list[1], TaxonomyTerm)
def test_create_taxonomy(app, db):
    """
    Test if creating taxonomy working. Test uses SQLite db.
    """

    # management task that creates flask-taxonomies tables
    # subprocess.run(["invenio", "taxonomies", "init"])

    current_flask_taxonomies.create_taxonomy("root", extra_data={}, session=db.session)
    db.session.commit()
    res = current_flask_taxonomies.list_taxonomies(session=db.session).all()
    print(res)
    assert len(res) == 1
Пример #5
0
def list_taxonomies(prefer=None, page=None, size=None, q=None):
    current_flask_taxonomies.permissions.taxonomy_list.enforce(request=request)
    taxonomies = current_flask_taxonomies.list_taxonomies(
        return_descendants_count=INCLUDE_DESCENDANTS_COUNT in prefer,
        return_descendants_busy_count=INCLUDE_STATUS in prefer)
    if q:
        taxonomies = current_flask_taxonomies.apply_taxonomy_query(
            taxonomies, q)
    paginator = Paginator(prefer,
                          taxonomies,
                          page,
                          size,
                          json_converter=lambda data:
                          [x.json(representation=prefer) for x in data],
                          envelope_links=EnvelopeLinks(
                              envelope={'self': request.url},
                              headers={'self': request.url}))
    return paginator.jsonify()
Пример #6
0
def test_taxonomy_delete_2(app, db, taxonomy_tree):
    taxonomies = current_flask_taxonomies.list_taxonomies(session=None).all()
    assert len(taxonomies) == 1
    current_flask_taxonomies.delete_taxonomy(taxonomies[0])
    taxonomies = current_flask_taxonomies.list_taxonomies(session=None).all()
    assert len(taxonomies) == 0