我正在使用supertest测试我的API端点,它工作得很好,但我无法弄清楚如何测试文件下载是否成功.
在我的路由文件中,我已将端点定义为:
app.get('/api/attachment/:id/file', attachment.getFile);
Run Code Online (Sandbox Code Playgroud)
并且函数getFile()看起来像这样:
exports.getFile = function(req, res, next) {
Attachment.getById(req.params.id, function(err, att) {
[...]
if (att) {
console.log('File found!');
return res.download(att.getPath(), att.name);
}
Run Code Online (Sandbox Code Playgroud)
然后,在我的测试文件中,我尝试以下方法:
describe('when trying to download file', function() {
it('should respond with "200 OK"', function(done) {
request(url)
.get('/api/attachment/' + attachment._id + '/file');
.expect(200)
.end(function(err, res) {
if (err) {
return done(err);
}
return done();
});
});
});
Run Code Online (Sandbox Code Playgroud)
我确定找到了该文件,因为它已注销File found!.如果我手动尝试它也可以正常工作,但由于某种原因,mocha返回Error: expected 200 "OK", got 404 "Not Found".
我尝试过不同的mime-types和supertest .set("Accept-Encoding": …
我知道这听起来像我可以谷歌,但事实是,我没有找到或不理解很少的Python 3来源解释.
所以这是我的问题:
input()的stdin在Python 3的功能?这是否意味着当你打开你的filename.py程序时,stdin用户输入的是什么?print()的stdout函数,还是必须写入文件?stdin和stdout?更新:这是否意味着我可以使用:
import sys
unfmtdDate = str(sys.stdin.read())
Run Code Online (Sandbox Code Playgroud)
...代替...
unfmtdDate = str(input())
Run Code Online (Sandbox Code Playgroud)
?
我是编程的新手,需要一些修复工具的帮助来将为Python 3.x编写的代码重构为可以在2.x解释器上运行的代码.
我有Python 3.2,但Spotify Puzzle的入场许可(http://www.spotify.com/us/jobs/tech/best-before/)要求代码是用2.6编写的.因此,我找到了3to2的转换器.我有"3to2_py3k-1.0.tar.gz"版本,您可以从这里下载:https://bitbucket.org/amentajo/lib3to2 .
README文件告诉您
(...)运行"./3to2"转换stdin(" - "),作为参数给出的文件或目录.(...)
此站点上的文本与README文件相同.
我理解这个我应该运行命令行然后写:
C:\ Python32> 3to2 Spotify.py
3to2不被识别为实习或外部命令,程序或批处理文件.
(从挪威语翻译).
我试图找到特定文件的路径,但没有名为"3to2"的文件.我试图直接找到"main.py"文件和"Spotify.py",看起来好像发生了事情(就像它需要一点点时间,没有错误),但是当我打开"Spotify"时.py"再一次,文件没有发生任何事情.
我感谢所有的帮助.
谢谢spatz,这帮了很多忙.最后,我设法安装了包cd C:\Python32>python.exe setup.py install
无论如何,我仍然有一些问题.以print("Hello World!")程序为例.当我运行python.exe 3to2 HelloWorld.py(没有python.exe它没有工作)它回答:
RefractingTool: Skipping implicit fixer: collections
RefractingTool: Skipping implicit fixer: int
RefractingTool: Skipping implicit fixer: memoryview
RefractingTool: Skipping implicit fixer: printfunction
RefractingTool: Skipping implicit fixer: inittest
RefractingTool: Refactored HelloWorld.py
--- HelloWorld.py (original)
+++ HelloWorld.py (refactored)
@@ -1 +1 @@
-print("Hello World!")
+print u"Hello World!" …Run Code Online (Sandbox Code Playgroud) python ×2
converter ×1
express ×1
javascript ×1
mocha.js ×1
node.js ×1
python-3.x ×1
stdin ×1
stdout ×1
supertest ×1