def test_request_intervals_for_staff_at_location(self):
     request_dict = self.request.as_dict()
     request_dict['location']['site'] = 'tst'
     request_dict['location']['enclosure'] = 'domd'
     request_dict['location']['telescope'] = '1m0a'
     request_dict['configurations'][0]['instrument_type'] = '1M0-SCICAM-SBAG'
     intervals = get_filtered_rise_set_intervals_by_site(request_dict, is_staff=False).get('tst', [])
     self.assertEqual(intervals, [])
     intervals = get_filtered_rise_set_intervals_by_site(request_dict, is_staff=True).get('tst', [])
     self.assertNotEqual(intervals, [])
    def test_request_intervals_for_multiple_targets_intersected(self):
        request_dict = self.request.as_dict()
        intervals = get_filtered_rise_set_intervals_by_site(request_dict).get('tst', [])
        truth_intervals = [
            (datetime(2016, 10, 1, 0, 0, tzinfo=timezone.utc),
            datetime(2016, 10, 1, 3, 20, 31, 366820, tzinfo=timezone.utc)),
            (datetime(2016, 10, 1, 19, 13, 14, 944205, tzinfo=timezone.utc),
            datetime(2016, 10, 2, 3, 19, 9, 181040, tzinfo=timezone.utc)),
            (datetime(2016, 10, 2, 19, 9, 19, 241762, tzinfo=timezone.utc),
            datetime(2016, 10, 3, 3, 17, 47, 117329, tzinfo=timezone.utc)),
            (datetime(2016, 10, 3, 19, 5, 23, 539011, tzinfo=timezone.utc),
            datetime(2016, 10, 4, 3, 16, 25, 202612, tzinfo=timezone.utc)),
            (datetime(2016, 10, 4, 19, 1, 27, 835928, tzinfo=timezone.utc),
            datetime(2016, 10, 5, 3, 15, 3, 464340, tzinfo=timezone.utc)),
            (datetime(2016, 10, 5, 18, 57, 32, 132481, tzinfo=timezone.utc),
            datetime(2016, 10, 6, 3, 12, 5, 895932, tzinfo=timezone.utc)),
            (datetime(2016, 10, 6, 18, 53, 36, 428629, tzinfo=timezone.utc),
            datetime(2016, 10, 7, 3, 8, 10, 183626, tzinfo=timezone.utc)),
            (datetime(2016, 10, 7, 18, 49, 40, 724307, tzinfo=timezone.utc),
            datetime(2016, 10, 8, 0, 0, tzinfo=timezone.utc))
        ]

        self.assertEqual(intervals, truth_intervals)
        # now create get the intervals for a request with the second target
        configuration2 = deepcopy(request_dict['configurations'][0])
        configuration2['target']['ra'] = 85.0  # change the RA so the target has different visibility
        request_dict2 = deepcopy(request_dict)
        request_dict2['configurations'][0] = configuration2
        intervals2 = get_filtered_rise_set_intervals_by_site(request_dict2).get('tst', [])
        truth_intervals2 = [
            (datetime(2016, 10, 1, 0, 0, tzinfo=timezone.utc), datetime(2016, 10, 1, 3, 20, 31, 366820, tzinfo=timezone.utc)),
            (datetime(2016, 10, 1, 23, 24, 4, 392218, tzinfo=timezone.utc), datetime(2016, 10, 2, 3, 19, 9, 181040, tzinfo=timezone.utc)),
            (datetime(2016, 10, 2, 23, 20, 8, 717423, tzinfo=timezone.utc), datetime(2016, 10, 3, 3, 17, 47, 117329, tzinfo=timezone.utc)),
            (datetime(2016, 10, 3, 23, 16, 13, 42308, tzinfo=timezone.utc), datetime(2016, 10, 4, 3, 16, 25, 202612, tzinfo=timezone.utc)),
            (datetime(2016, 10, 4, 23, 12, 17, 366627, tzinfo=timezone.utc), datetime(2016, 10, 5, 3, 15, 3, 464340, tzinfo=timezone.utc)),
            (datetime(2016, 10, 5, 23, 8, 21, 690204, tzinfo=timezone.utc), datetime(2016, 10, 6, 3, 13, 41, 930536, tzinfo=timezone.utc)),
            (datetime(2016, 10, 6, 23, 4, 26, 12943, tzinfo=timezone.utc), datetime(2016, 10, 7, 3, 12, 20, 629833, tzinfo=timezone.utc)),
            (datetime(2016, 10, 7, 23, 0, 30, 334810, tzinfo=timezone.utc), datetime(2016, 10, 8, 0, 0, tzinfo=timezone.utc)),
        ]
        self.assertEqual(intervals2, truth_intervals2)

        # now get the intervals for both targets combined in the request and verify they are intersected
        request_dict3 = deepcopy(request_dict)
        request_dict3['configurations'].append(configuration2)
        intervals3 = get_filtered_rise_set_intervals_by_site(request_dict3).get('tst', [])
        truth_intervals_combined = Intervals(truth_intervals).intersect([Intervals(truth_intervals2)]).toTupleList()
        self.assertEqual(intervals3, truth_intervals_combined)
    def test_request_intervals_for_one_week_overlapping_downtime(self, downtime_data):
        downtime_data.return_value = [{'start': '2016-10-01T22:00:00Z',
                                       'end': '2016-10-04T00:00:00Z',
                                       'site': 'tst',
                                       'enclosure': 'doma',
                                       'telescope': '1m0a',
                                       'instrument_type': '',
                                       'reason': 'Whatever'},
                                      {'start': '2016-10-01T22:00:00Z',
                                       'end': '2016-10-04T00:00:00Z',
                                       'site': 'tst',
                                       'enclosure': 'domb',
                                       'telescope': '1m0a',
                                       'instrument_type': '',
                                       'reason': 'Whatever'},
                                      {'start': '2016-10-02T00:00:00Z',
                                       'end': '2016-10-03T00:00:00Z',
                                       'site': 'tst',
                                       'enclosure': 'doma',
                                       'telescope': '1m0a',
                                       'instrument_type': '',
                                       'reason': 'Whatever'},
                                      {'start': '2016-10-02T00:00:00Z',
                                       'end': '2016-10-03T00:00:00Z',
                                       'site': 'tst',
                                       'enclosure': 'domb',
                                       'telescope': '1m0a',
                                       'instrument_type': '',
                                       'reason': 'Whatever'},
                                      {'start': '2016-10-02T00:00:00Z',
                                       'end': '2016-10-06T00:00:00Z',
                                       'site': 'tst',
                                       'enclosure': 'doma',
                                       'telescope': '1m0a',
                                       'instrument_type': '',
                                       'reason': 'Whatever'},
                                      {'start': '2016-10-02T00:00:00Z',
                                       'end': '2016-10-06T00:00:00Z',
                                       'site': 'tst',
                                       'enclosure': 'domb',
                                       'telescope': '1m0a',
                                       'instrument_type': '',
                                       'reason': 'Whatever'}
                                      ]

        intervals = get_filtered_rise_set_intervals_by_site(self.request.as_dict()).get('tst', [])

        truth_intervals = [(datetime(2016, 10, 1, 0, 0, tzinfo=timezone.utc),
                            datetime(2016, 10, 1, 3, 20, 31, 366820, tzinfo=timezone.utc)),
                           (datetime(2016, 10, 1, 19, 13, 14, 944205, tzinfo=timezone.utc),
                            datetime(2016, 10, 1, 22, 0, 0, tzinfo=timezone.utc)),
                           (datetime(2016, 10, 6, 0, 0, 0, tzinfo=timezone.utc),
                            datetime(2016, 10, 6, 3, 12, 5, 895932, tzinfo=timezone.utc)),
                           (datetime(2016, 10, 6, 18, 53, 36, 428629, tzinfo=timezone.utc),
                            datetime(2016, 10, 7, 3, 8, 10, 183626, tzinfo=timezone.utc)),
                           (datetime(2016, 10, 7, 18, 49, 40, 724307, tzinfo=timezone.utc),
                            datetime(2016, 10, 8, 0, 0, tzinfo=timezone.utc))]

        self.assertEqual(intervals, truth_intervals)
    def test_request_intervals_for_multiple_targets_empty_if_one_is_empty(self):
        request_dict = self.request.as_dict()

        # now create get the intervals for a request with the second target that isn't visible
        configuration2 = deepcopy(request_dict['configurations'][0])
        configuration2['target']['dec'] = 70.0  # change the DEC so the target isn't visible
        request_dict2 = deepcopy(request_dict)
        request_dict2['configurations'][0] = configuration2
        intervals = get_filtered_rise_set_intervals_by_site(request_dict2).get('tst', [])
        truth_intervals = [
        ]
        self.assertEqual(intervals, truth_intervals)

        # now get the intervals for both targets combined in the request and verify they are intersected and empty
        request_dict3 = deepcopy(request_dict)
        request_dict3['configurations'].append(configuration2)
        intervals3 = get_filtered_rise_set_intervals_by_site(request_dict3).get('tst', [])
        self.assertEqual(intervals3, [])
    def test_request_intervals_for_one_week_downtime_out_of_range(self, downtime_data):
        downtime_data.return_value = [{'start': '2016-09-01T22:00:00Z',
                                       'end': '2016-10-01T00:00:00Z',
                                       'site': 'tst',
                                       'enclosure': 'doma',
                                       'telescope': '1m0a',
                                       'instrument_type': '',
                                       'reason': 'Whatever'},
                                      {'start': '2016-09-01T22:00:00Z',
                                       'end': '2016-10-01T00:00:00Z',
                                       'site': 'tst',
                                       'enclosure': 'domb',
                                       'telescope': '1m0a',
                                       'instrument_type': '',
                                       'reason': 'Whatever'},
                                      {'start': '2016-10-08T00:00:00Z',
                                       'end': '2016-11-01T00:00:00Z',
                                       'site': 'tst',
                                       'enclosure': 'doma',
                                       'telescope': '1m0a',
                                       'instrument_type': '',
                                       'reason': 'Whatever'},
                                      {'start': '2016-10-08T00:00:00Z',
                                       'end': '2016-11-01T00:00:00Z',
                                       'site': 'tst',
                                       'enclosure': 'domb',
                                       'telescope': '1m0a',
                                       'instrument_type': '',
                                       'reason': 'Whatever'}
                                      ]

        intervals = get_filtered_rise_set_intervals_by_site(self.request.as_dict()).get('tst', [])

        truth_intervals = [(datetime(2016, 10, 1, 0, 0, tzinfo=timezone.utc),
                            datetime(2016, 10, 1, 3, 20, 31, 366820, tzinfo=timezone.utc)),
                           (datetime(2016, 10, 1, 19, 13, 14, 944205, tzinfo=timezone.utc),
                            datetime(2016, 10, 2, 3, 19, 9, 181040, tzinfo=timezone.utc)),
                           (datetime(2016, 10, 2, 19, 9, 19, 241762, tzinfo=timezone.utc),
                            datetime(2016, 10, 3, 3, 17, 47, 117329, tzinfo=timezone.utc)),
                           (datetime(2016, 10, 3, 19, 5, 23, 539011, tzinfo=timezone.utc),
                            datetime(2016, 10, 4, 3, 16, 25, 202612, tzinfo=timezone.utc)),
                           (datetime(2016, 10, 4, 19, 1, 27, 835928, tzinfo=timezone.utc),
                            datetime(2016, 10, 5, 3, 15, 3, 464340, tzinfo=timezone.utc)),
                           (datetime(2016, 10, 5, 18, 57, 32, 132481, tzinfo=timezone.utc),
                            datetime(2016, 10, 6, 3, 12, 5, 895932, tzinfo=timezone.utc)),
                           (datetime(2016, 10, 6, 18, 53, 36, 428629, tzinfo=timezone.utc),
                            datetime(2016, 10, 7, 3, 8, 10, 183626, tzinfo=timezone.utc)),
                           (datetime(2016, 10, 7, 18, 49, 40, 724307, tzinfo=timezone.utc),
                            datetime(2016, 10, 8, 0, 0, tzinfo=timezone.utc))]

        self.assertEqual(intervals, truth_intervals)
    def test_request_intervals_for_one_week(self):
        intervals = get_filtered_rise_set_intervals_by_site(self.request.as_dict()).get('tst', [])

        truth_intervals = [(datetime(2016, 10, 1, 0, 0, tzinfo=timezone.utc),
                            datetime(2016, 10, 1, 3, 20, 31, 366820, tzinfo=timezone.utc)),
                           (datetime(2016, 10, 1, 19, 13, 14, 944205, tzinfo=timezone.utc),
                            datetime(2016, 10, 2, 3, 19, 9, 181040, tzinfo=timezone.utc)),
                           (datetime(2016, 10, 2, 19, 9, 19, 241762, tzinfo=timezone.utc),
                            datetime(2016, 10, 3, 3, 17, 47, 117329, tzinfo=timezone.utc)),
                           (datetime(2016, 10, 3, 19, 5, 23, 539011, tzinfo=timezone.utc),
                            datetime(2016, 10, 4, 3, 16, 25, 202612, tzinfo=timezone.utc)),
                           (datetime(2016, 10, 4, 19, 1, 27, 835928, tzinfo=timezone.utc),
                            datetime(2016, 10, 5, 3, 15, 3, 464340, tzinfo=timezone.utc)),
                           (datetime(2016, 10, 5, 18, 57, 32, 132481, tzinfo=timezone.utc),
                            datetime(2016, 10, 6, 3, 12, 5, 895932, tzinfo=timezone.utc)),
                           (datetime(2016, 10, 6, 18, 53, 36, 428629, tzinfo=timezone.utc),
                            datetime(2016, 10, 7, 3, 8, 10, 183626, tzinfo=timezone.utc)),
                           (datetime(2016, 10, 7, 18, 49, 40, 724307, tzinfo=timezone.utc),
                            datetime(2016, 10, 8, 0, 0, tzinfo=timezone.utc))]

        self.assertEqual(intervals, truth_intervals)
    def test_request_intervals_for_one_week_all_downtime(self, downtime_data):
        downtime_data.return_value = [{'start': '2016-09-01T22:00:00Z',
                                       'end': '2016-11-03T00:00:00Z',
                                       'site': 'tst',
                                       'enclosure': 'doma',
                                       'telescope': '1m0a',
                                       'instrument_type': '',
                                       'reason': 'Whatever'},
                                      {'start': '2016-09-01T22:00:00Z',
                                       'end': '2016-11-03T00:00:00Z',
                                       'site': 'tst',
                                       'enclosure': 'domb',
                                       'telescope': '1m0a',
                                       'instrument_type': '',
                                       'reason': 'Whatever'}
                                      ]

        intervals = get_filtered_rise_set_intervals_by_site(self.request.as_dict()).get('tst', [])

        truth_intervals = []

        self.assertEqual(intervals, truth_intervals)
