def setUp(self):
     super(TestMaintenanceActivityGroup, self).setUp()
     self.week = datetime(2011, 04, 11)
     per_data = ((datetime(2011, 04, 12, 8), 8),
                 (datetime(2011, 04, 13, 8), 8),
                 (datetime(2011, 04, 14, 8), 8),
                 (datetime(2011, 04, 15, 8), 8))
     self.me1 = create_maintenance_elective(per_data)
     self.me2 = create_maintenance_elective(per_data)
     self.mp1 = create_maintenance_period(datetime(2011, 04, 11, 8), 8,
                                          'Pending')
     self.mp2 = create_maintenance_period(datetime(2011, 04, 14, 8), 8,
                                          'Pending')
     self.deleted = Period_State.objects.get(name = 'Deleted')
     self.pending = Period_State.objects.get(name = 'Pending')
     self.scheduled = Period_State.objects.get(name = 'Scheduled')
Exemple #2
0
    def test_get_gbt_schedule_events_repeats_electives(self):
        "Focus on the behavoir of repeats with elective maintenance"

        # first, make sure an empty schedule looks empty
        start = datetime(2011, 9, 25)
        end   = datetime(2011, 10, 8)
        timezone = 'UTC'
        exp = self.assert_empty_schedule(start, end)

        # create an elective for both weeks
        per_data_1 = ((datetime(2011, 9, 27, 8), 8),
                    (datetime(2011, 9, 28, 8), 8),
                    (datetime(2011, 9, 29, 8), 8),
                    (datetime(2011, 9, 30, 8), 8))
        me1 = create_maintenance_elective(per_data_1)
        per_data_2 = ((datetime(2011, 10, 4, 8), 8),
                    (datetime(2011, 10, 5, 8), 8),
                    (datetime(2011, 10, 6, 8), 8),
                    (datetime(2011, 10, 7, 8), 8))
        me2 = create_maintenance_elective(per_data_2)
    
        # now check out the schedule
        sch = get_gbt_schedule_events(start, end, timezone)
        nonBlankDays = [1,8]
        blankDays = [i for i in range(0,13) if i not in nonBlankDays] 
        for i in blankDays:
            self.assertEqual(exp[i], sch[i])

        # check out Mondays    
        mags = []
        for day in nonBlankDays:
            calEvents = sch[day][1]
            self.assertEqual(1,len(calEvents))
            self.assertEqual('CalEventFloatingMaintenance'
                           , calEvents[0].__class__.__name__)
            mag = calEvents[0].contained
            self.assertEqual([], mag.get_maintenance_activity_set())
            mags.append(mag) # for use below

        # now create a daily repeating activity that spans our whole cal.
        ma = create_maintenance_activity()
        ma.subject = "Repeat Daily 1"
        ma.group = mags[0] # the first one from the list above
        ma.set_start(datetime(2011, 9, 27, 9), 'UTC')
        ma.repeat_interval = 1
        ma.repeat_end = datetime(2011, 10, 9, 10)
        ma.save()

        sch = get_gbt_schedule_events(start, end, timezone)
        for i in blankDays:
            self.assertEqual(exp[i], sch[i])

        # check out the first Monday    
        calEvents = sch[1][1]
        self.assertEqual(1,len(calEvents))
        self.assertEqual('CalEventFloatingMaintenance'
                       , calEvents[0].__class__.__name__)
        mag = calEvents[0].contained
        mas = mag.get_maintenance_activity_set()
        self.assertEqual(1, len(mas))
        self.assertEqual("Repeat Daily 1", mas[0].subject)

        # check out the second Monday
        calEvents = sch[8][1]
        self.assertEqual(1,len(calEvents))
        self.assertEqual('CalEventFloatingMaintenance'
                       , calEvents[0].__class__.__name__)
        mag = calEvents[0].contained
        mas = mag.get_maintenance_activity_set()
        self.assertEqual(1, len(mas))
