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

UpdateBasicCredential.from_dict()   A

Complexity

Conditions 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 3.6875
Metric Value
cc 2
dl 0
loc 6
ccs 1
cts 4
cp 0.25
crap 3.6875
rs 9.4285
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