Exemple #1
0
class SessionTestCase(unittest.TestCase):
    def setUp(self):
        super(SessionTestCase, self).setUp()
        Session._reset()
        self.session = Session()

    def test_get_core_service(self):
        client = self.session.get_core_service('sqs')
        self.assertTrue(isinstance(client, BotocoreService))

    def test_get_service_exists(self):
        self.assertEqual(len(Session.conn_classes), 0)
        # Put in a sentinel.
        Session.conn_classes['test'] = None
        self.assertEqual(len(Session.conn_classes), 1)

        client = self.session.get_service('test')
        self.assertTrue(client is None)

    def test_get_service_does_not_exist(self):
        self.assertEqual(len(self.session.conn_classes), 0)
        client = self.session.get_service('sqs')
        self.assertEqual(client.__name__, 'SqsConnection')
        self.assertEqual(len(self.session.conn_classes), 1)

    def test_connect_to_region(self):
        client = self.session.connect_to('sqs', region_name='us-west-2')
        self.assertEqual(client.__class__.__name__, 'SqsConnection')
        self.assertEqual(client.region_name, 'us-west-2')
 def setUp(self):
     super(ServiceDetailsTestCase, self).setUp()
     self.session = Session(FakeSession(TestCoreService()))
     self.sd = ServiceDetails(
         service_name='test',
         session=self.session
     )
    def setUp(self):
        super(BaseMethodTestCase, self).setUp()
        self.fake_resource = FakeResource()
        self.create_method = BaseMethod('create_queue')
        self.create_method.resource = self.fake_resource

        self.session = Session(FakeSession(TestCoreService()))
        self.sf = ServiceFactory(session=self.session)
        self.conn_class = self.sf.construct_for('test')
        self.conn = self.conn_class()
Exemple #4
0
class ConnectionTestCase(object):
    """
    A base class to make testing connections a little less verbose/more
    standard.

    This automatically sets up a connection object for the service
    (``self.conn``) & runs a test to ensure the connection has all the right
    API methods.

    Usage::

        from tests.integration.base import ConnectionTestCase
        from tests import unittest


        class MyConnTest(ConnectionTestCase, unittest.TestCase):
            service_name = 's3'
            ops = [
                'abort_multipart_upload',
                'complete_multipart_upload',
                'copy_object',
                'create_bucket',
                'create_multipart_upload',
                # ...
            ]

            # You can add your own test methods here...

    """
    service_name = None
    ops = []

    def setUp(self):
        super(ConnectionTestCase, self).setUp()
        self.session = Session()
        self.conn_class = self.session.get_connection(self.service_name)
        self.conn = self.conn_class()

    def test_op_methods(self):
        if not self.service_name:
            return

        if not len(self.ops):
            self.fail("There are no expected Connection methods supplied.")

        for op_name in self.ops:
            self.assertTrue(
                hasattr(self.conn, op_name),
                msg="{0} is missing.".format(op_name)
            )
            self.assertTrue(
                callable(getattr(self.conn, op_name)),
                msg="{0} is not callable.".format(op_name)
            )
Exemple #5
0
    def test_init_with_session(self):
        # With an explicit session.
        mpo = mock.patch.object
        session = Session()

        with mpo(session, 'connect_to', return_value=self.conn) as mock_conn:
            test = TestResource(session=session)
            self.assertEqual(test._session, session)
            self.assertEqual(test._data, {})

        mock_conn.assert_called_once_with('test')
    def test_init_with_session(self):
        # With an explicit session.
        mpo = mock.patch.object
        session = Session()

        with mpo(session, 'connect_to', return_value=self.conn) as mock_conn:
            test = TestResourceCollection(session=session)
            self.assertEqual(test._session, session)
            self.assertEqual(
                test._resource_class,
                'tests.unit.core.resources.test_collections.FakeQueue'
            )

        mock_conn.assert_called_once_with('test')
    def test_reload_service_data(self):
        service_data = self.sd._introspect_service(
            self.session.core_session,
            'test'
        )
        self.assertEqual(sorted(list(service_data.keys())), [
            'create_queue',
            'delete_queue'
        ])

        # Now it changed.
        self.sd.session = Session(FakeSession(ChangedTestCoreService()))
        self.sd.reload_service_data()
        self.assertEqual(sorted(list(self.sd.service_data.keys())), [
            'delete_queue'
        ])
