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

NOISSUE - Test and Enhance Py SDK #42

Merged
merged 31 commits into from
Oct 27, 2023
Merged

Conversation

Musilah
Copy link
Contributor

@Musilah Musilah commented Aug 10, 2023

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

Musilah added 4 commits August 10, 2023 19:14
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>
Musilah added 2 commits August 21, 2023 12:11
Signed-off-by: Musilah <nataleigh.nk@gmail.co>
Signed-off-by: Musilah <nataleigh.nk@gmail.co>
Musilah added 5 commits August 21, 2023 16:57
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>
@Musilah Musilah marked this pull request as ready for review August 24, 2023 08:21
mainflux/users.py Outdated Show resolved Hide resolved
tests/test_bootstrap.py Outdated Show resolved Hide resolved
tests/test_users.py Outdated Show resolved Hide resolved
examples/examples.py Outdated Show resolved Hide resolved
examples/examples.py Outdated Show resolved Hide resolved
examples/examples.py Outdated Show resolved Hide resolved
examples/examples.py Outdated Show resolved Hide resolved
mainflux/things.py Outdated Show resolved Hide resolved
mainflux/users.py Outdated Show resolved Hide resolved
mainflux/users.py Outdated Show resolved Hide resolved
Musilah added 2 commits August 25, 2023 11:47
Signed-off-by: Musilah <nataleigh.nk@gmail.co>
Signed-off-by: Musilah <nataleigh.nk@gmail.co>
mainflux/boostrap.py Outdated Show resolved Hide resolved
mainflux/certs.py Outdated Show resolved Hide resolved
Musilah added 2 commits August 26, 2023 08:23
Signed-off-by: Musilah <nataleigh.nk@gmail.co>
Signed-off-by: Musilah <nataleigh.nk@gmail.co>
Copy link
Member

@rodneyosodo rodneyosodo left a comment

Choose a reason for hiding this comment

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

mainflux/groups.py Outdated Show resolved Hide resolved
mainflux/groups.py Outdated Show resolved Hide resolved
mainflux/messages.py Show resolved Hide resolved
mainflux/things.py Outdated Show resolved Hide resolved
mainflux/users.py Outdated Show resolved Hide resolved
tests/test_bootstrap.py Outdated Show resolved Hide resolved
tests/test_channels.py Outdated Show resolved Hide resolved
tests/test_users.py Outdated Show resolved Hide resolved
Signed-off-by: Musilah <nataleigh.nk@gmail.co>
tests/test_certs.py Outdated Show resolved Hide resolved
Signed-off-by: Musilah <nataleigh.nk@gmail.co>
Copy link
Member

@rodneyosodo rodneyosodo left a 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

mainflux/messages.py Show resolved Hide resolved
mainflux/sdk.py Show resolved Hide resolved
Musilah added 7 commits September 18, 2023 16:26
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>
examples/examples.py Outdated Show resolved Hide resolved
examples/examples.py Show resolved Hide resolved
examples/examples.py Show resolved Hide resolved
examples/examples.py Show resolved Hide resolved
examples/examples.py Outdated Show resolved Hide resolved
examples/examples.py Show resolved Hide resolved
examples/examples.py Show resolved Hide resolved
examples/examples.py Show resolved Hide resolved
@@ -1,21 +1,22 @@
from mainflux import sdk
import json

default_url = "http://localhost"

Copy link
Contributor

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 ?

Copy link
Member

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.

Musilah added 2 commits October 5, 2023 18:21
Signed-off-by: Musilah <nataleigh.nk@gmail.co>
Signed-off-by: Musilah <nataleigh.nk@gmail.co>
docs/boostrap.md Show resolved Hide resolved
Musilah added 3 commits October 23, 2023 14:31
Signed-off-by: Musilah <nataleigh.nk@gmail.co>
Signed-off-by: Musilah <nataleigh.nk@gmail.co>
Signed-off-by: Musilah <nataleigh.nk@gmail.co>
@fbugarski
Copy link
Contributor

LGTM

Copy link
Member

@drasko drasko left a comment

Choose a reason for hiding this comment

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

Fix the Markdown

Musilah added 2 commits October 27, 2023 14:05
Signed-off-by: Musilah <nataleigh.nk@gmail.co>
Signed-off-by: Musilah <nataleigh.nk@gmail.co>
Copy link
Member

@drasko drasko left a comment

Choose a reason for hiding this comment

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

LGTM

@drasko drasko merged commit 7c17220 into mainflux:main Oct 27, 2023
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants