def test_run_test_environment_task(self): """ Test that we can start tests in the test environment """ test_id = '34fef34fsdf' name = 'livetest-pythonserver-{}'.format(test_id) container = GunicornDockerRunner( name=name, image='adsabs/pythonsimpleserver:v1.0.0') container.start() run_test_in_environment(test_id=test_id, test_services=['adsrex'], api_name=name)
def setUp(self): """ Setup the tests """ self.name = 'livetest-adsws-pythonsimpleserver-{}'.format(gen_salt(5)) self.builder = GunicornDockerRunner( image='adsabs/pythonsimpleserver:v1.0.0', name=self.name, ) self.builder.start() info = self.builder.client.port( self.builder.container['Id'], 80 )[0] self.host = info['HostIp'] self.port = info['HostPort']
def test_run_test_environment_task(self): """ Test that we can start tests in the test environment """ test_id = '34fef34fsdf' name = 'livetest-pythonserver-{}'.format(test_id) container = GunicornDockerRunner( name=name, image='adsabs/pythonsimpleserver:v1.0.0' ) container.start() run_test_in_environment( test_id=test_id, test_services=['adsrex'], api_name=name )
class TestGunicornDockerRunner(unittest.TestCase): """ Test the docker runner for the Postgres service """ def setUp(self): self.name = 'livetest-gunicorn-{}'.format(gen_salt(5)) self.builder = GunicornDockerRunner( image='adsabs/pythonsimpleserver:v1.0.0', name=self.name, ) def tearDown(self): """ teardown the containers """ try: self.builder.teardown() except: pass def test_is_ready(self): """ Check if the instance is ready """ self.builder.start() self.assertTrue(self.builder.running) self.assertTrue(self.builder.ready) self.builder.teardown() self.assertFalse(self.builder.ready) self.assertFalse(self.builder.running)
class TestTestProvisioner(unittest.TestCase): """ Test the provisioning of the test cluster script """ def setUp(self): """ Setup the tests """ self.name = 'livetest-adsws-pythonsimpleserver-{}'.format(gen_salt(5)) self.builder = GunicornDockerRunner( image='adsabs/pythonsimpleserver:v1.0.0', name=self.name, ) self.builder.start() info = self.builder.client.port( self.builder.container['Id'], 80 )[0] self.host = info['HostIp'] self.port = info['HostPort'] def tearDown(self): """ Teardown the tests """ self.builder.teardown() def test_that_the_script_file_is_provisioned(self): """ Tests that the script file is provisioned as we expect it to be """ test_provisioner = TestProvisioner(services=['adsrex']) api_url = 'API_URL="http://{host}:{port}"'.format( host=self.host, port=self.port ) self.assertIn(api_url, test_provisioner.scripts[0])
def setUp(self, mocked): instance = mocked.return_value instance.create_container.return_value = {'Id': 'mocked'} instance.port.return_value = [{ 'HostIp': '127.0.0.1', 'HostPort': 1234 }] instance.containers.return_value = [{ u'Command': u'/entrypoint.sh redis-server', u'Created': 1443632967, u'Id': u'mocked', u'Image': u'redis', u'Labels': {}, u'Names': [u'/livetest-redis-tLJpZ'], u'Ports': [{ u'PrivatePort': 6379, u'Type': u'tcp' }], u'Status': u'Up About a minute' }] instance.create_host_config.return_value = { 'PortBindings': { '80/tcp': [{ 'HostPort': '', 'HostIp': '' }] }, 'NetworkMode': 'host' } self.instance = instance self.environment = dict(consul_host='localhost', consul_port=8500) self.builder = GunicornDockerRunner(network_mode="host", environment=self.environment)
def setUp(self, mocked): instance = mocked.return_value instance.create_container.return_value = {'Id': 'mocked'} instance.port.return_value = [{'HostIp': '127.0.0.1', 'HostPort': 1234}] instance.containers.return_value = [ { u'Command': u'/entrypoint.sh redis-server', u'Created': 1443632967, u'Id': u'mocked', u'Image': u'redis', u'Labels': {}, u'Names': [u'/livetest-redis-tLJpZ'], u'Ports': [{u'PrivatePort': 6379, u'Type': u'tcp'}], u'Status': u'Up About a minute' } ] instance.create_host_config.return_value = {'PortBindings': { '80/tcp': [{'HostPort': '', 'HostIp': ''}] }, 'NetworkMode': 'host'} self.instance = instance self.environment = dict(consul_host='localhost', consul_port=8500) self.builder = GunicornDockerRunner(network_mode="host", environment=self.environment)
class TestGunicornDockerRunner(unittest.TestCase): """ Test the docker runner """ @mock.patch('mc.builders.Client') def setUp(self, mocked): instance = mocked.return_value instance.create_container.return_value = {'Id': 'mocked'} instance.port.return_value = [{'HostIp': '127.0.0.1', 'HostPort': 1234}] instance.containers.return_value = [ { u'Command': u'/entrypoint.sh redis-server', u'Created': 1443632967, u'Id': u'mocked', u'Image': u'redis', u'Labels': {}, u'Names': [u'/livetest-redis-tLJpZ'], u'Ports': [{u'PrivatePort': 6379, u'Type': u'tcp'}], u'Status': u'Up About a minute' } ] instance.create_host_config.return_value = {'PortBindings': { '80/tcp': [{'HostPort': '', 'HostIp': ''}] }, 'NetworkMode': 'host'} self.instance = instance self.environment = dict(consul_host='localhost', consul_port=8500) self.builder = GunicornDockerRunner(network_mode="host", environment=self.environment) def test_can_set_consul(self): """ Tests that consul properties get passed correctly """ expected_call = mock.call( command=None, image=None, name=None, environment={'consul_host': 'localhost', 'consul_port': 8500}, host_config={'PortBindings': { '80/tcp': [{'HostPort': '', 'HostIp': ''}] }, 'NetworkMode': 'host'} ) self.instance.create_container.assert_has_calls( [expected_call] ) def test_ready(self): """ Tests the health check of the service """ with mock.patch.object(mc.builders.requests, 'get', side_effect=requests.ConnectionError): self.assertFalse(self.builder.ready) with HTTMock(response_500): self.assertFalse(self.builder.ready) with HTTMock(response_200): self.assertTrue(self.builder.ready) def test_can_provision(self): """ Tests that there is a method that allows provisioning """ try: self.builder.provision(services=['adsaws']) except Exception as e: self.fail('Provisioning failed: {}'.format(e))
class TestGunicornDockerRunner(unittest.TestCase): """ Test the docker runner """ @mock.patch('mc.builders.Client') def setUp(self, mocked): instance = mocked.return_value instance.create_container.return_value = {'Id': 'mocked'} instance.port.return_value = [{ 'HostIp': '127.0.0.1', 'HostPort': 1234 }] instance.containers.return_value = [{ u'Command': u'/entrypoint.sh redis-server', u'Created': 1443632967, u'Id': u'mocked', u'Image': u'redis', u'Labels': {}, u'Names': [u'/livetest-redis-tLJpZ'], u'Ports': [{ u'PrivatePort': 6379, u'Type': u'tcp' }], u'Status': u'Up About a minute' }] instance.create_host_config.return_value = { 'PortBindings': { '80/tcp': [{ 'HostPort': '', 'HostIp': '' }] }, 'NetworkMode': 'host' } self.instance = instance self.environment = dict(consul_host='localhost', consul_port=8500) self.builder = GunicornDockerRunner(network_mode="host", environment=self.environment) def test_can_set_consul(self): """ Tests that consul properties get passed correctly """ expected_call = mock.call(command=None, image=None, name=None, environment={ 'consul_host': 'localhost', 'consul_port': 8500 }, host_config={ 'PortBindings': { '80/tcp': [{ 'HostPort': '', 'HostIp': '' }] }, 'NetworkMode': 'host' }) self.instance.create_container.assert_has_calls([expected_call]) def test_ready(self): """ Tests the health check of the service """ with mock.patch.object(mc.builders.requests, 'get', side_effect=requests.ConnectionError): self.assertFalse(self.builder.ready) with HTTMock(response_500): self.assertFalse(self.builder.ready) with HTTMock(response_200): self.assertTrue(self.builder.ready) def test_can_provision(self): """ Tests that there is a method that allows provisioning """ try: self.builder.provision(services=['adsaws']) except Exception as e: self.fail('Provisioning failed: {}'.format(e))
def setUp(self): self.name = 'livetest-gunicorn-{}'.format(gen_salt(5)) self.builder = GunicornDockerRunner( image='adsabs/pythonsimpleserver:v1.0.0', name=self.name, )