Merge "Fixed unit tests for hosts model"

This commit is contained in:
Jenkins 2013-05-20 19:14:51 +00:00 committed by Gerrit Code Review
commit 0d241c4282
1 changed files with 34 additions and 17 deletions

View File

@ -5,23 +5,35 @@ from cloudcafe.compute.hosts_api.models.hosts import Host
class HostDomainTest(object):
def test_host_name(self):
self.assertEqual(self.host.name, "host_name")
def test_resource_length(self):
self.assertTrue(len(self.host.resources) > 0)
def test_host_service(self):
self.assertEqual(self.host.service, "compute")
def test_host_resource_cpu(self):
self.assertEqual(self.host.resources[0].cpu, "1")
def test_host_zone(self):
self.assertEqual(self.host.zone, "nova")
def test_host_resource_disk(self):
self.assertEqual(self.host.resources[0].disk_gb, "1028")
def test_resource_host_name(self):
self.assertEqual(self.host.resources[0].host, "nova")
def test_host_resource_memory(self):
self.assertEqual(self.host.resources[0].memory_mb, "8192")
def test_host_resource_project(self):
self.assertEqual(self.host.resources[0].project, "(total)")
class HostDomainJSONTest(unittest.TestCase, HostDomainTest):
@classmethod
def setUp(cls):
cls.host_json = '{"host":{"host_name":' \
' "host_name","service":' \
' "compute","zone": "nova"}}'
cls.host_json = '{"host":[{"resource":' \
'{"cpu": "1",' \
'"disk_gb": "1028", ' \
' "host": "nova", ' \
'"memory_mb": "8192", ' \
'"project": "(total)"}}]}'
cls.host = Host.deserialize(cls.host_json, "json")
@ -30,8 +42,13 @@ class HostDomainXMLTest(unittest.TestCase, HostDomainTest):
@classmethod
def setUp(cls):
cls.host_xml = '<?xml version="1.0" encoding="UTF-8"?>' \
'<host host_name="host_name"' \
' service="compute" zone="nova"/>'
'<host> <resource>' \
' <project>(total)</project>' \
' <memory_mb>8192</memory_mb>' \
' <host>nova</host> <cpu>1</cpu>' \
' <disk_gb>1028</disk_gb>' \
' </resource> </host>'
cls.host = Host.deserialize(cls.host_xml, "xml")
@ -41,8 +58,8 @@ class HostDomainCollectionTest(object):
self.assertEqual(len(self.hosts), 2)
def test_host_names(self):
self.assertEqual(self.hosts[0].name, "host_name1")
self.assertEqual(self.hosts[1].name, "host_name2")
self.assertEqual(self.hosts[0].host_name, "host_name1")
self.assertEqual(self.hosts[1].host_name, "host_name2")
def test_host_services(self):
self.assertEqual(self.hosts[0].service, "compute1")
@ -59,11 +76,11 @@ class HostDomainCollectionJSONTest(unittest.TestCase,
@classmethod
def setUp(cls):
cls.hosts_json = '{"hosts":' \
'[{"host":{"host_name":' \
'[{"host_name":' \
' "host_name1","service": "compute1",' \
'"zone": "nova1"}},' \
'{"host":{"host_name": "host_name2",' \
'"service": "compute2","zone": "nova2"}}]}'
'"zone": "nova1"},' \
'{"host_name": "host_name2",' \
'"service": "compute2","zone": "nova2"}]}'
cls.hosts = Host.deserialize(cls.hosts_json, "json")