-
Notifications
You must be signed in to change notification settings - Fork 7
updated test and methods #2
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
base: main
Are you sure you want to change the base?
Conversation
pyigloo/__init__.py
Outdated
| Creates community attachment entry | ||
| """ | ||
| url = '{0}{1}v1/communities/{2}/attachments'.format(self.endpoint, self.IGLOO_API_ROOT_V2, communityKey) |
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 should use the self.communitykey value instead of passing it to the routine.
You can see an example of this:
- getting called: https://github.com/xkahn/pyigloo/blob/main/tests/getSpaceGroups.py#L45
- being used in a library routine: https://github.com/xkahn/pyigloo/blob/main/pyigloo/__init__.py#L394
This allows us to not pass the value around. Also, a single Igloo session should keep the same community key the whole session.
tests/uploadUserProfilePic.py
Outdated
| parser.add_argument("communityKey", help="Community Key") | ||
| parser.add_argument("userid", help="User ID") | ||
| parser.add_argument("image", help="Path to the image") | ||
| parser.add_argument("contentType", help="Content Type of the image") |
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.
It's fine to allow passing this, but if not specified, it should get detected by:
magic.detect_from_filename("/path/to/file").mime_type
from the "magic" library
tests/uploadUserProfilePic.py
Outdated
| import argparse | ||
| parser = argparse.ArgumentParser() | ||
| parser.add_argument("communityKey", help="Community Key") | ||
| parser.add_argument("userid", help="User ID") |
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.
User UUID? Namespace?
tests/uploadUserProfilePic.py
Outdated
|
|
||
| if args.contentType not in allowedContentType: | ||
| print("Allowed contentTypes "+str(" ".joing(allowedContentType)) | ||
| return |
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.
Should exit with an error code?
tests/uploadUserProfilePic.py
Outdated
|
|
||
|
|
||
| image = pathlib.Path(args.image).read_bytes() | ||
| update_profile_picture(self, args.communityKey, args.userId, image, args.contentType) No newline at end of file |
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.
Maybe pass the filename here.
pyigloo/__init__.py
Outdated
| result = self.igloo.post(url, data=payload) | ||
| return result.headers['Location'] | ||
|
|
||
| def send_image_to_url(self, url, image, headers): |
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.
don't pass headers. Should calculate them in this function
| Uploads attachment to entry provided from previous call | ||
| """ | ||
| url = '{0}{1}'.format(self.endpoint, url) | ||
| result = self.igloo.patch(url, headers=headers, data=image) |
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.
file_size = os.path.getsize(file_path)
headers = {
"Content-Length": f"\"{file_size}\"",
"Content-Range": f"bytes 0-{file_size-1}/{file_size}"
}
response = requests.put(
url, open(file_path, "rb"), headers=headers
)
No description provided.