def test_tasks_are_correctly_scheduled_when_compute_resources_is_True(self):
        """testing if the tasks are correctly scheduled when the compute
        resources is True
        """
        tjp_sched = TaskJugglerScheduler(compute_resources=True)
        test_studio = Studio(name="Test Studio", now=datetime.datetime(2013, 4, 16, 0, 0))
        test_studio.start = datetime.datetime(2013, 4, 16, 0, 0)
        test_studio.end = datetime.datetime(2013, 4, 30, 0, 0)
        test_studio.daily_working_hours = 9
        DBSession.add(test_studio)

        tjp_sched.studio = test_studio
        tjp_sched.schedule()
        db.DBSession.commit()

        # check if the task and project timings are all adjusted
        self.assertEqual(datetime.datetime(2013, 4, 16, 9, 0), self.test_proj1.computed_start)
        self.assertEqual(datetime.datetime(2013, 4, 24, 10, 0), self.test_proj1.computed_end)

        self.assertEqual(datetime.datetime(2013, 4, 16, 9, 0), self.test_task1.computed_start)
        self.assertEqual(datetime.datetime(2013, 4, 18, 16, 0), self.test_task1.computed_end)
        self.assertEqual(
            sorted([self.test_user1, self.test_user2], key=lambda x: x.name),
            sorted(self.test_task1.computed_resources, key=lambda x: x.name),
        )

        self.assertEqual(datetime.datetime(2013, 4, 18, 16, 0), self.test_task2.computed_start)
        self.assertEqual(datetime.datetime(2013, 4, 24, 10, 0), self.test_task2.computed_end)
        self.assertEqual(
            sorted([self.test_user4, self.test_user5], key=lambda x: x.name),
            sorted(self.test_task2.computed_resources, key=lambda x: x.name),
        )
    def test_tasks_of_given_projects_are_correctly_scheduled(self):
        """testing if the tasks of given projects are correctly scheduled
        """
        # create a dummy project
        # create a dummy Project to schedule
        dummy_project = Project(name='Dummy Project',
                                code='DP',
                                repository=self.test_repo)

        dt1 = Task(name='Dummy Task 1',
                   project=dummy_project,
                   schedule_timing=4,
                   schedule_unit='h',
                   resources=[self.test_user1])

        dt2 = Task(name='Dummy Task 2',
                   project=dummy_project,
                   schedule_timing=4,
                   schedule_unit='h',
                   resources=[self.test_user2])
        db.DBSession.add_all([dummy_project, dt1, dt2])
        db.DBSession.commit()

        tjp_sched = TaskJugglerScheduler(compute_resources=True,
                                         projects=[dummy_project])
        test_studio = Studio(name='Test Studio',
                             now=datetime.datetime(2013, 4, 16, 0, 0))
        test_studio.start = datetime.datetime(2013, 4, 16, 0, 0)
        test_studio.end = datetime.datetime(2013, 4, 30, 0, 0)
        test_studio.daily_working_hours = 9
        DBSession.add(test_studio)
        db.DBSession.commit()

        tjp_sched.studio = test_studio
        tjp_sched.schedule()
        db.DBSession.commit()

        # check if the task and project timings are all adjusted
        self.assertEqual(self.test_proj1.computed_start, None)
        self.assertEqual(self.test_proj1.computed_end, None)

        self.assertEqual(self.test_task1.computed_start, None)
        self.assertEqual(self.test_task1.computed_end, None)
        self.assertEqual(self.test_task1.computed_resources,
                         [self.test_user1, self.test_user2])

        self.assertEqual(self.test_task2.computed_start, None)
        self.assertEqual(self.test_task2.computed_end, None)
        self.assertEqual(self.test_task2.computed_resources,
                         [self.test_user1, self.test_user2])

        self.assertEqual(dt1.computed_start,
                         datetime.datetime(2013, 4, 16, 9, 0))
        self.assertEqual(dt1.computed_end,
                         datetime.datetime(2013, 4, 16, 13, 0))

        self.assertEqual(dt2.computed_start,
                         datetime.datetime(2013, 4, 16, 9, 0))
        self.assertEqual(dt2.computed_end,
                         datetime.datetime(2013, 4, 16, 13, 0))
    def test_tasks_are_correctly_scheduled_when_compute_resources_is_False(
            self):
        """testing if the tasks are correctly scheduled when the compute
        resources is False
        """
        tjp_sched = TaskJugglerScheduler(compute_resources=False)
        from stalker import Studio
        test_studio = Studio(name='Test Studio',
                             now=datetime.datetime(2013,
                                                   4,
                                                   16,
                                                   0,
                                                   0,
                                                   tzinfo=pytz.utc))
        test_studio.start = \
            datetime.datetime(2013, 4, 16, 0, 0, tzinfo=pytz.utc)
        test_studio.end = datetime.datetime(2013, 4, 30, 0, 0, tzinfo=pytz.utc)
        test_studio.daily_working_hours = 9
        from stalker.db.session import DBSession
        DBSession.add(test_studio)

        tjp_sched.studio = test_studio
        tjp_sched.schedule()
        DBSession.commit()

        # check if the task and project timings are all adjusted
        assert \
            datetime.datetime(2013, 4, 16, 9, 0, tzinfo=pytz.utc) == \
            self.test_proj1.computed_start
        assert \
            datetime.datetime(2013, 4, 24, 10, 0, tzinfo=pytz.utc) == \
            self.test_proj1.computed_end

        assert \
            datetime.datetime(2013, 4, 16, 9, 0, tzinfo=pytz.utc) == \
            self.test_task1.computed_start
        assert \
            datetime.datetime(2013, 4, 18, 16, 0, tzinfo=pytz.utc) == \
            self.test_task1.computed_end
        assert len(self.test_task1.computed_resources) == 2
        assert self.test_task1.computed_resources[0] in \
            [self.test_user1, self.test_user2, self.test_user3,
             self.test_user4, self.test_user5]
        assert self.test_task1.computed_resources[1] in \
            [self.test_user1, self.test_user2, self.test_user3,
             self.test_user4, self.test_user5]

        assert \
            datetime.datetime(2013, 4, 18, 16, 0, tzinfo=pytz.utc) == \
            self.test_task2.computed_start
        assert \
            datetime.datetime(2013, 4, 24, 10, 0, tzinfo=pytz.utc) == \
            self.test_task2.computed_end
        assert len(self.test_task2.computed_resources) == 2
        assert self.test_task2.computed_resources[0] in \
            [self.test_user1, self.test_user2, self.test_user3,
             self.test_user4, self.test_user5]
        assert self.test_task2.computed_resources[1] in \
            [self.test_user1, self.test_user2, self.test_user3,
             self.test_user4, self.test_user5]
