# Path: zengine/lib/test_utils.py
# class BaseTestCase:
#     """
#     Base test case.
#     """
#     client = None
# 
#     def setup_method(self, method):
#         """
#         Creates a new user and Role with all Permissions.
#         """
# 
#         # if not '--ignore=fixture' in sys.argv:
#         #     if hasattr(self, 'fixture'):
#         #         print("\nREPORT:: Running test cases own fixture() method")
#         #         self.fixture()
#         #         sleep(2)
#         #
#         #     else:
#         #         fixture_guess = 'fixtures/%s.csv' % method.__self__.__module__.split('.test_')[1]
#         #         if os.path.exists(fixture_guess) and fixture_guess not in sys.LOADED_FIXTURES:
#         #             sys.LOADED_FIXTURES.append(fixture_guess)
#         #             FlushDB(model='all', wait_sync=True,
#         #                     exclude=settings.TEST_FLUSHING_EXCLUDES).run()
#         #             print("\nREPORT:: Test fixture will be loaded: %s" % fixture_guess)
#         #             LoadData(path=fixture_guess, update=True).run()
#         #             sleep(2)
#         #         else:
#         #             print(
#         #                 "\nREPORT:: Test case does not have a fixture file like %s" % fixture_guess)
#         #
#         # else:
#         #     print("\nREPORT:: Fixture loading disabled by user. (by --ignore=fixture)")
#         # clear all caches
#         if not hasattr(sys, 'cache_cleared'):
#             sys.cache_cleared = True
#             print(ClearCache.flush())
#             print("\nREPORT:: Cache cleared")
# 
#     @classmethod
#     def prepare_client(cls, path='', reset=False, user=None, login=None, token='', username=None):
#         """
#         Setups the path, logs in if necessary
# 
#         Args:
#             path: change or set path
#             reset: Create a new client
#             login: Login to system
#             token: Set token
#         """
# 
#         if not cls.client or reset or user:
#             cls.client = TestClient(path)
#             login = True if login is None else login
# 
#         if username:
#             cls.client.username = username
# 
#         if user:
#             cls.client.user = user
#             login = True if login is None else login
# 
#         if login:
#             cls._do_login()
# 
#         cls.client.set_path(path, token)
# 
#     @classmethod
#     def _do_login(self):
#         """
#         logs in the "test_user"
#         """
#         self.client.sess_id = uuid4().hex
#         self.client.set_path("/login/")
#         resp = self.client.post()
#         assert resp.json['forms']['schema']['title'] == 'LoginForm'
#         req_fields = resp.json['forms']['schema']['required']
#         assert all([(field in req_fields) for field in ('username', 'password')])
#         resp = self.client.post(username=self.client.username or self.client.user.username,
#                                 password="123", cmd="do")
#         log.debug("login result :\n%s" % resp.json)
#         assert resp.json['cmd'] == 'upgrade'
# 
#     def get_user_token(self, username):
#         user = User.objects.get(username=username)
#         token = self.client.current.token
#         return token, user
# 
# Path: tests/models.py
# class Project(Model):
#     class Employee(ListNode):
# class Teacher(Model):
#     class Meta:
# class Exam(Model):
#     class Meta:
# class Program(Model):
#     class Meta:
#         def get_user(self):
#     def assigned_employees(self):
#     def __unicode__(self):
#     def __unicode__(self):
#     def __unicode__(self):
#     def get_test_role(cls):
# 
# Path: tests/models.py
# class Project(Model):
#     class Employee(ListNode):
# class Teacher(Model):
#     class Meta:
# class Exam(Model):
#     class Meta:
# class Program(Model):
#     class Meta:
#         def get_user(self):
#     def assigned_employees(self):
#     def __unicode__(self):
#     def __unicode__(self):
#     def __unicode__(self):
#     def get_test_role(cls):


from zengine.lib.test_utils import BaseTestCase
from .models import User, TaskInvitation, WFInstance, Role, Teacher
from .models import Task, BPMNWorkflow, Unit, AbstractRole
from datetime import datetime, timedelta
from pyoko.conf import settings
from pyoko.lib.utils import get_object_from_path
import time
        task.finish_date = datetime.strptime(tomorrow.strftime("%d.%m.%Y"), '%d.%m.%Y')
        task.run = True
        task.save()

        self.prepare_client(user=usr)
        time.sleep(1)
        # call active data
        resp = self.client.post(view='_zops_get_tasks', state='active')
        # We control the get_tasks view
        assert resp.json['task_list'][0]['wf_type'] == 'workflow_management'
        assert resp.json['task_list'][0]['title'] == 'Workflow Management'
        assert resp.json['task_list'][0]['state'] == 30
        assert resp.json['task_list'][0][
                   'description'] == 'Test workflow management bpmn description'
        assert resp.json['task_count']['active'] == active_task_count + 1

        key = resp.json['task_list'][0]['key']  # TaskInvitation key
        resp = self.client.post(view='_zops_get_task_actions', key=key)
        # We control the get_task_actions view
        assert len(resp.json['actions']) == 4

        resp = self.client.post(view='_zops_get_task_types')
        # We control the get_task_types view

        assert len(resp.json['task_types']) == len(
            [bpmn_wf for bpmn_wf in BPMNWorkflow.objects.all()
             if self.client.current.has_permission(bpmn_wf.name)])

    def test_workflow_management_state_future(self):


