Skip to content

Commit

Permalink
fixed test after the sub branch merged
Browse files Browse the repository at this point in the history
  • Loading branch information
rugeli committed Aug 2, 2023
1 parent 2d0859d commit 3c09ce9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
5 changes: 3 additions & 2 deletions cellpack/autopack/DBRecipeHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ def upload_gradients(self, gradients):
gradient_doc = GradientDoc(settings=gradient)
_, doc_id = gradient_doc.should_write(self.db, gradient_name)
if doc_id:
print(f"gradients/{gradient_name} already exists in firestore")
print(f"gradients/{gradient_name} is already in firestore")
self.grad_to_path_map[gradient_name] = self.db.create_path(
"gradients", doc_id
)
Expand All @@ -422,8 +422,9 @@ def upload_gradients(self, gradients):
def upload_objects(self, objects):
for obj_name in objects:
objects[obj_name]["name"] = obj_name
# modify a copy of objects to avoid key error when resolving local regions
modify_objects = copy.deepcopy(objects)
# replace gradient name with path before uploading
# replace gradient name with path to check if gradient exists in db
if "gradient" in modify_objects[obj_name]:
grad_name = modify_objects[obj_name]["gradient"]
modify_objects[obj_name]["gradient"] = self.grad_to_path_map[grad_name]
Expand Down
18 changes: 12 additions & 6 deletions cellpack/tests/test_db_recipe_handler.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from cellpack.autopack.DBRecipeHandler import DBRecipeHandler
from cellpack.tests.mocks.mock_db import MockDB

from unittest.mock import MagicMock, patch
mock_db = MockDB({})


Expand Down Expand Up @@ -65,12 +65,18 @@ def test_upload_objects():


def test_upload_objects_with_gradient():
# the value of gradient in obj should be changed to the path instead of the name before uploading
data = {"test": {"test_key": "test_value", "gradient": "test_grad_name"}}
object_doc = DBRecipeHandler(mock_db)
object_doc.grad_to_path_map = {"test_grad_name": "firebase:gradients/test_id"}
object_doc.upload_objects(data)
assert data["test"]["gradient"] == "firebase:gradients/test_id"
object_handler = DBRecipeHandler(mock_db)
object_handler.grad_to_path_map = {"test_grad_name": "firebase:gradients/test_id"}

with patch('cellpack.autopack.DBRecipeHandler.ObjectDoc', return_value=MagicMock()) as mock_object_doc:
mock_object_doc.return_value.should_write.return_value = (None, "firebase:gradients/test_id")
object_handler.upload_objects(data)
mock_object_doc.assert_called()
called_with_settings = mock_object_doc.call_args.kwargs["settings"]
assert data["test"]["gradient"] == "test_grad_name"
assert called_with_settings["gradient"] == "firebase:gradients/test_id"



def test_upload_compositions():
Expand Down

0 comments on commit 3c09ce9

Please sign in to comment.