Esempio n. 4
0
    def test_tasks_are_correctly_scheduled(self):
        """testing if the tasks are correctly scheduled
        """
        tjp_sched = TaskJugglerScheduler(compute_resources=True)
        from stalker import Studio
        test_studio = Studio(
            name='Test Studio',
            now=datetime.datetime(2013, 4, 16, 0, 0, tzinfo=pytz.utc)
        )
        test_studio.start = \
            datetime.datetime(2013, 4, 16, 0, 0, tzinfo=pytz.utc)
        test_studio.end = \
            datetime.datetime(2013, 4, 30, 0, 0, tzinfo=pytz.utc)
        test_studio.daily_working_hours = 9
        from stalker.db.session import DBSession
        DBSession.add(test_studio)

        tjp_sched.studio = test_studio
        tjp_sched.schedule()
        DBSession.commit()

        # check if the task and project timings are all adjusted
        assert \
            datetime.datetime(2013, 4, 16, 9, 0, tzinfo=pytz.utc) == \
            self.test_proj1.computed_start
        assert \
            datetime.datetime(2013, 4, 24, 10, 0, tzinfo=pytz.utc) == \
            self.test_proj1.computed_end

        assert \
            datetime.datetime(2013, 4, 16, 9, 0, tzinfo=pytz.utc) == \
            self.test_task1.computed_start
        assert \
            datetime.datetime(2013, 4, 18, 16, 0, tzinfo=pytz.utc) == \
            self.test_task1.computed_end
        assert \
            sorted([self.test_user1, self.test_user2],
                   key=lambda x: x.name) == \
            sorted(self.test_task1.computed_resources, key=lambda x: x.name)

        assert \
            datetime.datetime(2013, 4, 18, 16, 0, tzinfo=pytz.utc) == \
            self.test_task2.computed_start
        assert \
            datetime.datetime(2013, 4, 24, 10, 0, tzinfo=pytz.utc) == \
            self.test_task2.computed_end

        assert len(self.test_task2.computed_resources) == 2

        possible_resources = [
            self.test_user2, self.test_user3,
            self.test_user4, self.test_user5
        ]
        for r in self.test_task2.computed_resources:
            assert r in possible_resources
    def test_tasks_are_correctly_scheduled(self):
        """testing if the tasks are correctly scheduled
        """
        tjp_sched = TaskJugglerScheduler(compute_resources=True)
        test_studio = Studio(name='Test Studio',
                             now=datetime.datetime(2013, 4, 16, 0, 0))
        test_studio.start = datetime.datetime(2013, 4, 16, 0, 0)
        test_studio.end = datetime.datetime(2013, 4, 30, 0, 0)
        test_studio.daily_working_hours = 9
        DBSession.add(test_studio)

        tjp_sched.studio = test_studio
        tjp_sched.schedule()
        db.DBSession.commit()

        # check if the task and project timings are all adjusted
        self.assertEqual(
            datetime.datetime(2013, 4, 16, 9, 0),
            self.test_proj1.computed_start
        )
        self.assertEqual(
            datetime.datetime(2013, 4, 24, 10, 0),
            self.test_proj1.computed_end
        )

        self.assertEqual(
            datetime.datetime(2013, 4, 16, 9, 0),
            self.test_task1.computed_start
        )
        self.assertEqual(
            datetime.datetime(2013, 4, 18, 16, 0),
            self.test_task1.computed_end
        )
        self.assertEqual(
            sorted([self.test_user1, self.test_user2], key=lambda x: x.name),
            sorted(self.test_task1.computed_resources, key=lambda x: x.name)
        )

        self.assertEqual(
            datetime.datetime(2013, 4, 18, 16, 0),
            self.test_task2.computed_start
        )
        self.assertEqual(
            datetime.datetime(2013, 4, 24, 10, 0),
            self.test_task2.computed_end
        )

        self.assertEqual(2, len(self.test_task2.computed_resources))

        possible_resources = [
            self.test_user2, self.test_user3,
            self.test_user4, self.test_user5
        ]
        for r in self.test_task2.computed_resources:
            self.assertIn(r, possible_resources)
    def test_tasks_of_given_projects_are_correctly_scheduled(self):
        """testing if the tasks of given projects are correctly scheduled
        """
        # create a dummy project
        # create a dummy Project to schedule
        dummy_project = Project(name="Dummy Project", code="DP", repository=self.test_repo)

        dt1 = Task(
            name="Dummy Task 1",
            project=dummy_project,
            schedule_timing=4,
            schedule_unit="h",
            resources=[self.test_user1],
        )

        dt2 = Task(
            name="Dummy Task 2",
            project=dummy_project,
            schedule_timing=4,
            schedule_unit="h",
            resources=[self.test_user2],
        )
        db.DBSession.add_all([dummy_project, dt1, dt2])
        db.DBSession.commit()

        tjp_sched = TaskJugglerScheduler(compute_resources=True, projects=[dummy_project])
        test_studio = Studio(name="Test Studio", now=datetime.datetime(2013, 4, 16, 0, 0))
        test_studio.start = datetime.datetime(2013, 4, 16, 0, 0)
        test_studio.end = datetime.datetime(2013, 4, 30, 0, 0)
        test_studio.daily_working_hours = 9
        DBSession.add(test_studio)
        db.DBSession.commit()

        tjp_sched.studio = test_studio
        tjp_sched.schedule()
        db.DBSession.commit()

        # check if the task and project timings are all adjusted
        self.assertEqual(self.test_proj1.computed_start, None)
        self.assertEqual(self.test_proj1.computed_end, None)

        self.assertEqual(self.test_task1.computed_start, None)
        self.assertEqual(self.test_task1.computed_end, None)
        self.assertEqual(self.test_task1.computed_resources, [self.test_user1, self.test_user2])

        self.assertEqual(self.test_task2.computed_start, None)
        self.assertEqual(self.test_task2.computed_end, None)
        self.assertEqual(self.test_task2.computed_resources, [self.test_user1, self.test_user2])

        self.assertEqual(dt1.computed_start, datetime.datetime(2013, 4, 16, 9, 0))
        self.assertEqual(dt1.computed_end, datetime.datetime(2013, 4, 16, 13, 0))

        self.assertEqual(dt2.computed_start, datetime.datetime(2013, 4, 16, 9, 0))
        self.assertEqual(dt2.computed_end, datetime.datetime(2013, 4, 16, 13, 0))
    def test_tasks_are_correctly_scheduled_when_compute_resources_is_False(self):
        """testing if the tasks are correctly scheduled when the compute
        resources is False
        """
        tjp_sched = TaskJugglerScheduler(compute_resources=False)
        test_studio = Studio(name='Test Studio',
                             now=datetime.datetime(2013, 4, 16, 0, 0))
        test_studio.start = datetime.datetime(2013, 4, 16, 0, 0)
        test_studio.end = datetime.datetime(2013, 4, 30, 0, 0)
        test_studio.daily_working_hours = 9
        DBSession.add(test_studio)

        tjp_sched.studio = test_studio
        tjp_sched.schedule()
        db.DBSession.commit()

        # check if the task and project timings are all adjusted
        self.assertEqual(
            datetime.datetime(2013, 4, 16, 9, 0),
            self.test_proj1.computed_start
        )
        self.assertEqual(
            datetime.datetime(2013, 4, 19, 12, 0),
            self.test_proj1.computed_end
        )

        self.assertEqual(
            datetime.datetime(2013, 4, 16, 9, 0),
            self.test_task1.computed_start
        )
        self.assertEqual(
            datetime.datetime(2013, 4, 18, 16, 0),
            self.test_task1.computed_end
        )
        self.assertItemsEqual(
            self.test_task1.resources,
            self.test_task1.computed_resources
        )

        self.assertEqual(
            datetime.datetime(2013, 4, 16, 9, 0),
            self.test_task2.computed_start
        )
        self.assertEqual(
            datetime.datetime(2013, 4, 19, 12, 0),
            self.test_task2.computed_end
        )
        self.assertItemsEqual(
            self.test_task2.resources,
            self.test_task2.computed_resources
        )
    def test_tasks_are_correctly_scheduled_when_compute_resources_is_False(self):
        """testing if the tasks are correctly scheduled when the compute
        resources is False
        """
        tjp_sched = TaskJugglerScheduler(compute_resources=False)
        test_studio = Studio(name='Test Studio',
                             now=datetime.datetime(2013, 4, 16, 0, 0))
        test_studio.start = datetime.datetime(2013, 4, 16, 0, 0)
        test_studio.end = datetime.datetime(2013, 4, 30, 0, 0)
        test_studio.daily_working_hours = 9
        DBSession.add(test_studio)

        tjp_sched.studio = test_studio
        tjp_sched.schedule()
        db.DBSession.commit()

        # check if the task and project timings are all adjusted
        self.assertEqual(
            datetime.datetime(2013, 4, 16, 9, 0),
            self.test_proj1.computed_start
        )
        self.assertEqual(
            datetime.datetime(2013, 4, 24, 10, 0),
            self.test_proj1.computed_end
        )

        self.assertEqual(
            datetime.datetime(2013, 4, 16, 9, 0),
            self.test_task1.computed_start
        )
        self.assertEqual(
            datetime.datetime(2013, 4, 18, 16, 0),
            self.test_task1.computed_end
        )
        self.assertEqual(
            sorted(self.test_task1.resources, key=lambda x: x.name),
            sorted(self.test_task1.computed_resources, key=lambda x: x.name)
        )

        self.assertEqual(
            datetime.datetime(2013, 4, 18, 16, 0),
            self.test_task2.computed_start
        )
        self.assertEqual(
            datetime.datetime(2013, 4, 24, 10, 0),
            self.test_task2.computed_end
        )
        self.assertEqual(
            sorted(self.test_task2.resources, key=lambda x: x.name),
            sorted(self.test_task2.computed_resources, key=lambda x: x.name)
        )