# Path: zengine/lib/test_utils.py
# class BaseTestCase:
#     """
#     Base test case.
#     """
#     client = None
# 
#     def setup_method(self, method):
#         """
#         Creates a new user and Role with all Permissions.
#         """
# 
#         # if not '--ignore=fixture' in sys.argv:
#         #     if hasattr(self, 'fixture'):
#         #         print("\nREPORT:: Running test cases own fixture() method")
#         #         self.fixture()
#         #         sleep(2)
#         #
#         #     else:
#         #         fixture_guess = 'fixtures/%s.csv' % method.__self__.__module__.split('.test_')[1]
#         #         if os.path.exists(fixture_guess) and fixture_guess not in sys.LOADED_FIXTURES:
#         #             sys.LOADED_FIXTURES.append(fixture_guess)
#         #             FlushDB(model='all', wait_sync=True,
#         #                     exclude=settings.TEST_FLUSHING_EXCLUDES).run()
#         #             print("\nREPORT:: Test fixture will be loaded: %s" % fixture_guess)
#         #             LoadData(path=fixture_guess, update=True).run()
#         #             sleep(2)
#         #         else:
#         #             print(
#         #                 "\nREPORT:: Test case does not have a fixture file like %s" % fixture_guess)
#         #
#         # else:
#         #     print("\nREPORT:: Fixture loading disabled by user. (by --ignore=fixture)")
#         # clear all caches
#         if not hasattr(sys, 'cache_cleared'):
#             sys.cache_cleared = True
#             print(ClearCache.flush())
#             print("\nREPORT:: Cache cleared")
# 
#     @classmethod
#     def prepare_client(cls, path='', reset=False, user=None, login=None, token='', username=None):
#         """
#         Setups the path, logs in if necessary
# 
#         Args:
#             path: change or set path
#             reset: Create a new client
#             login: Login to system
#             token: Set token
#         """
# 
#         if not cls.client or reset or user:
#             cls.client = TestClient(path)
#             login = True if login is None else login
# 
#         if username:
#             cls.client.username = username
# 
#         if user:
#             cls.client.user = user
#             login = True if login is None else login
# 
#         if login:
#             cls._do_login()
# 
#         cls.client.set_path(path, token)
# 
#     @classmethod
#     def _do_login(self):
#         """
#         logs in the "test_user"
#         """
#         self.client.sess_id = uuid4().hex
#         self.client.set_path("/login/")
#         resp = self.client.post()
#         assert resp.json['forms']['schema']['title'] == 'LoginForm'
#         req_fields = resp.json['forms']['schema']['required']
#         assert all([(field in req_fields) for field in ('username', 'password')])
#         resp = self.client.post(username=self.client.username or self.client.user.username,
#                                 password="123", cmd="do")
#         log.debug("login result :\n%s" % resp.json)
#         assert resp.json['cmd'] == 'upgrade'
# 
#     def get_user_token(self, username):
#         user = User.objects.get(username=username)
#         token = self.client.current.token
#         return token, user
# 
# Path: tests/models.py
# class Project(Model):
#     class Employee(ListNode):
# class Teacher(Model):
#     class Meta:
# class Exam(Model):
#     class Meta:
# class Program(Model):
#     class Meta:
#         def get_user(self):
#     def assigned_employees(self):
#     def __unicode__(self):
#     def __unicode__(self):
#     def __unicode__(self):
#     def get_test_role(cls):
# 
# Path: tests/models.py
# class Project(Model):
#     class Employee(ListNode):
# class Teacher(Model):
#     class Meta:
# class Exam(Model):
#     class Meta:
# class Program(Model):
#     class Meta:
#         def get_user(self):
#     def assigned_employees(self):
#     def __unicode__(self):
#     def __unicode__(self):
#     def __unicode__(self):
#     def get_test_role(cls):


# Path: tests/test_workflow_manager.py
from zengine.lib.test_utils import BaseTestCase
from .models import User, TaskInvitation, WFInstance, Role, Teacher
from .models import Task, BPMNWorkflow, Unit, AbstractRole
from datetime import datetime, timedelta
from pyoko.conf import settings
from pyoko.lib.utils import get_object_from_path
import time

        task.finish_date = datetime.strptime(tomorrow.strftime("%d.%m.%Y"), '%d.%m.%Y')
        task.run = True
        task.save()

        self.prepare_client(user=usr)
        time.sleep(1)
        # call active data
        resp = self.client.post(view='_zops_get_tasks', state='active')
        # We control the get_tasks view
        assert resp.json['task_list'][0]['wf_type'] == 'workflow_management'
        assert resp.json['task_list'][0]['title'] == 'Workflow Management'
        assert resp.json['task_list'][0]['state'] == 30
        assert resp.json['task_list'][0][
                   'description'] == 'Test workflow management bpmn description'
        assert resp.json['task_count']['active'] == active_task_count + 1

        key = resp.json['task_list'][0]['key']  # TaskInvitation key
        resp = self.client.post(view='_zops_get_task_actions', key=key)
        # We control the get_task_actions view
        assert len(resp.json['actions']) == 4

        resp = self.client.post(view='_zops_get_task_types')
        # We control the get_task_types view

        assert len(resp.json['task_types']) == len(
            [bpmn_wf for bpmn_wf in BPMNWorkflow.objects.all()
             if self.client.current.has_permission(bpmn_wf.name)])

    def test_workflow_management_state_future(self):


        usr = User.objects.get(username='test_user2')