def test_get_system_report_time_range(self, mock_gmp: GmpMockFactory):
        """
        Test getting a system report with a start and end time as well
        as a sensorId.
        """
        mock_gmp.mock_response(
            'get_system_reports',
            self.make_mock_response(
                '',
                '2020-11-18T12:30:00Z',
                '2020-11-18T18:30:00Z',
            ),
        )

        self.login('foo', 'bar')

        response = self.query(
            '''
            query {
                systemReport(
                    name: "load"
                    sensorId: "08b69003-5fc2-4037-a479-93b440211c73"
                    startTime: "2020-11-18T12:30:00Z"
                    endTime: "2020-11-18T18:30:00Z"
                ) {
                    name
                    title
                    report {
                        format
                        startTime
                        endTime
                        duration
                        content
                    }
                }
            }
            '''
        )

        json = response.json()

        self.assertResponseNoErrors(response)

        system_report = json['data']['systemReport']
        self.assertEqual(system_report['name'], 'proc')
        self.assertEqual(system_report['title'], 'Processes')
        inner_report = system_report['report']
        self.assertEqual(inner_report['format'], 'png')
        self.assertEqual(inner_report['duration'], None)
        self.assertEqual(inner_report['startTime'], "2020-11-18T12:30:00+00:00")
        self.assertEqual(inner_report['endTime'], "2020-11-18T18:30:00+00:00")
        self.assertEqual(inner_report['content'], 'iVBORw0KGgoAAAA...')

        mock_gmp.gmp_protocol.get_system_reports.assert_called_with(
            name='load',
            slave_id='08b69003-5fc2-4037-a479-93b440211c73',
            duration=None,
            start_time=parse_datetime('2020-11-18T12:30:00Z'),
            end_time=parse_datetime('2020-11-18T18:30:00Z'),
        )
Beispiel #2
0
 def test_iso_like_format(self):
     dt = parse_datetime('2020-01-08T14:36:21Z')
     self.assertEqual(dt.day, 8)
     self.assertEqual(dt.month, 1)
     self.assertEqual(dt.year, 2020)
     self.assertEqual(dt.hour, 14)
     self.assertEqual(dt.minute, 36)
     self.assertEqual(dt.second, 21)
     self.assertEqual(dt.tzinfo.tzname(dt), 'UTC')
Beispiel #3
0
def get_datetime_from_element(element: XmlElement, name) -> Optional[datetime]:
    return parse_datetime(get_text_from_element(element, name))
Beispiel #4
0
 def resolve_date(root, _info):
     submitted = root.find('{*}dates/{*}submitted')
     if submitted is not None:
         return parse_datetime(submitted.get('date'))
     return None
Beispiel #5
0
 def resolve_date(root, _info):
     return parse_datetime(root.get('date'))
Beispiel #6
0
 def test_none(self):
     self.assertIsNone(parse_datetime(None))
     self.assertIsNone(parse_datetime(''))
Beispiel #7
0
 def resolve_end_time(root, _info):
     if root.attrib['end_time']:
         return parse_datetime(root.attrib['end_time'])
     else:
         return None