Esempio n. 9
0
def create_studio(request):
    """creates the studio
    """
    name = request.params.get('name', None)
    dwh = request.params.get('dwh', None)
    wh_mon_start = get_time(request, 'mon_start')
    wh_mon_end   = get_time(request, 'mon_end')
    wh_tue_start = get_time(request, 'tue_start')
    wh_tue_end   = get_time(request, 'tue_end')
    wh_wed_start = get_time(request, 'wed_start')
    wh_wed_end   = get_time(request, 'wed_end')
    wh_thu_start = get_time(request, 'thu_start')
    wh_thu_end   = get_time(request, 'thu_end')
    wh_fri_start = get_time(request, 'fri_start')
    wh_fri_end   = get_time(request, 'fri_end')
    wh_sat_start = get_time(request, 'sat_start')
    wh_sat_end   = get_time(request, 'sat_end')
    wh_sun_start = get_time(request, 'sun_start')
    wh_sun_end   = get_time(request, 'sun_end')

    if name and dwh:
        # create new studio
        studio = Studio(
            name=name,
            daily_working_hours=int(dwh)
        )
        wh = WorkingHours()

        def set_wh_for_day(day, start, end):
            if start != end:
                wh[day] = [[start.seconds/60, end.seconds/60]]
            else:
                wh[day] = []

        set_wh_for_day('mon', wh_mon_start, wh_mon_end)
        set_wh_for_day('tue', wh_tue_start, wh_tue_end)
        set_wh_for_day('wed', wh_wed_start, wh_wed_end)
        set_wh_for_day('thu', wh_thu_start, wh_thu_end)
        set_wh_for_day('fri', wh_fri_start, wh_fri_end)
        set_wh_for_day('sat', wh_sat_start, wh_sat_end)
        set_wh_for_day('sun', wh_sun_start, wh_sun_end)

        studio.working_hours = wh

        DBSession.add(studio)
        # Commit will be handled by the zope transaction extension

    return HTTPOk()
