Repository: boto/boto3
File: tests/unit/test_session.py (Python)

Code before:

    def test_get_available_services(self):
        bc_session = self.bc_session_cls.return_value

        session = Session()
        session.get_available_services()

        self.assertTrue(bc_session.get_available_services.called,
            'Botocore session get_available_services not called')

    def test_get_available_resources(self):
        session = Session()
        resources = session.get_available_resources()
        self.assertIsInstance(resources, list)

    def test_create_client(self):
        bc_session = self.bc_session_cls.return_value

        session = Session(region_name='us-east-1')
        client = session.client('sqs', region_name='us-west-2')

        bc_session.create_client.assert_called_with(
            'sqs', aws_secret_access_key=None, aws_access_key_id=None,
            endpoint_url=None, use_ssl=True, aws_session_token=None,
            verify=None, region_name='us-west-2', api_version=None)
        self.assertTrue(client,
            'No low-level client was returned')

    def test_create_resource(self):
        session = Session()
        session.client = mock.Mock()
        session.resource_factory.create_class = mock.Mock()
        cls = session.resource_factory.create_class.return_value

        sqs = session.resource('sqs', verify=False)

        session.client.assert_called_with(
            'sqs', aws_secret_access_key=None, aws_access_key_id=None,
            endpoint_url=None, use_ssl=True, aws_session_token=None,
            verify=False, region_name=None, api_version=None)
        self.assertTrue(session.resource_factory.create_class.called,
            'Resource factory did not look up class')
        self.assertTrue(cls.called,
            'Resource instance was not created')
        self.assertEqual(sqs, cls.return_value,
            'Returned instance is not an instance of the looked up resource '
            'class from the factory')


Review comment (suggestion):
I would just make it a separate test for testing if region gets overridden. I feel that warrants a separate test since this test just makes sure that the botocore session is used to make the client. 


Code after:

    def test_get_available_services(self):
        bc_session = self.bc_session_cls.return_value

        session = Session()
        session.get_available_services()

        self.assertTrue(bc_session.get_available_services.called,
            'Botocore session get_available_services not called')

    def test_get_available_resources(self):
        session = Session()
        resources = session.get_available_resources()
        self.assertIsInstance(resources, list)

    def test_create_client(self):
        session = Session(region_name='us-east-1')
        client = session.client('sqs', region_name='us-west-2')

        self.assertTrue(client,
            'No low-level client was returned')

    def test_create_client_with_args(self):
        bc_session = self.bc_session_cls.return_value

        session = Session(region_name='us-east-1')
        session.client('sqs', region_name='us-west-2')

        bc_session.create_client.assert_called_with(
            'sqs', aws_secret_access_key=None, aws_access_key_id=None,
            endpoint_url=None, use_ssl=True, aws_session_token=None,
            verify=None, region_name='us-west-2', api_version=None)

    def test_create_resource(self):
        session = Session()
        session.client = mock.Mock()
        session.resource_factory.create_class = mock.Mock()
        cls = session.resource_factory.create_class.return_value

        sqs = session.resource('sqs', verify=False)

        self.assertTrue(session.resource_factory.create_class.called,
            'Resource factory did not look up class')
        self.assertTrue(cls.called,
            'Resource instance was not created')
        self.assertEqual(sqs, cls.return_value,
            'Returned instance is not an instance of the looked up resource '
            'class from the factory')

    def test_create_resource_with_args(self):
        session = Session()