| Total Complexity | 8 |
| Total Lines | 29 |
| Duplicated Lines | 0 % |
| Coverage | 95.45% |
| 1 | 1 | from ..domain import Image |
|
| 6 | 1 | class ImageService(Service): |
|
| 7 | |||
| 8 | 1 | def __init__(self, template_store, image_store, **kwargs): |
|
| 9 | 1 | super().__init__(**kwargs) |
|
| 10 | 1 | self.template_store = template_store |
|
| 11 | 1 | self.image_store = image_store |
|
| 12 | |||
| 13 | 1 | def create(self, template, text, style=None): |
|
| 14 | 1 | image = Image(template, text, style=style) |
|
| 15 | |||
| 16 | 1 | try: |
|
| 17 | 1 | self.image_store.create(image) |
|
| 18 | 1 | except OSError as exception: |
|
| 19 | 1 | if "name too long" in str(exception): |
|
| 20 | 1 | exception = self.exceptions.FilenameTooLong |
|
| 21 | 1 | elif "image file" in str(exception): |
|
| 22 | 1 | exception = self.exceptions.InvalidImageLink |
|
| 23 | 1 | raise exception from None |
|
| 24 | |||
| 25 | 1 | return image |
|
| 26 | |||
| 27 | 1 | def get_latest(self, count): |
|
| 28 | 1 | if count != 1: |
|
| 29 | raise NotImplementedError("TODO: support multiple") |
||
| 30 | 1 | return self.image_store.latest |
|
| 31 | |||
| 32 | 1 | @property |
|
| 33 | def latest(self): |
||
| 34 | return self.get_latest(1) |
||
| 35 |