Esempio n. 10
0
def create_studio(request):
    """creates the studio
    """
    name = request.params.get('name', None)
    dwh = request.params.get('dwh', None)
    wh_mon_start = get_time(request, 'mon_start')
    wh_mon_end   = get_time(request, 'mon_end')
    wh_tue_start = get_time(request, 'tue_start')
    wh_tue_end   = get_time(request, 'tue_end')
    wh_wed_start = get_time(request, 'wed_start')
    wh_wed_end   = get_time(request, 'wed_end')
    wh_thu_start = get_time(request, 'thu_start')
    wh_thu_end   = get_time(request, 'thu_end')
    wh_fri_start = get_time(request, 'fri_start')
    wh_fri_end   = get_time(request, 'fri_end')
    wh_sat_start = get_time(request, 'sat_start')
    wh_sat_end   = get_time(request, 'sat_end')
    wh_sun_start = get_time(request, 'sun_start')
    wh_sun_end   = get_time(request, 'sun_end')

    if name and dwh:
        # create new studio
        studio = Studio(
            name=name,
            daily_working_hours=int(dwh)
        )
        wh = WorkingHours()

        def set_wh_for_day(day, start, end):
            if start != end:
                wh[day] = [[start.seconds/60, end.seconds/60]]
            else:
                wh[day] = []

        set_wh_for_day('mon', wh_mon_start, wh_mon_end)
        set_wh_for_day('tue', wh_tue_start, wh_tue_end)
        set_wh_for_day('wed', wh_wed_start, wh_wed_end)
        set_wh_for_day('thu', wh_thu_start, wh_thu_end)
        set_wh_for_day('fri', wh_fri_start, wh_fri_end)
        set_wh_for_day('sat', wh_sat_start, wh_sat_end)
        set_wh_for_day('sun', wh_sun_start, wh_sun_end)

        studio.working_hours = wh

        DBSession.add(studio)
        # Commit will be handled by the zope transaction extension

    return HTTPOk()
Esempio n. 11
0
 def test_studio_attribute_is_working_properly(self):
     """testing if the studio attribute is working properly
     """
     from stalker import Studio
     new_studio = Studio(name='Test Studio 2')
     self.test_scheduler_base.studio = new_studio
     assert self.test_scheduler_base.studio == new_studio
    def test_tasks_are_correctly_scheduled(self):
        """testing if the tasks are correctly scheduled
        """
        tjp_sched = TaskJugglerScheduler()
        test_studio = Studio(name='Test Studio',
                             now=datetime.datetime(2013, 4, 16, 0, 0))
        test_studio.daily_working_hours = 9
        DBSession.add(test_studio)

        tjp_sched.studio = test_studio
        tjp_sched.schedule()

        # check if the task and project timings are all adjusted
        self.assertEqual(
            datetime.datetime(2013, 4, 16, 9, 0),
            self.test_proj1.computed_start
        )
        self.assertEqual(
            datetime.datetime(2013, 4, 19, 12, 0),
            self.test_proj1.computed_end
        )

        self.assertEqual(
            datetime.datetime(2013, 4, 16, 9, 0),
            self.test_task1.computed_start
        )
        self.assertEqual(
            datetime.datetime(2013, 4, 18, 16, 0),
            self.test_task1.computed_end
        )
        self.assertItemsEqual(
            [self.test_user5, self.test_user4],
            self.test_task1.computed_resources
        )

        self.assertEqual(
            datetime.datetime(2013, 4, 16, 9, 0),
            self.test_task2.computed_start
        )
        self.assertEqual(
            datetime.datetime(2013, 4, 19, 12, 0),
            self.test_task2.computed_end
        )
        self.assertItemsEqual(
            [self.test_user1, self.test_user2],
            self.test_task2.computed_resources
        )
