Skip to content

Commit

Permalink
[AAP-14629] Changed activation events list ordered by received_at (#333)
Browse files Browse the repository at this point in the history
Co-authored-by: Alex <aizquier@redhat.com>
  • Loading branch information
hsong-rh and Alex-Izquierdo authored Aug 2, 2023
1 parent ed74136 commit 7e78ff2
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/aap_eda/api/views/rulebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ def events(self, _request, id):
for audit_action in audit_actions:
eqs = eqs.union(
self.filter_queryset(audit_action.audit_events.all())
)
).order_by("-received_at")

results = self.paginate_queryset(eqs)
serializer = serializers.AuditEventSerializer(results, many=True)
Expand Down
16 changes: 16 additions & 0 deletions src/aap_eda/core/migrations/0004_alter_auditevent_options.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Generated by Django 3.2.18 on 2023-08-02 15:25

from django.db import migrations


class Migration(migrations.Migration):
dependencies = [
("core", "0003_alter_project_name"),
]

operations = [
migrations.AlterModelOptions(
name="auditevent",
options={"ordering": ("-received_at", "-rule_fired_at")},
),
]
2 changes: 1 addition & 1 deletion src/aap_eda/core/models/rulebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class Meta:
class AuditEvent(models.Model):
class Meta:
db_table = "core_audit_event"
ordering = ("-rule_fired_at", "-received_at")
ordering = ("-received_at", "-rule_fired_at")

id = models.UUIDField(primary_key=True)
source_name = models.TextField()
Expand Down
17 changes: 9 additions & 8 deletions tests/integration/api/test_rulebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ def test_list_events_from_audit_rule(client: APIClient, init_db):

events = response.data["results"]
assert len(events) == 4
assert events[0]["received_at"] > events[1]["received_at"]


# ------------------------------------------
Expand All @@ -464,7 +465,7 @@ def test_list_audit_events(client: APIClient, init_db):
audit_events = response.data["results"]

assert len(audit_events) == 4
assert audit_events[0]["rule_fired_at"] > audit_events[1]["rule_fired_at"]
assert audit_events[0]["received_at"] > audit_events[1]["received_at"]


@pytest.mark.django_db
Expand Down Expand Up @@ -655,21 +656,21 @@ def init_db():
source_name="event-2",
source_type="type-2",
rule_fired_at="2023-03-23T01:36:36.835248Z",
received_at="2023-03-30T20:59:42.042148Z",
received_at="2023-03-30T20:59:43.042148Z",
)
audit_event_3 = models.AuditEvent.objects.create(
id=str(uuid.uuid4()),
source_name="event-3",
source_type="type-3",
rule_fired_at="2023-03-23T03:58:36.835248Z",
received_at="2023-03-30T20:59:42.042148Z",
rule_fired_at="2023-03-23T01:28:36.835248Z",
received_at="2023-03-30T20:59:44.042148Z",
)
audit_event_4 = models.AuditEvent.objects.create(
id=str(uuid.uuid4()),
source_name="event-2",
source_type="type-2",
rule_fired_at="2023-03-23T06:56:36.835248Z",
received_at="2023-03-30T20:59:42.042148Z",
source_name="event-4",
source_type="type-4",
rule_fired_at="2023-03-23T01:16:36.835248Z",
received_at="2023-03-30T20:59:45.042148Z",
)
audit_event_1.audit_actions.add(action_1)
audit_event_1.audit_actions.add(action_2)
Expand Down

0 comments on commit 7e78ff2

Please sign in to comment.