Esempio n. 1
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'
     }]
     self.instance = instance
     self.builder = PostgresDockerRunner(network_mode="host")
 def setUp(self):
     self.name = 'livetest-postgres-{}'.format(gen_salt(5))
     self.builder = PostgresDockerRunner(
         name=self.name,
     )
     self.builder.start()
     self.port = self.builder.client.port(
         self.builder.container['Id'],
         5432
     )[0]['HostPort']
Esempio n. 3
0
class TestPostgresDockerRunner(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'
            }
        ]
        self.instance = instance
        self.builder = PostgresDockerRunner(network_mode="host")

    def test_ready(self):
        """
        Tests the health check of the service
        """

        with mock.patch('mc.builders.create_engine') as mocked:
            engine_instance = mocked.return_value
            engine_instance.connect.side_effect = OperationalError('', '', '', '')
            self.assertFalse(self.builder.ready)

        with mock.patch('mc.builders.create_engine') as mocked:
            engine_instance = mocked.return_value
            engine_instance.connect.return_value = ''
            self.assertTrue(self.builder.ready)

    @mock.patch('mc.builders.PostgresDockerRunner.service_provisioner')
    def test_can_provision(self, mocked):
        """
        Tests that there is a method that allows provisioning
        """
        self.builder.provision(services=['adsaws'])

        mocked.assert_has_calls([
            mock.call(container=self.builder, requirements=None, services=['adsaws']),
            mock.call()()
        ])
Esempio n. 4
0
class TestPostgresDockerRunner(unittest.TestCase):
    """
    Test the docker runner for the Postgres service
    """
    def setUp(self):
        self.name = 'livetest-postgres-{}'.format(gen_salt(5))
        self.builder = PostgresDockerRunner(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)
Esempio n. 5
0
class TestPostgresDockerRunner(unittest.TestCase):
    """
    Test the docker runner for the Postgres service
    """

    def setUp(self):
        self.name = 'livetest-postgres-{}'.format(gen_salt(5))
        self.builder = PostgresDockerRunner(
            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)
Esempio n. 6
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'
         }
     ]
     self.instance = instance
     self.builder = PostgresDockerRunner(network_mode="host")
class TestPostgresProvisioner(unittest.TestCase):
    """
    Test the PostgresProvisioner. Use the Docker builder to create the database
    """

    def setUp(self):
        self.name = 'livetest-postgres-{}'.format(gen_salt(5))
        self.builder = PostgresDockerRunner(
            name=self.name,
        )
        self.builder.start()
        self.port = self.builder.client.port(
            self.builder.container['Id'],
            5432
        )[0]['HostPort']

    def tearDown(self):
        self.builder.teardown()

    def _make_db_connection(self, db, user=None):
        """
        retruns a sqlalchemy connection object to a database
        """
        if user is None:
            user = db

        engine = create_engine(
            'postgresql://{user}@localhost:{port}/{db}'.format(
                user=user, port=self.port, db=db
            )
        )
        return engine.connect()

    def _provision(self, service):
        """
        Run the provision for a given service
        """
        # Modifying a live application's config is the most straightforward
        # way to connect to a non-default port for this test case

        PostgresProvisioner(service, container=self.builder)()

    def test_provisioning_adsws(self):
        """
        after running the provisioner, make sure that the anon user and
        anon oauth2client exist within the postgres instance
        """

        self._provision('adsws')
        conn = self._make_db_connection('adsws')
        res = conn.execute('SELECT * FROM users').fetchall()
        anon_user = filter(
            lambda i: i['email'] == 'anonymous@ads',
            res,
        )[0]
        self.assertIsNotNone(anon_user)

        res = conn.execute('SELECT * FROM oauth2client').fetchall()
        anon_client = filter(
            lambda i: i['user_id'] == anon_user['id'],
            res,
        )
        self.assertIsNotNone(anon_client)

    def test_provisioning_recommender(self):
        """
        after running the provisioner, make sure that the recommender has the
        expected tables and that they return at least 1 row
        """

        self._provision('recommender')
        conn = self._make_db_connection('recommender')
        coreads = conn.execute('SELECT * FROM coreads').fetchall()
        clusters = conn.execute('SELECT * FROM clusters').fetchall()
        clustering = conn.execute('SELECT * FROM clustering').fetchall()

        self.assertGreater(len(coreads), 0)
        self.assertGreater(len(clusters), 0)
        self.assertGreater(len(clustering), 0)
Esempio n. 8
0
class TestPostgresDockerRunner(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'
        }]
        self.instance = instance
        self.builder = PostgresDockerRunner(network_mode="host")

    def test_ready(self):
        """
        Tests the health check of the service
        """

        with mock.patch('mc.builders.create_engine') as mocked:
            engine_instance = mocked.return_value
            engine_instance.connect.side_effect = OperationalError(
                '', '', '', '')
            self.assertFalse(self.builder.ready)

        with mock.patch('mc.builders.create_engine') as mocked:
            engine_instance = mocked.return_value
            engine_instance.connect.return_value = ''
            self.assertTrue(self.builder.ready)

    @mock.patch('mc.builders.PostgresDockerRunner.service_provisioner')
    def test_can_provision(self, mocked):
        """
        Tests that there is a method that allows provisioning
        """
        self.builder.provision(services=['adsaws'])

        mocked.assert_has_calls([
            mock.call(container=self.builder,
                      requirements=None,
                      services=['adsaws']),
            mock.call()()
        ])
Esempio n. 9
0
 def setUp(self):
     self.name = 'livetest-postgres-{}'.format(gen_salt(5))
     self.builder = PostgresDockerRunner(name=self.name, )
Esempio n. 10
0
 def setUp(self):
     self.name = 'livetest-postgres-{}'.format(gen_salt(5))
     self.builder = PostgresDockerRunner(
         name=self.name,
     )