Skip to content

Commit

Permalink
Websub Topic names updated
Browse files Browse the repository at this point in the history
Signed-off-by: Lalith Kota <[email protected]>
  • Loading branch information
lalithkota committed Jan 17, 2025
1 parent 4f990da commit 1345f8f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 194 deletions.
175 changes: 0 additions & 175 deletions g2p_registry_datashare_websub/i18n/g2p_registry_datashare_websub.pot

This file was deleted.

12 changes: 6 additions & 6 deletions g2p_registry_datashare_websub/models/datashare_config_websub.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ class G2PDatashareConfigWebsub(models.Model):

event_type = fields.Selection(
[
("GROUP_CREATED", "GROUP_CREATED"),
("GROUP_UPDATED", "GROUP_UPDATED"),
("GROUP_DELETED", "GROUP_DELETED"),
("INDIVIDUAL_CREATED", "INDIVIDUAL_CREATED"),
("INDIVIDUAL_UPDATED", "INDIVIDUAL_UPDATED"),
("INDIVIDUAL_DELETED", "INDIVIDUAL_DELETED"),
("WEBSUB_GROUP_CREATED", "Group Created"),
("WEBSUB_GROUP_UPDATED", "Group Updated"),
("WEBSUB_GROUP_DELETED", "Group Deleted"),
("WEBSUB_INDIVIDUAL_CREATED", "Individual Created"),
("WEBSUB_INDIVIDUAL_UPDATED", "Individual Updated"),
("WEBSUB_INDIVIDUAL_DELETED", "Individual Deleted"),
],
required=True,
)
Expand Down
6 changes: 3 additions & 3 deletions g2p_registry_datashare_websub/models/registrant.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def create(self, vals):
new_vals = vals[i].copy()
new_vals["id"] = res[i].id
self.env["g2p.datashare.config.websub"].with_delay().publish_event(
"GROUP_CREATED" if res[i].is_group else "INDIVIDUAL_CREATED", new_vals
"WEBSUB_GROUP_CREATED" if res[i].is_group else "WEBSUB_INDIVIDUAL_CREATED", new_vals
)
return res

Expand All @@ -27,14 +27,14 @@ def write(self, vals):
new_vals = vals.copy()
new_vals["id"] = rec.id
self.env["g2p.datashare.config.websub"].with_delay().publish_event(
"GROUP_UPDATED" if rec.is_group else "INDIVIDUAL_UPDATED", new_vals
"WEBSUB_GROUP_UPDATED" if rec.is_group else "WEBSUB_INDIVIDUAL_UPDATED", new_vals
)
return res

def unlink(self):
for rec in self:
if rec.is_registrant:
self.env["g2p.datashare.config.websub"].with_delay().publish_event(
"GROUP_DELETED" if rec.is_group else "INDIVIDUAL_DELETED", dict(id=rec.id)
"WEBSUB_GROUP_DELETED" if rec.is_group else "WEBSUB_INDIVIDUAL_DELETED", dict(id=rec.id)
)
return super().unlink()
20 changes: 10 additions & 10 deletions g2p_registry_datashare_websub/tests/test_datashare_websub.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def setUp(self, mock_post):
{
"name": "Test WebSub Config",
"partner_id": self.env.ref("base.main_partner").id, # Use existing partner
"event_type": "GROUP_CREATED",
"event_type": "WEBSUB_GROUP_CREATED",
"websub_base_url": "http://test.websub/hub",
"websub_auth_url": "http://test.auth/token",
"websub_auth_client_id": "test_client",
Expand Down Expand Up @@ -146,12 +146,12 @@ def test_publish_event(self, mock_post):

# Ensure websub config matches event type
self.websub_config.write(
{"event_type": "GROUP_CREATED", "transform_data_jq": ".", "condition_jq": "true"}
{"event_type": "WEBSUB_GROUP_CREATED", "transform_data_jq": ".", "condition_jq": "true"}
)

# Test publishing with matching event type
self.env["g2p.datashare.config.websub"].with_context(test_mode=True).publish_event(
"GROUP_CREATED", test_data
"WEBSUB_GROUP_CREATED", test_data
)

# Verify that call was made
Expand All @@ -160,7 +160,7 @@ def test_publish_event(self, mock_post):
# Test with non-matching event type
mock_post.reset_mock()
self.env["g2p.datashare.config.websub"].with_context(test_mode=True).publish_event(
"INDIVIDUAL_CREATED", test_data
"WEBSUB_INDIVIDUAL_CREATED", test_data
)

# Verify no calls for non-matching type
Expand Down Expand Up @@ -198,7 +198,7 @@ def test_transform_data_jq(self, mock_post):
}"""

self.websub_config.write(
{"transform_data_jq": transform_jq, "event_type": "GROUP_CREATED", "condition_jq": "true"}
{"transform_data_jq": transform_jq, "event_type": "WEBSUB_GROUP_CREATED", "condition_jq": "true"}
)

# Reset mock to clear write() calls
Expand All @@ -208,7 +208,7 @@ def test_transform_data_jq(self, mock_post):
record_data = test_record.read(["id", "name"])[0]
test_data = {
"id": test_record.id,
"publisher": {"event_type": "GROUP_CREATED"},
"publisher": {"event_type": "WEBSUB_GROUP_CREATED"},
"record_data": record_data,
"curr_datetime": "2024-12-27T17:05:05.936Z",
}
Expand All @@ -221,7 +221,7 @@ def test_transform_data_jq(self, mock_post):
published_data = call_args[1].get("json", {})

# Verify the transformed data
self.assertEqual(published_data.get("event"), "GROUP_CREATED")
self.assertEqual(published_data.get("event"), "WEBSUB_GROUP_CREATED")
self.assertIsNotNone(published_data.get("ts_ms"), "Timestamp should not be None")
self.assertTrue(isinstance(published_data.get("ts_ms"), str), "Timestamp should be a string")
# Cleanup
Expand Down Expand Up @@ -254,13 +254,13 @@ def test_condition_jq(self, mock_post):
self.websub_config.write(
{
"condition_jq": "true", # First test with default condition
"event_type": "GROUP_CREATED",
"event_type": "WEBSUB_GROUP_CREATED",
"transform_data_jq": ".",
}
)

# Prepare test data
test_data = {"id": test_record.id, "publisher": {"event_type": "GROUP_CREATED"}}
test_data = {"id": test_record.id, "publisher": {"event_type": "WEBSUB_GROUP_CREATED"}}

# Should pass condition and make API call with default "true" condition
mock_post.reset_mock()
Expand Down Expand Up @@ -300,7 +300,7 @@ def test_unlink(self, mock_post):
{
"name": "Test Unlink Config",
"partner_id": self.env.ref("base.main_partner").id,
"event_type": "GROUP_CREATED",
"event_type": "WEBSUB_GROUP_CREATED",
"websub_base_url": "http://test.websub/hub",
"websub_auth_url": "http://test.auth/token",
"websub_auth_client_id": "test_client",
Expand Down

0 comments on commit 1345f8f

Please sign in to comment.