Esempio n. 13
0
 def setUp(self):
     """set up the test
     """
     self.test_studio = Studio(name='Test Studio')
     self.kwargs = {
         'studio': self.test_studio
     }
     self.test_scheduler_base = SchedulerBase(**self.kwargs)
Esempio n. 14
0
    def setUp(self):
        """set up the test
        """
        super(SchedulerBaseTester, self).setUp()

        from stalker import Studio
        self.test_studio = Studio(name='Test Studio')
        self.kwargs = {'studio': self.test_studio}
        self.test_scheduler_base = SchedulerBase(**self.kwargs)
Esempio n. 15
0
    def setUp(self):
        """set up the test
        """
        super(SchedulerBaseTester, self).setUp()

        from stalker import db, Studio
        self.test_studio = Studio(name='Test Studio')
        db.DBSession.add(self.test_studio)
        db.DBSession.commit()
        self.kwargs = {'studio': self.test_studio}
        self.test_scheduler_base = SchedulerBase(**self.kwargs)
Esempio n. 16
0
 def test_studio_attribute_is_working_properly(self):
     """testing if the studio attribute is working properly
     """
     new_studio = Studio(name='Test Studio 2')
     self.test_scheduler_base.studio = new_studio
     self.assertEqual(self.test_scheduler_base.studio, new_studio)
Esempio n. 17
0
from stalker import db
db.setup({"sqlalchemy.url": "sqlite:///"})
db.init()

from stalker import Studio
my_studio = Studio(name='My Great Studio')

from stalker import User
me = User(name="Erkan Ozgur Yilmaz",
          login="******",
          email="*****@*****.**",
          password="******",
          description="This is me")

from stalker import Department
tds_department = Department(name="TDs",
                            description="This is the TDs department")

tds_department.users.append(me)

print(me.departments)
# you should get something like
# [<TDs (Department)>]

from stalker.db.session import DBSession
DBSession.add(my_studio)
DBSession.add(me)
DBSession.add(tds_department)
DBSession.commit()

