Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[LD-19] restructure Python SDK (#32)
* [WiP] first changes to restructure the SDK * The currently written tests work properly * Necessary changes made according to the comments * Changes made to the constants.py, since the tests were ran again, recipient.json is also changed * Changes made to the constants.py, since the tests were ran again, recipient.json is also changed * Onboarding Responses for MQTT * Changed made to the code according to the comments. Identifer class added , test script changed * Add exception during onboarding * fix merging mistakes * Added some comments. Format the file. Rename the "WrongGateWay" to "WrongGateWayType" to match the related exception. * Changes made to Identifier and test script Changes made to the test script since Identifier class was changed. The tests were ran again to check if everything works, hence the registration codes are changed. Under MQTT there are 2 folders P12 and PEM, each containing a Sender and a Recipient. * Adapt comments. * Add comments. Fix code smells. * Add comments. Fix code smells. * Change folders. * mqtt capabilities service test with one technical message type * updated the onboard response The previously created onboard response is used * SequenceNumberService Class added and test cleaned up according to the comments * Add new type for direction. Add comments. Rename type. * Remove typos. Add comments. Refactoring to avoid literals. * Added tests with SEND and RECEIVE directions * Docstrings should be defined outside the dict The docstrings defined in the dictionary. It should be defined outside. * SequenceNumberService class improved SequenceNumberService Class improved test_capability_service improved by making the methods static and adding the tests with SEND and RECEIVE directions * Format files. * remove typos. * Update test names. * Use existing sleeper methods. Refactor constant names. Adapt comments. * PEP-8 | Constants should be uppercase * Added Subscription Service Tests (#40) * Added Subscription Service Tests * Add comments. * Necessary Changes made to the test script 1. Subscription Service Tests shifted to another folder 2. Name of the test function changed 3. Removed the redundant load_onboard_response() staticmethod. --------- Co-authored-by: Sascha Doemer <[email protected]> * SendMessageService and SendMessageParameters added (#41) * SendMessageService and SendMessageParameters written * Added a test script to send message along with DataProvider Class. * Sending direct message with push notifications turned on Test code refactored compared to previous commits * Fix format. * Fix format. * Fix format. * Fix format. * Push Notification decoded * Fix format. * Add missing comments. * Add missing comments. * Fix format. * Remove unused methods. Add comments. Move static method. * Move function. Adapt calls. --------- Co-authored-by: Sascha Doemer <[email protected]> * Test for QueryHeaderService (#42) * Test for QueryHeaderService * 3 tests for QueryheaderService with different attributes * Test for incomplete attributes passed to the QueryHeaderParameters should return 400 * Few more tests added and the clean setup is done and messages within the feed are now deleted using FeedDeleteService * Fix format. * Update test structure. Add fixture to create sender and recipient. Fix typo in `GateWays`. * Update application ID. Update certification version ID. * Setup between the Sender and Recipient. Query Header Service tests with different scenarios * Fix naming. Fix variable names. Fix typos. * Add common package for onboarding. Adapt test structure. Add missing response checking for onboarding. Add missing requirement in `requirements.txt`. Fix method calls. * Adapt method name. * Fix comment length. * Fix naming. * Decrease time interval. * Adapt naming. * Remove unused parameters. * Remove useless waiting since the response is already there. * Remove unused parameters. * Remove useless waiting. * Optimize imports. * Optimize imports. * Move data to the data package. * Add missing comments. * Remove unused data. * Fix identifiers. Remove unused functions and data. Remove unused parameters. * Optimize imports. * Adapt waiting intervall. * Remove unused parameters. * Remove useless waiting time. * Remove typo. * Remove typo. * Fix compile error. * Adapt test cases to check if the callback is called. * Use default interval. * Adapt test to use the right framework. * Adapt test structure. Update recipient. Adapt test intervall. Adapt naming. * Replace if with an assertion. * Adapt reading of onboard responses. * Adapt test case to run with the correct framework. * Adapt sleep time. Adapt callbacks. * Remove messages after successful testing. * Update log messages. * Add comment. * Feed Delete Service callback * Fix coding error. * Adapt wait time. * Update reference. * Update PEM recipient. * Update ´skip` option. * Test Structure fixed for subscription tests * Disconnect client, before reconnecting it. * Disconnect client, before performing tear down. * Disconnect client, before performing tear down. * Adapt logging. * Fix test case structure. * Update test fixture. Fix test structure. * Remove unused folder. * Move common classes to dedicated package. * Code bugfix in delete_all_messages_within_the_feed * FeedDeleteService callback assertions fix * Fix callback name * Revert changes. * Remove validity period. * Adapt implementation. * QueryHeaderService Tests code refactored * Validity Period bugfix * Remove test function usage in official SDK outside of tests. Adapt implementation regarding DRY. * No setup outside the test case or the fixture to ensure failing test cases. * Reformat file. * Variable names updated * Adapt implementation. * Fixture messaging services and callback bugfix * bugfix in test for valid validity period * Addtional logging. --------- Co-authored-by: Sascha Doemer <[email protected]> * Test for sending chunked messages (#43) * Test for QueryHeaderService * 3 tests for QueryheaderService with different attributes * Test for incomplete attributes passed to the QueryHeaderParameters should return 400 * Few more tests added and the clean setup is done and messages within the feed are now deleted using FeedDeleteService * Fix format. * Update test structure. Add fixture to create sender and recipient. Fix typo in `GateWays`. * Update application ID. Update certification version ID. * Setup between the Sender and Recipient. Query Header Service tests with different scenarios * Test for sending chunked messages * Fix naming. Fix variable names. Fix typos. * Add common package for onboarding. Adapt test structure. Add missing response checking for onboarding. Add missing requirement in `requirements.txt`. Fix method calls. * Adapt method name. * Fix comment length. * Fix naming. * Decrease time interval. * Adapt naming. * Remove unused parameters. * Remove useless waiting since the response is already there. * Remove unused parameters. * Remove useless waiting. * Optimize imports. * Optimize imports. * Move data to the data package. * Add missing comments. * Remove unused data. * Fix identifiers. Remove unused functions and data. Remove unused parameters. * Optimize imports. * Adapt waiting intervall. * Remove unused parameters. * Remove useless waiting time. * Remove typo. * Remove typo. * Fix compile error. * Adapt test cases to check if the callback is called. * Use default interval. * Adapt test to use the right framework. * Adapt test structure. Update recipient. Adapt test intervall. Adapt naming. * Replace if with an assertion. * Adapt reading of onboard responses. * Adapt test case to run with the correct framework. * Adapt sleep time. Adapt callbacks. * Remove messages after successful testing. * Update log messages. * Add comment. * Feed Delete Service callback * Fix coding error. * Adapt wait time. * Update reference. * Update PEM recipient. * Update ´skip` option. * Test Structure fixed for subscription tests * Disconnect client, before reconnecting it. * Disconnect client, before performing tear down. * Disconnect client, before performing tear down. * Adapt logging. * Fix test case structure. * Update test fixture. Fix test structure. * Remove unused folder. * Move common classes to dedicated package. * Code bugfix in delete_all_messages_within_the_feed * FeedDeleteService callback assertions fix * Fix callback name * Revert changes. * Remove validity period. * Adapt implementation. * QueryHeaderService Tests code refactored * Validity Period bugfix * Remove test function usage in official SDK outside of tests. Adapt implementation regarding DRY. * No setup outside the test case or the fixture to ensure failing test cases. * Reformat file. * Variable names updated * Adapt implementation. * Adapted test structure for chunked message service test * Test for receiving chunked messages using Query Header Sevice, i.e. within the feed of an endpoint * Adapt test structure and improve coding style * Change the name of the test script for better readability * Adapt code structure for maximum length for raw message content required for chunking * Fixture messaging services and callback bugfix * Move messaging services from fixture to test method codefix * Fix naming for the recipient_callback * Fix sender callback naming convention * Remove unnecessary class variables and callback bugfix * Remove unnecessary class variables and update flag in recipient callback * Update sender callback to non checking callback * Update the name of the recipient callback * bugfix in test for valid validity period * Additional logging * Restructure code. Remove constant from external class. * Adapt wait time to send messages. * Add assertion for number of chunks * Return raw data for large contents that need chunking * Update doc strings * Reformat code. * Removed redundant test files and fixed newline error Deleted unnecessary test files, 'test_onboard_response_integration_service.py' and 'test_update_onboard_responses.py', to improve the simplicity and readability of the project. Also fixed the absence of a newline issue at the end of file in 'identifier.py' to adhere to code style guidelines. --------- Co-authored-by: Sascha Doemer <[email protected]> * Feature/update onboarding responses (#44) * Update communication unit and capabilities for HTTP, add tests Updated communication unit identifiers to use HTTP and encryption type to use `PEM`. Renamed sensor types in messaging enums for clarity and added test cases for HTTP recipient update. Changes are to aid development and testing. The reason for the change from P12 to PEM in communication unit is currently not specified. More information might be required here. * Remove redundant test data and update onboard tests The redundant test data, 'Recipient.json' and 'Sender.json' under 'CommunicationUnit', were removed and the onboard tests were updated accordingly. It improves manageability by eliminating unnecessary test resources. The replaced 'test_update_http_cu_recipient' and 'test_update_http_cu_sender' methods update onboarding with a specific device id and save the onboard response. Lastly, added 'Recipient.json' under 'PEM' in 'CommunicationUnit' containing new authentication data - useful for upcoming tests. * Remove outdated test fixtures and update onboarding This commit removes outdated test fixtures related to message sending and recipient in MQTT protocol. These were too specific and had hardcoded QA environments and registration codes. In its place, the 'onboard_response_update.py' is renamed to 'update_http_onboard_responses.py' and updated to use function 'onboard_communication_unit'. This is to align with the practice of using widely generic onboarding function which will provide more flexibility for testing. Importantly, the new testing functions are currently marked to be skipped unless the registration code is changed. This is to avoid breaking the tests with invalid registration codes. It should be updated with valid codes when used. * Update PEM certificate and secret for MQTT messages sender and recipient PEM certificates and secrets for both the MQTT messages sender and recipient have been updated to accommodate new secure communication requirements. This change is mirrored in the corresponding test fixtures used to simulate the onboarding response during testing. The original hard-coded registration codes have also been updated to simulate the new onboarding process. * Remove setup.py and update dependencies Setup.py was removed as it's unnecessary in the project. Dependencies in requirements.txt were updated to more recent versions (setuptools to v68.2.2, certifi to v2023.7.22, and requests to v2.31.0), supporting better performance and security. Some installation instructions from README.adoc were also deleted as they were related to setup.py. * Refactor README.adoc and enhance unit tests Refactored README.adoc for better readability and included detailed instructions for Python environment setup. Enhanced unit tests in test_query_header_service.py to ensure message receipt. These changes improve documentation clarity for easier project setup and ensure robustness of unit tests. * Add MQTT message publish tests Added unit test scenarios for MQTT message publishing service. The new tests include message publishing, message receipt, and clear up processes ensuring successful message sending and receiving. These were added to increase code coverage and improve robustness of MQTT service. * Improve MQTT messaging testing A new test suite has been added to cover MQTT messaging services. This includes tests for sending and receiving messages and cleaning up received messages. The addition is aimed to increase code coverage and ensure the robustness and reliability of the MQTT messaging service. * Improve MQTT messaging testing A new test suite has been added to cover MQTT messaging services. This includes tests for sending and receiving messages and cleaning up received messages. The addition is aimed to increase code coverage and ensure the robustness and reliability of the MQTT messaging service. * Add tests for FeedDeleteService in MQTT messaging Added a new file 'test_feed_delete_service.py'. This new test file contains unittests verifying the deletion of messages in MQTT messaging system. Test cases covered include: deletion of messages from a specified sender id, deletion of a specified message, deletion of messages within a specified timeframe, and handling deletion commands with incorrect/incomplete parameters. The new tests will help ensure the effectiveness and accuracy of the FeedDeleteService module in the MQTT messaging application. * Add tests for QueryMessageService in MQTT messaging The new file 'test_query_message_service.py' contains unit tests for the MQTT messaging system. The tests include: message querying with specified sender id, message id, validity period, and handling edge cases with incorrect parameters. This helps verify the robustness and accuracy of QueryMessageService module ensuring that it correctly fetches messages meeting the specified criteria. * Updated requirements and project config * Update Python versions in Github actions A new Python version, "3.11", was added to the testing matrix in the GitHub Actions workflow configuration. This ensures that the package is tested across the newly released version, maintaining extensive compatibility. * Remove Python 3.6 from testing matrix Python 3.6 has been removed from the testing matrix in the GitHub Actions workflow configuration. This is due to Python 3.6 reaching end-of-life status and is no longer supported. As a result, it isn't necessary to test on this version. * Downgrade setuptools to version 68.0.0 The setuptools package version was downgraded from 68.2.2 to 68.0.0 in the requirements.txt file. This was necessary because version 68.2.2 is not compatible with Python 3.6 which has now been removed from our testing matrix due to its end-of-life status. * Update GitHub actions version The versions of actions/checkout and actions/setup-python GitHub actions used in the workflow file (python-package.yml) have been updated. This change was necessary to ensure compatibility with the latest features and improvements provided by these action versions. * Refactor multiple lines of code for cleaner syntax and better code readability The changes in this commit opt for more concise syntax and improves code readability by improving the formatting of the code lines. Overly long lines were split into multiple lines for easier viewing. Some superfluous details in the text strings were also removed. Some variable names were changed for better context. Additionally, indentation has been improved for better visual hierarchy of the code structure. * Update workflow configuration to use 'run' instead of 'uses' This commit replaces the 'uses' command in the Python-Package GitHub workflow with 'run'. This change aligns with the official syntax for executing commands during a GitHub Actions workflow while maintaining the same functionality. Normally, 'uses' is used to reference action repositories, but 'run' is more appropriate for executing scripts, enhancing clarity and readability in the workflow file. * Restrict parallel jobs in GitHub workflow This commit adds 'max-parallel: 1' to the action strategy matrix in the Python-Package GitHub workflow. This change ensures that jobs in the workflow run sequentially instead of concurrently, preventing potential race conditions and conflicts in the testing environment. This helps to maintain the integrity of our test results and also keeps resource usage in check. * Update python-package.yml to ensure sequential workflow jobs The commit moves the 'max-parallel: 1' configuration from the matrix to the strategy. This change ensures jobs do not run in parallel causing potential race conditions during testing. The tests are now forced to run sequentially improving the reliability of our results and resource usage efficiency. * Remove unused import in type_url.py This commit removes the unused import statement "PushNotification" from the type_url.py file. This contributes towards keeping the codebase clean and efficient, while also focusing on reducing unnecessary dependencies in the agrirouter software development kit code. * Correct comment spacing in headers.py file This commit corrects the comment spacing in the headers.py file of the agrirouter onboarding package. By maintaining consistent formatting standards, we improve the readability and overall quality of our application's source code. * Refactor comment formatting in agrirouter/onboarding files The commit adjusts spaces in commented code within two agrirouter/onboarding files, improving and maintaining code readability. The changes help promote consistent coding style across the application source code. * Fix typo in agrirouter/messaging/parameters/service.py This commit corrects a misspelling in the BaseOnboardingResponse parameter and enhances code readability by fixing the whitespaces. These changes result in better, consistent coding style and runtime stability. * Refactor and fix typo in agrirouter messaging service This commit corrects a typo in the technical message type of CapabilityType and refines the import order and whitespace for better readability. This change improves code consistency, contributing to better stability and implementation. * Remove unnecessary line in agrirouter signature file This commit simplifies the agrirouter onboarding signature.py file by eliminating an unnecessary line. This minor change contributes to overall code cleanliness and readability. * Uncommented import line in agrirouter/revoking/request.py The import line for creating a signature in the agrirouter revoking request file was uncommented. This change improves script efficiency and eliminates redundancy in the codebase. * Correct comparison operation in response.py The incorrect comparison operation, comparing "http_response" with "None" using "!=" is modified to the correct operation "is not None" in agrirouter/onboarding/response.py. This change follows the correct Pythonic way to compare something to None and makes the code cleaner. * Refactor auth response verification code Refactored the currently commented-out signature verification code in agrirouter/auth/response.py. It has been formatted and repositioned within the class for better readability. This refactoring does not introduce any functionality changes but prepares for potential future use. * Remove AR_PROD_PUBLIC_KEY import Removed the import of AR_PROD_PUBLIC_KEY in the environments.py file. Although there has been no change in functionality, this clean-up step is necessary to maintain readable and concise code, removing potentially unnecessary import. * Refactor NONE comparison in encode method Modified the 'None' comparisons in the encode method of the Messaging service in the Agrirouter project. Instead of using '!= None', the more Pythonic 'is not None' is used. This change contributes to maintaining a consistent and idiomatic style across the codebase. * Remove return type hint in parameters.py The return type hint (`object`) is removed from the constructor of a class in the file parameters.py in the Agrirouter onboarding module. This is done to enhance readability and for maintaining consistency, as the function does not have a return statement and thus does not return anything. * Commit message: Remove unnecessary import in request.py A commented out import statement (importing create_signature, verify_signature from signature) has been removed from request.py file in the Agrirouter onboarding module. It was unnecessary and not being used in the file, hence it's removed to maintain clean and clutter-free code. * Remove unused commented import in revoking.py An unused and commented out import: 'RequestNotSigned' from agrirouter.onboarding.exceptions has been removed in revoking.py. This change is made to ensure clarity and to avoid any confusion from lingering unused code in the project. * Correct typo in service.py The class name 'BaseOnboardingResonse' has been corrected to 'BaseOnboardingResponse' in two places within the service.py file. This minor typographical error was resolved to ensure that the code implementation aligns with the intended design. * Enable request signing in revoking.py The code block in the _perform_request function that handles request signing has been uncommented. This ensures that every request must be signed using the private key before it is sent, and raises an exception if a request is not signed, increasing the security of the revoking process. * Enable request signing in revoking.py The uncommented code block now enables request signing functionality in _perform_request function. Consequently, each request must now be signed using a private key before it is sent, thereby enhancing the security of the revoking process through enforcement of signed requests. * Add SendChunkedMessageService to imported services SendChunkedMessageService was added to the imported services in agrirouter/__init__.py. This makes it possible for messages to be sent in chunks, which could be useful for handling larger data transfers more efficiently. * "Activate public and private key in onboarding service" A commented code has been uncommented in the onboarding.py file to activate usage of public and private keys in the SecuredOnboardingService class. Simultaneously, an unnecessary import was also removed, ensuring optimised resource handling. * Refactor and enhance the onboarding process Implemented significant changes in the code to streamline the onboarding process. This includes modifying the SecuredOnboardingService constructor for better parameter handling and the activation of public and private keys usage, which was previously commented out. Additionally, exceptions and environment classes were refined as part of the code clean-up. * Update import paths and refactor onboarding process This commit updates import paths and refactorizes the SecuredOnboardingService constructor for better parameter management. Comment out sections regarding application IDs and signatures have been enabled, contributing towards an enhanced onboarding process. The manner in which exceptions and environment classes are handled has also been refined for a clearer, cleaner codebase. * Remove exception files and rename workflow file This commit involves two major changes: deletion of exception files in various directories and renaming the workflow file for clarity. With the removal of exception files, the handling of exceptions and environment classes has been refined. Further, the workflow file has been renamed from 'python-package.yml' to 'continuous_integration.yml' to better reflect its function. * Refactor CI workflow and limit Python versions This commit renames the 'continuous_integration.yml' workflow to match standard naming conventions and refactor its operations. The workflow now only runs on Python version "3.11". Additionally, a new workflow file, 'linting-for-all-versions.yml', is added to maintain linting for all Python versions, expanding quality control measures. * Refactor environment import paths and reenable auth response signature verification This commit refactors the import paths relating to environments across multiple files, moving the environment related modules under the 'api' directory for better organization. Also, sections of commented-out code in the authentication response module were uncommented to reenable the verification of the signature in the auth response, improving the security of auth responses. Lastly, any instance of strings used to denote an environment has been replaced with their corresponding enumerated types. * Refactor import paths and use enum for environments This commit refactors the import paths for environment-related modules, organizing them under the 'api' directory for better structure. It also replaces instances of strings used to denote an environment with the corresponding enumerated types, enhancing code clarity and preventing potential errors. * Update exception handling and request handling in onboarding This commit includes significant refactoring of the exceptions raised during the onboarding process, making them more descriptive and specific. In addition, it updates the method of handling requests where it now makes them static. Lastly, some updates include enabling the signing of requests and tweaking the logic of setting request headers. * Refactor messaging parameters and update function names This commit changes the handling of messaging parameters by making certain parameters mandatory and removing setter methods. It also modifies the function name from 'get_chunk_components' to 'get_chunk_component'. These changes aim to streamline how parameters are managed and improve the readability of the function names. * Fix comma error in chunk_component assignment This commit corrects a syntax error in the assignment of the chunk_component parameter in the messaging parameters module. Previously, a comma at the end of the assignment operation was causing it to be treated as a tuple, which is now removed. * Remove pull_request trigger from CI workflow The pull_request trigger has been removed from the continuous integration workflow. This change means that the workflow will no longer run automatically on pull requests to the master branch. * type hint was removed from the chunk_component assignment in the agrirouter messaging parameters dto. This simplification makes the code more readable and easier to maintain. --------- Co-authored-by: YashRunwal <[email protected]> Co-authored-by: Sascha Doemer <[email protected]> Co-authored-by: YashRunwal <[email protected]>
- Loading branch information