# Path: threebot/models.py
# class Workflow(models.Model):
#     unique_identifier = models.CharField(max_length=255, null=True, blank=True, help_text="Unique Identifier to group multiple Workflow Versions")
#     version_major = models.PositiveIntegerField(null=True, blank=True, default=0)
#     version_minor = models.PositiveIntegerField(null=True, blank=True, default=0)
# 
#     date_created = models.DateTimeField(auto_now_add=True)
#     date_modified = models.DateTimeField(auto_now=True)
# 
#     owner = models.ForeignKey(Organization, help_text="Workflow owner")
#     title = models.CharField(max_length=255)
#     slug = models.SlugField(_('slug'), max_length=50, unique=True)
#     desc = models.TextField(null=True, blank=True)
# 
#     pre_task = models.TextField(null=True, blank=True, help_text='This will run as a Script before the worker runs a task of the current workflow. (Runs before each task)')
#     post_task = models.TextField(null=True, blank=True, help_text='This will run as a Script after the worker has executed a task of the current workflow. (Runs after each task)')
# 
#     tasks = models.ManyToManyField(Task, through='WorkflowTask')
# 
#     class Meta():
#         ordering = ['owner', 'title']
#         verbose_name = _("Workflow")
#         verbose_name_plural = _("Workflows")
#         unique_together = (('unique_identifier', 'version_major', 'version_minor'),)
# 
#     def number_of_tasks(self):
#         return WorkflowTask.objects.filter(workflow=self).count()
# 
#     def save(self, *args, **kwargs):
#         if not self.pk:  # first save
#             self.slug = random.randint(1000, 9999)
#             super(Workflow, self).save(*args, **kwargs)
# 
#         if not self.unique_identifier:
#             md_hash = hashlib.md5()
#             md_hash.update(self.title.encode('utf-8') + str(datetime.datetime.now()))
#             self.unique_identifier = md_hash.hexdigest()
# 
#         s = str(self.owner_id) + "-" + str(self.id) + "-" + slugify(self.title)
#         self.slug = s[:50]
#         super(Workflow, self).save(*args, **kwargs)
# 
#     @models.permalink
#     def get_absolute_url(self):
#         return ('core_workflow_detail', (), {
#             'slug': self.slug})
# 
#     def permalink(self):
#         return reverse('core_workflow_permalink', kwargs={'id': self.id})
# 
#     def __str__(self):
#         return self.title or self.desc or str(self.pk)
# 
# class WorkflowLog(models.Model):
#     SUCCESS = 0
#     ERROR = 1
#     PENDING = 2
# 
#     EXIT_CODE_CHOICES = (
#         (SUCCESS, 'Success'),
#         (ERROR, 'Error'),
#         (PENDING, 'Pending'),
#     )
# 
#     workflow = models.ForeignKey(Workflow, verbose_name=_("Workflow"))
#     date_created = models.DateTimeField(auto_now_add=True, help_text='Date the workflow was performed')
#     date_started = models.DateTimeField(help_text='Date the workflow was performed', blank=True, null=True)
#     date_finished = models.DateTimeField(help_text='Date the workflow was performed', blank=True, null=True)
#     exit_code = models.PositiveIntegerField(choices=EXIT_CODE_CHOICES, default=PENDING)
#     performed_by = models.ForeignKey(settings.AUTH_USER_MODEL, help_text="The User who performed the Worfkflow")
#     performed_on = models.ForeignKey(Worker, help_text="The Worker Worfkflow was performed on")
# 
#     inputs = JSONField()
#     outputs = JSONField(null=True, blank=True)
# 
#     class Meta():
#         ordering = ['-date_created', ]
#         verbose_name = _("Workflow Log")
#         verbose_name_plural = _("Workflow Logs")
# 
#     @models.permalink
#     def get_absolute_url(self):
#         return ('core_workflow_log_detail', (), {
#             'slug': self.workflow.slug,
#             'id': self.id})
# 
#     def permalink(self):
#         return reverse('core_workflow_log_permalink', kwargs={'id': self.id})
# 
#     def __str__(self):
#         return "%s - %s logged %s" % (self.date_created.strftime('%d.%m.%y %H:%M'), str(self.performed_by), self.workflow.title, )
# 
# Path: tests/data.py



import time
from django.contrib.auth import get_user_model
from django.test import Client
from django.core.urlresolvers import reverse
from django.test import TestCase
from factory.django import DjangoModelFactory
from factory.fuzzy import FuzzyInteger, FuzzyText
from threebot.models import Workflow, WorkflowLog
from organizations.models import Organization
from organizations.utils import create_organization
from tests.data import inputs, outputs


User = get_user_model()
NO_ORG = 10
NO_WF = 10
NO_WFL = 1000

class OrganizationFactory(DjangoModelFactory):
    class Meta:
        model = Organization

    name = FuzzyText(length=12)
    slug = FuzzyText(length=12)


class WorkflowFactory(DjangoModelFactory):
    class Meta:
        model = Workflow

    owner_id = FuzzyInteger(0, 10)
    title = FuzzyText(length=12)


class WorkflowLogFactory(DjangoModelFactory):
    class Meta:
        model = WorkflowLog

    workflow_id = FuzzyInteger(0, 10,)
    performed_by_id = FuzzyInteger(0, 10,)
    performed_on_id = FuzzyInteger(0, 10,)

