Skip to content

Commit 911d7b2

Browse files
committed
run ruff and ruff format to pass lint check
1 parent 9f7d0b5 commit 911d7b2

File tree

4 files changed

+106
-96
lines changed

4 files changed

+106
-96
lines changed

trigger/api_v2/serializers.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def get_ref_cond(self, obj: TriggerActionValue) -> EntryAttributeValueObject | N
4343
"schema": {
4444
"id": obj.ref_cond.schema.id,
4545
"name": obj.ref_cond.schema.name,
46-
}
46+
},
4747
}
4848
else:
4949
return None
@@ -84,11 +84,12 @@ def get_ref_cond(self, obj: TriggerCondition) -> EntryAttributeValueObject | Non
8484
"schema": {
8585
"id": obj.ref_cond.schema.id,
8686
"name": obj.ref_cond.schema.name,
87-
}
87+
},
8888
}
8989
else:
9090
return None
9191

92+
9293
class TriggerParentSerializer(serializers.ModelSerializer):
9394
entity = EntitySerializer(read_only=True)
9495
actions = TriggerActionSerializer(many=True)

trigger/models.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ def get_serializer_acceptable_value(self, value=None, attr_type=None):
188188
elif attr_type == AttrTypeValue["boolean"]:
189189
return value.bool_cond
190190
elif attr_type == AttrTypeValue["named_object"]:
191-
entry = value.ref_cond.id if isinstance(value.ref_cond, Entry) else None
191+
value.ref_cond.id if isinstance(value.ref_cond, Entry) else None
192192
return {
193193
"name": value.str_cond,
194194
"id": value.ref_cond.id,
@@ -329,6 +329,7 @@ def is_match_condition(self, recv_value) -> bool:
329329
This checks specified value, which is compatible with APIv2 standard, matches
330330
with this condition.
331331
"""
332+
332333
# This is a helper method when AttrType is "object" or "named_object"
333334
def _is_match_object(val):
334335
if isinstance(val, int) or isinstance(val, str):

trigger/tests/test_api_v2.py

+44-40
Original file line numberDiff line numberDiff line change
@@ -43,22 +43,29 @@ def setUp(self):
4343
)
4444

4545
def _assert_resp_results_of_action_values(self, resp_action_values, ref_entry):
46-
ref_action_values = [x for x in sum(
47-
[x["values"] for x in resp_action_values if x["attr"]["name"] == "borrowed_by"],
48-
[]
49-
)]
50-
self.assertEqual([x for x in ref_action_values if x["ref_cond"] != None][0]["ref_cond"], {
51-
"id": ref_entry.id,
52-
"name": ref_entry.name,
53-
"schema": {
54-
"id": ref_entry.schema.id,
55-
"name": ref_entry.schema.name,
46+
ref_action_values = [
47+
x
48+
for x in sum(
49+
[x["values"] for x in resp_action_values if x["attr"]["name"] == "borrowed_by"], []
50+
)
51+
]
52+
self.assertEqual(
53+
[x for x in ref_action_values if x["ref_cond"] is not None][0]["ref_cond"],
54+
{
55+
"id": ref_entry.id,
56+
"name": ref_entry.name,
57+
"schema": {
58+
"id": ref_entry.schema.id,
59+
"name": ref_entry.schema.name,
60+
},
5661
},
57-
})
58-
bool_action_values = [x for x in sum(
59-
[x["values"] for x in resp_action_values if x["attr"]["name"] == "is_overdue"],
60-
[]
61-
)]
62+
)
63+
bool_action_values = [
64+
x
65+
for x in sum(
66+
[x["values"] for x in resp_action_values if x["attr"]["name"] == "is_overdue"], []
67+
)
68+
]
6269
self.assertTrue(all([x["bool_cond"] for x in bool_action_values]))
6370

6471
def test_list_trigger_condition_and_action(self):
@@ -78,7 +85,7 @@ def test_list_trigger_condition_and_action(self):
7885
{
7986
"attr_id": self.entity_book.attrs.get(name="is_overdue").id,
8087
"value": str(True),
81-
}
88+
},
8289
]
8390
TriggerCondition.register(
8491
self.entity_book,
@@ -133,17 +140,21 @@ def test_list_trigger_condition_and_action(self):
133140

134141
# check ref_cond value format is correctly in the conditions
135142
elem_ref_cond = [
136-
x["ref_cond"] for x in sum([t["conditions"] for t in resp.json()["results"]], [])
143+
x["ref_cond"]
144+
for x in sum([t["conditions"] for t in resp.json()["results"]], [])
137145
if x["ref_cond"] is not None
138146
][0]
139-
self.assertEqual(elem_ref_cond, {
140-
"id": entry_tom.id,
141-
"name": entry_tom.name,
142-
"schema": {
143-
"id": entry_tom.schema.id,
144-
"name": entry_tom.schema.name,
147+
self.assertEqual(
148+
elem_ref_cond,
149+
{
150+
"id": entry_tom.id,
151+
"name": entry_tom.name,
152+
"schema": {
153+
"id": entry_tom.schema.id,
154+
"name": entry_tom.schema.name,
155+
},
145156
},
146-
})
157+
)
147158

148159
# list specified Entity's triggers
149160
resp = self.client.get("/trigger/api/v2/?entity_id=%s" % self.entity_book.id)
@@ -282,8 +293,10 @@ def test_create_trigger_condition(self):
282293
# test to handle request to create TriggerCondition that is exactly same with others
283294
err_resp = self.client.post("/trigger/api/v2/", json.dumps(params), "application/json")
284295
self.assertEqual(err_resp.status_code, 400)
285-
self.assertEqual(err_resp.json()[0]["message"],
286-
"There is condition that have same condition with specified one")
296+
self.assertEqual(
297+
err_resp.json()[0]["message"],
298+
"There is condition that have same condition with specified one",
299+
)
287300

288301
# This checks expected Conditions are created properly
289302
created_trigger = TriggerParent.objects.get(id=resp.json()["id"])
@@ -315,24 +328,18 @@ def test_create_trigger_condition(self):
315328
def test_create_conditions_with_empty_value(self):
316329
entry_john = self.add_entry(self.user, "John Doe", self.entity_people)
317330
test_cases = [
318-
(
319-
self.entity_book.attrs.get(name="title").id,
320-
{"value": "-- DEFAULT TITLE --"}
321-
),
331+
(self.entity_book.attrs.get(name="title").id, {"value": "-- DEFAULT TITLE --"}),
322332
(
323333
self.entity_book.attrs.get(name="authors").id,
324334
{"values": ["John Doe"]},
325335
),
326-
(
327-
self.entity_book.attrs.get(name="in_preparation").id,
328-
{"value": "True"}
329-
),
336+
(self.entity_book.attrs.get(name="in_preparation").id, {"value": "True"}),
330337
(
331338
self.entity_book.attrs.get(name="recommended_by").id,
332339
{"values": [str(entry_john.id)]},
333340
),
334341
]
335-
for (attr_id, value_param) in test_cases:
342+
for attr_id, value_param in test_cases:
336343
params = {
337344
"entity_id": self.entity_book.id,
338345
"conditions": [{"attr_id": attr_id, "cond": ""}],
@@ -383,7 +390,7 @@ def test_update_trigger_condition(self):
383390
{
384391
"attr_id": self.entity_book.attrs.get(name="history").id,
385392
"named_valued": [{"id": str(entry_tom.id), "name": "tom"}],
386-
}
393+
},
387394
],
388395
}
389396
resp = self.client.put(
@@ -417,10 +424,7 @@ def test_update_trigger_condition(self):
417424
)
418425
for a in created_trigger.actions.all()
419426
],
420-
[
421-
("memo", [("deploy a staff to the Tom's house!", None, False)]),
422-
("history", [])
423-
],
427+
[("memo", [("deploy a staff to the Tom's house!", None, False)]), ("history", [])],
424428
)
425429

426430
def test_delete_trigger_condition(self):

trigger/tests/test_models.py

+57-53
Original file line numberDiff line numberDiff line change
@@ -385,36 +385,36 @@ def test_condition_can_be_invoked_for_each_attribute_types(self):
385385
"value": self.entry_refs[2],
386386
"will_invoke": True,
387387
},
388-
# {
389-
# "attrname": "named_trigger",
390-
# "value": {"name": "Open Sesame", "id": self.entry_refs[0].id},
391-
# "will_invoke": False,
392-
# },
393-
# {
394-
# "attrname": "named_trigger",
395-
# "value": {"name": "", "id": self.entry_refs[0].id},
396-
# "will_invoke": False,
397-
# },
398-
# {
399-
# "attrname": "named_trigger",
400-
# "value": {"name": "Unexpected words", "id": None},
401-
# "will_invoke": False,
402-
# },
403-
# {
404-
# "attrname": "named_trigger",
405-
# "value": {"name": FAT_LADY_PASSWD, "id": None},
406-
# "will_invoke": True,
407-
# },
408-
# {
409-
# "attrname": "named_trigger",
410-
# "value": {"name": "", "id": self.entry_refs[2].id},
411-
# "will_invoke": True,
412-
# },
413-
# {
414-
# "attrname": "named_trigger",
415-
# "value": {"name": FAT_LADY_PASSWD, "id": self.entry_refs[2].id},
416-
# "will_invoke": True,
417-
# },
388+
# {
389+
# "attrname": "named_trigger",
390+
# "value": {"name": "Open Sesame", "id": self.entry_refs[0].id},
391+
# "will_invoke": False,
392+
# },
393+
# {
394+
# "attrname": "named_trigger",
395+
# "value": {"name": "", "id": self.entry_refs[0].id},
396+
# "will_invoke": False,
397+
# },
398+
# {
399+
# "attrname": "named_trigger",
400+
# "value": {"name": "Unexpected words", "id": None},
401+
# "will_invoke": False,
402+
# },
403+
# {
404+
# "attrname": "named_trigger",
405+
# "value": {"name": FAT_LADY_PASSWD, "id": None},
406+
# "will_invoke": True,
407+
# },
408+
# {
409+
# "attrname": "named_trigger",
410+
# "value": {"name": "", "id": self.entry_refs[2].id},
411+
# "will_invoke": True,
412+
# },
413+
# {
414+
# "attrname": "named_trigger",
415+
# "value": {"name": FAT_LADY_PASSWD, "id": self.entry_refs[2].id},
416+
# "will_invoke": True,
417+
# },
418418
{"attrname": "arr_str_trigger", "value": [""], "will_invoke": False},
419419
{
420420
"attrname": "arr_str_trigger",
@@ -437,19 +437,19 @@ def test_condition_can_be_invoked_for_each_attribute_types(self):
437437
"value": self.entry_refs,
438438
"will_invoke": True,
439439
},
440-
# {
441-
# "attrname": "arr_named_trigger",
442-
# "value": [{"name": "Open Sesame", "id": self.entry_refs[0].id}],
443-
# "will_invoke": False,
444-
# },
445-
# {
446-
# "attrname": "arr_named_trigger",
447-
# "value": [
448-
# {"name": "Open Sesame", "id": self.entry_refs[0].id},
449-
# {"name": FAT_LADY_PASSWD, "id": self.entry_refs[2].id},
450-
# ],
451-
# "will_invoke": True,
452-
# },
440+
# {
441+
# "attrname": "arr_named_trigger",
442+
# "value": [{"name": "Open Sesame", "id": self.entry_refs[0].id}],
443+
# "will_invoke": False,
444+
# },
445+
# {
446+
# "attrname": "arr_named_trigger",
447+
# "value": [
448+
# {"name": "Open Sesame", "id": self.entry_refs[0].id},
449+
# {"name": FAT_LADY_PASSWD, "id": self.entry_refs[2].id},
450+
# ],
451+
# "will_invoke": True,
452+
# },
453453
]
454454
for test_input_param in test_input_params:
455455
attr = self.entity.attrs.get(name=test_input_param["attrname"])
@@ -483,7 +483,7 @@ def test_register_conditions_with_blank_values(self):
483483
self.assertFalse(cond.bool_cond)
484484

485485
# test cases for specifying empty value
486-
for (index, cond_info) in enumerate(self.FULL_CONDITION_CONFIGURATION_PARAMETERS_BUT_EMPTY):
486+
for index, cond_info in enumerate(self.FULL_CONDITION_CONFIGURATION_PARAMETERS_BUT_EMPTY):
487487
target_attr = self.entity.attrs.get(id=cond_info["attr_id"])
488488
actions = TriggerCondition.get_invoked_actions(
489489
self.entity, [{"id": target_attr.id, "value": cond_info["cond"]}]
@@ -502,7 +502,7 @@ def test_register_actions_with_blank_values(self):
502502
parent_condition = TriggerCondition.register(
503503
self.entity,
504504
[{"attr_id": cond_attr.id, "cond": True}],
505-
self.FULL_ACTION_CONFIGURATION_PARAMETERS_BUT_EMPTY
505+
self.FULL_ACTION_CONFIGURATION_PARAMETERS_BUT_EMPTY,
506506
)
507507

508508
for value in TriggerActionValue.objects.filter(action__condition=parent_condition):
@@ -511,14 +511,18 @@ def test_register_actions_with_blank_values(self):
511511
self.assertFalse(value.bool_cond)
512512

513513
# create an Entry with valid attribute value to cehck action processing
514-
target_entry = self.add_entry(self.user, "test entry", self.entity, values={
515-
"str_action": "test-value",
516-
"ref_action": self.entry_refs[0],
517-
"bool_action": True,
518-
"arr_str_action": ["foo", "bar", "baz"],
519-
"arr_ref_action": self.entry_refs,
520-
"bool_action": False,
521-
})
514+
target_entry = self.add_entry(
515+
self.user,
516+
"test entry",
517+
self.entity,
518+
values={
519+
"str_action": "test-value",
520+
"ref_action": self.entry_refs[0],
521+
"arr_str_action": ["foo", "bar", "baz"],
522+
"arr_ref_action": self.entry_refs,
523+
"bool_action": True,
524+
},
525+
)
522526

523527
# invoke trigger action
524528
actions = TriggerCondition.get_invoked_actions(

0 commit comments

Comments
 (0)