requests.compat.StringIO

Here are the examples of the python api requests.compat.StringIO taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

2 Examples 7

Example 1

Project: python-scrapinghub Source File: legacy.py
    def add_report(self, key, content, content_type='text/plain'):
        from requests.compat import StringIO
        params = {
            'project': self.project.id,
            'job': self.id,
            'key': key,
            'content_type': content_type,
        }
        files = {'content': ('report', StringIO(content))}
        self._post('reports_add', 'json', params, files=files)

Example 2

Project: python-scrapinghub Source File: test_job.py
def test_job_add_report(job):
    job._post = mock.Mock()
    job.add_report('testkey', 'testcontent', content_type='custom/type')
    args = job._post.call_args_list[0]
    assert args[0] == ('reports_add', 'json', {
        'project': 12345, 'job': '1/2/3',
        'key': 'testkey', 'content_type': 'custom/type'})
    content = args[1].get('files').get('content')
    assert len(content) == 2
    assert content[0] == 'report'
    assert isinstance(content[1], requests.compat.StringIO)
    assert content[1].read() == 'testcontent'