Exemple #3
0
    def test_get_gbt_schedule_events_elective_2(self):

        # first, make sure an empty schedule looks empty
        start = datetime(2011, 9, 25)
        end   = datetime(2011, 10, 1)
        timezone = 'UTC'
        exp = self.assert_empty_schedule(start, end)

        # create the Maintenance Project
        proj = create_maintenance_project()

        #week = datetime(2011, 04, 11)
        per_data = ((datetime(2011, 9, 27, 8), 8),
                    (datetime(2011, 9, 28, 8), 8),
                    (datetime(2011, 9, 29, 8), 8),
                    (datetime(2011, 9, 30, 8), 8))
        me = create_maintenance_elective(per_data)    

        # need to call this to create the first maint. group
        sch = get_gbt_schedule_events(start, end, timezone)
        mag = Maintenance_Activity_Group.objects.all()[0]

        # now create simple events
        ma1 = create_maintenance_activity()
        ma1.set_start(datetime(2011, 9, 26, 10), 'UTC')
        ma1.group = mag
        ma1.save()
        ma2 = create_maintenance_activity()
        ma2.set_start(datetime(2011, 9, 26, 11), 'UTC')
        ma2.subject = "ma2"
        ma2.group = mag
        ma2.save()

        # now publish the period on Wed (9/28)!
        p = me.periods.all().order_by("start")[1]
        p.publish()
        p.save()

        # see what it looks like
        sch = get_gbt_schedule_events(start, end, timezone)
        # now there's nothing on monday, but there is on Wed. 
        blankDays = [0,1,2,4,5]
        for i in blankDays: 
            self.assertEqual(exp[i], sch[i])
        # check out Wed.    
        calEvents = sch[3][1]
        self.assertEqual(1,len(calEvents))
        self.assertEqual('CalEventFixedMaintenance', calEvents[0].__class__.__name__)
        mag = calEvents[0].contained
        self.assertEqual("1 -- 2011-09-26; (2011-09-28); A; active; ma2, Test Maintenance Activity", mag.__unicode__())
        mas = mag.get_maintenance_activity_set()
        self.assertEqual(2, len(mas))
        ma = mas[0]
        self.assertEqual("Test Maintenance Activity", ma.subject)
        self.assertEqual(False, ma.is_repeat_activity())
        self.assertEqual(False, ma.is_repeat_template())
        ma = mas[1]
        self.assertEqual("ma2", ma.subject)
        self.assertEqual(False, ma.is_repeat_activity())
        self.assertEqual(False, ma.is_repeat_template())

        # now, schedule an emergency maint. activity for Tuesday.
        ms = create_maintenance_sesshun()
        ms.name = "Emergency Maintenance"
        ms.session_type = Session_Type.objects.get(type = "fixed")
        ms.save()
   
        pa = Period_Accounting(scheduled = 1.0)
        pa.save()
        scheduled = Period_State.get_state("S")
        p = Period(session = ms
                 , start = datetime(2011, 9, 27, 10)
                 , duration = 1.0
                 , state = scheduled
                 , accounting = pa
                  )
        p.save()

        # see what it looks like
        sch = get_gbt_schedule_events(start, end, timezone)
        # now there's nothing on monday, but there is on Wed. 
        blankDays = [0,1,4,5]

        for i in blankDays: 
            self.assertEqual(exp[i], sch[i])

        calEvents = sch[2][1]
        self.assertEqual(1,len(calEvents))
        self.assertEqual('CalEventFixedMaintenance', calEvents[0].__class__.__name__)
        mag = calEvents[0].contained
        # make sure it is the 'emergency' mag, not the one that belongs on Wed.
        self.assertEqual("2 -- 2011-09-26; (2011-09-27); x; active; Empty", mag.__unicode__())
        # And it's empty; we didn't add anything above.
        mas = mag.get_maintenance_activity_set()
        self.assertEqual(0, len(mas))
        # check out Wed.
        calEvents = sch[3][1]
        self.assertEqual(1,len(calEvents))
        self.assertEqual('CalEventFixedMaintenance', calEvents[0].__class__.__name__)
        mag = calEvents[0].contained
        self.assertEqual('1 -- 2011-09-26; (2011-09-28); A; active; ma2, Test Maintenance Activity',
                         mag.__unicode__())
        mas = mag.get_maintenance_activity_set()
        self.assertEqual(2, len(mas))
