def test_get_options(self): create_sesshun() c = Client() response = c.get('/scheduler/sessions/options', dict(mode='project_codes')) self.assertEquals(response.content, '{"project codes": ["GBT09A-001"], "project ids": [1]}') response = c.get('/scheduler/sessions/options', dict(mode='session_handles', notcomplete='true', enabled='true')) self.assertEquals(response.content, '{"ids": [1], "session handles": ["Low Frequency With No RFI (GBT09A-001)"]}')
def setUp(self): super(PeriodsTestCase, self).setUp() # setup some periods self.start = datetime(2000, 1, 1, 0) self.end = self.start + timedelta(hours = 12) times = [(datetime(2000, 1, 1, 0), 5.0, "one", "S") , (datetime(2000, 1, 1, 5), 3.0, "two", "P") , (datetime(2000, 1, 1, 8), 4.0, "three", "S") ] self.ps = [] for start, dur, name, st in times: s = create_sesshun() s.name = name s.save() scheduled = dur if st == "S" else 0.0 pa = Period_Accounting(scheduled = scheduled) pa.save() state = Period_State.objects.get(abbreviation = st) p = Period( session = s , start = start , duration = dur , state = state , accounting = pa ) p.save() self.ps.append(p)
def setUp(self): # Don't use CAS for authentication during unit tests if "django_cas.backends.CASBackend" in settings.AUTHENTICATION_BACKENDS: settings.AUTHENTICATION_BACKENDS = settings.AUTHENTICATION_BACKENDS[:-1] if "django_cas.middleware.CASMiddleware" in settings.MIDDLEWARE_CLASSES: settings.MIDDLEWARE_CLASSES = settings.MIDDLEWARE_CLASSES[:-1] self.client = Client() self.auth_user = m.User.objects.create_user("dss", "*****@*****.**", "asdf5!") self.auth_user.is_staff = True self.auth_user.save() # create the user self.u = User( first_name="dss", # "Test" last_name="account", # "User" pst_id=3251 # , username = self.auth_user.username ) self.u.save() self.u.addRole("Administrator") self.u.addRole("Staff") self.client.login(username="******", password="******") self.sess = create_sesshun() self.fdata = {"session": self.sess.id, "date": "2009-06-01", "time": "00:00", "duration": 1.0, "backup": True} # create the dss period self.period = Period() adapter = PeriodHttpAdapter(self.period) adapter.init_from_post(self.fdata, "UTC") self.period.save()
def setUp(self): super(TestWinAlertNotifier, self).setUp() self.project = Project() self.project_adapter = ProjectHttpAdapter(self.project) pdata = {"semester" : "09A" , "pcode" : "AGBT09C-047" , "type" : "science" , "total_time" : "10.0" , "PSC_time" : "10.0" , "sem_time" : "10.0" , "grade" : "4.0" , "notes" : "notes" , "schd_notes" : "scheduler's notes" } self.project_adapter.update_from_post(pdata) # make a session self.sesshun = create_sesshun() self.sesshun.session_type = \ Session_Type.objects.get(type = "windowed") self.sesshun.project = self.project # make the first window self.window = Window(session = self.sesshun , total_time = 4.0 , complete = False) self.window.save() wr = WindowRange(window = self.window , start_date = date(2009, 4, 5) , duration = 7) wr.save()
def test_reportProjectSummary(self): filename = "DBReporter.txt" db = DBReporter(quiet=True, filename = filename) # see what the report looks like w/ just one empty project db.reportProjectSummary(Project.objects.all()) f = open(filename, 'r') lines = f.readlines() f.close() self.assertEquals(49, len(lines)) self.assertTrue(" 09A 1 0" in lines[21]) self.assertTrue(" 09B 0 0" in lines[22]) self.assertTrue("Total # of Projects: 1, Total Hrs: 0.00" in lines[2]) self.assertTrue("GBT09A-001 0 0.00" in lines[-2]) # now add a different project project = Project() project_adapter = ProjectHttpAdapter(project) pdata = {"semester" : "09B" , "pcode" : "GBT09B-047" , "type" : "science" , "total_time" : "10.0" , "PSC_time" : "10.0" , "sem_time" : "10.0" , "grade" : "4.0" , "notes" : "notes" , "schd_notes" : "scheduler's notes" } project_adapter.update_from_post(pdata) # make a session sesshun = create_sesshun() sesshun.allotment.total_time = 10.0 sesshun.allotment.save() sesshun.original_id = 123 sesshun.project = project sesshun.save() # init os.remove(filename) # now see what the report looks like db = DBReporter(quiet=True, filename = filename) db.reportProjectSummary(Project.objects.all()) f = open(filename, 'r') lines = f.readlines() f.close() self.assertEquals(50, len(lines)) self.assertTrue(" 09A 1 0" in lines[21]) self.assertTrue(" 09B 1 10.0" in lines[22]) self.assertTrue("Total # of Projects: 2, Total Hrs: 10.00" in lines[2]) self.assertTrue("GBT09A-001 0 0.00" in lines[-3]) self.assertTrue("GBT09B-047 1 10.00 123" in lines[-2])
def setUp(self): super(TestProposal, self).setUp() # this project has no allotments! self.project = DSSProject.objects.order_by('pcode').all()[0] # setup some periods self.start = datetime(2000, 1, 1, 0) self.end = self.start + timedelta(hours = 12) times = [(datetime(2000, 1, 1, 0), 5.0, "one") , (datetime(2000, 1, 1, 5), 3.0, "two") , (datetime(2000, 1, 1, 8), 4.0, "three") ] self.ps = [] state = DSSPeriod_State.objects.get(abbreviation = 'P') for start, dur, name in times: # each session has grade 4, time = 3 s = create_sesshun() s.name = name s.save() pa = DSSPeriod_Accounting(scheduled = dur) pa.save() p = DSSPeriod( session = s , start = start , duration = dur , state = state , accounting = pa ) p.save() self.ps.append(p) # Okay, now set up the corresponding proposal now = datetime.now().strftime("%Y-%m-%d %H:%M:%S") sqlResult = { 'PROP_ID' : self.project.pcode , 'PROPOSAL_TYPE' : 'Regular' , 'STATUS' : 'Draft' , 'SUBMITTED_DATE' : now , 'CREATED_DATE' : now , 'MODIFIED_DATE' : now , 'TITLE' : 'Lynrd Sknyrd' , 'ABSTRACT' : 'What song do you wanna hear?' , 'proposal_id' : 0 , 'JOINT_PROPOSAL_TYPE' : 'Not a joint Proposal' } proposal = Proposal.createFromSqlResult(sqlResult) proposal.dss_project = self.project proposal.setSemester(self.project.semester.semester) proposal.save() self.proposal = proposal self.ta = TimeAccounting()
def setUp(self): super(TestElectiveResource, self).setUp() self.client = Client() self.sesshun = create_sesshun() self.sesshun.session_type = Session_Type.get_type("elective") self.sesshun.save() dt = datetime(2009, 6, 1, 12, 15) dur = 5.0 self.deleted = Period_State.get_state("D") self.pending = Period_State.get_state("P") self.scheduled = Period_State.get_state("S") # create an elective to group the periods by self.elec = Elective(session = self.sesshun, complete = False) self.elec.save() # create 3 periods separated by a week pa = Period_Accounting(scheduled = 0.0) pa.save() self.period1 = Period(session = self.sesshun , start = dt , duration = dur , state = self.pending , accounting = pa , elective = self.elec ) self.period1.save() pa = Period_Accounting(scheduled = 0.0) pa.save() self.period2 = Period(session = self.sesshun , start = dt + timedelta(days = 7) , duration = dur , state = self.pending , accounting = pa , elective = self.elec ) self.period2.save() pa = Period_Accounting(scheduled = 0.0) pa.save() self.period3 = Period(session = self.sesshun , start = dt + timedelta(days = 2*7) , duration = dur , state = self.pending , accounting = pa , elective = self.elec ) self.period3.save() self.fdata = {"session": self.sesshun.id , "true": "false" }
def test_get_period_day_time2(self): # create a period s = create_sesshun() state = Period_State.objects.get(abbreviation = 'S') p = Period(session = s , start = datetime(2009, 9, 2, 1) , duration = 6.0 , state = state) p.save() day = datetime(2009, 9, 1) # make sure it comes back in the correct day for UTC data = { 'start' : day.strftime("%m/%d/%Y") , 'days' : 3 , 'tz' : 'UTC' } response = self.post('/schedule/public', data) calendar = response.context['calendar'] exp = [(datetime(2009, 9, 1), []), (datetime(2009, 9, 2), [CalEventPeriod(p)]), (datetime(2009, 9, 3), [])] self.assertEqual(exp, calendar) # make sure it comes back in the correct day for EST data = { 'start' : day.strftime("%m/%d/%Y") , 'days' : 3 , 'tz' : 'ET' } response = self.post('/schedule/public', data) calendar = response.context['calendar'] day1 = datetime(2009, 9, 1) day2 = datetime(2009, 9, 2) day3 = datetime(2009, 9, 3) exp = [(day1, [CalEventPeriod(p, p.start < day1, p.end() > day2, True, 'ET')]), (day2, [CalEventPeriod(p, p.start < day2, p.end() > day3, True, 'ET')]), (day3, [])] self.assertEqual(exp, calendar) # show the cutoff: '(..)' data = { 'start' : day.strftime("%m/%d/%Y") , 'days' : 1 , 'tz' : 'ET' } response = self.post('/schedule/public', data) calendar = response.context['calendar'] day1 = datetime(2009, 9, 1) ev1 = CalEventPeriod(p, p.start < day1, p.end() > (day1 + timedelta(1)), True, 'ET') exp = [(day1, [ev1])] self.assertEqual(exp, calendar) # clean up p.remove() #delete() s.delete()
def setUp(self): super(TestPeriodResource, self).setUp() self.rootURL = '/scheduler/periods' self.sess = create_sesshun() self.client = Client() self.fdata = {'session' : self.sess.id , 'date' : '2009-06-01' , 'time' : '00:00' , 'duration' : 1.0 , 'backup' : True} self.p = Period() adapter = PeriodHttpAdapter(self.p) adapter.init_from_post(self.fdata, 'UTC') self.p.save()
def test_importProposals(self): session = create_sesshun() # add some rcvrs rg = scheduler.Receiver_Group(session = session) rg.save() r = scheduler.Receiver.get_rcvr('L') rg.receivers.add(r) r = scheduler.Receiver.get_rcvr('X') rg.receivers.add(r) rg.save() backfill = BackfillImport(quiet = True) backfill.importProjects() for p in pht.Proposal.objects.all(): p.delete()
def testUpdate(self): up = UpdateEphemeris.UpdateEphemeris() up.quietReport = True # the no-op up.update() self.assertEquals(0, len(up.updates)) self.assertEquals(0, len(up.errors)) # let's observe Mars! s = create_sesshun() s.target.system = System.objects.get(name = "Ephemeris") s.target.source = "Mars" s.target.save() # make sure we update it! up.update() self.assertEquals(1, len(up.updates)) self.assertEquals(0, len(up.errors)) # now let's observe a famouse comet s.target.source = "129P/Shoemaker-Levy" s.target.save() up.update() self.assertEquals(1, len(up.updates)) self.assertEquals(0, len(up.errors)) # now let's observe a famouse asteroid s.target.source = "Europa" s.target.save() up.update() self.assertEquals(1, len(up.updates)) self.assertEquals(0, len(up.errors)) # make sure we catch errors! s.target.source = "Mr. Nubbles!" s.target.save() up.update() self.assertEquals(0, len(up.updates)) self.assertEquals(1, len(up.errors)) # cleanup s.delete()
def setUp(self): super(TestElecAlertNotifier, self).setUp() self.project = Project() self.project_adapter = ProjectHttpAdapter(self.project) pdata = {"semester" : "09A" , "pcode" : "AGBT09C-047" , "type" : "science" , "total_time" : "10.0" , "PSC_time" : "10.0" , "sem_time" : "10.0" , "grade" : "4.0" , "notes" : "notes" , "schd_notes" : "scheduler's notes" } self.project_adapter.update_from_post(pdata) # make a session self.sesshun = create_sesshun() self.sesshun.session_type = \ Session_Type.objects.get(type = "elective") self.sesshun.project = self.project # make an elective self.elective = Elective( session = self.sesshun , complete = False) self.elective.save() # make a couple of periods dates = ['2009-04-02', '2009-04-09'] for date in dates: fdata = {'session' : self.sesshun.id , 'date' : date , 'time' : '10:00' , 'duration' : 4.0 , 'backup' : False} period = Period() period_adapter = PeriodHttpAdapter(period) period_adapter.init_from_post(fdata, 'UTC') # link the period and elective period.elective = self.elective period.save()
def setUp(self): super(TestSessionHttpAdapter, self).setUp() self.s = create_sesshun() self.adapter = SessionHttpAdapter(self.s) self.exp = { "req_max": 6.0, "grade": 4.0, "time_of_day": "AnyTimeOfDay", "transit": False, "sem_time": 0.0, "lst_in": "", "id": 1L, "guaranteed": True, "lst_ex": "", "source": u"test source", "pcode": u"GBT09A-001", "authorized": True, "between": "0", "type": u"open", "req_min": 2.0, "total_time": 3.0, "coord_mode": u"J2000", "handle": u"Low Frequency With No RFI (GBT09A-001) 0", "complete": False, "project_complete": "No", "source_h": 3.8197186342054881, "source_v": 131.78029288008932, "trk_err_threshold": 0.20000000000000001, "PSC_time": 2.0, "freq": 6.0, "name": "Low Frequency With No RFI", "science": u"pulsar", "orig_ID": 0, "enabled": True, "remaining": 3.0, "xi_factor": 1.0, "gas": False, "receiver": "", "backup": False, }
def test_get_period_day_time(self): # create a period s = create_sesshun() state = Period_State.objects.get(abbreviation = 'S') p = Period(session = s , start = datetime(2009, 9, 9, 12) , duration = 1.0 , state = state) p.save() day = datetime(2009, 9, 9) # make sure it comes back in the correct day for UTC data = { 'start': day.strftime("%m/%d/%Y") , 'days' : 3 , 'tz' : 'UTC' } response = self.post('/schedule/public', data) calendar = response.context['calendar'] exp = [(datetime(2009, 9, 9, 0, 0), [CalEventPeriod(p)]), (datetime(2009, 9, 10, 0, 0), []), (datetime(2009, 9, 11, 0, 0), [])] self.assertEqual(exp, calendar) # make sure it comes back in the correct day for EST data = { 'start': day.strftime("%m/%d/%Y") , 'days' : 3 , 'tz' : 'ET' } response = self.post('/schedule/public', data) calendar = response.context['calendar'] exp = [(datetime(2009, 9, 9, 0, 0), [CalEventPeriod(p)]), (datetime(2009, 9, 10, 0, 0), []), (datetime(2009, 9, 11, 0, 0), [])] self.assertEqual(exp, calendar) # clean up p.remove() #delete() s.delete()
def setUp(self): super(TestWindowAlerts, self).setUp() # setup a project with: # * a user with blackouts # * a windowed session # * a number of windows # make the calendar look like this: # windows: # 4/5 - 4/12 5/5 - 5/12 # default periods: # 4/10 # user 1 blackouts: # 4/1 - 4/3 # 4/1 - 4/7 # 4/2 - 4/4 # user 1 blackouts: # 4/1 - 4/3 # 4/1 - 4/7 # blacked out time: # 4/1 - 4/7 self.project = Project() self.project_adapter = ProjectHttpAdapter(self.project) pdata = {"semester" : "09A" , "type" : "science" , "total_time" : "10.0" , "PSC_time" : "10.0" , "sem_time" : "10.0" , "grade" : "4.0" , "notes" : "notes" , "schd_notes" : "scheduler's notes" } self.project_adapter.update_from_post(pdata) # Create the first user (on project) self.user1 = User(sanctioned = True) self.user1.save() self.user1.addRole("Observer") self.investigator1 = Investigator(project = self.project , user = self.user1 , observer = True) self.investigator1.save() # Create the second user (on project) self.user2 = User(sanctioned = True) self.user2.save() self.user2.addRole("Observer") self.investigator2 = Investigator(project = self.project , user = self.user2 , observer = True) self.investigator2.save() # Create Investigator1's 3 blackouts. blackout11 = create_blackout(user = self.user1, repeat = 'Once', start = datetime(2009, 4, 1, 11), end = datetime(2009, 4, 3, 11)) blackout12 = create_blackout(user = self.user1, repeat = 'Once', start = datetime(2009, 4, 1, 18), end = datetime(2009, 4, 7, 18)) blackout13 = create_blackout(user = self.user1, repeat = 'Once', start = datetime(2009, 4, 2, 12), end = datetime(2009, 4, 7, 20)) # Create Investigator2's 2 blackouts. blackout21 = create_blackout(user = self.user2, repeat = 'Once', start = datetime(2009, 4, 1, 11), end = datetime(2009, 4, 3, 11)) blackout22 = create_blackout(user = self.user2, repeat = 'Once', start = datetime(2009, 4, 1, 18), end = datetime(2009, 4, 7, 13)) # make a session self.sesshun = create_sesshun() self.sesshun.session_type = \ Session_Type.objects.get(type = "windowed") self.sesshun.project = self.project # '1070' available 4/6 - 4/16 SessionHttpAdapter(self.sesshun).save_receivers('1070') self.sesshun.save() # make the first window self.window = Window(session = self.sesshun #, start_date = date(2009, 4, 5) #, duration = 7 , total_time = 4.0 , complete = False) self.window.save() wr = WindowRange(window = self.window , start_date = date(2009, 4, 5) , duration = 7) wr.save() # make a period for it fdata = {'session' : self.sesshun.id , 'date' : '2009-04-10' , 'time' : '10:00' , 'duration' : 4.0 , 'backup' : False} self.period = Period() self.period_adapter = PeriodHttpAdapter(self.period) self.period_adapter.init_from_post(fdata, 'UTC') # link the period and window self.period.window = self.window self.period.save() self.window.default_period = self.period self.window.save() # setup a receiver schedule # Schedule = 4/01/2009: 450, 600, 800 # 4/06/2009: 600, 800, 1070 # 4/11/2009: 800, 1070, 1_2 # 4/16/2009: 1070, 1_2, 2_3 # 4/21/2009: 1_2, 2_3, 4_6 # 4/26/2009: 2_3, 4_6, 8_10 # 5/01/2009: 4_6, 8_10, 12_18 # 5/06/2009: 8_10, 12_18, 18_26 # 5/11/2009: 12_18, 18_26, 26_40 start = datetime(2009, 4, 1, 0) end = datetime(2009, 6, 1, 0) rcvr_id = 3 for i in range(9): start_date = start + timedelta(5*i) for j in range(1, 4): rcvr_id = rcvr_id + 1 rs = Receiver_Schedule() rs.start_date = start_date rs.receiver = Receiver.objects.get(id = rcvr_id) rs.save() rcvr_id = rcvr_id - 2
def test_setPeriods_deletedElective(self): self.setupUser() # setup a deleted elective period s = create_sesshun() s.name = "wtf" s.session_type = Session_Type.objects.get(type = "elective") s.save() e = Elective(session = s, complete = False) e.save() pa = Period_Accounting(scheduled = 0) pa.save() p = Period(session = s , start = datetime(2000, 1, 1, 3) , duration = 1 , state = Period_State.get_state("D") , accounting = pa , elective = e ) p.save() self.ps.append(p) # now, we have to make these changes show up in the revisions system #self.sn.periodChanges.revisions.versions[p] = {} #self.sn.periodChanges.revisions.diffs[p] = {} self.addToTestRevisions(p) self.sn.setPeriods(self.ps, self.ps) for x in ["observer", "changed", "staff"]: staffEmail = self.sn.email_templates.getObject(x) #print "!!!!!!!!!!!!!!!!!!: ", x #print staffEmail.subject #print staffEmail.recipients #print staffEmail.body self.assertEquals([], self.sn.deletedPeriods) self.assertEquals([p], self.sn.deletedElectivePeriods) # test the staff email email = self.sn.email_templates.getObject("staff") exp = ["*****@*****.**" , "*****@*****.**" , "*****@*****.**" , '*****@*****.**' , '*****@*****.**' , '*****@*****.**'] self.assertEquals(exp, email.recipients) self.assertEquals(email.subject, "GBT schedule for Dec 31-Jan 01") partialBody = """Dec 31 19:00 | Jan 01 00:00 | 01:18 | 5.00 | Nubbles | | one Jan 01 00:00 | Jan 01 05:00 | 06:19 | 3.00 | Nubbles | | two Jan 01 03:00 | Jan 01 08:00 | 09:19 | 4.00 | Nubbles | | three""" #print email.body self.assertTrue(partialBody in email.body) self.assertTrue("Note: Project GBT09A-001 will not be scheduled on Dec 31 22:00" in email.body) # test the observer email email = self.sn.email_templates.getObject("observer") exp = [u'*****@*****.**', u'*****@*****.**', u'*****@*****.**'] self.assertEquals(exp, email.recipients) self.assertEquals("Your GBT project has been scheduled (Dec 31-Jan 01)", email.subject) self.assertTrue(partialBody in email.body) # test the changed email - no changes to scheduled period, # so no recipients email = self.sn.email_templates.getObject("changed") self.assertEquals([], email.recipients) # okay, now complete this elective, and make sure it # doesn't cause a notification e.complete = True e.save() self.sn.setPeriods(self.ps, self.ps) self.assertEquals([], self.sn.deletedPeriods) self.assertEquals([], self.sn.deletedElectivePeriods) email = self.sn.email_templates.getObject("staff") exp = ["*****@*****.**" , "*****@*****.**" , "*****@*****.**"] self.assertEquals(exp, email.recipients)
def test_examinePeriods_2(self): # now delete one of these periods #p = self.ps[0] self.ps[0].state = Period_State.get_state("D") self.ps[0].accounting.lost_time_other = self.ps[0].duration self.ps[0].save() # The above change must be caught by the scheduling notifier, # but teh revision system that it relies on doesn't work in unit # tests, so we have to fake it here. # What would the revision system look like? dt1 = self.start + timedelta(minutes = 1) dt2 = self.start + timedelta(minutes = 2) versions = [VersionTester(fields = {'state' : 2} , dt = dt1) , VersionTester(fields = {'state' : 3} , dt = dt2) ] self.setVersions(self.ps[0], versions) stateDiff = VersionDiff(dt = dt2 , field = 'state' , value1 = 2 , value2 = 3) self.setDiffs(self.ps[0], [stateDiff]) ltoDiff = VersionDiff(dt = dt2 , field = 'lost_time_other' , value1 = 0 , value2 = self.ps[0].duration) self.setDiffs(self.ps[0].accounting, [ltoDiff]) # also create a windowed session with default period that # is in the deleted state s = create_sesshun() s.session_type = Session_Type.objects.get(type = "windowed") s.save() # new default period for a window that is after the original periods start_time = self.ps[2].start + timedelta(hours = self.ps[2].duration) dur = 3.0 pa = Period_Accounting(scheduled = 0) pa.save() state = Period_State.objects.get(abbreviation = "D") p = Period( session = s , start = start_time , duration = dur , state = state , accounting = pa ) p.save() w1 = Window( session = s #, start_date = p.start.date() - timedelta(days = 7) #, duration = 10 # days , default_period = p ) w1.save() wr = WindowRange(window = w1 , start_date = p.start.date() - timedelta(days = 7) , duration = 10 # days ) wr.save() self.addToTestRevisions(p) ps = [self.ps[0] , self.ps[1] , self.ps[2] , p ] self.sn.examinePeriods(ps, ps) obsPeriods = self.ps[1:] self.assertEquals(obsPeriods, self.sn.observingPeriods) self.assertEquals([self.ps[0]], self.sn.changedPeriods) self.assertEquals([self.ps[0]], self.sn.deletedPeriods) self.assertEquals(1, len(self.sn.changes.keys())) self.assertEquals(2, len(self.sn.changes[self.ps[0]])) self.assertEquals(stateDiff, self.sn.changes[self.ps[0]][0]) self.assertEquals(ltoDiff, self.sn.changes[self.ps[0]][1])
def setUp(self): super(TestPeriodHttpAdapter, self).setUp() self.s = create_sesshun()
def setUp(self): super(TestElectiveAlerts, self).setUp() # setup a project with: # * two users with blackouts # * two elective sessions # * limited receiver availability # make the calendar look like this: # electives: # 1: 4/2,4/3,4/7,4/9 & 2: 4/8,4/14,4/20 # user 1 blackouts: # 4/1 - 4/3 # 4/5 - 4/7 # user 2 blackouts: # 4/1 - 4/4 # 4/3 - 4/8 self.project = Project() self.project_adapter = ProjectHttpAdapter(self.project) pdata = { "semester": "09A", "type": "science", "total_time": "10.0", "PSC_time": "10.0", "sem_time": "10.0", "grade": "4.0", "notes": "notes", "schd_notes": "scheduler's notes", } self.project_adapter.update_from_post(pdata) # Create the first user (on project) self.user1 = User(sanctioned=True) self.user1.save() self.investigator1 = Investigator(project=self.project, user=self.user1, observer=True) self.investigator1.save() # Create the second user (on project) self.user2 = User(sanctioned=True) self.user2.save() self.investigator2 = Investigator(project=self.project, user=self.user2, observer=True) self.investigator2.save() # Create Investigator1's blackouts. blackout11 = create_blackout( user=self.user1, repeat="Once", start=datetime(2009, 4, 1, 11), end=datetime(2009, 4, 4, 20) ) blackout12 = create_blackout( user=self.user1, repeat="Once", start=datetime(2009, 4, 5, 18), end=datetime(2009, 4, 8, 9) ) blackout13 = create_blackout( user=self.user1, repeat="Once", start=datetime(2009, 4, 9, 2), end=datetime(2009, 4, 17, 9) ) # Create Investigator2's blackouts. blackout21 = create_blackout( user=self.user2, repeat="Once", start=datetime(2009, 4, 1, 11), end=datetime(2009, 4, 5, 11) ) blackout22 = create_blackout( user=self.user2, repeat="Once", start=datetime(2009, 4, 6, 18), end=datetime(2009, 4, 8, 10) ) blackout23 = create_blackout( user=self.user2, repeat="Once", start=datetime(2009, 4, 13, 18), end=datetime(2009, 4, 25, 13) ) # make a session self.sesshun = create_sesshun() self.sesshun.session_type = Session_Type.objects.get(type="elective") self.sesshun.project = self.project # '1070' available 4/6 - 4/16 SessionHttpAdapter(self.sesshun).save_receivers("1070") self.sesshun.save() # make the first elective self.elective1 = Elective(session=self.sesshun, complete=False) self.elective1.save() # make periods for it (10:15-14:15) dates = ["2009-04-02", "2009-04-03", "2009-04-07", "2009-04-09"] for date in dates: fdata = {"session": self.sesshun.id, "date": date, "time": "10:00", "duration": 4.0, "backup": False} period = Period() period_adapter = PeriodHttpAdapter(period) period_adapter.init_from_post(fdata, "UTC") # link the period and elective period.elective = self.elective1 period.save() # make the second elective self.elective2 = Elective(session=self.sesshun, complete=False) self.elective2.save() # make periods for it (09:30-13:30) dates = ["2009-04-08", "2009-04-14", "2009-04-20"] for date in dates: fdata = {"session": self.sesshun.id, "date": date, "time": "09:30", "duration": 4.5, "backup": False} period = Period() period_adapter = PeriodHttpAdapter(period) period_adapter.init_from_post(fdata, "UTC") # link the period and elective period.elective = self.elective2 period.save() # setup a receiver schedule # Schedule = 4/01/2009: 450, 600, 800 # 4/06/2009: 600, 800, 1070 # 4/11/2009: 800, 1070, 1_2 # 4/16/2009: 1070, 1_2, 2_3 # 4/21/2009: 1_2, 2_3, 4_6 # 4/26/2009: 2_3, 4_6, 8_10 # 5/01/2009: 4_6, 8_10, 12_18 # 5/06/2009: 8_10, 12_18, 18_26 # 5/11/2009: 12_18, 18_26, 26_40 start = datetime(2009, 4, 1, 0) end = datetime(2009, 6, 1, 0) rcvr_id = 3 for i in range(9): start_date = start + timedelta(5 * i) for j in range(1, 4): rcvr_id = rcvr_id + 1 rs = Receiver_Schedule() rs.start_date = start_date rs.receiver = Receiver.objects.get(id=rcvr_id) rs.save() rcvr_id = rcvr_id - 2
def makeSession(self): # make a session self.sesshun = create_sesshun() self.sesshun.project = self.project self.sesshun.save()
def test_windowsReport(self): # first, nothing much to report wr = WindowsReport(filename = "WindowsReport.txt") wr.quietReport = True wr.report() report = "".join(wr.reportLines) self.assertEquals(468, len(report)) self.assertTrue("Number of Windowed Sessions w/ out Windows (VERY BAD): 0" in report) # now create a Windowed sesssion s = create_sesshun() s.session_type = Session_Type.objects.get(type = "windowed") s.name = "Win" s.save() # test wr.reportLines = [] wr.report() report = "".join(wr.reportLines) self.assertEquals(468, len(report)) self.assertTrue("Number of Windowed Sessions w/ out Windows (VERY BAD): 1" in report) # now create a window for it w = Window(session = s) w.save() # test wr.reportLines = [] wr.report() report = "".join(wr.reportLines) self.assertEquals(897, len(report)) self.assertTrue("Number of Windowed Sessions w/ out Windows (VERY BAD): 0" in report) # now create a period for it rg = Receiver_Group(session = s) L = (Receiver.get_rcvr('L')) rg.save() rg.receivers.add(L) rg.save() dt1 = datetime(2010, 1, 1, 0) scheduled = Period_State.get_state("S") dur = 2.0 pa = Period_Accounting(scheduled = dur) pa.save() p = Period(session = s , start = dt1 , duration = dur , state = scheduled , accounting = pa ) p.save() pg = Period_Receiver(period = p, receiver = L) pg.save() w.default_period = p w.save() # test wr.reportLines = [] wr.report() report = "".join(wr.reportLines) self.assertEquals(988, len(report)) self.assertTrue("Number of Windowed Sessions w/ out Windows (VERY BAD): 0" in report)
def test_restore_schedule_electives(self): "Similar to previous test, but with an elective session" # elective session s = create_sesshun() s.name = "elec" s.session_type = Session_Type.objects.get(type = "elective") s.save() # a window that covers test scheduling range e = Elective(session = s) #, total_time = 1.0) e.save() # a deleted elective period pending = Period_State.get_state("P") deleted = Period_State.get_state("D") pa = Period_Accounting(scheduled = 0) pa.save() p1 = Period(session = s , elective = e , start = datetime(2000, 1, 1, 12) , duration = 1.0 # hr , state = deleted , accounting = pa ) p1.save() # a pending elective period pa = Period_Accounting(scheduled = 0) pa.save() p2 = Period(session = s , elective = e , start = datetime(2000, 1, 1, 13) , duration = 1.0 # hr , state = pending , accounting = pa ) p2.save() # check the initial state ps = Period.objects.order_by("start") exp = ["S", "P", "S", "D", "P"] self.assertEquals(exp, [p.state.abbreviation for p in ps]) # have to use the scheduling range dt = self.ps[0].start - timedelta(days = 1) time = dt.strftime("%Y-%m-%d %H:%M:%S") tz = "ET" duration = 3 # days url = "/scheduler/periods/restore_schedule" response = Client().post(url, dict(start = time , tz = tz , duration = duration )) self.failUnless("ok" in response.content) # now, p1 should be gone, but p2 is still there ps = Period.objects.order_by("start") exp = ["S", "S", "P", "P"] self.assertEquals(exp, [p.state.abbreviation for p in ps]) exp = [5.0, 4.0, 0.0, 0.0] self.assertEquals(exp, [p.accounting.scheduled for p in ps]) self.assertEquals(p1.id, ps[2].id) self.assertEquals(p2.id, ps[3].id)
def test_restore_schedule_windows(self): "Similar to previous test, but with a windowed session" # windowed session s = create_sesshun() s.name = "win" s.session_type = Session_Type.objects.get(type = "windowed") s.save() # make this session not guaranteed notGuaranteed = Parameter.objects.get(name = "Not Guaranteed") op = Observing_Parameter(session = s, parameter = notGuaranteed) op.save() op.setValue(True) op.save() # a window that covers test scheduling range w = Window(session = s, total_time = 1.0) w.save() wstart = self.ps[0].start - timedelta(days = 3) wr = WindowRange(window = w , start_date = wstart , duration = 10 # days) ) wr.save() # a non-default period pending = Period_State.get_state("P") pa = Period_Accounting(scheduled = 0) pa.save() p1 = Period(session = s , window = w , start = datetime(2000, 1, 1, 12) , duration = 1.0 # hr , state = pending , accounting = pa ) p1.save() # a default period pa = Period_Accounting(scheduled = 0) pa.save() p2 = Period(session = s , window = w , start = datetime(2000, 1, 1, 13) , duration = 1.0 # hr , state = pending , accounting = pa ) p2.save() w.default_period = p2 w.save() # have to use the scheduling range dt = self.ps[0].start - timedelta(days = 1) time = dt.strftime("%Y-%m-%d %H:%M:%S") tz = "ET" duration = 3 # days url = "/scheduler/periods/restore_schedule" response = Client().post(url, dict(start = time , tz = tz , duration = duration )) self.failUnless("ok" in response.content) # now, p1 should be gone, but p2 is still there ps = Period.objects.order_by("start") exp = ["S", "S", "P"] self.assertEquals(exp, [p.state.abbreviation for p in ps]) exp = [5.0, 4.0, 0.0] self.assertEquals(exp, [p.accounting.scheduled for p in ps]) self.assertEquals(p2.id, ps[2].id) # now, put p2 in the deleted state, and watch it come back! deleted = Period_State.get_state("D") p2.state = deleted p2.save() ps = Period.objects.order_by("start") exp = ["S", "S", "D"] self.assertEquals(exp, [p.state.abbreviation for p in ps]) # restore the schedule response = Client().post(url, dict(start = time , tz = tz , duration = duration )) self.failUnless("ok" in response.content) # the default windowed period came back! ps = Period.objects.order_by("start") exp = ["S", "S", "P"] self.assertEquals(exp, [p.state.abbreviation for p in ps]) exp = [5.0, 4.0, 0.0] self.assertEquals(exp, [p.accounting.scheduled for p in ps]) self.assertEquals(p2.id, ps[2].id)
def setUp(self): super(TestReports, self).setUp() # setup some data to report on # period dates dt1 = datetime(2010, 1, 1, 0) dt2 = datetime(2010, 1, 1, 2) dt3 = datetime(2010, 1, 1, 5) dt4 = datetime(2010, 1, 1, 6) dt5 = datetime(2010, 1, 1, 8) scheduled = Period_State.get_state("S") # an L band sesssion self.s1 = create_sesshun() self.s1.name = "One" self.s1.save() rg = Receiver_Group(session = self.s1) L = (Receiver.get_rcvr('L')) rg.save() rg.receivers.add(L) rg.save() # two periods for this session dur = 2.0 pa = Period_Accounting(scheduled = dur) pa.save() p = Period(session = self.s1 , start = dt1 , duration = dur , state = scheduled , accounting = pa ) p.save() pg = Period_Receiver(period = p, receiver = L) pg.save() dur = 1.0 pa = Period_Accounting(scheduled = dur, lost_time_rfi = 0.5) pa.save() p = Period(session = self.s1 , start = dt3 , duration = dur , state = scheduled , accounting = pa ) p.save() pg = Period_Receiver(period = p, receiver = L) pg.save() # an X band session self.s2 = create_sesshun() self.s2.name = "Two" self.s2.save() rg = Receiver_Group(session = self.s2) rg.save() X = Receiver.get_rcvr('X') rg.receivers.add(X) rg.save() # two periods for this session dur = 3.0 pa = Period_Accounting(scheduled = dur) pa.save() p = Period(session = self.s2 , start = dt2 , duration = dur , state = scheduled , accounting = pa ) p.save() pg = Period_Receiver(period = p, receiver = X) pg.save() dur = 2.0 pa = Period_Accounting(scheduled = dur, not_billable = 0.5) pa.save() p = Period(session = self.s2 , start = dt4 , duration = dur , state = scheduled , accounting = pa ) p.save() pg = Period_Receiver(period = p, receiver = X) pg.save()
def test_passesInclusionCheck(self): """ Examples: (assume today is March 21, 2013) Grade A, last observed date January 1, 2012 ignore since more than one year ago Grade B, last observed date January 1, 2012 ignore since more than one year ago Grade C, last observed date January 1, 2012 ignore since more than one year ago Grade N ignore since never approved Grade N* ignore since never approved Grade W ignore since never approved Grade A, last observed date June 1, 2012 conflict possible Grade B, last observed date June 1, 2012 conflict possible Grade C, last observed date June 1, 2012 conflict possible Grade A, last observed date is blank conflict possible Grade B, last observed date is blank, project is open conflict possible Grade C, last observed date is blank, project is open conflict possible Grade B, last observed date is blank, project is complete/closed ignore - never observed Grade C, last observed date is blank, project is complete/closed ignore - never observed """ now = datetime(2013, 3, 21) sc = SourceConflicts(now = now) # create a new proposal w/ sessions and sources newP = createProposal() newS = self.createSession(newP) newS.receivers.add(Receiver.objects.get(abbreviation = 'Q')) newS.receivers.add(Receiver.objects.get(abbreviation = '800')) newS.save() src1 = self.createSrc(newP) src2 = self.createSrc(newP) for g in ['N', 'N*', 'W']: newS.grade = SessionGrade.objects.get(grade = g) newS.save() self.assertEqual(False, sc.passesInclusionCheck(newP, now = now)) # now see how it works for other grades; this depends on dss project: project = dss.Project.objects.order_by('pcode').all()[0] project.complete = False project.save() newP.dss_project = project newP.save() for g in ['A', 'B', 'C']: newS.grade = SessionGrade.objects.get(grade = g) newS.save() # clear the cache sc.includeProposals = {} self.assertEqual(True, sc.passesInclusionCheck(newP, now = now)) project.complete = True project.save() for g in ['B', 'C']: newS.grade = SessionGrade.objects.get(grade = g) newS.save() # clear the cache sc.includeProposals = {} self.assertEqual(False, sc.passesInclusionCheck(newP, now = now)) # now some tests using the last observed date. s = create_sesshun() s.project = newP.dss_project s.save() start = now - timedelta(days = 365 + 10) # more then a year ago dur = 1 pa = dss.Period_Accounting(scheduled = dur) pa.save() state = dss.Period_State.objects.get(abbreviation = 'S') p = dss.Period(session = s , start = start , duration = dur , state = state , accounting = pa ) p.save() for g in ['A', 'B', 'C']: newS.grade = SessionGrade.objects.get(grade = g) newS.save() # clear the cache sc.includeProposals = {} self.assertEqual(False, sc.passesInclusionCheck(newP, now = now)) start = now - timedelta(days = 365 - 10) # less then a year ago p.start = start p.save() for g in ['A', 'B', 'C']: newS.grade = SessionGrade.objects.get(grade = g) newS.save() # clear the cache sc.includeProposals = {} self.assertEqual(True, sc.passesInclusionCheck(newP, now = now))