Skip to content

Fixed a bug which caused allow_redirects to be listed twice in python requests #74

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 30, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion codegens/python-requests/lib/python-requests.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ self = module.exports = {
', data = payload, files = files' : ', data = payload';
snippet += !options.followRedirect ? ', allow_redirects=False' : '';
Copy link
Member

@VShingala VShingala Aug 21, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leave space behind and after = in allow_redirects=False in generated python code. as we are doing the same in other places. i.e data = payload and files = files.

Also update test according to it.

snippet += options.requestTimeout !== 0 ? `, timeout=${options.requestTimeout}` : '';
snippet += options.followRedirect ? '' : ', allow_redirects=false';
snippet += ')\n\n';
snippet += 'print(response.text.encode(\'utf8\'))\n';

Expand Down
27 changes: 27 additions & 0 deletions codegens/python-requests/test/unit/converter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,31 @@ describe('Python- Requests converter', function () {
.to.throw('Python-Requests~convert: Callback is not a function');
});

it('should not have allow_redirects=False twice in generated snippet when' +
' followRedirect option is set as false', function () {
var request = new sdk.Request(mainCollection.item[0].request),
options = { followRedirect: false };
convert(request, options, function (err, snippet) {
if (err) {
expect.fail(null, null, err);
}
expect(snippet).to.be.a('string');
expect(snippet).to.not.include('allow_redirects=False, allow_redirects=false');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If options.requestTimeout !== 0 is true than this will be not valid as generated snippet will have allow_redirects=False, timeout=${options.requestTimeout}, allow_redirects=false.

});
});

it('should have correct boolean value for allow_redirects(False, uppercased F) in generated snippet when' +
' followRedirect option is set as false', function () {
var request = new sdk.Request(mainCollection.item[0].request),
options = { followRedirect: false };
convert(request, options, function (err, snippet) {
if (err) {
expect.fail(null, null, err);
}
expect(snippet).to.be.a('string');
expect(snippet).to.include('allow_redirects=False');
expect(snippet).to.not.include('allow_redirects=false');
});
});

});