Пример #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 taxonomy_delete(taxonomy):
    """Delete whole taxonomy tree."""
    try:
        current_flask_taxonomies.delete_taxonomy(taxonomy)
        response = make_response()
        response.status_code = 204
        return response
    except TaxonomyDeleteError as e:
        abort(409, {'reason': str(e), 'records': e.records})
Пример #3
0
    def test_delete_taxonomy(self, db, root_taxonomy, TaxonomyTerm):
        """Test deleting the whole Taxonomy."""

        leaf = root_taxonomy.create_term(slug="leaf")
        nested = leaf.create_term(slug="nested")

        root_taxonomy.check()

        current_flask_taxonomies.delete_taxonomy(root_taxonomy)

        assert TaxonomyTerm.query.get(root_taxonomy.id) is None
        assert TaxonomyTerm.query.get(leaf.id) is None
        assert TaxonomyTerm.query.get(nested.id) is None
Пример #4
0
def delete_taxonomy(code=None):
    """
    Deletes a taxonomy.

    Note: this call is destructive in a sense that all its terms, regardless if used or not,
    are deleted as well. A tight user permissions should be employed.
    """
    try:
        tax = current_flask_taxonomies.get_taxonomy(code=code)
    except NoResultFound:
        json_abort(404, {})
        return  # make pycharm happy

    current_flask_taxonomies.permissions.taxonomy_delete.enforce(
        request=request, code=code)
    current_flask_taxonomies.delete_taxonomy(tax)
    current_flask_taxonomies.commit()
    return Response(status=204)
Пример #5
0
def create_update_taxonomy(data, drop) -> Taxonomy:
    tax_dict = convert_data_to_dict(data)[0]
    if 'code' not in tax_dict:
        raise ValueError('Taxonomy does not contain "code"')
    code = tax_dict.pop('code')
    taxonomy = current_flask_taxonomies.get_taxonomy(code, fail=False)
    if taxonomy and drop:
        current_flask_taxonomies.delete_taxonomy(taxonomy)
        taxonomy = None

    if taxonomy:
        merged_dict = taxonomy.extra_data
        merged_dict.update(tax_dict)
        current_flask_taxonomies.update_taxonomy(taxonomy, merged_dict)
    else:
        taxonomy = current_flask_taxonomies.create_taxonomy(code, extra_data=tax_dict)
    db.session.commit()
    return taxonomy
Пример #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
Пример #7
0
def delete_taxonomy(code):
    t = Taxonomy.get(code)
    current_flask_taxonomies.delete_taxonomy(t)