all_departments = Department.query.all()
    def test_tasks_of_given_projects_are_correctly_scheduled(self):
        """testing if the tasks of given projects are correctly scheduled
        """
        # create a dummy project
        # create a dummy Project to schedule
        from stalker import Project
        dummy_project = Project(name='Dummy Project',
                                code='DP',
                                repository=self.test_repo)

        from stalker import Task
        dt1 = Task(name='Dummy Task 1',
                   project=dummy_project,
                   schedule_timing=4,
                   schedule_unit='h',
                   resources=[self.test_user1])

        dt2 = Task(name='Dummy Task 2',
                   project=dummy_project,
                   schedule_timing=4,
                   schedule_unit='h',
                   resources=[self.test_user2])
        from stalker.db.session import DBSession
        DBSession.add_all([dummy_project, dt1, dt2])
        DBSession.commit()

        tjp_sched = TaskJugglerScheduler(compute_resources=True,
                                         projects=[dummy_project])
        from stalker import Studio
        test_studio = Studio(name='Test Studio',
                             now=datetime.datetime(2013,
                                                   4,
                                                   16,
                                                   0,
                                                   0,
                                                   tzinfo=pytz.utc))
        test_studio.start = \
            datetime.datetime(2013, 4, 16, 0, 0, tzinfo=pytz.utc)
        test_studio.end = datetime.datetime(2013, 4, 30, 0, 0, tzinfo=pytz.utc)
        test_studio.daily_working_hours = 9
        DBSession.add(test_studio)
        DBSession.commit()

        tjp_sched.studio = test_studio
        tjp_sched.schedule()
        DBSession.commit()

        # check if the task and project timings are all adjusted
        assert self.test_proj1.computed_start is None
        assert self.test_proj1.computed_end is None

        assert self.test_task1.computed_start is None
        assert self.test_task1.computed_end is None
        assert self.test_task1.computed_resources == \
            [self.test_user1, self.test_user2]

        assert self.test_task2.computed_start is None
        assert self.test_task2.computed_end is None
        assert self.test_task2.computed_resources == \
            [self.test_user1, self.test_user2]

        assert \
            dt1.computed_start == \
            datetime.datetime(2013, 4, 16, 9, 0, tzinfo=pytz.utc)
        assert \
            dt1.computed_end == \
            datetime.datetime(2013, 4, 16, 13, 0, tzinfo=pytz.utc)

        assert \
            dt2.computed_start == \
            datetime.datetime(2013, 4, 16, 9, 0, tzinfo=pytz.utc)
        assert \
            dt2.computed_end == \
            datetime.datetime(2013, 4, 16, 13, 0, tzinfo=pytz.utc)
    def test_tjp_file_content_is_correct(self):
        """testing if the tjp file content is correct
        """
        # enter a couple of time logs
        from stalker import TimeLog
        tlog1 = TimeLog(resource=self.test_user1,
                        task=self.test_task1,
                        start=datetime.datetime(2013,
                                                4,
                                                16,
                                                6,
                                                0,
                                                tzinfo=pytz.utc),
                        end=datetime.datetime(2013,
                                              4,
                                              16,
                                              9,
                                              0,
                                              tzinfo=pytz.utc))
        from stalker.db.session import DBSession
        DBSession.add(tlog1)
        DBSession.commit()

        tjp_sched = TaskJugglerScheduler()
        from stalker import Studio
        test_studio = Studio(name='Test Studio',
                             timing_resolution=datetime.timedelta(minutes=30))
        test_studio.daily_working_hours = 9

        test_studio.id = 564
        test_studio.start = \
            datetime.datetime(2013, 4, 16, 0, 7, tzinfo=pytz.utc)
        test_studio.end = datetime.datetime(2013, 6, 30, 0, 0, tzinfo=pytz.utc)
        test_studio.now = datetime.datetime(2013, 4, 16, 0, 0, tzinfo=pytz.utc)
        tjp_sched.studio = test_studio

        tjp_sched._create_tjp_file()
        tjp_sched._create_tjp_file_content()

        assert TimeLog.query.all() != []

        import jinja2
        expected_tjp_template = jinja2.Template(
            """# Generated By Stalker v{{stalker.__version__}}
        
project Studio_564 "Studio_564" 2013-04-16 - 2013-06-30 {
    timingresolution 30min
    now 2013-04-16-00:00
    dailyworkinghours 9
    weekstartsmonday
    workinghours mon 09:00 - 18:00
    workinghours tue 09:00 - 18:00
    workinghours wed 09:00 - 18:00
    workinghours thu 09:00 - 18:00
    workinghours fri 09:00 - 18:00
    workinghours sat off
    workinghours sun off
    timeformat "%Y-%m-%d"
    scenario plan "Plan"
    trackingscenario plan
}

        # resources
        resource resources "Resources" {
            resource User_3 "User_3" {
    efficiency 1.0
}
            resource User_{{user1.id}} "User_{{user1.id}}" {
    efficiency 1.0
}
            resource User_{{user2.id}} "User_{{user2.id}}" {
    efficiency 1.0
}
            resource User_{{user3.id}} "User_{{user3.id}}" {
    efficiency 1.0
}
            resource User_{{user4.id}} "User_{{user4.id}}" {
    efficiency 1.0
}
            resource User_{{user5.id}} "User_{{user5.id}}" {
    efficiency 1.0
}
            resource User_{{user6.id}} "User_{{user6.id}}" {
    efficiency 1.0
}
        }

# tasks
task Project_{{proj.id}} "Project_{{proj.id}}" {
  task Task_{{task1.id}} "Task_{{task1.id}}" {
    effort 50.0h
    allocate User_{{user1.id}} { alternative User_{{user3.id}}, User_{{user4.id}}, User_{{user5.id}} select minallocated persistent }, User_{{user2.id}} { alternative User_{{user3.id}}, User_{{user4.id}}, User_{{user5.id}} select minallocated persistent }
    booking User_{{user1.id}} 2013-04-16-06:00:00 - 2013-04-16-09:00:00 { overtime 2 }
  }
  task Task_{{task2.id}} "Task_{{task2.id}}" {
    priority 800
    depends Project_{{proj.id}}.Task_{{task1.id}} {onend}
    effort 60.0h
    allocate User_{{user1.id}} { alternative User_{{user3.id}}, User_{{user4.id}}, User_{{user5.id}} select minallocated persistent }, User_{{user2.id}} { alternative User_{{user3.id}}, User_{{user4.id}}, User_{{user5.id}} select minallocated persistent }
  }
}

# reports
taskreport breakdown "{{csv_path}}"{
    formats csv
    timeformat "%Y-%m-%d-%H:%M"
    columns id, start, end
}
""")
        import stalker
        expected_tjp_content = expected_tjp_template.render({
            'stalker':
            stalker,
            'studio':
            test_studio,
            'csv_path':
            tjp_sched.temp_file_name,
            'user1':
            self.test_user1,
            'user2':
            self.test_user2,
            'user3':
            self.test_user3,
            'user4':
            self.test_user4,
            'user5':
            self.test_user5,
            'user6':
            self.test_user6,
            'proj':
            self.test_proj1,
            'task1':
            self.test_task1,
            'task2':
            self.test_task2,
        })

        self.maxDiff = None
        tjp_content = tjp_sched.tjp_content
        # print tjp_content
        tjp_sched._clean_up()
        # print(expected_tjp_content)
        # print('----------------')
        # print(tjp_content)
        assert tjp_content == expected_tjp_content
    def test_tjp_file_content_is_correct(self):
        """testing if the tjp file content is correct
        """
        tjp_sched = TaskJugglerScheduler()
        test_studio = Studio(
            name='Test Studio',
            timing_resolution=datetime.timedelta(minutes=30)
        )
        test_studio.daily_working_hours = 9

        test_studio.id = 564
        test_studio.start = datetime.datetime(2013, 4, 16, 0, 7)
        test_studio.end = datetime.datetime(2013, 6, 30, 0, 0)
        test_studio.now = datetime.datetime(2013, 4, 16, 0, 0)
        tjp_sched.studio = test_studio

        tjp_sched._create_tjp_file()
        tjp_sched._create_tjp_file_content()

        import jinja2

        expected_tjp_template = jinja2.Template(
            """# Generated By Stalker v{{stalker.__version__}}
        
project Studio_564 "Studio_564" 2013-04-16 - 2013-06-30 {
    timingresolution 30min
    now 2013-04-16-00:00
    dailyworkinghours 9
    weekstartsmonday
    workinghours mon 09:00 - 18:00
    workinghours tue 09:00 - 18:00
    workinghours wed 09:00 - 18:00
    workinghours thu 09:00 - 18:00
    workinghours fri 09:00 - 18:00
    workinghours sat off
    workinghours sun off
    timeformat "%Y-%m-%d"
    scenario plan "Plan"
    trackingscenario plan
}

        # resources
        resource resources "Resources" {
            resource User_3 "User_3" {
    efficiency 1.0
}
            resource User_{{user1.id}} "User_{{user1.id}}" {
    efficiency 1.0
}
            resource User_{{user2.id}} "User_{{user2.id}}" {
    efficiency 1.0
}
            resource User_{{user3.id}} "User_{{user3.id}}" {
    efficiency 1.0
}
            resource User_{{user4.id}} "User_{{user4.id}}" {
    efficiency 1.0
}
            resource User_{{user5.id}} "User_{{user5.id}}" {
    efficiency 1.0
}
            resource User_{{user6.id}} "User_{{user6.id}}" {
    efficiency 1.0
}
        }

# tasks
task Project_{{proj1.id}} "Project_{{proj1.id}}" {
  task Task_{{task1.id}} "Task_{{task1.id}}" {
    effort 50.0h
    allocate User_{{user1.id}} { alternative User_{{user3.id}}, User_{{user4.id}}, User_{{user5.id}} select minallocated persistent }, User_{{user2.id}} { alternative User_{{user3.id}}, User_{{user4.id}}, User_{{user5.id}} select minallocated persistent }
  }
  task Task_{{task2.id}} "Task_{{task2.id}}" {
    depends Project_{{proj1.id}}.Task_{{task1.id}} {onend}
    effort 60.0h
    allocate User_{{user1.id}} { alternative User_{{user3.id}}, User_{{user4.id}}, User_{{user5.id}} select minallocated persistent }, User_{{user2.id}} { alternative User_{{user3.id}}, User_{{user4.id}}, User_{{user5.id}} select minallocated persistent }
  }
}

# reports
taskreport breakdown "{{csv_path}}"{
    formats csv
    timeformat "%Y-%m-%d-%H:%M"
    columns id, start, end
}""")
        expected_tjp_content = expected_tjp_template.render(
            {
                'stalker': stalker,
                'studio': test_studio,
                'csv_path': tjp_sched.temp_file_full_path,
                'user1': self.test_user1,
                'user2': self.test_user2,
                'user3': self.test_user3,
                'user4': self.test_user4,
                'user5': self.test_user5,
                'user6': self.test_user6,
                'proj1': self.test_proj1,
                'task1': self.test_task1,
                'task2': self.test_task2,
            }
        )

        self.maxDiff = None
        tjp_content = tjp_sched.tjp_content
        # print tjp_content
        tjp_sched._clean_up()
        self.assertEqual(tjp_content, expected_tjp_content)
    def test_tjp_file_content_is_correct(self):
        """testing if the tjp file content is correct
        """
        tjp_sched = TaskJugglerScheduler()
        test_studio = Studio(
            name='Test Studio',
            timing_resolution=datetime.timedelta(minutes=30)
        )
        test_studio.daily_working_hours = 9

        test_studio.id = 564
        test_studio.start = datetime.datetime(2013, 4, 16, 0, 7)
        test_studio.end = datetime.datetime(2013, 6, 30, 0, 0)
        test_studio.now = datetime.datetime(2013, 4, 16, 0, 0)
        tjp_sched.studio = test_studio

        tjp_sched._create_tjp_file()
        tjp_sched._create_tjp_file_content()

        import jinja2

        expected_tjp_template = jinja2.Template(
            """# Generated By Stalker v0.2.5.2
        
project Studio_564 "Test Studio" 2013-04-16 - 2013-06-30 {
    timingresolution 30min
    now 2013-04-16-00:00
    dailyworkinghours 9
    weekstartsmonday
    workinghours mon 09:00 - 18:00
    workinghours tue 09:00 - 18:00
    workinghours wed 09:00 - 18:00
    workinghours thu 09:00 - 18:00
    workinghours fri 09:00 - 18:00
    workinghours sat off
    workinghours sun off
    timeformat "%Y-%m-%d"
    scenario plan "Plan"
    trackingscenario plan
}

        # resources
        resource resources "Resources" {
            resource User_3 "admin"
            resource User_28 "User1"
            resource User_30 "User2"
            resource User_31 "User3"
            resource User_33 "User4"
            resource User_34 "User5"
            resource User_35 "User6"
        }

        # tasks
        
            
task Project_43 "Test Project 1" {
        
task Task_44 "Task1" {

    
            
            
            effort 50.0h
            allocate User_28 {
                    alternative
                    User_31, User_33, User_34 select minallocated
                    persistent
                }, User_30 {
                    alternative
                    User_31, User_33, User_34 select minallocated
                    persistent
                }            
}        
task Task_45 "Task2" {

    
            
            
            effort 60.0h
            allocate User_28 {
                    alternative
                    User_31, User_33, User_34 select minallocated
                    persistent
                }, User_30 {
                    alternative
                    User_31, User_33, User_34 select minallocated
                    persistent
                }            
}}
        

        # reports
        taskreport breakdown "{{csv_path}}"{
            formats csv
            timeformat "%Y-%m-%d-%H:%M"
            columns id, start, end, resources
        }
        
""")
        expected_tjp_content = expected_tjp_template.render(
            {
                'stalker': stalker,
                'studio': test_studio,
                'csv_path': tjp_sched.temp_file_full_path
            }
        )

        # self.maxDiff = None
        tjp_content = tjp_sched.tjp_content
        # print tjp_content
        tjp_sched._clean_up()
        self.assertEqual(tjp_content, expected_tjp_content)
    def test_tjp_file_content_is_correct(self):
        """testing if the tjp file content is correct
        """
        tjp_sched = TaskJugglerScheduler()
        test_studio = Studio(
            name='Test Studio',
            timing_resolution=datetime.timedelta(minutes=30)
        )
        test_studio.daily_working_hours = 9

        test_studio.id = 564
        test_studio.start = datetime.datetime(2013, 4, 16, 0, 7)
        test_studio.end = datetime.datetime(2013, 6, 30, 0, 0)
        test_studio.now = datetime.datetime(2013, 4, 16, 0, 0)
        tjp_sched.studio = test_studio

        tjp_sched._create_tjp_file()
        tjp_sched._create_tjp_file_content()

        import jinja2

        expected_tjp_template = jinja2.Template(
            """# Generated By Stalker v{{stalker.__version__}}
        
project Studio_564 "Studio_564" 2013-04-16 - 2013-06-30 {
    timingresolution 30min
    now 2013-04-16-00:00
    dailyworkinghours 9
    weekstartsmonday
    workinghours mon 09:00 - 18:00
    workinghours tue 09:00 - 18:00
    workinghours wed 09:00 - 18:00
    workinghours thu 09:00 - 18:00
    workinghours fri 09:00 - 18:00
    workinghours sat off
    workinghours sun off
    timeformat "%Y-%m-%d"
    scenario plan "Plan"
    trackingscenario plan
}

        # resources
        resource resources "Resources" {
            resource User_3 "User_3" {
    efficiency 1.0
}
            resource User_{{user1.id}} "User_{{user1.id}}" {
    efficiency 1.0
}
            resource User_{{user2.id}} "User_{{user2.id}}" {
    efficiency 1.0
}
            resource User_{{user3.id}} "User_{{user3.id}}" {
    efficiency 1.0
}
            resource User_{{user4.id}} "User_{{user4.id}}" {
    efficiency 1.0
}
            resource User_{{user5.id}} "User_{{user5.id}}" {
    efficiency 1.0
}
            resource User_{{user6.id}} "User_{{user6.id}}" {
    efficiency 1.0
}
        }

# tasks
task Project_{{proj1.id}} "Project_{{proj1.id}}" {
  task Task_{{task1.id}} "Task_{{task1.id}}" {
    effort 50.0h
    allocate User_{{user1.id}} { alternative User_{{user3.id}}, User_{{user4.id}}, User_{{user5.id}} select minallocated persistent }, User_{{user2.id}} { alternative User_{{user3.id}}, User_{{user4.id}}, User_{{user5.id}} select minallocated persistent }
  }
  task Task_{{task2.id}} "Task_{{task2.id}}" {
    depends Project_{{proj1.id}}.Task_{{task1.id}} {onend}
    effort 60.0h
    allocate User_{{user1.id}} { alternative User_{{user3.id}}, User_{{user4.id}}, User_{{user5.id}} select minallocated persistent }, User_{{user2.id}} { alternative User_{{user3.id}}, User_{{user4.id}}, User_{{user5.id}} select minallocated persistent }
  }
}

# reports
taskreport breakdown "{{csv_path}}"{
    formats csv
    timeformat "%Y-%m-%d-%H:%M"
    columns id, start, end
}""")
        expected_tjp_content = expected_tjp_template.render(
            {
                'stalker': stalker,
                'studio': test_studio,
                'csv_path': tjp_sched.temp_file_name,
                'user1': self.test_user1,
                'user2': self.test_user2,
                'user3': self.test_user3,
                'user4': self.test_user4,
                'user5': self.test_user5,
                'user6': self.test_user6,
                'proj1': self.test_proj1,
                'task1': self.test_task1,
                'task2': self.test_task2,
            }
        )

        self.maxDiff = None
        tjp_content = tjp_sched.tjp_content
        # print tjp_content
        tjp_sched._clean_up()
        self.assertEqual(tjp_content, expected_tjp_content)
Esempio n. 23
0
from stalker import db
db.setup()

db.init()

import datetime
from stalker import Studio
my_studio = Studio(
    name='My Great Studio'
)

from stalker import User
me = User(
    name="Erkan Ozgur Yilmaz",
    login="******",
    email="*****@*****.**",
    password="******",
    description="This is me"
)

from stalker import Department
tds_department = Department(
    name="TDs",
    description="This is the TDs department"
)

tds_department.users.append(me)

print(me.departments)
# you should get something like