Merge "model: change play.completed to play.status"
This commit is contained in:
commit
34953a4783
|
@ -1,4 +1,4 @@
|
|||
# Generated by Django 2.1.2 on 2018-10-16 00:43
|
||||
# Generated by Django 2.1.3 on 2018-11-14 19:34
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
@ -75,7 +75,7 @@ class Migration(migrations.Migration):
|
|||
('ended', models.DateTimeField(blank=True, null=True)),
|
||||
('name', models.CharField(blank=True, max_length=255, null=True)),
|
||||
('uuid', models.UUIDField()),
|
||||
('completed', models.BooleanField(default=False)),
|
||||
('status', models.CharField(choices=[('unknown', 'unknown'), ('running', 'running'), ('completed', 'completed')], default='unknown', max_length=25)),
|
||||
],
|
||||
options={
|
||||
'db_table': 'plays',
|
||||
|
|
|
@ -156,9 +156,15 @@ class Play(Duration):
|
|||
class Meta:
|
||||
db_table = "plays"
|
||||
|
||||
# A play in ARA can be running (in progress) or completed (regardless of success or failure)
|
||||
UNKNOWN = "unknown"
|
||||
RUNNING = "running"
|
||||
COMPLETED = "completed"
|
||||
STATUS = ((UNKNOWN, "unknown"), (RUNNING, "running"), (COMPLETED, "completed"))
|
||||
|
||||
name = models.CharField(max_length=255, blank=True, null=True)
|
||||
uuid = models.UUIDField()
|
||||
completed = models.BooleanField(default=False)
|
||||
status = models.CharField(max_length=25, choices=STATUS, default=UNKNOWN)
|
||||
playbook = models.ForeignKey(Playbook, on_delete=models.CASCADE, related_name="plays")
|
||||
|
||||
def __str__(self):
|
||||
|
|
|
@ -69,7 +69,7 @@ class PlayFactory(factory.DjangoModelFactory):
|
|||
model = models.Play
|
||||
|
||||
name = "test play"
|
||||
completed = True
|
||||
status = "running"
|
||||
uuid = "5c5f67b9-e63c-6297-80da-000000000005"
|
||||
playbook = factory.SubFactory(PlaybookFactory)
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ class PlayTestCase(APITestCase):
|
|||
serializer = serializers.PlaySerializer(
|
||||
data={
|
||||
"name": "serializer",
|
||||
"completed": True,
|
||||
"status": "completed",
|
||||
"uuid": "5c5f67b9-e63c-6297-80da-000000000005",
|
||||
"playbook": playbook.id,
|
||||
}
|
||||
|
@ -43,6 +43,7 @@ class PlayTestCase(APITestCase):
|
|||
play = serializer.save()
|
||||
play.refresh_from_db()
|
||||
self.assertEqual(play.name, "serializer")
|
||||
self.assertEqual(play.status, "completed")
|
||||
|
||||
def test_get_no_plays(self):
|
||||
request = self.client.get("/api/v1/plays")
|
||||
|
@ -68,7 +69,7 @@ class PlayTestCase(APITestCase):
|
|||
"/api/v1/plays",
|
||||
{
|
||||
"name": "create",
|
||||
"completed": False,
|
||||
"status": "running",
|
||||
"uuid": "5c5f67b9-e63c-6297-80da-000000000005",
|
||||
"playbook": playbook.id,
|
||||
},
|
||||
|
@ -109,3 +110,11 @@ class PlayTestCase(APITestCase):
|
|||
play = factories.PlayFactory(started=started, ended=ended)
|
||||
request = self.client.get("/api/v1/plays/%s" % play.id)
|
||||
self.assertEqual(request.data["duration"], datetime.timedelta(0, 3600))
|
||||
|
||||
def test_update_wrong_play_status(self):
|
||||
play = factories.PlayFactory()
|
||||
self.assertNotEqual("wrong", play.status)
|
||||
request = self.client.patch("/api/v1/plays/%s" % play.id, {"status": "wrong"})
|
||||
self.assertEqual(400, request.status_code)
|
||||
play_updated = models.Play.objects.get(id=play.id)
|
||||
self.assertNotEqual("wrong", play_updated.status)
|
||||
|
|
Loading…
Reference in New Issue