From 924c8b5cca85f3a454f09776d4fc1c7d03115334 Mon Sep 17 00:00:00 2001 From: David Moreau Simard Date: Fri, 22 Feb 2019 14:40:24 -0500 Subject: [PATCH] Add missing relationship from result to play Allowing the results for a specific play to be found easily. Change-Id: I8b4c630b70665c5e8214cff263a0e44a4d83248e --- ara/api/migrations/0001_initial.py | 3 ++- ara/api/models.py | 1 + ara/api/tests/factories.py | 1 + ara/api/tests/tests_result.py | 20 +++++++++++++++++--- 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/ara/api/migrations/0001_initial.py b/ara/api/migrations/0001_initial.py index 17023525..2a04c562 100644 --- a/ara/api/migrations/0001_initial.py +++ b/ara/api/migrations/0001_initial.py @@ -1,4 +1,4 @@ -# Generated by Django 2.1.5 on 2019-01-10 22:42 +# Generated by Django 2.1.7 on 2019-02-22 19:43 from django.db import migrations, models import django.db.models.deletion @@ -126,6 +126,7 @@ class Migration(migrations.Migration): ('status', models.CharField(choices=[('ok', 'ok'), ('failed', 'failed'), ('skipped', 'skipped'), ('unreachable', 'unreachable'), ('changed', 'changed'), ('ignored', 'ignored'), ('unknown', 'unknown')], default='unknown', max_length=25)), ('content', models.BinaryField(max_length=4294967295)), ('host', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='results', to='api.Host')), + ('play', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='results', to='api.Play')), ('playbook', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='results', to='api.Playbook')), ], options={ diff --git a/ara/api/models.py b/ara/api/models.py index f3fff098..7c059e03 100644 --- a/ara/api/models.py +++ b/ara/api/models.py @@ -284,6 +284,7 @@ class Result(Duration): content = models.BinaryField(max_length=(2 ** 32) - 1) host = models.ForeignKey(Host, on_delete=models.CASCADE, related_name="results") task = models.ForeignKey(Task, on_delete=models.CASCADE, related_name="results") + play = models.ForeignKey(Play, on_delete=models.CASCADE, related_name="results") playbook = models.ForeignKey(Playbook, on_delete=models.CASCADE, related_name="results") def __str__(self): diff --git a/ara/api/tests/factories.py b/ara/api/tests/factories.py index 5f64c930..95317cae 100644 --- a/ara/api/tests/factories.py +++ b/ara/api/tests/factories.py @@ -109,6 +109,7 @@ class ResultFactory(factory.DjangoModelFactory): status = "ok" host = factory.SubFactory(HostFactory) task = factory.SubFactory(TaskFactory) + play = factory.SubFactory(PlayFactory) playbook = factory.SubFactory(PlaybookFactory) diff --git a/ara/api/tests/tests_result.py b/ara/api/tests/tests_result.py index 5438631a..fa555d80 100644 --- a/ara/api/tests/tests_result.py +++ b/ara/api/tests/tests_result.py @@ -30,7 +30,13 @@ class ResultTestCase(APITestCase): host = factories.HostFactory() task = factories.TaskFactory() serializer = serializers.ResultSerializer( - data={"status": "skipped", "host": host.id, "task": task.id, "playbook": task.playbook.id} + data={ + "status": "skipped", + "host": host.id, + "task": task.id, + "play": task.play.id, + "playbook": task.playbook.id, + } ) serializer.is_valid() result = serializer.save() @@ -43,7 +49,14 @@ class ResultTestCase(APITestCase): host = factories.HostFactory() task = factories.TaskFactory() serializer = serializers.ResultSerializer( - data={"host": host.id, "task": task.id, "content": factories.RESULT_CONTENTS, "playbook": task.playbook.id} + data={ + "content": factories.RESULT_CONTENTS, + "status": "changed", + "host": host.id, + "task": task.id, + "play": task.play.id, + "playbook": task.playbook.id, + } ) serializer.is_valid() result = serializer.save() @@ -79,10 +92,11 @@ class ResultTestCase(APITestCase): request = self.client.post( "/api/v1/results", { + "content": factories.RESULT_CONTENTS, "status": "ok", "host": host.id, "task": task.id, - "content": factories.RESULT_CONTENTS, + "play": task.play.id, "playbook": task.playbook.id, }, )