-
Notifications
You must be signed in to change notification settings - Fork 0
feat: TT-384 Refactor Tables #337
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
Changes from 11 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
6f83435
feat: file stream from azure blob storage
Jobzi ee8a966
refactor: add new python package in dev.txt
Jobzi be714fd
feat: implement new methods to read files from blob storage
Jobzi da9c1b3
feat: implemented the reading of the blob storage to the endpoint act…
Jobzi 36cd17d
fix: TT-384 Change blob storage connection input names
Jobzi 52a4359
fix: TT-384 Add the file name as a parameter of the function
Jobzi 94d196a
test: TT-384 Add a tests to obtain activities from blob storage, endp…
Jobzi 169853a
fix: TT-384 revert changes
Jobzi a6ee691
test: TT-384 Change blob storage connection input names
Jobzi 054798b
feat: TT-384 implemented the reading of the storage blob to the endpo…
Jobzi afd537d
test: TT-384 Add a tests to obtain activities from blob storage, endp…
Jobzi f9532ea
test: TT-384 changed test name with correct formatting
Jobzi e3480cc
refactor: TT-384 change import to global and name method
Jobzi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import os | ||
| from azure.storage.blob.blockblobservice import BlockBlobService | ||
|
|
||
| ACCOUNT_KEY = os.environ.get('AZURE_STORAGE_ACCOUNT_KEY') | ||
|
|
||
| class FileStream: | ||
| def __init__(self, account_name:str, container_name:str): | ||
| """ | ||
| Initialize the FileStream object. which is used to get the file stream from Azure Blob Storage. | ||
| `account_name`: The name of the Azure Storage account. | ||
| `container_name`: The name of the Azure Storage container. | ||
| """ | ||
| self.account_name = account_name | ||
| self.container_name = container_name | ||
| self.blob_service = BlockBlobService(account_name=self.account_name, account_key=ACCOUNT_KEY) | ||
|
|
||
| def get_file_stream(self, filename:str): | ||
| import tempfile | ||
| try: | ||
| local_file = tempfile.NamedTemporaryFile() | ||
| self.blob_service.get_blob_to_stream(self.container_name, filename, stream=local_file) | ||
|
|
||
| local_file.seek(0) | ||
| return local_file | ||
| except Exception as e: | ||
| print(e) | ||
| return None |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import json | ||
|
|
||
| from commons.data_access_layer.file_stream import FileStream | ||
|
|
||
| fs = FileStream("storageaccounteystr82c5","tt-common-files") | ||
|
|
||
| def test_get_file_stream_return_file_when_enter_file_name(): | ||
| result = fs.get_file_stream("activity_test.json") | ||
|
|
||
| assert len(json.load(result)) == 15 | ||
|
|
||
| def test_get_file_stream_return_None_when_not_enter_file_name_or_incorrect_name(): | ||
Jobzi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| result = fs.get_file_stream("") | ||
|
|
||
| assert result == None | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.