Skip to content
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

CB-230: Migrate OAuth Client code off the ORM. #95

Merged
merged 2 commits into from Apr 17, 2017

Conversation

ferbncode
Copy link
Member

Added functions and tests to migrate code for OAuthClient model. Also, made changes to frontend for using migrated code.

@ferbncode ferbncode force-pushed the migrate-oauth branch 2 times, most recently from 157e652 to c9ed69a Compare March 31, 2017 20:09


def create(*, user_id, name, desc, website, redirect_uri):
"""Create new OAuth client and generates secret key for it.
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be either "Creates new OAuth client and generates a secret key for it." or "Create new OAuth client and generate a secret key for it."

}
"""
client_id = generate_string(20)
client_secret = generate_string(40)
Copy link
Contributor

Choose a reason for hiding this comment

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

These variables seem unnecessary. Calls to generate_string can be moved into the dictionary below.

I'd also move lengths into "constants" in this module: CLIENT_ID_LENGTH and CLIENT_SECRET_LENGTH.

:user_id, :name, :desc, :website)
"""), client)

return client
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the return value being used anywhere outside of tests? If not, you can remove it and move dictionary directly into the connection.execute call.

updates.append("name = :name")
update_data["name"] = name
if desc is not None:
updates.append(""" "desc" = :desc""")
Copy link
Contributor

Choose a reason for hiding this comment

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

""" should be used for multi-line strings and docstrings. Here you can use ' instead.

})
row = result.fetchone()
if not row:
raise db_exceptions.NoDataFoundException("No client with ID: {} found".format(client_id))
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor thing, but I'd expect text after : to be just the ID. Can't find OAuth client with ID: %(id)s would be a better message, I think.

website=form.website.data, redirect_uri=form.redirect_uri.data)
db_oauth_client.update(
client_id=application["client_id"],
name=form.name.data, desc=form.desc.data,
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't stack arguments like that. It's easy to miss it if someone is expecting each to be on a new line.

try:
application = db_oauth_client.get(client_id)
except db_exceptions.NoDataFoundException:
abort(404)
Copy link
Contributor

Choose a reason for hiding this comment

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

raise NotFound and abort(404) give pretty much the same result. Let's just stick with NotFound. Can also pass a message from the "parent" exception.

modify db.oauth_client.create and tests and syntax
fixes
@gentlecat gentlecat merged commit 896b74b into metabrainz:master Apr 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants