~ubuntu-branches/ubuntu/raring/maas/raring-updates

« back to all changes in this revision

Viewing changes to src/maastesting/tests/test_yui3.py

  • Committer: Package Import Robot
  • Author(s): Andres Rodriguez
  • Date: 2012-07-03 17:42:37 UTC
  • mfrom: (1.1.13)
  • Revision ID: package-import@ubuntu.com-20120703174237-p8l0keuuznfg721k
Tags: 0.1+bzr709+dfsg-0ubuntu1
* New Upstream release
* debian/control:
  - Depends on python-celery, python-tempita, libjs-yui3-{full,min},
    libjs-raphael
* debian/maas.install:
  - Install apiclient, celeryconfig.py, maas-import-pxe-files, preseeds_v2.
  - Update to install various files from chroot, rather tha manually copy
    them from the source.
* debian/maas.links: symlink celeryconfig.py
* debian/maas.maas-celery.upstart: Add job.
* debian/rules:
  - Install celery upstart job.
  - Do not install jslibs as packages are now used.
  - Drop copying of maas_local_settings_sample.py as source now ships
    a maas_local_settings.py
* debian/patches:
  - 04-maas-http-fix.patch: Drop. Merged upstream.
  - 01-fix-database-settings.patch: Refreshed.
  - 99_enums_js.patch: Added until creation of enum.js / build process
    is fixed.
* debian/maas.postinst: Update bzr version to correctly handle upgrades.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2012 Canonical Ltd.  This software is licensed under the
 
2
# GNU Affero General Public License version 3 (see the file LICENSE).
 
3
 
 
4
"""Tests for `maasserver.testing.yui3`."""
 
5
 
 
6
from __future__ import (
 
7
    absolute_import,
 
8
    print_function,
 
9
    unicode_literals,
 
10
    )
 
11
 
 
12
__metaclass__ = type
 
13
__all__ = []
 
14
 
 
15
from maastesting.testcase import TestCase
 
16
from maastesting.yui3 import (
 
17
    extract_tests,
 
18
    gen_failed_test_messages,
 
19
    get_failed_tests_message,
 
20
    )
 
21
from nose.tools import nottest
 
22
 
 
23
# Nose is over-zealous.
 
24
nottest(extract_tests)
 
25
nottest(gen_failed_test_messages)
 
26
nottest(get_failed_tests_message)
 
27
 
 
28
 
 
29
# From http://yuilibrary.com/yui/docs/test/#testsuite-level-events
 
30
example_results = {
 
31
    'failed': 3,
 
32
    'ignored': 0,
 
33
    'name': 'Test Suite 0',
 
34
    'passed': 3,
 
35
    'testCase0': {
 
36
        'failed': 1,
 
37
        'ignored': 0,
 
38
        'name': 'testCase0',
 
39
        'passed': 1,
 
40
        'test0': {
 
41
            'message': 'Test passed.',
 
42
            'name': 'test0',
 
43
            'result': 'pass',
 
44
            'type': 'test',
 
45
            },
 
46
        'test1': {
 
47
            'message': 'Assertion failed.',
 
48
            'name': 'test1',
 
49
            'result': 'fail',
 
50
            'type': 'test',
 
51
            },
 
52
        'total': 2,
 
53
        'type': 'testcase',
 
54
        },
 
55
    'testCase1': {
 
56
        'failed': 1,
 
57
        'ignored': 0,
 
58
        'name': 'testCase1',
 
59
        'passed': 1,
 
60
        'test0': {
 
61
            'message': 'Test passed.',
 
62
            'name': 'test0',
 
63
            'result': 'pass',
 
64
            'type': 'test',
 
65
            },
 
66
        'test1': {
 
67
            'message': 'Assertion failed.',
 
68
            'name': 'test1',
 
69
            'result': 'fail',
 
70
            'type': 'test',
 
71
            },
 
72
        'total': 2,
 
73
        'type': 'testcase',
 
74
        },
 
75
    'testSuite0': {
 
76
        'failed': 1,
 
77
        'ignored': 0,
 
78
        'name': 'testSuite0',
 
79
        'passed': 1,
 
80
        'testCase2': {
 
81
            'failed': 1,
 
82
            'ignored': 0,
 
83
            'name': 'testCase2',
 
84
            'passed': 1,
 
85
            'test0': {
 
86
                'message': 'Test passed.',
 
87
                'name': 'test0',
 
88
                'result': 'pass',
 
89
                'type': 'test',
 
90
                },
 
91
            'test1': {
 
92
                'message': 'Assertion failed.',
 
93
                'name': 'test1',
 
94
                'result': 'fail',
 
95
                'type': 'test',
 
96
                },
 
97
            'total': 2,
 
98
            'type': 'testcase'},
 
99
        'total': 2,
 
100
        'type': 'testsuite'},
 
101
    'total': 6,
 
102
    'type': 'testsuite',
 
103
    }
 
104
 
 
105
 
 
106
class TestFunctions(TestCase):
 
107
 
 
108
    def test_extract_tests_names(self):
 
109
        expected_names = {
 
110
            "testCase0.test0",
 
111
            "testCase0.test1",
 
112
            "testCase1.test0",
 
113
            "testCase1.test1",
 
114
            "testSuite0.testCase2.test0",
 
115
            "testSuite0.testCase2.test1",
 
116
            }
 
117
        observed_tests = extract_tests(example_results)
 
118
        observed_test_names = set(observed_tests)
 
119
        self.assertSetEqual(expected_names, observed_test_names)
 
120
 
 
121
    def test_extract_tests(self):
 
122
        expected_results = {
 
123
            "testCase0.test0": "pass",
 
124
            "testCase0.test1": "fail",
 
125
            "testCase1.test0": "pass",
 
126
            "testCase1.test1": "fail",
 
127
            "testSuite0.testCase2.test0": "pass",
 
128
            "testSuite0.testCase2.test1": "fail",
 
129
            }
 
130
        observed_results = {
 
131
            name: test["result"]
 
132
            for name, test in extract_tests(example_results).items()
 
133
            }
 
134
        self.assertDictEqual(expected_results, observed_results)
 
135
 
 
136
    def test_gen_failed_test_messages(self):
 
137
        expected_messages = {
 
138
            "testCase0.test1: Assertion failed.",
 
139
            "testCase1.test1: Assertion failed.",
 
140
            "testSuite0.testCase2.test1: Assertion failed.",
 
141
            }
 
142
        observed_messages = gen_failed_test_messages(example_results)
 
143
        self.assertSetEqual(expected_messages, set(observed_messages))
 
144
 
 
145
    def test_get_failed_tests_message(self):
 
146
        expected_message = (
 
147
            "testCase0.test1: Assertion failed."
 
148
            "\n\n"
 
149
            "testCase1.test1: Assertion failed."
 
150
            "\n\n"
 
151
            "testSuite0.testCase2.test1: Assertion failed."
 
152
            )
 
153
        observed_message = get_failed_tests_message(example_results)
 
154
        self.assertEqual(expected_message, observed_message)