# Path: threebot/models.py
# class Workflow(models.Model):
#     unique_identifier = models.CharField(max_length=255, null=True, blank=True, help_text="Unique Identifier to group multiple Workflow Versions")
#     version_major = models.PositiveIntegerField(null=True, blank=True, default=0)
#     version_minor = models.PositiveIntegerField(null=True, blank=True, default=0)
# 
#     date_created = models.DateTimeField(auto_now_add=True)
#     date_modified = models.DateTimeField(auto_now=True)
# 
#     owner = models.ForeignKey(Organization, help_text="Workflow owner")
#     title = models.CharField(max_length=255)
#     slug = models.SlugField(_('slug'), max_length=50, unique=True)
#     desc = models.TextField(null=True, blank=True)
# 
#     pre_task = models.TextField(null=True, blank=True, help_text='This will run as a Script before the worker runs a task of the current workflow. (Runs before each task)')
#     post_task = models.TextField(null=True, blank=True, help_text='This will run as a Script after the worker has executed a task of the current workflow. (Runs after each task)')
# 
#     tasks = models.ManyToManyField(Task, through='WorkflowTask')
# 
#     class Meta():
#         ordering = ['owner', 'title']
#         verbose_name = _("Workflow")
#         verbose_name_plural = _("Workflows")
#         unique_together = (('unique_identifier', 'version_major', 'version_minor'),)
# 
#     def number_of_tasks(self):
#         return WorkflowTask.objects.filter(workflow=self).count()
# 
#     def save(self, *args, **kwargs):
#         if not self.pk:  # first save
#             self.slug = random.randint(1000, 9999)
#             super(Workflow, self).save(*args, **kwargs)
# 
#         if not self.unique_identifier:
#             md_hash = hashlib.md5()
#             md_hash.update(self.title.encode('utf-8') + str(datetime.datetime.now()))
#             self.unique_identifier = md_hash.hexdigest()
# 
#         s = str(self.owner_id) + "-" + str(self.id) + "-" + slugify(self.title)
#         self.slug = s[:50]
#         super(Workflow, self).save(*args, **kwargs)
# 
#     @models.permalink
#     def get_absolute_url(self):
#         return ('core_workflow_detail', (), {
#             'slug': self.slug})
# 
#     def permalink(self):
#         return reverse('core_workflow_permalink', kwargs={'id': self.id})
# 
#     def __str__(self):
#         return self.title or self.desc or str(self.pk)
# 
# class WorkflowLog(models.Model):
#     SUCCESS = 0
#     ERROR = 1
#     PENDING = 2
# 
#     EXIT_CODE_CHOICES = (
#         (SUCCESS, 'Success'),
#         (ERROR, 'Error'),
#         (PENDING, 'Pending'),
#     )
# 
#     workflow = models.ForeignKey(Workflow, verbose_name=_("Workflow"))
#     date_created = models.DateTimeField(auto_now_add=True, help_text='Date the workflow was performed')
#     date_started = models.DateTimeField(help_text='Date the workflow was performed', blank=True, null=True)
#     date_finished = models.DateTimeField(help_text='Date the workflow was performed', blank=True, null=True)
#     exit_code = models.PositiveIntegerField(choices=EXIT_CODE_CHOICES, default=PENDING)
#     performed_by = models.ForeignKey(settings.AUTH_USER_MODEL, help_text="The User who performed the Worfkflow")
#     performed_on = models.ForeignKey(Worker, help_text="The Worker Worfkflow was performed on")
# 
#     inputs = JSONField()
#     outputs = JSONField(null=True, blank=True)
# 
#     class Meta():
#         ordering = ['-date_created', ]
#         verbose_name = _("Workflow Log")
#         verbose_name_plural = _("Workflow Logs")
# 
#     @models.permalink
#     def get_absolute_url(self):
#         return ('core_workflow_log_detail', (), {
#             'slug': self.workflow.slug,
#             'id': self.id})
# 
#     def permalink(self):
#         return reverse('core_workflow_log_permalink', kwargs={'id': self.id})
# 
#     def __str__(self):
#         return "%s - %s logged %s" % (self.date_created.strftime('%d.%m.%y %H:%M'), str(self.performed_by), self.workflow.title, )
# 
# Path: tests/data.py



# Path: tests/test_utils.py
import time
from django.contrib.auth import get_user_model
from django.test import Client
from django.core.urlresolvers import reverse
from django.test import TestCase
from factory.django import DjangoModelFactory
from factory.fuzzy import FuzzyInteger, FuzzyText
from threebot.models import Workflow, WorkflowLog
from organizations.models import Organization
from organizations.utils import create_organization
from tests.data import inputs, outputs



User = get_user_model()
NO_ORG = 10
NO_WF = 10
NO_WFL = 1000

class OrganizationFactory(DjangoModelFactory):
    class Meta:
        model = Organization

    name = FuzzyText(length=12)
    slug = FuzzyText(length=12)


class WorkflowFactory(DjangoModelFactory):
    class Meta:
        model = Workflow

    owner_id = FuzzyInteger(0, 10)
    title = FuzzyText(length=12)


class WorkflowLogFactory(DjangoModelFactory):
    class Meta:
        model = WorkflowLog

    workflow_id = FuzzyInteger(0, 10,)
    performed_by_id = FuzzyInteger(0, 10,)
    performed_on_id = FuzzyInteger(0, 10,)

    inputs = inputs