Completed
Pull Request — master (#394)
by Jace
08:10
created

ImageService   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 85%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 29
ccs 17
cts 20
cp 0.85
rs 10
c 1
b 0
f 0
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __init__() 0 5 1
B create() 0 21 5
1 1
import logging
2
3 1
from ..domain import Image, Font
4
5 1
from ._base import Service
6
7
8 1
log = logging.getLogger(__name__)
9
10
11 1
class ImageService(Service):
12
13 1
    def __init__(self, template_store, font_store, image_store, **kwargs):
14 1
        super().__init__(**kwargs)
15 1
        self.template_store = template_store
16 1
        self.font_store = font_store
17 1
        self.image_store = image_store
18
19 1
    def create(self, template, text, font=None, **options):
20 1
        image = Image(
21
            template, text,
22
            font=font or self.font_store.find(Font.DEFAULT),
23
            watermark_font=self.font_store.find(Font.DEFAULT),
24
            **options,
0 ignored issues
show
introduced by
invalid syntax
Loading history...
25
        )
26
27 1
        try:
28 1
            self.image_store.create(image)
29 1
        except OSError as exception:
30 1
            if "name too long" in str(exception):
31 1
                exception = self.exceptions.FilenameTooLong
32 1
            elif "image file" in str(exception):
33 1
                exception = self.exceptions.InvalidImageLink
34 1
            raise exception from None  # pylint: disable=raising-bad-type
35
        except SystemError as exception:
36
            log.warning(exception)
37
            raise self.exceptions.InvalidImageLink from None
38
39
        return image
40