Esempio n. 8
0
    def test_request_intervals_for_one_week_removes_lots_of_downtime(
            self, downtime_data):
        downtime_data.return_value = [
            {
                'start': '2016-10-01T22:00:00Z',
                'end': '2016-10-03T00:00:00Z',
                'site': 'tst',
                'observatory': 'doma',
                'telescope': '1m0a',
                'reason': 'Whatever'
            },
            {
                'start': '2016-10-01T22:00:00Z',
                'end': '2016-10-03T00:00:00Z',
                'site': 'tst',
                'observatory': 'domb',
                'telescope': '1m0a',
                'reason': 'Whatever'
            },
            {
                'start': '2016-10-07T12:00:00Z',
                'end': '2017-10-03T00:00:00Z',
                'site': 'tst',
                'observatory': 'doma',
                'telescope': '1m0a',
                'reason': 'Whatever'
            },
            {
                'start': '2016-10-07T12:00:00Z',
                'end': '2017-10-03T00:00:00Z',
                'site': 'tst',
                'observatory': 'domb',
                'telescope': '1m0a',
                'reason': 'Whatever'
            },
            {
                'start': '2016-10-02T12:00:00Z',
                'end': '2016-10-06T00:00:00Z',
                'site': 'tst',
                'observatory': 'doma',
                'telescope': '1m0a',
                'reason': 'Whatever'
            },
            {
                'start': '2016-10-02T12:00:00Z',
                'end': '2016-10-06T00:00:00Z',
                'site': 'tst',
                'observatory': 'domb',
                'telescope': '1m0a',
                'reason': 'Whatever'
            },
        ]

        intervals = get_filtered_rise_set_intervals_by_site(
            self.request.as_dict()).get('tst', [])

        truth_intervals = [(datetime(2016, 10, 1, 0, 0, tzinfo=timezone.utc),
                            datetime(2016,
                                     10,
                                     1,
                                     3,
                                     20,
                                     31,
                                     366820,
                                     tzinfo=timezone.utc)),
                           (datetime(2016,
                                     10,
                                     1,
                                     19,
                                     13,
                                     14,
                                     944205,
                                     tzinfo=timezone.utc),
                            datetime(2016,
                                     10,
                                     1,
                                     22,
                                     0,
                                     0,
                                     tzinfo=timezone.utc)),
                           (datetime(2016, 10, 6, 0, 0, 0,
                                     tzinfo=timezone.utc),
                            datetime(2016,
                                     10,
                                     6,
                                     3,
                                     12,
                                     5,
                                     895932,
                                     tzinfo=timezone.utc)),
                           (datetime(2016,
                                     10,
                                     6,
                                     18,
                                     53,
                                     36,
                                     428629,
                                     tzinfo=timezone.utc),
                            datetime(2016,
                                     10,
                                     7,
                                     3,
                                     8,
                                     10,
                                     183626,
                                     tzinfo=timezone.utc))]

        self.assertEqual(intervals, truth_intervals)