-
-
Couldn't load subscription status.
- Fork 7
solution of issue #9 #124
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
VigneshVSV
merged 3 commits into
hololinked-dev:main
from
katerinaonusk:feature/mongoDBaddition
Oct 17, 2025
Merged
solution of issue #9 #124
Changes from all commits
Commits
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
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,80 @@ | ||
| import unittest | ||
| from hololinked.core.property import Property | ||
| from hololinked.core import Thing | ||
| from hololinked.storage.database import MongoThingDB | ||
| from pymongo import MongoClient | ||
|
|
||
| class TestMongoDBOperations(unittest.TestCase): | ||
| @classmethod | ||
| def setUpClass(cls): | ||
| # Clear MongoDB 'properties' collection before tests | ||
| try: | ||
| client = MongoClient("mongodb://localhost:27017") | ||
| db = client["hololinked"] | ||
| db["properties"].delete_many({}) | ||
| except Exception as e: | ||
| print(f"Warning: Could not clear MongoDB test data: {e}") | ||
|
|
||
| def test_mongo_string_property(self): | ||
| class MongoTestThing(Thing): | ||
| str_prop = Property(default="hello", db_persist=True) | ||
| instance = MongoTestThing(id="mongo_str", use_mongo_db=True) | ||
| instance.str_prop = "world" | ||
| value_from_db = instance.db_engine.get_property("str_prop") | ||
| self.assertEqual(value_from_db, "world") | ||
|
|
||
| def test_mongo_float_property(self): | ||
| class MongoTestThing(Thing): | ||
| float_prop = Property(default=1.23, db_persist=True) | ||
| instance = MongoTestThing(id="mongo_float", use_mongo_db=True) | ||
| instance.float_prop = 4.56 | ||
| value_from_db = instance.db_engine.get_property("float_prop") | ||
| self.assertAlmostEqual(value_from_db, 4.56) | ||
|
|
||
| def test_mongo_bool_property(self): | ||
| class MongoTestThing(Thing): | ||
| bool_prop = Property(default=False, db_persist=True) | ||
| instance = MongoTestThing(id="mongo_bool", use_mongo_db=True) | ||
| instance.bool_prop = True | ||
| value_from_db = instance.db_engine.get_property("bool_prop") | ||
| self.assertTrue(value_from_db) | ||
|
|
||
| def test_mongo_dict_property(self): | ||
| class MongoTestThing(Thing): | ||
| dict_prop = Property(default={"a": 1}, db_persist=True) | ||
| instance = MongoTestThing(id="mongo_dict", use_mongo_db=True) | ||
| instance.dict_prop = {"b": 2, "c": 3} | ||
| value_from_db = instance.db_engine.get_property("dict_prop") | ||
| self.assertEqual(value_from_db, {"b": 2, "c": 3}) | ||
|
|
||
| def test_mongo_list_property(self): | ||
| class MongoTestThing(Thing): | ||
| list_prop = Property(default=[1, 2], db_persist=True) | ||
| instance = MongoTestThing(id="mongo_list", use_mongo_db=True) | ||
| instance.list_prop = [3, 4, 5] | ||
| value_from_db = instance.db_engine.get_property("list_prop") | ||
| self.assertEqual(value_from_db, [3, 4, 5]) | ||
|
|
||
| def test_mongo_none_property(self): | ||
| class MongoTestThing(Thing): | ||
| none_prop = Property(default=None, db_persist=True, allow_None=True) | ||
| instance = MongoTestThing(id="mongo_none", use_mongo_db=True) | ||
| instance.none_prop = None | ||
| value_from_db = instance.db_engine.get_property("none_prop") | ||
| self.assertIsNone(value_from_db) | ||
|
|
||
| def test_mongo_property_persistence(self): | ||
| thing_id = "mongo_test_persistence_unique" | ||
| prop_name = "test_prop_unique" | ||
| client = MongoClient("mongodb://localhost:27017") | ||
| db = client["hololinked"] | ||
| db["properties"].delete_many({"id": thing_id, "name": prop_name}) | ||
| class MongoTestThing(Thing): | ||
| test_prop_unique = Property(default=123, db_persist=True) | ||
| instance = MongoTestThing(id=thing_id, use_mongo_db=True) | ||
| instance.test_prop_unique = 456 | ||
| value_from_db = instance.db_engine.get_property(prop_name) | ||
| self.assertEqual(value_from_db, 456) | ||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() |
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.