~allanlesage/uci-engine/coverage-extractor-plus-nfss-juju-deployment

« back to all changes in this revision

Viewing changes to ticket_system/ticket/tests/test_commands.py

  • Committer: Allan LeSage
  • Date: 2014-10-18 01:02:13 UTC
  • mfrom: (817.1.42 uci-engine)
  • Revision ID: allan.lesage@canonical.com-20141018010213-um3fn28281v2204v
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Ubuntu Continuous Integration Engine
 
2
# Copyright 2014 Canonical Ltd.
 
3
 
 
4
# This program is free software: you can redistribute it and/or modify it
 
5
# under the terms of the GNU Affero General Public License version 3, as
 
6
# published by the Free Software Foundation.
 
7
 
 
8
# This program is distributed in the hope that it will be useful, but
 
9
# WITHOUT ANY WARRANTY; without even the implied warranties of
 
10
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
 
11
# PURPOSE.  See the GNU Affero General Public License for more details.
 
12
 
 
13
# You should have received a copy of the GNU Affero General Public License
 
14
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 
 
16
import os
 
17
import tempfile
 
18
 
 
19
from django.test import TestCase
 
20
from django.core.management import call_command, CommandError
 
21
 
 
22
 
 
23
class TestCreatClient(TestCase):
 
24
 
 
25
    def _call_create_client(self, redirect_uri):
 
26
 
 
27
        fd, filepath = tempfile.mkstemp()
 
28
        output = ""
 
29
        with os.fdopen(fd, 'rb+') as f:
 
30
            call_command('create_client', redirect_uri, stdout=f)
 
31
            f.seek(0)
 
32
            output = f.read()
 
33
            self.assertIn(':', output)
 
34
 
 
35
        return output
 
36
 
 
37
    def test_create_client_success(self):
 
38
        output = self._call_create_client('http://example.com/')
 
39
        self.assert_(output)
 
40
 
 
41
    def test_create_client_again_success(self):
 
42
        """Test that a second call with the same redirect_uri returns the
 
43
        same data not new data."""
 
44
 
 
45
        output = self._call_create_client('http://example.com/')
 
46
        second_output = self._call_create_client('http://example.com/')
 
47
 
 
48
        self.assertEqual(output, second_output)
 
49
 
 
50
    def test_requires_argument_none(self):
 
51
        with self.assertRaises(CommandError):
 
52
            output = self._call_create_client(None)
 
53
            self.assert_(output)
 
54
 
 
55
    def test_requires_argument_blank(self):
 
56
        with self.assertRaises(CommandError):
 
57
            output = self._call_create_client("")
 
58
            self.assert_(output)