|
7 | 7 |
|
8 | 8 | import yaml
|
9 | 9 | from django.conf import settings
|
| 10 | +from django.db.models import Q |
10 | 11 | from django.http import HttpResponse
|
11 | 12 | from django.http.response import JsonResponse
|
12 | 13 | from django.urls import reverse
|
@@ -4926,45 +4927,61 @@ def test_invoke_trigger_by_revert_attrv(self):
|
4926 | 4927 | user,
|
4927 | 4928 | "Entity",
|
4928 | 4929 | [
|
4929 |
| - {"name": "cond", "type": AttrTypeValue["string"]}, |
| 4930 | + {"name": "cond_str", "type": AttrTypeValue["string"]}, |
| 4931 | + {"name": "cond_name", "type": AttrTypeValue["named_object"]}, |
4930 | 4932 | {"name": "action", "type": AttrTypeValue["string"]},
|
4931 | 4933 | ],
|
4932 | 4934 | )
|
4933 |
| - entry = self.add_entry( |
4934 |
| - user, |
4935 |
| - "TestEntry", |
4936 |
| - entity, |
4937 |
| - values={ |
4938 |
| - "cond": "hoge", |
4939 |
| - }, |
4940 |
| - ) |
4941 |
| - |
4942 |
| - # changed value to retrieve |
4943 |
| - changing_attr = entry.attrs.get(name="cond") |
4944 |
| - changing_attr.add_value(user, "changed") |
4945 | 4935 |
|
4946 | 4936 | # register TriggerAction configuration before creating an Entry
|
4947 | 4937 | TriggerCondition.register(
|
4948 | 4938 | entity,
|
4949 |
| - [{"attr_id": entity.attrs.get(name="cond").id, "cond": "hoge"}], |
| 4939 | + [{"attr_id": entity.attrs.get(name="cond_str").id, "cond": "hoge"}], |
4950 | 4940 | [{"attr_id": entity.attrs.get(name="action").id, "value": "fuga"}],
|
4951 | 4941 | )
|
4952 |
| - |
4953 |
| - # send request to revert attribute value of "cond" |
4954 |
| - revert_attrv = changing_attr.values.filter(value="hoge").last() |
4955 |
| - params = {"attr_id": str(changing_attr.id), "attrv_id": str(revert_attrv.id)} |
4956 |
| - resp = self.client.post( |
4957 |
| - reverse("entry:revert_attrv"), json.dumps(params), "application/json" |
| 4942 | + TriggerCondition.register( |
| 4943 | + entity, |
| 4944 | + [{"attr_id": entity.attrs.get(name="cond_name").id, "cond": "foo"}], |
| 4945 | + [{"attr_id": entity.attrs.get(name="action").id, "value": "fuga"}], |
4958 | 4946 | )
|
4959 |
| - self.assertEqual(resp.status_code, 200) |
4960 | 4947 |
|
4961 |
| - # This check that Attribute value of "action" would be updated by TriggerAction |
4962 |
| - self.assertEqual(entry.get_attrv("action").value, "fuga") |
| 4948 | + # changed value to retrieve |
| 4949 | + testing_params = [ |
| 4950 | + ("cond_str", "hoge", "changed", Q(value="hoge")), |
| 4951 | + ( |
| 4952 | + "cond_name", |
| 4953 | + {"name": "foo", "id": None}, |
| 4954 | + {"name": "changed", "id": None}, |
| 4955 | + Q(value="foo"), |
| 4956 | + ), |
| 4957 | + ] |
| 4958 | + for index, (attrname, initial_value, changed_value, query) in enumerate(testing_params): |
| 4959 | + entry = self.add_entry( |
| 4960 | + user, |
| 4961 | + "TestEntry", |
| 4962 | + entity, |
| 4963 | + values={ |
| 4964 | + attrname: initial_value, |
| 4965 | + }, |
| 4966 | + ) |
| 4967 | + changing_attr = entry.attrs.get(name=attrname) |
| 4968 | + changing_attr.add_value(user, changed_value) |
4963 | 4969 |
|
4964 |
| - # check trigger action was worked properly |
4965 |
| - job_query = Job.objects.filter(operation=JobOperation.MAY_INVOKE_TRIGGER) |
4966 |
| - self.assertEqual(job_query.count(), 1) |
4967 |
| - self.assertEqual(job_query.first().status, JobStatus.DONE) |
| 4970 | + # send request to revert attribute value of "cond" |
| 4971 | + revert_attrv = changing_attr.values.filter(query).last() |
| 4972 | + params = {"attr_id": str(changing_attr.id), "attrv_id": str(revert_attrv.id)} |
| 4973 | + resp = self.client.post( |
| 4974 | + reverse("entry:revert_attrv"), json.dumps(params), "application/json" |
| 4975 | + ) |
| 4976 | + self.assertEqual(resp.status_code, 200) |
| 4977 | + |
| 4978 | + # This check that Attribute value of "action" would be updated by TriggerAction |
| 4979 | + self.assertEqual(entry.get_attrv("action").value, "fuga") |
| 4980 | + |
| 4981 | + # check trigger action was worked properly |
| 4982 | + job_query = Job.objects.filter(operation=JobOperation.MAY_INVOKE_TRIGGER) |
| 4983 | + self.assertEqual(job_query.count(), 1 + index) |
| 4984 | + self.assertEqual(job_query.last().status, JobStatus.DONE) |
4968 | 4985 |
|
4969 | 4986 | def test_revert_attrv_with_invalid_value(self):
|
4970 | 4987 | user = self.guest_login()
|
|
0 commit comments