1
# Copyright 2012 Canonical Ltd. This software is licensed under the
2
# GNU Affero General Public License version 3 (see the file LICENSE).
4
"""Test generation of commissioning user data."""
6
from __future__ import (
17
from maasserver.testing.factory import factory
18
from maasserver.testing.testcase import TestCase
19
from maastesting.matchers import ContainsAll
20
from metadataserver.commissioning.user_data import (
29
class TestUserData(TestCase):
31
def test_read_snippet_reads_snippet_file(self):
32
contents = factory.getRandomString()
33
snippet = self.make_file(contents=contents)
36
read_snippet(os.path.dirname(snippet), os.path.basename(snippet)))
38
def test_strip_name_leaves_simple_names_intact(self):
39
simple_name = factory.getRandomString()
40
self.assertEqual(simple_name, strip_name(simple_name))
42
def test_strip_name_replaces_dots(self):
43
self.assertEqual('_x_y_', strip_name('.x.y.'))
45
def test_is_snippet(self):
53
'__init__.pyc': False,
57
{name: is_snippet(name) for name in are_snippets})
59
def test_list_snippets(self):
60
snippets_dir = self.make_dir()
61
factory.make_file(snippets_dir, 'snippet')
62
factory.make_file(snippets_dir, '.backup.pyc')
63
self.assertItemsEqual(['snippet'], list_snippets(snippets_dir))
65
def test_generate_user_data_produces_commissioning_script(self):
66
# generate_user_data produces a commissioning script which contains
67
# both definitions and use of various commands in python.
69
generate_user_data(), ContainsAll({
72
'def authenticate_headers',
73
'def encode_multipart_data',