JSONExportTestCase   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
dl 0
loc 33
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B test_flow() 0 30 3
1
# -*- coding: utf-8 -*-
2
from django.test.utils import override_settings
3
from django.contrib.auth.models import User
4
from taggit.models import Tag
5
6
from pages.models import Page
7
from pages.tests.testcase import TestCase
8
from pages.plugins.jsonexport.utils import pages_to_json, json_to_pages
9
10
11
class JSONExportTestCase(TestCase):
12
    """Django page CMS JSON Export tests suite class."""
13
14
    @override_settings(PAGE_TAGGING=True)
15
    def test_flow(self):
16
        # Export
17
        page1 = self.new_page(content={'title': 'page1', 'slug': 'slug1'})
18
        tag1 = Tag.objects.create(name="t1")
19
        page1.tags.add(tag1)
20
21
        page2 = self.new_page(content={'title': 'page2', 'slug': 'slug2'})
22
        tag2 = Tag.objects.create(name="t2")
23
        page2.tags.add(tag2)
24
25
        data = pages_to_json(Page.objects.all())
26
27
        # Clear
28
        Page.objects.all().delete()
29
        Tag.objects.all().delete()
30
31
        # Import
32
        user = User.objects.create()
33
        json_to_pages(data, user)
34
        pages = Page.objects.all()
35
        self.assertEqual(pages.count(), 2)
36
37
        page1 = Page.objects.from_slug('slug1')
38
        self.assertEqual(page1.title(), 'page1')
39
        self.assertEqual([t.name for t in page1.tags.all()], ['t1'])
40
41
        page1 = Page.objects.from_slug('slug2')
42
        self.assertEqual(page1.title(), 'page2')
43
        self.assertEqual([t.name for t in page1.tags.all()], ['t2'])
44