Exemple #4
0
    def test_get_gbt_schedule_events_elective(self):
        """
        Step through the setup of a single elective maintenance, 
        with two simple activities, and watch what happens when a
        period gets published.
        """

        # first, make sure an empty schedule looks empty
        start = datetime(2011, 9, 25)
        end   = datetime(2011, 10, 1)
        timezone = 'UTC'
        exp = self.assert_empty_schedule(start, end)

        # create the Maintenance Project
        proj = create_maintenance_project()

        #week = datetime(2011, 04, 11)
        per_data = ((datetime(2011, 9, 27, 8), 8),
                    (datetime(2011, 9, 28, 8), 8),
                    (datetime(2011, 9, 29, 8), 8),
                    (datetime(2011, 9, 30, 8), 8))
        me = create_maintenance_elective(per_data)    

        # now see what the calendar brings up - the elective
        # is actually diplayed as a 'floating maintenance day' on the 
        # monday of the week (9/26)
        sch = get_gbt_schedule_events(start, end, timezone)
        # all other days are still blank
        blankDays = [0,2,3,4,5]
        for i in blankDays: 
            self.assertEqual(exp[i], sch[i])
       
        # what's on the monday?
        calEvents = sch[1][1]
        self.assertEqual(1,len(calEvents))
        mag = calEvents[0].contained
        self.assertEqual("1 -- 2011-09-26; (2011-09-26); A; active; Empty", mag.__unicode__())
        self.assertEqual([], mag.get_maintenance_activity_set())

        # now create a simple event
        ma = create_maintenance_activity()
        ma.set_start(datetime(2011, 9, 26, 10), 'UTC')
        ma.group = mag
        ma.save()

        # make sure it shows up in the floating maint. day
        sch = get_gbt_schedule_events(start, end, timezone)
        # all other days are still blank
        for i in blankDays: 
            self.assertEqual(exp[i], sch[i])
       
        # what's on the monday?  Should show our new activity too!
        calEvents = sch[1][1]
        self.assertEqual(1,len(calEvents))
        mag = calEvents[0].contained
        self.assertEqual("1 -- 2011-09-26; (2011-09-26); A; active; Test Maintenance Activity", mag.__unicode__())
        mas = mag.get_maintenance_activity_set()
        self.assertEqual(1, len(mas))
        ma = mas[0]
        self.assertEqual("Test Maintenance Activity", ma.subject)
        self.assertEqual(False, ma.is_repeat_activity())

        # now create a daily repeat!
        ma = create_maintenance_activity()
        ma.subject = "Repeat Daily 1"
        ma.set_start(datetime(2011, 9, 26, 9), 'UTC')
        ma.group = mag
        ma.repeat_interval = 1
        ma.repeat_end = datetime(2011, 9, 30, 10)
        ma.save()
        # where does it show up?  It should only appear once on the
        # floating day:
        sch = get_gbt_schedule_events(start, end, timezone)
        # all other days are still blank
        for i in blankDays: 
            self.assertEqual(exp[i], sch[i])

        # Monday?    
        calEvents = sch[1][1]
        self.assertEqual(1,len(calEvents))
        self.assertEqual('CalEventFloatingMaintenance', calEvents[0].__class__.__name__)
        mag = calEvents[0].contained
        self.assertEqual("1 -- 2011-09-26; (2011-09-26); A; active; Test Maintenance Activity", mag.__unicode__())
        mas = mag.get_maintenance_activity_set()
        self.assertEqual(2, len(mas))
        ma = mas[0]
        self.assertEqual("Repeat Daily 1", ma.subject)
        self.assertEqual(True, ma.is_repeat_activity())
        self.assertEqual(False, ma.is_repeat_template())
        ma = mas[1]
        self.assertEqual("Test Maintenance Activity", ma.subject)
        self.assertEqual(False, ma.is_repeat_activity())
        self.assertEqual(False, ma.is_repeat_template())

        # make sure the DB makes sense.  One maintenance activity
        # group, 3 maintenance activities: one non-repeat, one repeat
        # template, one instantiated from the template.
        self.assertEqual(3, len(Maintenance_Activity.objects.all()))
        self.assertEqual(1, len(Maintenance_Activity_Group.objects.all()))

        # now publish the period on Wed (9/28)!
        p = me.periods.all().order_by("start")[1]
        p.publish()
        p.save()

        # make sure the DB makes sense.  Nothing should have changed.
        self.assertEqual(3, len(Maintenance_Activity.objects.all()))
        self.assertEqual(1, len(Maintenance_Activity_Group.objects.all()))

        # that really changes things!
        sch = get_gbt_schedule_events(start, end, timezone)
        # now there's nothing on monday, but there is on thursday 
        blankDays = [0,1,2,4,5]
        for i in blankDays: 
            self.assertEqual(exp[i], sch[i])
        # check out Wed.    
        calEvents = sch[3][1]
        self.assertEqual(1,len(calEvents))
        # see how the class has changed!
        self.assertEqual('CalEventFixedMaintenance', calEvents[0].__class__.__name__)
        mag = calEvents[0].contained
        # note how the .week is the same, but .date() has changed
        self.assertEqual("1 -- 2011-09-26; (2011-09-28); A; active; Repeat Daily 1, Test Maintenance Activity", mag.__unicode__())
        mas = mag.get_maintenance_activity_set()
        self.assertEqual(2, len(mas))
        ma = mas[0]
        self.assertEqual("Repeat Daily 1", ma.subject)
        self.assertEqual(True, ma.is_repeat_activity())
        self.assertEqual(False, ma.is_repeat_template())
        self.assertEqual(2, ma.repeat_template_id)
        ma = mas[1]
        self.assertEqual("Test Maintenance Activity", ma.subject)
        self.assertEqual(False, ma.is_repeat_activity())
        self.assertEqual(False, ma.is_repeat_template())
        
        # make sure the DB makes sense
        self.assertEqual(1, len(Maintenance_Activity_Group.objects.all()))
        # Woah!  check it out: 2 -> 3 because the original repeat stays
        # as is, but there's a new one for display on Thursday
        self.assertEqual(3, len(Maintenance_Activity.objects.all()))