def test_collection_help(self): with mock.patch('sys.stdout', six.StringIO()) as mock_stdout: help(self.resource.__class__.samples) collection_method_docstring = mock_stdout.getvalue() self.assert_contains_lines_in_order( [' A collection of Sample resources'], collection_method_docstring)
def test_batch_action_help(self): with mock.patch('sys.stdout', six.StringIO()) as mock_stdout: help(self.resource.samples.operate) batch_action_docstring = mock_stdout.getvalue() self.assert_contains_lines_in_order([ ' **Request Syntax** ', ' ::', ' response = myservice.samples.operate(', " Foo='string',", " Bar='string'", ' )', ' :type Foo: string', ' :param Foo: Documents Foo', ' :type Bar: string', ' :param Bar: Documents Bar', ' :rtype: dict', ' :returns: ', ' **Response Syntax** ', ' ::', ' {', " 'Foo': 'string',", " 'Bar': 'string'", ' }', ' **Response Structure** ', ' - *(dict) --* ', ' - **Foo** *(string) --* Documents Foo', ' - **Bar** *(string) --* Documents Bar', ], batch_action_docstring)
def test_attribute_help(self): with mock.patch('sys.stdout', six.StringIO()) as mock_stdout: help(self.resource.Sample('id').__class__.foo) attribute_docstring = mock_stdout.getvalue() self.assert_contains_lines_in_order([ ' - *(string) --* Documents Foo' ], attribute_docstring)
def test_identifier_help(self): with mock.patch('sys.stdout', six.StringIO()) as mock_stdout: help(self.resource.Sample('id').__class__.name) identifier_docstring = mock_stdout.getvalue() self.assert_contains_lines_in_order([ " *(string)* The Sample's name identifier. This " "**must** be set." ], identifier_docstring)
def test_reference_help(self): sample_resource = self.resource.Sample('id') with mock.patch('sys.stdout', six.StringIO()) as mock_stdout: help(sample_resource.__class__.related_sample) reference_docstring = mock_stdout.getvalue() self.assert_contains_lines_in_order([ " (:py:class:`Sample`) The related related_sample " "if set, otherwise ``None``." ], reference_docstring)
def test_region_required_due_to_sigv4(self): stream = six.StringIO('{"fakejson": true}') service = self.session.get_service('cloudsearchdomain') operation = service.get_operation('UploadDocuments') built = operation.build_parameters(contentType='application/json', documents=stream) # Note we're not giving a region name. with self.assertRaises(NoRegionError): endpoint = service.get_endpoint(endpoint_url='http://example.com')
def test_sub_resource_help(self): with mock.patch('sys.stdout', six.StringIO()) as mock_stdout: help(self.resource.Sample) sub_resource_docstring = mock_stdout.getvalue() self.assert_contains_lines_in_order([ ' Creates a Sample resource.::', " sample = myservice.Sample('name')", ' :type name: string', " :param name: The Sample's name identifier.", ' :rtype: :py:class:`MyService.Sample`', ' :returns: A Sample resource', ], sub_resource_docstring)
def test_collection_all_method_help(self): with mock.patch('sys.stdout', six.StringIO()) as mock_stdout: help(self.resource.samples.all) collection_method_docstring = mock_stdout.getvalue() self.assert_contains_lines_in_order([ (' Creates an iterable of all Sample resources in the ' 'collection.'), ' **Request Syntax** ', ' ::', ' sample_iterator = myservice.samples.all()', ' :rtype: list(:py:class:`myservice.Sample`)', ' :returns: A list of Sample resources', ], collection_method_docstring)
def test_load_help(self): sub_resource = self.resource.Sample('Id') with mock.patch('sys.stdout', six.StringIO()) as mock_stdout: help(sub_resource.load) load_docstring = mock_stdout.getvalue() self.assert_contains_lines_in_order([ (' Calls :py:meth:`MyService.Client.sample_operation` to update ' 'the attributes of the Sample resource'), ' **Request Syntax** ', ' ::', ' sample.load()', ' :returns: None', ], load_docstring)
def test_debug_log_contains_headers_and_body(self): # This test just verifies that the response headers/body # are in the debug log. It's an integration test so that # we can refactor the code however we want, as long as we don't # lose this feature. session = botocore.session.get_session() client = session.create_client('s3', region_name='us-west-2') debug_log = six.StringIO() session.set_stream_logger('', logging.DEBUG, debug_log) client.list_buckets() debug_log_contents = debug_log.getvalue() self.assertIn('Response headers', debug_log_contents) self.assertIn('Response body', debug_log_contents)
def test_collection_page_size_method_help(self): with mock.patch('sys.stdout', six.StringIO()) as mock_stdout: help(self.resource.samples.page_size) collection_method_docstring = mock_stdout.getvalue() self.assert_contains_lines_in_order([ ' **Request Syntax** ', ' ::', ' sample_iterator = myservice.samples.page_size(', ' count=123', ' )', ' :type count: integer', (' :param count: The number of items returned by ' 'each service call'), ' :rtype: list(:py:class:`myservice.Sample`)', ' :returns: A list of Sample resources', ], collection_method_docstring)
def test_client_method_help(self): creator = self.create_client_creator() service_client = creator.create_client('myservice', 'us-west-2', credentials=self.credentials) with mock.patch('sys.stdout', six.StringIO()) as mock_stdout: help(service_client.test_operation) method_docstring = mock_stdout.getvalue() ref_docstring_lines = [ 'Documents TestOperation', '**Request Syntax**', ' response = client.test_operation(', ' Bar=\'string\'', ' Foo=\'string\'', ' )', ':type Bar: string', ':param Bar: Documents Bar', ':type Foo: string', ':param Foo: **[REQUIRED]** Documents Foo' ] for line in ref_docstring_lines: self.assertIn(line, method_docstring)
def test_collection_filter_method_help(self): with mock.patch('sys.stdout', six.StringIO()) as mock_stdout: help(self.resource.samples.filter) collection_method_docstring = mock_stdout.getvalue() self.assert_contains_lines_in_order([ ' **Request Syntax** ', ' ::', ' sample_iterator = myservice.samples.filter(', " Foo='string',", " Bar='string'", ' )', ' :type Foo: string', ' :param Foo: Documents Foo', ' :type Bar: string', ' :param Bar: Documents Bar', ' :rtype: list(:py:class:`myservice.Sample`)', ' :returns: A list of Sample resources', ], collection_method_docstring)
def test_resource_waiter_help(self): with mock.patch('sys.stdout', six.StringIO()) as mock_stdout: help(self.resource.Sample('id').wait_until_complete) resource_waiter_docstring = mock_stdout.getvalue() self.assert_contains_lines_in_order([ (' Waits until this Sample is complete. This method calls ' ':py:meth:`MyService.Waiter.sample_operation_complete.wait` ' 'which polls. :py:meth:`MyService.Client.sample_operation` every ' '15 seconds until a successful state is reached. An error ' 'is returned after 40 failed checks.'), ' **Request Syntax** ', ' ::', ' sample.wait_until_complete(', " Bar='string'", ' )', ' :type Bar: string', ' :param Bar: Documents Bar', ' :returns: None', ], resource_waiter_docstring)
def test_waiter_help_documentation(self): waiter_name = 'WaiterName' waiter = create_waiter_with_client(waiter_name, self.waiter_model, self.client) with mock.patch('sys.stdout', six.StringIO()) as mock_stdout: help(waiter.wait) content = mock_stdout.getvalue() lines = [ (' Polls :py:meth:`MyService.Client.foo` every 1 ' 'seconds until a successful state is reached. An error ' 'is returned after 1 failed checks.'), ' **Request Syntax** ', ' ::', ' waiter.wait(', " bar='string'", ' )', ' :type bar: string', ' :param bar: Documents bar', ' :returns: None', ] for line in lines: self.assertIn(line, content)
def test_file(self): body = six.StringIO() params = {'Body': body} handlers.convert_body_to_file_like_object(params) self.assertEqual(params['Body'], body)