def test_multipart_encoding_in_body(self):
        from coreapi.utils import File

        client = CoreAPIClient()
        schema = client.get('http://api.example.com/')

        example = {
            'foo': File(name='example.txt', content='123'),
            'bar': 'abc'
        }
        data = client.action(schema, ['encoding', 'multipart-body'],
                             params={'example': example})

        expected = {
            'method': 'POST',
            'content_type': 'multipart/form-data',
            'query_params': {},
            'data': {
                'bar': 'abc'
            },
            'files': {
                'foo': {
                    'name': 'example.txt',
                    'content': '123'
                }
            }
        }
        assert data == expected
Пример #2
0
    def test_raw_upload_explicit_content_type(self):
        from coreapi.utils import File

        client = CoreAPIClient()
        schema = client.get('http://api.example.com/')

        example = File('example.txt', '123', 'text/html')
        data = client.action(schema, ['encoding', 'raw_upload'], params={'example': example})

        expected = {
            'method': 'POST',
            'files': {'file': {'name': 'example.txt', 'content': '123'}},
            'content_type': 'text/html'
        }
        assert data == expected
Пример #3
0
 def testServices(self):
     self.assertTrue(True)
     serviceClient = ServiceClient("http://127.0.0.1:8000/api/")
     services = serviceClient.list()
     self.assertGreater(len(services), 0)
     serv1 = services[0]
     details = serviceClient.details(serv1['service_app_name'])
     submissions = serviceClient.submissions(serv1['service_app_name'])
     self.assertIsNotNone(submissions[0].details())
     subdetails = submissions[0].details()
     self.assertIsNotNone(subdetails)
     jobclient = JobClient(base_url="http://127.0.0.1:8000/api/", app_key="411874c8ad92e52918df13908c168e9368b33183")
     self.assertIsNotNone(jobclient.list())
     with open(join(dirname(__file__), "test.txt"), 'r') as f:
         new_job = jobclient.create(service_app_name='service_1', submission_app_name="default",
                                    inputs={"dir": "/home/", "file": File("test.txt", f)})
     print(new_job)
Пример #4
0
    def test_multipart_encoding_string_file_content(self):
        # Test for `coreapi.utils.File` support.
        from coreapi.utils import File

        client = CoreAPIClient()
        schema = client.get('http://api.example.com/')

        example = File(name='example.txt', content='123')
        data = client.action(schema, ['encoding', 'multipart'], params={'example': example})

        expected = {
            'method': 'POST',
            'content_type': 'multipart/form-data',
            'query_params': {},
            'data': {},
            'files': {'example': {'name': 'example.txt', 'content': '123'}}
        }
        assert data == expected