# Path: yawn/workflow/models.py
# class WorkflowName(models.Model):
#     name = models.TextField(unique=True)
#     current_version = models.OneToOneField('Workflow', on_delete=models.CASCADE,
#                                            null=True, related_name='is_current')
# 
#     def new_version(self, **kwargs):
#         """Create a new version of a workflow"""
#         version = 0
#         if self.current_version_id:
#             version = self.current_version.version
# 
#             # disable the past schedule
#             self.current_version.schedule_active = False
#             self.current_version.save()
# 
#         workflow = Workflow.objects.create(name=self, version=version + 1, **kwargs)
#         self.current_version = workflow
#         self.save()
#         return workflow
# 
# Path: yawn/workflow/tests/utils.py
# def load_sample_workflow():
#     filename = os.path.join(os.path.dirname(__file__), 'workflow.yaml')
#     return yaml.safe_load(open(filename).read())


import pytest
from django.utils.dateparse import parse_datetime
from yawn.workflow.models import WorkflowName
from yawn.workflow.tests.utils import load_sample_workflow



data = pytest.fixture(load_sample_workflow)


def test_create_workflow(client, data):
    response = client.post('/api/workflows/', data)
    assert response.status_code == 201
    assert response.data['name'] == data['name']
    assert response.data['next_run'] is not None

# Path: yawn/workflow/models.py
# class WorkflowName(models.Model):
#     name = models.TextField(unique=True)
#     current_version = models.OneToOneField('Workflow', on_delete=models.CASCADE,
#                                            null=True, related_name='is_current')
# 
#     def new_version(self, **kwargs):
#         """Create a new version of a workflow"""
#         version = 0
#         if self.current_version_id:
#             version = self.current_version.version
# 
#             # disable the past schedule
#             self.current_version.schedule_active = False
#             self.current_version.save()
# 
#         workflow = Workflow.objects.create(name=self, version=version + 1, **kwargs)
#         self.current_version = workflow
#         self.save()
#         return workflow
# 
# Path: yawn/workflow/tests/utils.py
# def load_sample_workflow():
#     filename = os.path.join(os.path.dirname(__file__), 'workflow.yaml')
#     return yaml.safe_load(open(filename).read())


# Path: yawn/workflow/tests/test_views.py
import pytest
from django.utils.dateparse import parse_datetime
from yawn.workflow.models import WorkflowName
from yawn.workflow.tests.utils import load_sample_workflow




data = pytest.fixture(load_sample_workflow)


def test_create_workflow(client, data):
    response = client.post('/api/workflows/', data)
    assert response.status_code == 201
    assert response.data['name'] == data['name']
    assert response.data['next_run'] is not None

    assert response.data['schedule'] == data['schedule']