Split tests into unit and integration

This commit is contained in:
Ben Firshman 2014-04-25 22:58:21 +01:00
parent 6e932794f7
commit ca7151aeb1
12 changed files with 124 additions and 105 deletions

View File

View File

@ -2,8 +2,8 @@ from __future__ import unicode_literals
from __future__ import absolute_import from __future__ import absolute_import
from .testcases import DockerClientTestCase from .testcases import DockerClientTestCase
from mock import patch from mock import patch
from fig.packages.six import StringIO
from fig.cli.main import TopLevelCommand from fig.cli.main import TopLevelCommand
from fig.packages.six import StringIO
class CLITestCase(DockerClientTestCase): class CLITestCase(DockerClientTestCase):
def setUp(self): def setUp(self):
@ -15,16 +15,6 @@ class CLITestCase(DockerClientTestCase):
self.command.project.kill() self.command.project.kill()
self.command.project.remove_stopped() self.command.project.remove_stopped()
def test_yaml_filename_check(self):
self.command.base_dir = 'tests/fixtures/longer-filename-figfile'
project = self.command.project
self.assertTrue( project.get_service('definedinyamlnotyml'), "Service: definedinyamlnotyml should have been loaded from .yaml file" )
def test_help(self):
self.assertRaises(SystemExit, lambda: self.command.dispatch(['-h'], None))
@patch('sys.stdout', new_callable=StringIO) @patch('sys.stdout', new_callable=StringIO)
def test_ps(self, mock_stdout): def test_ps(self, mock_stdout):
self.command.project.get_service('simple').create_container() self.command.project.get_service('simple').create_container()

View File

@ -4,65 +4,6 @@ from .testcases import DockerClientTestCase
class ProjectTest(DockerClientTestCase): class ProjectTest(DockerClientTestCase):
def test_from_dict(self):
project = Project.from_dicts('figtest', [
{
'name': 'web',
'image': 'ubuntu'
},
{
'name': 'db',
'image': 'ubuntu'
}
], self.client)
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'
}
], self.client)
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',
},
}, self.client)
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',
}, self.client)
def test_get_service(self):
web = self.create_service('web')
project = Project('test', [web], self.client)
self.assertEqual(project.get_service('web'), web)
def test_start_stop_kill_remove(self): def test_start_stop_kill_remove(self):
web = self.create_service('web') web = self.create_service('web')
db = self.create_service('db') db = self.create_service('db')

View File

@ -1,35 +1,11 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from __future__ import absolute_import from __future__ import absolute_import
from fig import Service from fig import Service
from fig.service import CannotBeScaledError, ConfigError from fig.service import CannotBeScaledError
from fig.packages.docker.errors import APIError from fig.packages.docker.errors import APIError
from .testcases import DockerClientTestCase from .testcases import DockerClientTestCase
class ServiceTest(DockerClientTestCase): class ServiceTest(DockerClientTestCase):
def test_name_validations(self):
self.assertRaises(ConfigError, lambda: Service(name=''))
self.assertRaises(ConfigError, lambda: Service(name=' '))
self.assertRaises(ConfigError, lambda: Service(name='/'))
self.assertRaises(ConfigError, lambda: Service(name='!'))
self.assertRaises(ConfigError, lambda: Service(name='\xe2'))
self.assertRaises(ConfigError, lambda: Service(name='_'))
self.assertRaises(ConfigError, lambda: Service(name='____'))
self.assertRaises(ConfigError, lambda: Service(name='foo_bar'))
self.assertRaises(ConfigError, lambda: Service(name='__foo_bar__'))
Service('a')
Service('foo')
def test_project_validation(self):
self.assertRaises(ConfigError, lambda: Service(name='foo', project='_'))
Service(name='foo', project='bar')
def test_config_validation(self):
self.assertRaises(ConfigError, lambda: Service(name='foo', port=['8000']))
Service(name='foo', ports=['8000'])
def test_containers(self): def test_containers(self):
foo = self.create_service('foo') foo = self.create_service('foo')
bar = self.create_service('bar') bar = self.create_service('bar')
@ -277,5 +253,3 @@ class ServiceTest(DockerClientTestCase):
self.assertEqual(len(containers), 2) self.assertEqual(len(containers), 2)
for container in containers: for container in containers:
self.assertEqual(list(container.inspect()['HostConfig']['PortBindings'].keys()), ['8000/tcp']) self.assertEqual(list(container.inspect()['HostConfig']['PortBindings'].keys()), ['8000/tcp'])

