mirror of https://github.com/docker/compose.git
70 lines
2.3 KiB
Python
70 lines
2.3 KiB
Python
|
from __future__ import unicode_literals
|
||
|
from .. import unittest
|
||
|
from fig.service import Service
|
||
|
from fig.project import Project, ConfigurationError
|
||
|
|
||
|
class ProjectTest(unittest.TestCase):
|
||
|
def test_from_dict(self):
|
||
|
project = Project.from_dicts('figtest', [
|
||
|
{
|
||
|
'name': 'web',
|
||
|
'image': 'ubuntu'
|
||
|
},
|
||
|
{
|
||
|
'name': 'db',
|
||
|
'image': 'ubuntu'
|
||
|
}
|
||
|
], None)
|
||
|
self.assertEqual(len(project.services), 2)
|
||
|
self.assertEqual(project.get_service('web').name, 'web')
|
||
|
self.assertEqual(project.get_service('web').options['image'], 'ubuntu')
|
||
|
self.assertEqual(project.get_service('db').name, 'db')
|
||
|
self.assertEqual(project.get_service('db').options['image'], 'ubuntu')
|
||
|
|
||
|
def test_from_dict_sorts_in_dependency_order(self):
|
||
|
project = Project.from_dicts('figtest', [
|
||
|
{
|
||
|
'name': 'web',
|
||
|
'image': 'ubuntu',
|
||
|
'links': ['db'],
|
||
|
},
|
||
|
{
|
||
|
'name': 'db',
|
||
|
'image': 'ubuntu'
|
||
|
}
|
||
|
], None)
|
||
|
|
||
|
self.assertEqual(project.services[0].name, 'db')
|
||
|
self.assertEqual(project.services[1].name, 'web')
|
||
|
|
||
|
def test_from_config(self):
|
||
|
project = Project.from_config('figtest', {
|
||
|
'web': {
|
||
|
'image': 'ubuntu',
|
||
|
},
|
||
|
'db': {
|
||
|
'image': 'ubuntu',
|
||
|
},
|
||
|
}, None)
|
||
|
self.assertEqual(len(project.services), 2)
|
||
|
self.assertEqual(project.get_service('web').name, 'web')
|
||
|
self.assertEqual(project.get_service('web').options['image'], 'ubuntu')
|
||
|
self.assertEqual(project.get_service('db').name, 'db')
|
||
|
self.assertEqual(project.get_service('db').options['image'], 'ubuntu')
|
||
|
|
||
|
def test_from_config_throws_error_when_not_dict(self):
|
||
|
with self.assertRaises(ConfigurationError):
|
||
|
project = Project.from_config('figtest', {
|
||
|
'web': 'ubuntu',
|
||
|
}, None)
|
||
|
|
||
|
def test_get_service(self):
|
||
|
web = Service(
|
||
|
project='figtest',
|
||
|
name='web',
|
||
|
client=None,
|
||
|
image="ubuntu",
|
||
|
)
|
||
|
project = Project('test', [web], None)
|
||
|
self.assertEqual(project.get_service('web'), web)
|