ViewsTestCase.testBulkGraphCopy()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 4
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nop 1
1
from ore.models import Graph
2
from .common import fixt_simple, OreTestCase
3
4
5
class ViewsTestCase(OreTestCase):
6
7
    """
8
        Tests for different Django views and their form submissions.
9
    """
10
    fixtures = fixt_simple['files']
11
12
    # TODO: Test root view rendering with existing notification
13
    # TODO: Test dismiss click for existing notification
14
15
    def setUp(self):
16
        self.setUpLogin()
17
18
    def testRootView(self):
19
        ''' Root view shall redirect to projects overview. '''
20
        response = self.get('/')
21
        self.assertEqual(response.status_code, 302)
22
23
    def testProjectsView(self):
24
        response = self.get('/projects/')
25
        self.assertEqual(response.status_code, 200)
26
27
    def testEditorView(self):
28
        for graphId, kind in fixt_simple['graphs'].iteritems():
29
            response = self.get('/editor/%u' % graphId)
30
            self.assertEqual(response.status_code, 200)
31
32
    def testInvalidEditorView(self):
33
        response = self.get('/editor/999')
34
        self.assertEqual(response.status_code, 404)
35
36
    def testNewGraphFromDashboard(self):
37
        response = self.post('/projects/%u/dashboard/new/faulttree' % fixt_simple['pkProject'],
38
                             {'save': 'save', 'name': 'My new graph'})
39
        # TODO: Check that the new fault tree contains a top event node
40
        self.assertEqual(response.status_code, 302)
41
42
    def testBulkGraphCopy(self):
43
        response = self.post('/projects/%u/dashboard/edit/' % fixt_simple['pkProject'],
44
                             {'copy': 'copy', 'graph_id[]': fixt_simple['graphs']})
45
        self.assertEqual(response.status_code, 302)
46
47
    def testBulkGraphSnapshot(self):
48
        response = self.post('/projects/%u/dashboard/edit/' % fixt_simple['pkProject'],
49
                             {'snapshot': 'snapshot', 'graph_id[]': fixt_simple['graphs']})
50
        self.assertEqual(response.status_code, 302)
51
52
    def testSingleGraphCopy(self):
53
        for graphid, kind in fixt_simple['graphs'].iteritems():
54
            response = self.post('/projects/%u/dashboard/edit/' % fixt_simple['pkProject'],
55
                                 {'copy': 'copy', 'graph_id[]': graphid})
56
            self.assertEqual(response.status_code, 302)
57
            # The view code has no reason to return the new graph ID, so the redirect is to the dashboard
58
            # We therefore determine the new graph by the creation time
59
            copy = Graph.objects.all().order_by('-created')[0]
60
            original = Graph.objects.get(pk=graphid)
61
            self.assertTrue(original.same_as(copy))
62