Exemple #8
0
 def setUp(self):
     super(SessionTestCase, self).setUp()
     Session._reset()
     self.session = Session()
Exemple #9
0
 def setUp(self):
     super(ConnectionTestCase, self).setUp()
     self.session = Session()
     self.conn_class = self.session.get_connection(self.service_name)
     self.conn = self.conn_class()
Exemple #10
0
 def setUp(self):
     super(SQSConnectionTestCase, self).setUp()
     self.sqs_class = Session().get_service('sqs')
     self.sqs = self.sqs_class()
 def setUp(self):
     super(ServiceFactoryTestCase, self).setUp()
     self.session = Session(FakeSession(TestCoreService()))
     self.sf = ServiceFactory(session=self.session)
     self.test_service_class = self.sf.construct_for('test')
Exemple #12
0
def get_version(full=False):
    """
    Returns a string-ified version number.

    Optionally accepts a ``full`` parameter, which if ``True``, will include
    any pre-release information. (Default: ``False``)
    """
    version = '.'.join([str(bit) for bit in __version__[:3]])

    if full:
        version = '-'.join([version] + list(__version__[3:]))

    return version


# Set up logging to ``/dev/null`` like a library is supposed to.
# http://docs.python.org/3.3/howto/logging.html#configuring-logging-for-a-library
class NullHandler(logging.Handler):
    def emit(self, record):
        pass


log = logging.getLogger('boto3')
log.addHandler(NullHandler())
# End logging setup.

# A plain default ``Session`` (for convenience).
from boto3.core.session import Session
session = Session()
Exemple #13
0
class SessionTestCase(unittest.TestCase):
    def setUp(self):
        super(SessionTestCase, self).setUp()
        self.session = Session()

    def test_get_core_service(self):
        client = self.session.get_core_service('sqs')
        self.assertTrue(isinstance(client, BotocoreService))

    def test_get_connection_exists(self):
        self.assertEqual(len(self.session.cache), 0)
        # Put in a sentinel.
        self.session.cache.set_connection('test', FakeConnection)
        self.assertEqual(len(self.session.cache), 1)

        client = self.session.get_connection('test')
        self.assertTrue(client is FakeConnection)

    def test_get_connection_does_not_exist(self):
        self.assertEqual(len(self.session.cache), 0)
        client = self.session.get_connection('sqs')
        self.assertEqual(client.__name__, 'SqsConnection')
        self.assertEqual(len(self.session.cache), 1)

    def test_get_resource_exists(self):
        self.assertEqual(len(self.session.cache), 0)
        # Put in a sentinel.
        self.session.cache.set_resource('test', 'Test', FakeConnection)
        self.assertEqual(len(self.session.cache), 1)

        # Ugly, but needed due to our faking connections above.
        Test = self.session.get_resource('test', 'Test', base_class=object)
        self.assertTrue(Test is FakeConnection)

    def test_get_resource_does_not_exist(self):
        self.assertEqual(len(self.session.cache), 0)
        Queue = self.session.get_resource('sqs', 'Queue')
        self.assertEqual(Queue.__name__, 'Queue')
        self.assertEqual(len(self.session.cache), 1)

    def test_get_collection_exists(self):
        self.assertEqual(len(self.session.cache), 0)
        # Put in a sentinel.
        self.session.cache.set_collection('test', 'Test', FakeConnection)
        self.assertEqual(len(self.session.cache), 1)

        # Ugly, but needed due to our faking connections above.
        TestCollection = self.session.get_collection(
            'test',
            'Test',
            base_class=object
        )
        self.assertTrue(TestCollection is FakeConnection)

    def test_get_collection_does_not_exist(self):
        self.assertEqual(len(self.session.cache), 0)
        QueueCollection = self.session.get_collection('sqs', 'QueueCollection')
        self.assertEqual(QueueCollection.__name__, 'QueueCollection')
        self.assertEqual(len(self.session.cache), 1)

    def test_connect_to_region(self):
        client = self.session.connect_to('sqs', region_name='us-west-2')
        self.assertEqual(client.__class__.__name__, 'SqsConnection')
        self.assertEqual(client.region_name, 'us-west-2')
 def setUp(self):
     super(ResourceCollectionTestCase, self).setUp()
     self.session = Session(FakeSession(TestCoreService()))
     self.sf = ServiceFactory(session=self.session)
     self.conn_class = self.sf.construct_for('test')
     self.conn = self.conn_class()