当前位置: 首页>>代码示例>>Python>>正文


Python utils.upload_path函数代码示例

本文整理汇总了Python中tuneful.utils.upload_path函数的典型用法代码示例。如果您正苦于以下问题:Python upload_path函数的具体用法?Python upload_path怎么用?Python upload_path使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了upload_path函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_file_upload

 def test_file_upload(self):
     data = {
         "file": (BytesIO(b"File contents"), "test.txt")
     }
     
     response = self.client.post("/api/files",
         data=data,
         content_type="multipart/form-data",
         headers=[("Accept", "application/json")]
     )
     
     self.assertEqual(response.status_code, 201)
     self.assertEqual(response.mimetype, "application/json")
     
     data = json.loads(response.data.decode("ascii"))
     self.assertEqual(urlparse(data["path"]).path, "/uploads/test.txt")
     
     path = upload_path("test.txt")
     self.assertTrue(os.path.isfile(path))
     
     with open(path, "rb") as f:
         contents = f.read()
     self.assertEqual(contents, b"File contents")
     
     
开发者ID:l1onh3art88,项目名称:tuneful,代码行数:23,代码来源:api_tests.py

示例2: test_file_upload

    def test_file_upload(self):
        # Construct form data as a dictionary,
        # Use Py StringIO Class to simulate a file object
        data = {
            "file": (StringIO("File contents"), "test.txt")
        }

        # Send dict to /api/files with content type of multipart/form-data
        response = self.client.post("/api/files",
            data=data,
            content_type="multipart/form-data",
            headers=[("Accept", "application/json")]
        )

        # Response status 201 CREATED expected
        self.assertEqual(response.status_code, 201)
        # Response in JSON?
        self.assertEqual(response.mimetype, "application/json")
        # Decode JSON
        data = json.loads(response.data)
        # Validate file path
        self.assertEqual(urlparse(data["path"]).path, "/uploads/test.txt")
        # Create path from utils.py method
        path = upload_path("test.txt")
        # Verify file is in expected location
        self.assertTrue(os.path.isfile(path))
        # Read the file contents
        with open(path) as f:
            contents = f.read()
        # Verify contents are as expected
        self.assertEqual(contents, "File contents")
开发者ID:qmcdermott,项目名称:tuneful,代码行数:31,代码来源:api_tests.py

示例3: tearDown

    def tearDown(self):
        """ Test teardown """
        session.close()
        # Remove the tables and their data from the database
        Base.metadata.drop_all(engine)

        # Delete test upload folder
        shutil.rmtree(upload_path())
开发者ID:auslander70,项目名称:tuneful,代码行数:8,代码来源:api_tests.py

示例4: setUp

    def setUp(self):
        """ Test setup """
        self.client = app.test_client()

        # Set up the tables in the database
        Base.metadata.create_all(engine)

        # Create folder for test uploads
        os.mkdir(upload_path())
开发者ID:auslander70,项目名称:tuneful,代码行数:9,代码来源:api_tests.py

示例5: test_get_uploaded_file

    def test_get_uploaded_file(self):
        path =  upload_path("test.txt")
        with open(path, "w") as f:
            f.write("File contents")

        response = self.client.get("/uploads/test.txt")

        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.mimetype, "text/plain")
        self.assertEqual(response.data, b"File contents")
开发者ID:auslander70,项目名称:tuneful,代码行数:10,代码来源:api_tests.py

示例6: test_get_uploaded_file

 def test_get_uploaded_file(self):
     path = upload_path('test.txt')
     with open(path, 'wb') as f:
         f.write(b'File contents')
     
     response = self.client.get('/uploads/test.txt')
     
     self.assertEqual(response.status_code, 200)
     self.assertEqual(response.mimetype, 'text/plain')
     self.assertEqual(response.data, b'File contents')
开发者ID:kolohelios,项目名称:py-tuneful,代码行数:10,代码来源:api_tests.py

示例7: setUp

    def setUp(self):

        """ Test setup """
        # Configure our app to use the testing database
        app.config.from_object('tuneful.config.TestingConfig')
        self.client = app.test_client()

        # Set up the tables in the database
        Base.metadata.create_all(engine)

        # Create folder for test uploads
        try:
            os.mkdir(upload_path())
        except OSError:
            print "Folder already created!"
开发者ID:GLMeece,项目名称:thinkful-mentor,代码行数:15,代码来源:api_tests.py

示例8: test_get_uploaded_file

    def test_get_uploaded_file(self):
        # create the upload path with the filename
        # upload_path() is defined in utils.py
        path = upload_path("test.txt")
        # Fill the file with some foo
        with open(path, "w") as f:
            f.write("File contents")

        # Obtain the response from the app
        response = self.client.get("/uploads/test.txt")

        # Was the request successful?  200 OK expected.
        self.assertEqual(response.status_code, 200)
        # Is the response in plain text?
        self.assertEqual(response.mimetype, "text/plain")
        # Is the response data the contents of the file uploaded?
        self.assertEqual(response.data, "File contents")
开发者ID:qmcdermott,项目名称:tuneful,代码行数:17,代码来源:api_tests.py

示例9: test_file_upload

    def test_file_upload(self):
        data = {
            'file': (BytesIO(b'File contents'), 'test.txt')
        }
        
        response = self.client.post('/api/files',
            data = data,
            content_type = 'multipart/form-data',
            headers = [('Accept', 'application/json')]
        )
        
        self.assertEqual(response.status_code, 201)
        self.assertEqual(response.mimetype, 'application/json')
        
        data = json.loads(response.data.decode('ascii'))
        self.assertEqual(urlparse(data['path']).path, '/uploads/test.txt')

        path = upload_path('test.txt')
        self.assertTrue(os.path.isfile(path))
        with open(path, 'rb') as f:
            contents = f.read()
        self.assertEqual(contents, b'File contents')
开发者ID:kolohelios,项目名称:py-tuneful,代码行数:22,代码来源:api_tests.py


注:本文中的tuneful.utils.upload_path函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。