~cloud-init-dev/cloud-init/trunk

« back to all changes in this revision

Viewing changes to tests/unittests/test_cs_util.py

  • Committer: Scott Moser
  • Date: 2016-08-10 15:06:15 UTC
  • Revision ID: smoser@ubuntu.com-20160810150615-ma2fv107w3suy1ma
README: Mention move of revision control to git.

cloud-init development has moved its revision control to git.
It is available at 
  https://code.launchpad.net/cloud-init

Clone with 
  git clone https://git.launchpad.net/cloud-init
or
  git clone git+ssh://git.launchpad.net/cloud-init

For more information see
  https://git.launchpad.net/cloud-init/tree/HACKING.rst

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
from __future__ import print_function
2
 
 
3
 
from . import helpers as test_helpers
4
 
 
5
 
from cloudinit.cs_utils import Cepko
6
 
 
7
 
 
8
 
SERVER_CONTEXT = {
9
 
    "cpu": 1000,
10
 
    "cpus_instead_of_cores": False,
11
 
    "global_context": {"some_global_key": "some_global_val"},
12
 
    "mem": 1073741824,
13
 
    "meta": {"ssh_public_key": "ssh-rsa AAAAB3NzaC1yc2E.../hQ5D5 john@doe"},
14
 
    "name": "test_server",
15
 
    "requirements": [],
16
 
    "smp": 1,
17
 
    "tags": ["much server", "very performance"],
18
 
    "uuid": "65b2fb23-8c03-4187-a3ba-8b7c919e889",
19
 
    "vnc_password": "9e84d6cb49e46379"
20
 
}
21
 
 
22
 
 
23
 
class CepkoMock(Cepko):
24
 
    def all(self):
25
 
        return SERVER_CONTEXT
26
 
 
27
 
    def get(self, key="", request_pattern=None):
28
 
        return SERVER_CONTEXT['tags']
29
 
 
30
 
 
31
 
# 2015-01-22 BAW: This test is completely useless because it only ever tests
32
 
# the CepkoMock object.  Even in its original form, I don't think it ever
33
 
# touched the underlying Cepko class methods.
34
 
class CepkoResultTests(test_helpers.TestCase):
35
 
    def setUp(self):
36
 
        raise test_helpers.SkipTest('This test is completely useless')
37
 
 
38
 
    def test_getitem(self):
39
 
        result = self.c.all()
40
 
        self.assertEqual("65b2fb23-8c03-4187-a3ba-8b7c919e889", result['uuid'])
41
 
        self.assertEqual([], result['requirements'])
42
 
        self.assertEqual("much server", result['tags'][0])
43
 
        self.assertEqual(1, result['smp'])
44
 
 
45
 
    def test_len(self):
46
 
        self.assertEqual(len(SERVER_CONTEXT), len(self.c.all()))
47
 
 
48
 
    def test_contains(self):
49
 
        result = self.c.all()
50
 
        self.assertTrue('uuid' in result)
51
 
        self.assertFalse('uid' in result)
52
 
        self.assertTrue('meta' in result)
53
 
        self.assertFalse('ssh_public_key' in result)
54
 
 
55
 
    def test_iter(self):
56
 
        self.assertEqual(sorted(SERVER_CONTEXT.keys()),
57
 
                         sorted([key for key in self.c.all()]))
58
 
 
59
 
    def test_with_list_as_result(self):
60
 
        result = self.c.get('tags')
61
 
        self.assertEqual('much server', result[0])
62
 
        self.assertTrue('very performance' in result)
63
 
        self.assertEqual(2, len(result))