Passed
Push — master ( aedc00...4f3982 )
by Alexander
02:32
created

tcms.xmlrpc.api.attachment.remove_attachment()   A

Complexity

Conditions 2

Size

Total Lines 18
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 18
rs 10
c 0
b 0
f 0
cc 2
nop 2
1
# -*- coding: utf-8 -*-
2
3
from attachments.views import delete_attachment
4
from modernrpc.core import rpc_method, REQUEST_KEY
5
6
from tcms.xmlrpc.decorators import permissions_required
7
8
__all__ = (
9
    'remove_attachment',
10
)
11
12
13
@permissions_required('attachments.delete_attachment')
14
@rpc_method(name='Attachment.remove_attachment')
15
def remove_attachment(attachment_id, **kwargs):
16
    """
17
    .. function:: XML-RPC Attachment.remove_attachment(attachment_id)
18
19
        Remove the given attachment file.
20
21
        :param attachment_id: PK of attachment to remove
22
        :type attachment_id: int
23
        :return: None
24
        :raises: Exception if attachment doesn't exist,
25
                 InternalError or removal fails
26
    """
27
    request = kwargs.get(REQUEST_KEY)
28
    response = delete_attachment(request, attachment_id)
29
    if response.status_code == 404:
30
        raise Exception("Removing attachment %d failed" % attachment_id)
31