Completed
Branch master (28ef54)
by Fox
01:25
created

ServicesMgrTestCase   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 4
Bugs 1 Features 1
Metric Value
c 4
b 1
f 1
dl 0
loc 41
rs 10
wmc 6
1
# coding: utf-8
2
import uuid
3
4
from django.contrib.auth.models import User
5
6
try:
7
    from django.apps import apps
8
    get_model = apps.get_model
9
except ImportError:
10
    from django.db.models.loading import get_model
11
12
from django_th.services.services import ServicesMgr
13
from django_th.tests.test_main import MainTest
14
15
from th_rss.models import Rss
16
17
18
class ServicesMgrTestCase(MainTest):
19
20
    def setUp(self):
21
        try:
22
            self.user = User.objects.get(username='john')
23
        except User.DoesNotExist:
24
            self.user = User.objects.create_user(
25
                username='john', email='[email protected]', password='doe')
26
27
    def create_rss(self):
28
        trigger = self.create_triggerservice()
29
        name = 'Foobar RSS'
30
        url = 'https://blog.trigger-happy.eu/feeds/all.rss.xml'
31
        status = True
32
        return Rss.objects.create(uuid=uuid.uuid4(),
33
                                  url=url,
34
                                  name=name,
35
                                  trigger=trigger,
36
                                  status=status)
37
38
    def test_set_title(self):
39
        data = {'title': 'foobar'}
40
        self.assertTrue('title' in data)
41
        data = {'link': 'http://localhost/url/to/news'}
42
        self.assertTrue('title' not in data)
43
        self.assertTrue('link' in data)
44
45
    def test_set_content(self):
46
        data = {'summary_detail': 'some summary'}
47
        self.assertTrue('summary_detail' in data)
48
        data = {'description': 'foobar'}
49
        self.assertTrue('description' in data)
50
        self.assertTrue('summary_detail' not in data)
51
52
    def test_save_data(self):
53
        data = {'title': 'a title', 'summary_detail': 'a content'}
54
        s = ServicesMgr('')
55
        title = s.set_title(data)
56
        content = s.set_content(data)
57
        self.assertTrue(title)
58
        self.assertTrue(content)
59