diff --git a/tests/integration/__init__.py b/tests/integration/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/cli_test.py b/tests/integration/cli_test.py similarity index 88% rename from tests/cli_test.py rename to tests/integration/cli_test.py index 2b81e26b0..125b018ed 100644 --- a/tests/cli_test.py +++ b/tests/integration/cli_test.py @@ -2,8 +2,8 @@ from __future__ import unicode_literals from __future__ import absolute_import from .testcases import DockerClientTestCase from mock import patch -from fig.packages.six import StringIO from fig.cli.main import TopLevelCommand +from fig.packages.six import StringIO class CLITestCase(DockerClientTestCase): def setUp(self): @@ -15,16 +15,6 @@ class CLITestCase(DockerClientTestCase): self.command.project.kill() 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) def test_ps(self, mock_stdout): self.command.project.get_service('simple').create_container() diff --git a/tests/project_test.py b/tests/integration/project_test.py similarity index 61% rename from tests/project_test.py rename to tests/integration/project_test.py index bde40e89b..fa7e38586 100644 --- a/tests/project_test.py +++ b/tests/integration/project_test.py @@ -4,65 +4,6 @@ from .testcases import 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): web = self.create_service('web') db = self.create_service('db') diff --git a/tests/service_test.py b/tests/integration/service_test.py similarity index 90% rename from tests/service_test.py rename to tests/integration/service_test.py index 78947e1f6..78ddbd850 100644 --- a/tests/service_test.py +++ b/tests/integration/service_test.py @@ -1,35 +1,11 @@ from __future__ import unicode_literals from __future__ import absolute_import from fig import Service -from fig.service import CannotBeScaledError, ConfigError +from fig.service import CannotBeScaledError from fig.packages.docker.errors import APIError from .testcases import 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): foo = self.create_service('foo') bar = self.create_service('bar') @@ -277,5 +253,3 @@ class ServiceTest(DockerClientTestCase): self.assertEqual(len(containers), 2) for container in containers: self.assertEqual(list(container.inspect()['HostConfig']['PortBindings'].keys()), ['8000/tcp']) - - diff --git a/tests/testcases.py b/tests/integration/testcases.py similarity index 97% rename from tests/testcases.py rename to tests/integration/testcases.py index ac395040d..f913b7c3e 100644 --- a/tests/testcases.py +++ b/tests/integration/testcases.py @@ -3,7 +3,7 @@ from __future__ import absolute_import from fig.packages.docker import Client from fig.service import Service from fig.cli.utils import docker_url -from . import unittest +from .. import unittest class DockerClientTestCase(unittest.TestCase): diff --git a/tests/unit/__init__.py b/tests/unit/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/unit/cli_test.py b/tests/unit/cli_test.py new file mode 100644 index 000000000..a3f138048 --- /dev/null +++ b/tests/unit/cli_test.py @@ -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) diff --git a/tests/container_test.py b/tests/unit/container_test.py similarity index 84% rename from tests/container_test.py rename to tests/unit/container_test.py index 351a807a8..b1d87f7cf 100644 --- a/tests/container_test.py +++ b/tests/unit/container_test.py @@ -1,10 +1,10 @@ from __future__ import unicode_literals -from .testcases import DockerClientTestCase +from .. import unittest from fig.container import Container -class ContainerTest(DockerClientTestCase): +class ContainerTest(unittest.TestCase): def test_from_ps(self): - container = Container.from_ps(self.client, { + container = Container.from_ps(None, { "Id":"abc", "Image":"ubuntu:12.04", "Command":"sleep 300", @@ -22,7 +22,7 @@ class ContainerTest(DockerClientTestCase): }) def test_environment(self): - container = Container(self.client, { + container = Container(None, { 'ID': 'abc', 'Config': { 'Env': [ @@ -37,7 +37,7 @@ class ContainerTest(DockerClientTestCase): }) def test_number(self): - container = Container.from_ps(self.client, { + container = Container.from_ps(None, { "Id":"abc", "Image":"ubuntu:12.04", "Command":"sleep 300", diff --git a/tests/unit/project_test.py b/tests/unit/project_test.py new file mode 100644 index 000000000..4a2ad1422 --- /dev/null +++ b/tests/unit/project_test.py @@ -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) diff --git a/tests/unit/service_test.py b/tests/unit/service_test.py new file mode 100644 index 000000000..490cb60d6 --- /dev/null +++ b/tests/unit/service_test.py @@ -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']) diff --git a/tests/sort_service_test.py b/tests/unit/sort_service_test.py similarity index 99% rename from tests/sort_service_test.py rename to tests/unit/sort_service_test.py index 13cff89d1..e2a7bdb38 100644 --- a/tests/sort_service_test.py +++ b/tests/unit/sort_service_test.py @@ -1,5 +1,5 @@ from fig.project import sort_service_dicts, DependencyError -from . import unittest +from .. import unittest class SortServiceTest(unittest.TestCase): diff --git a/tests/split_buffer_test.py b/tests/unit/split_buffer_test.py similarity index 97% rename from tests/split_buffer_test.py rename to tests/unit/split_buffer_test.py index b90463c07..a78e99a6e 100644 --- a/tests/split_buffer_test.py +++ b/tests/unit/split_buffer_test.py @@ -1,7 +1,7 @@ from __future__ import unicode_literals from __future__ import absolute_import from fig.cli.utils import split_buffer -from . import unittest +from .. import unittest class SplitBufferTest(unittest.TestCase): def test_single_line_chunks(self):