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

tcms.xmlrpc.api.attachment   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 13
dl 0
loc 31
rs 10
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A remove_attachment() 0 18 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