Skip to content

Commit

Permalink
fixed a bug in update_metrics helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
kzailac committed Mar 30, 2022
1 parent 9aabb5b commit 90f545a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
21 changes: 21 additions & 0 deletions poem/Poem/api/tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3256,6 +3256,27 @@ def test_update_all_metrics_on_metrictemplate_change(self, mock_update):
)
], any_order=True)

@patch("Poem.helpers.metrics_helpers.update_metric_in_schema")
def test_update_all_passive_metrics_on_metrictemplate_change(
self, mock_update
):
mock_update.side_effect = mocked_func
metrictemplate = admin_models.MetricTemplate.objects.get(
name="org.apel.APEL-Pub"
)
update_metrics(metrictemplate, "org.apel.APEL-Pub", None)
self.assertEqual(mock_update.call_count, 2)
mock_update.assert_has_calls([
call(
mt_id=metrictemplate.id, name="org.apel.APEL-Pub",
pk_id=None, schema="test", user=""
),
call(
mt_id=metrictemplate.id, name="org.apel.APEL-Pub",
pk_id=None, schema="test2", user=""
)
], any_order=True)


class MetricsInProfilesTests(TenantTestCase):
def setUp(self):
Expand Down
16 changes: 12 additions & 4 deletions poem/Poem/helpers/metrics_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,18 @@ def update_metrics(metrictemplate, name, probekey, user=''):

msgs = []
for schema in schemas:
msg = update_metric_in_schema(
mt_id=metrictemplate.id, name=name, pk_id=probekey.id,
schema=schema, user=user
)
if probekey:
msg = update_metric_in_schema(
mt_id=metrictemplate.id, name=name, pk_id=probekey.id,
schema=schema, user=user
)

else:
msg = update_metric_in_schema(
mt_id=metrictemplate.id, name=name, pk_id=None,
schema=schema, user=user
)

if msg:
msgs.append(msg)

Expand Down

0 comments on commit 90f545a

Please sign in to comment.