-
Notifications
You must be signed in to change notification settings - Fork 42
Fixing Unites functionality #252
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 all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
bb16cf7
Refactor NodeTemplate and create_next_states for improved unites hand…
NiveditJain aa05226
fixed test
NiveditJain d28ff50
fix PR review comments
NiveditJain fd60994
Enhance unit tests for state management and model validation
NiveditJain 5854664
fixed ruff checks @coderabbitai ingore these changes in review
NiveditJain 1a5d91c
fixed typing errors
NiveditJain 3729688
fixed more typing issues @coderabbitai ignore these changes also
NiveditJain 7219c0d
Refactor generate_next_state function and improve state creation logic
NiveditJain 7a60904
fixxed issue in unites
NiveditJain 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| import pytest | ||
| from datetime import datetime | ||
| from app.models.db.base import BaseDatabaseModel | ||
|
|
||
|
|
||
| class TestBaseDatabaseModel: | ||
| """Test cases for BaseDatabaseModel""" | ||
|
|
||
| def test_base_model_field_definitions(self): | ||
| """Test that BaseDatabaseModel has the expected fields""" | ||
| # Check that the model has the expected fields | ||
| model_fields = BaseDatabaseModel.model_fields | ||
|
|
||
| assert 'created_at' in model_fields | ||
| assert 'updated_at' in model_fields | ||
|
|
||
| # Check field descriptions | ||
| assert model_fields['created_at'].description == "Date and time when the model was created" | ||
| assert model_fields['updated_at'].description == "Date and time when the model was last updated" | ||
|
|
||
| def test_base_model_abc_inheritance(self): | ||
| """Test that BaseDatabaseModel is an abstract base class""" | ||
| # Should not be able to instantiate BaseDatabaseModel directly | ||
| with pytest.raises(Exception): # Could be TypeError or CollectionWasNotInitialized | ||
| BaseDatabaseModel() | ||
|
|
||
NiveditJain marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| def test_base_model_document_inheritance(self): | ||
| """Test that BaseDatabaseModel inherits from Document""" | ||
| # Check that it has the expected base classes | ||
| bases = BaseDatabaseModel.__bases__ | ||
| assert len(bases) >= 2 # Should have at least ABC and Document as base classes | ||
|
|
||
NiveditJain marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| def test_base_model_has_update_updated_at_method(self): | ||
| """Test that BaseDatabaseModel has the update_updated_at method""" | ||
| assert hasattr(BaseDatabaseModel, 'update_updated_at') | ||
| assert callable(BaseDatabaseModel.update_updated_at) | ||
|
|
||
| def test_base_model_field_types(self): | ||
| """Test that BaseDatabaseModel fields have correct types""" | ||
| model_fields = BaseDatabaseModel.model_fields | ||
|
|
||
| # Check that created_at and updated_at are datetime fields | ||
| created_at_field = model_fields['created_at'] | ||
| updated_at_field = model_fields['updated_at'] | ||
|
|
||
| assert created_at_field.annotation == datetime | ||
| assert updated_at_field.annotation == datetime | ||
|
|
||
| def test_base_model_has_before_event_decorator(self): | ||
| """Test that BaseDatabaseModel uses the before_event decorator""" | ||
| # Check that the update_updated_at method exists and is callable | ||
| update_method = BaseDatabaseModel.update_updated_at | ||
|
|
||
| # The method should exist and be callable | ||
| assert callable(update_method) | ||
NiveditJain marked this conversation as resolved.
Show resolved
Hide resolved
|
||
107 changes: 107 additions & 0 deletions
107
state-manager/tests/unit/models/test_graph_template_model.py
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,107 @@ | ||
| import pytest | ||
| from unittest.mock import patch | ||
| import base64 | ||
| from app.models.db.graph_template_model import GraphTemplate | ||
|
|
||
|
|
||
| class TestGraphTemplate: | ||
| """Test cases for GraphTemplate model""" | ||
|
|
||
| def test_validate_secrets_valid(self): | ||
| """Test validation of valid secrets""" | ||
| valid_secrets = { | ||
| "secret1": "valid_encrypted_string_that_is_long_enough_for_testing_32_chars", | ||
| "secret2": "another_valid_encrypted_string_that_is_long_enough_for_testing_32", | ||
| } | ||
|
|
||
| # Mock base64 decoding to succeed | ||
| with patch("base64.urlsafe_b64decode", return_value=b"x" * 20): | ||
| result = GraphTemplate.validate_secrets(valid_secrets) | ||
|
|
||
| assert result == valid_secrets | ||
|
|
||
| def test_validate_secrets_empty_name(self): | ||
| """Test validation with empty secret name""" | ||
| invalid_secrets = {"": "valid_value"} | ||
|
|
||
| with pytest.raises(ValueError, match="Secrets cannot be empty"): | ||
| GraphTemplate.validate_secrets(invalid_secrets) | ||
|
|
||
| def test_validate_secrets_empty_value(self): | ||
| """Test validation with empty secret value""" | ||
| invalid_secrets = {"secret1": ""} | ||
|
|
||
| with pytest.raises(ValueError, match="Secrets cannot be empty"): | ||
| GraphTemplate.validate_secrets(invalid_secrets) | ||
|
|
||
| def test_validate_secret_value_too_short(self): | ||
| """Test validation of secret value that's too short""" | ||
| short_value = "short" | ||
|
|
||
| with pytest.raises(ValueError, match="Value appears to be too short for an encrypted string"): | ||
| GraphTemplate._validate_secret_value(short_value) | ||
|
|
||
| def test_validate_secret_value_invalid_base64(self): | ||
| """Test validation of secret value with invalid base64""" | ||
| invalid_base64 = "invalid_base64_string_that_is_long_enough_but_not_valid_base64" | ||
|
|
||
| with pytest.raises(ValueError, match="Value is not valid URL-safe base64 encoded"): | ||
| GraphTemplate._validate_secret_value(invalid_base64) | ||
|
|
||
| def test_validate_secret_value_valid(self): | ||
| """Test validation of valid secret value""" | ||
| # Create a valid base64 string that decodes to at least 12 bytes and is long enough | ||
| valid_bytes = b"x" * 20 | ||
| valid_base64 = base64.urlsafe_b64encode(valid_bytes).decode() | ||
| # Pad to make it at least 32 characters | ||
| padded_base64 = valid_base64 + "x" * (32 - len(valid_base64)) | ||
|
|
||
| # Should not raise any exception | ||
| GraphTemplate._validate_secret_value(padded_base64) | ||
|
|
||
NiveditJain marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| def test_validate_secrets_with_long_valid_strings(self): | ||
| """Test validation with properly long secret values""" | ||
| long_secrets = { | ||
| "secret1": "x" * 50, # 50 characters | ||
| "secret2": "y" * 100, # 100 characters | ||
| } | ||
|
|
||
| # Mock base64 decoding to succeed | ||
| with patch("base64.urlsafe_b64decode", return_value=b"x" * 20): | ||
| result = GraphTemplate.validate_secrets(long_secrets) | ||
|
|
||
| assert result == long_secrets | ||
|
|
||
| def test_validate_secret_value_exactly_32_chars(self): | ||
| """Test validation with exactly 32 character string""" | ||
| exactly_32 = "x" * 32 | ||
|
|
||
| # Mock base64 decoding to succeed | ||
| with patch("base64.urlsafe_b64decode", return_value=b"x" * 20): | ||
| # Should not raise exception | ||
| GraphTemplate._validate_secret_value(exactly_32) | ||
|
|
||
| def test_validate_secret_value_31_chars_fails(self): | ||
| """Test validation with 31 character string fails""" | ||
| exactly_31 = "x" * 31 | ||
|
|
||
| with pytest.raises(ValueError, match="Value appears to be too short for an encrypted string"): | ||
| GraphTemplate._validate_secret_value(exactly_31) | ||
|
|
||
| def test_validate_secret_value_base64_decode_exception(self): | ||
| """Test validation when base64 decoding raises exception""" | ||
| invalid_base64 = "invalid_base64_string_that_is_long_enough_but_not_valid_base64" | ||
|
|
||
| with pytest.raises(ValueError, match="Value is not valid URL-safe base64 encoded"): | ||
| GraphTemplate._validate_secret_value(invalid_base64) | ||
|
|
||
| def test_validate_secret_value_decoded_exactly_12_bytes(self): | ||
| """Test validation with decoded value exactly 12 bytes""" | ||
| # Create a valid base64 string that decodes to exactly 12 bytes and is long enough | ||
| exactly_12_bytes = b"x" * 12 | ||
| base64_string = base64.urlsafe_b64encode(exactly_12_bytes).decode() | ||
| # Pad to make it at least 32 characters | ||
| padded_base64 = base64_string + "x" * (32 - len(base64_string)) | ||
|
|
||
| # Should not raise exception | ||
| GraphTemplate._validate_secret_value(padded_base64) | ||
NiveditJain marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Oops, something went wrong.
Oops, something went wrong.
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.