Passed
Push — master ( aeb165...d9ae97 )
by Dean
03:04
created

UpdateBasicCredential   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 9
Duplicated Lines 0 %

Test Coverage

Coverage 50%
Metric Value
dl 0
loc 9
ccs 3
cts 6
cp 0.5
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A from_dict() 0 6 2
1 1
from plugin.managers.core.base import Manager, Update
2 1
from plugin.models import PlexBasicCredential
3
4 1
import logging
5
6 1
log = logging.getLogger(__name__)
7
8
9 1
class UpdateBasicCredential(Update):
10 1
    keys = ['password', 'token_plex']
11
12 1
    def from_dict(self, basic_credential, changes, save=True):
13
        # Update `PlexBasicCredential`
14
        if not super(UpdateBasicCredential, self).from_dict(basic_credential, changes, save=save):
15
            return False
16
17
        return True
18
19
20 1
class PlexBasicCredentialManager(Manager):
21 1
    update = UpdateBasicCredential
22
23 1
    model = PlexBasicCredential
24
25 1
    @classmethod
26
    def delete(cls, *query, **kwargs):
27
        # Retrieve basic credential
28
        try:
29
            credential = cls.get(*query, **kwargs)
30
        except Exception, ex:
31
            log.warn('Unable to find basic credential (query: %r, kwargs: %r): %r', query, kwargs, ex)
32
            return False
33
34
        # Clear basic credential
35
        cls.update(credential, {
36
            'password': None,
37
38
            'token_plex': None,
39
            'token_server': None
40
        })
41
42
        return True
43