-
Notifications
You must be signed in to change notification settings - Fork 5
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
NOISSUE - Test and Enhance Py SDK #42
Conversation
Signed-off-by: Musilah <nataleigh.nk@gmail.co>
Signed-off-by: Musilah <nataleigh.nk@gmail.co>
Signed-off-by: Musilah <nataleigh.nk@gmail.co>
Signed-off-by: Musilah <nataleigh.nk@gmail.co>
40f8b1a
to
0dd8d62
Compare
1637e0a
to
f27b0f3
Compare
Signed-off-by: Musilah <nataleigh.nk@gmail.co>
Signed-off-by: Musilah <nataleigh.nk@gmail.co>
Signed-off-by: Musilah <nataleigh.nk@gmail.co>
Signed-off-by: Musilah <nataleigh.nk@gmail.co>
Signed-off-by: Musilah <nataleigh.nk@gmail.co>
Signed-off-by: Musilah <nataleigh.nk@gmail.co>
Signed-off-by: Musilah <nataleigh.nk@gmail.co>
Signed-off-by: Musilah <nataleigh.nk@gmail.co>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have a look at https://github.com/google/styleguide/blob/gh-pages/pyguide.md#38-comments-and-docstrings also https://www.dataquest.io/blog/documenting-in-python-with-docstrings/. So that we can enhance documentation of the sdk
Signed-off-by: Musilah <nataleigh.nk@gmail.co>
Signed-off-by: Musilah <nataleigh.nk@gmail.co>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For docstring I meant something similar to this
class Users:
"""Users API client.
Users API is used for creating and managing users.
It is used for creating new users, logging in, refreshing tokens,
getting user information, updating user information, disabling and enabling users.
Attributes:
URL: str - URL of the Users API
USERS_ENDPOINT: str - Users API endpoint
"""
USERS_ENDPOINT = "users"
def __init__(self, url: str):
"""Initializes Users API client.
params:
url: str - URL of the Users API
returns:
Users: Users - Users API client
raises:
None
"""
self.URL = url
def create(self, user: dict, token: str = ""):
"""Creates a new user.
Creates a new user with provided user information.
If token is provided, it will be used to create a new user.
params:
user: dict - user information for example:
{
"name": "example",
"credentials": {
"identity": "example@main.com",
"secret": "12345678"
}
}
token: str - token used for creating a new user
returns:
mf_resp: response.Response - response object
Usage::
>>> from mainflux import sdk
>>> mfsdk = sdk.SDK(users_url="http://localhost:9002")
>>> user = {
... "name": "example",
... "credentials": {
... "identity": "example@mail.com",
... "secret": "12345678"
... }
... }
>>> mf_resp = mfsdk.users.create(user)
>>> mf_resp
"""
mf_resp = response.Response()
http_resp = requests.post(
self.URL + "/users",
json=user,
headers=utils.construct_header(token, utils.CTJSON),
)
if http_resp.status_code != 201:
mf_resp.error.status = 1
mf_resp.error.message = errors.handle_error(
errors.users["create"], http_resp.status_code
)
else:
mf_resp.value = http_resp.json()
return mf_resp
Signed-off-by: Musilah <nataleigh.nk@gmail.co>
Signed-off-by: Musilah <nataleigh.nk@gmail.co>
Signed-off-by: Musilah <nataleigh.nk@gmail.co>
Signed-off-by: Musilah <nataleigh.nk@gmail.co>
Signed-off-by: Musilah <nataleigh.nk@gmail.co>
Signed-off-by: Musilah <nataleigh.nk@gmail.co>
Signed-off-by: Musilah <nataleigh.nk@gmail.co>
@@ -1,21 +1,22 @@ | |||
from mainflux import sdk | |||
import json | |||
|
|||
default_url = "http://localhost" | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can assign a value's to the access_token and rest variables like this:
`access_token = "<access_token>"
refresh_token = "<refresh_token>"
email=""
password =""`
and avoid it in every func
"""To start working with the Mainflux system, you need to create a user account""" mf_resp = mfsdk.users.create( user={"credentials": {"identity": email, "secret": password}}, token="", ) if mf_resp.error.status == 0: print(mf_resp.value) else: print(mf_resp.error.message)
@dborovcanin and @drasko what do you think ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not understand the question. Maybe @dborovcanin can answer.
Signed-off-by: Musilah <nataleigh.nk@gmail.co>
Signed-off-by: Musilah <nataleigh.nk@gmail.co>
Signed-off-by: Musilah <nataleigh.nk@gmail.co>
Signed-off-by: Musilah <nataleigh.nk@gmail.co>
Signed-off-by: Musilah <nataleigh.nk@gmail.co>
LGTM |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix the Markdown
Signed-off-by: Musilah <nataleigh.nk@gmail.co>
Signed-off-by: Musilah <nataleigh.nk@gmail.co>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
What does this do?
Test and Enhance Py SDK
Which issue(s) does this PR fix/relate to?
Resolves https://github.com/ultravioletrs/issues/issues/284
List any changes that modify/break current functionality
None so far
Have you included tests for your changes?
No
Did you document any new/modified functionality?
No
Notes