View File

@ -3,7 +3,7 @@ from __future__ import absolute_import
from fig.packages.docker import Client from fig.packages.docker import Client
from fig.service import Service from fig.service import Service
from fig.cli.utils import docker_url from fig.cli.utils import docker_url
from . import unittest from .. import unittest
class DockerClientTestCase(unittest.TestCase): class DockerClientTestCase(unittest.TestCase):

0
tests/unit/__init__.py Normal file
View File

16
tests/unit/cli_test.py Normal file
View File

@ -0,0 +1,16 @@
from __future__ import unicode_literals
from __future__ import absolute_import
from .. import unittest
from fig.cli.main import TopLevelCommand
from fig.packages.six import StringIO
class CLITestCase(unittest.TestCase):
def test_yaml_filename_check(self):
command = TopLevelCommand()
command.base_dir = 'tests/fixtures/longer-filename-figfile'
self.assertTrue(command.project.get_service('definedinyamlnotyml'))
def test_help(self):
command = TopLevelCommand()
with self.assertRaises(SystemExit):
command.dispatch(['-h'], None)

View File

@ -1,10 +1,10 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from .testcases import DockerClientTestCase from .. import unittest
from fig.container import Container from fig.container import Container
class ContainerTest(DockerClientTestCase): class ContainerTest(unittest.TestCase):
def test_from_ps(self): def test_from_ps(self):
container = Container.from_ps(self.client, { container = Container.from_ps(None, {
"Id":"abc", "Id":"abc",
"Image":"ubuntu:12.04", "Image":"ubuntu:12.04",
"Command":"sleep 300", "Command":"sleep 300",
@ -22,7 +22,7 @@ class ContainerTest(DockerClientTestCase):
}) })
def test_environment(self): def test_environment(self):
container = Container(self.client, { container = Container(None, {
'ID': 'abc', 'ID': 'abc',
'Config': { 'Config': {
'Env': [ 'Env': [
@ -37,7 +37,7 @@ class ContainerTest(DockerClientTestCase):
}) })
def test_number(self): def test_number(self):
container = Container.from_ps(self.client, { container = Container.from_ps(None, {
"Id":"abc", "Id":"abc",
"Image":"ubuntu:12.04", "Image":"ubuntu:12.04",
"Command":"sleep 300", "Command":"sleep 300",

View File

@ -0,0 +1,69 @@
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)

View File

@ -0,0 +1,29 @@
from __future__ import unicode_literals
from __future__ import absolute_import
from .. import unittest
from fig import Service
from fig.service import ConfigError
class ServiceTest(unittest.TestCase):
def test_name_validations(self):
self.assertRaises(ConfigError, lambda: Service(name=''))
self.assertRaises(ConfigError, lambda: Service(name=' '))
self.assertRaises(ConfigError, lambda: Service(name='/'))
self.assertRaises(ConfigError, lambda: Service(name='!'))
self.assertRaises(ConfigError, lambda: Service(name='\xe2'))
self.assertRaises(ConfigError, lambda: Service(name='_'))
self.assertRaises(ConfigError, lambda: Service(name='____'))
self.assertRaises(ConfigError, lambda: Service(name='foo_bar'))
self.assertRaises(ConfigError, lambda: Service(name='__foo_bar__'))
Service('a')
Service('foo')
def test_project_validation(self):
self.assertRaises(ConfigError, lambda: Service(name='foo', project='_'))
Service(name='foo', project='bar')
def test_config_validation(self):
self.assertRaises(ConfigError, lambda: Service(name='foo', port=['8000']))
Service(name='foo', ports=['8000'])

View File

@ -1,5 +1,5 @@
from fig.project import sort_service_dicts, DependencyError from fig.project import sort_service_dicts, DependencyError
from . import unittest from .. import unittest
class SortServiceTest(unittest.TestCase): class SortServiceTest(unittest.TestCase):

View File

@ -1,7 +1,7 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from __future__ import absolute_import from __future__ import absolute_import
from fig.cli.utils import split_buffer from fig.cli.utils import split_buffer
from . import unittest from .. import unittest
class SplitBufferTest(unittest.TestCase): class SplitBufferTest(unittest.TestCase):
def test_single_line_chunks(self): def test_single_line_chunks(self):