Added more tests for snapshot XML
Added factory_boy to test-requirements Added method for generating random strings using factory_boy Partial-Bug: #1462906 Change-Id: I23c09be4c6543f149edeabc45ec31b7826890c97
This commit is contained in:
parent
8c26cab916
commit
5e059e14a1
|
@ -0,0 +1,21 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright 2015 Mirantis, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
from factory import fuzzy
|
||||
|
||||
|
||||
def fuzzy_string(*args, **kwargs):
|
||||
"""Shortcut for getting fuzzy text"""
|
||||
return fuzzy.FuzzyText(*args, **kwargs).fuzz()
|
|
@ -19,6 +19,7 @@ from unittest import TestCase
|
|||
import mock
|
||||
|
||||
from devops.driver.libvirt.libvirt_xml_builder import LibvirtXMLBuilder
|
||||
from devops.tests import factories
|
||||
|
||||
|
||||
class BaseTestXMLBuilder(TestCase):
|
||||
|
@ -118,16 +119,43 @@ class TestVolumeXml(BaseTestXMLBuilder):
|
|||
|
||||
class TestSnapshotXml(BaseTestXMLBuilder):
|
||||
|
||||
def check_snaphot_xml(self, name, description, expected):
|
||||
result = self.xml_builder.build_snapshot_xml(name, description)
|
||||
self.assertIn(expected, result)
|
||||
|
||||
def test_no_name(self):
|
||||
name = None
|
||||
description = factories.fuzzy_string('test_description_')
|
||||
expected = '''
|
||||
<domainsnapshot>
|
||||
<description>{0}</description>
|
||||
</domainsnapshot>'''.format(description)
|
||||
self.check_snaphot_xml(name, description, expected)
|
||||
|
||||
def test_no_description(self):
|
||||
name = factories.fuzzy_string('test_snapshot_')
|
||||
description = None
|
||||
expected = '''
|
||||
<domainsnapshot>
|
||||
<name>{0}</name>
|
||||
</domainsnapshot>'''.format(name)
|
||||
self.check_snaphot_xml(name, description, expected)
|
||||
|
||||
def test_nothing_there(self):
|
||||
name = None
|
||||
description = None
|
||||
expected = '<domainsnapshot />'
|
||||
self.check_snaphot_xml(name, description, expected)
|
||||
|
||||
def test_snapshot(self):
|
||||
name = 'test_snapshot'
|
||||
description = 'test_description'
|
||||
xml = self.xml_builder.build_snapshot_xml(name, description)
|
||||
self.assertIn(
|
||||
'''
|
||||
name = factories.fuzzy_string('test_snapshot_')
|
||||
description = factories.fuzzy_string('test_description_')
|
||||
expected = '''
|
||||
<domainsnapshot>
|
||||
<name>{0}</name>
|
||||
<description>{1}</description>
|
||||
</domainsnapshot>'''.format(name, description), xml)
|
||||
</domainsnapshot>'''.format(name, description)
|
||||
self.check_snaphot_xml(name, description, expected)
|
||||
|
||||
|
||||
class TestNodeXml(BaseTestXMLBuilder):
|
||||
|
|
|
@ -2,3 +2,4 @@ mock >= 1.0.1
|
|||
pytest >= 2.7.1
|
||||
pytest-django >= 2.8.0
|
||||
py == 1.4.26 # https://bitbucket.org/pytest-dev/pytest/issue/752/internalerror-indexerror-list-index-out-of
|
||||
factory_boy == 2.5.2
|
||||
|
|
Loading…
Reference in New Issue