def test_associate(self, m):
        incident_url = self.build_incident_url(self.first_incident_id)
        self.mock_get_request(m, incident_url, self.first_incident_data)

        second_incident_url = self.build_incident_url(self.second_incident_id)
        self.mock_get_request(m, second_incident_url,
                              self.second_incident_data)

        alert_url = self.build_alert_url(self.first_incident_id,
                                         self.first_alert_id)
        self.mock_get_request(m, alert_url, self.first_alert_data)
        self.mock_put_request(m, alert_url, self.first_alert_data)

        incident = Incident.fetch(self.first_incident_id, api_key=self.api_key)
        new_incident = Incident.fetch(self.second_incident_id,
                                      api_key=self.api_key)
        alert = Alert.fetch(self.first_alert_id,
                            incident,
                            None,
                            api_key=self.api_key)

        alert.associate('*****@*****.**', new_incident)

        last_request_json = m.last_request.json()
        self.assertEqual('PUT', m.last_request.method)
        self.assertEqual(self.first_alert_id, last_request_json['alert']['id'])
        self.assertEqual(self.second_incident_id,
                         last_request_json['alert']['incident']['id'])
    def test_create_note_valid(self, m):
        """Coverage for valid snooze."""
        query = {
            'limit': 1,
            'offset': 0,
        }
        url = self.url + '?{}'.format(urlencode(query))
        m.register_uri('GET', url, json=self.query_datas[0], complete_qs=True)
        incident = Incident.find_one(api_key=self.api_key)
        path = os.path.join(
            self.base_path,
            'sample_incident_create_note_response.json'
        )
        with open(path) as f:
            create_response = json.load(f)
            content = create_response['note']['content']

        url = '{0}/{1}/notes'.format(self.url, incident['id'])
        m.register_uri('POST', url, json=create_response, complete_qs=True)
        note = incident.create_note(
            '*****@*****.**',
            content=content
        )
        self.assertNotEqual(incident['id'], note['id'])
        self.assertEqual(content, note['content'])
    def test_fetch_one_from_incident(self, m):
        incident_url = self.build_incident_url(self.first_incident_id)
        self.mock_get_request(m, incident_url, self.first_incident_data)

        incident_alerts_url = self.build_incident_alerts_url(
            self.first_incident_id
        )
        self.mock_get_request(
            m,
            incident_alerts_url,
            {'alerts': [self.first_alert, self.second_alert, ]}
        )

        alert_url = self.build_alert_url(
            self.first_incident_id,
            self.first_alert_id
        )
        self.mock_get_request(m, alert_url, self.first_alert_data)

        incident = Incident.fetch(self.first_incident_id, api_key=self.api_key)
        alerts = incident.alerts()
        alert = Alert.fetch(
            self.first_alert_id,
            incident,
            None,
            api_key=self.api_key
        )

        incident_alert_ids = [i.id for i in alerts]
        self.assertIn(alert.id, incident_alert_ids)
    def test_fetch_one_from_incident(self, m):
        incident_url = self.build_incident_url(self.first_incident_id)
        self.mock_get_request(m, incident_url, self.first_incident_data)

        incident_alerts_url = self.build_incident_alerts_url(
            self.first_incident_id)
        self.mock_get_request(
            m, incident_alerts_url,
            {'alerts': [
                self.first_alert,
                self.second_alert,
            ]})

        alert_url = self.build_alert_url(self.first_incident_id,
                                         self.first_alert_id)
        self.mock_get_request(m, alert_url, self.first_alert_data)

        incident = Incident.fetch(self.first_incident_id, api_key=self.api_key)
        alerts = incident.alerts()
        alert = Alert.fetch(self.first_alert_id,
                            incident,
                            None,
                            api_key=self.api_key)

        incident_alert_ids = [i.id for i in alerts]
        self.assertIn(alert.id, incident_alert_ids)
    def test_associate(self, m):
        incident_url = self.build_incident_url(self.first_incident_id)
        self.mock_get_request(m, incident_url, self.first_incident_data)

        second_incident_url = self.build_incident_url(self.second_incident_id)
        self.mock_get_request(
            m,
            second_incident_url,
            self.second_incident_data
        )

        alert_url = self.build_alert_url(
            self.first_incident_id,
            self.first_alert_id
        )
        self.mock_get_request(m, alert_url, self.first_alert_data)
        self.mock_put_request(m, alert_url, self.first_alert_data)

        incident = Incident.fetch(self.first_incident_id, api_key=self.api_key)
        new_incident = Incident.fetch(
            self.second_incident_id,
            api_key=self.api_key
        )
        alert = Alert.fetch(
            self.first_alert_id,
            incident,
            None,
            api_key=self.api_key
        )

        alert.associate('*****@*****.**', new_incident)

        last_request_json = m.last_request.json()
        self.assertEqual('PUT', m.last_request.method)
        self.assertEqual(self.first_alert_id, last_request_json['alert']['id'])
        self.assertEqual(
            self.second_incident_id,
            last_request_json['alert']['incident']['id']
        )
    def test_reassign_invalid_from_email(self, m):
        """Coverage for using an invalid (cheaply validated) from email."""
        query = {
            'limit': 1,
            'offset': 0,
        }
        url = self.url + '?{}'.format(urlencode(query))
        m.register_uri('GET', url, json=self.query_datas[0], complete_qs=True)
        incident = Incident.find_one(api_key=self.api_key)

        with self.assertRaises(MissingFromEmail):
            incident.reassign(None, ['foo'])
        with self.assertRaises(MissingFromEmail):
            incident.reassign(1, ['foo'])
        with self.assertRaises(MissingFromEmail):
            incident.reassign(incident, ['foo'])
Esempio n. 7
0
    def test_reassign_invalid_from_email(self, m):
        """Coverage for using an invalid (cheaply validated) from email."""
        query = {
            'limit': 1,
            'offset': 0,
        }
        url = self.url + '?{}'.format(urlencode(query))
        m.register_uri('GET', url, json=self.query_datas[0], complete_qs=True)
        incident = Incident.find_one(api_key=self.api_key)

        with self.assertRaises(MissingFromEmail):
            incident.reassign(None, ['foo'])
        with self.assertRaises(MissingFromEmail):
            incident.reassign(1, ['foo'])
        with self.assertRaises(MissingFromEmail):
            incident.reassign(incident, ['foo'])
    def test_snooze_invalid_from_email(self, m):
        """Coverage for invalid from email for snooze."""
        query = {
            'limit': 1,
            'offset': 0,
        }
        url = self.url + '?{}'.format(urlencode(query))
        m.register_uri('GET', url, json=self.query_datas[0], complete_qs=True)
        incident = Incident.find_one(api_key=self.api_key)
        duration = 3600

        with self.assertRaises(MissingFromEmail):
            incident.snooze(None, duration=duration)
        with self.assertRaises(MissingFromEmail):
            incident.snooze(1, duration=duration)
        with self.assertRaises(MissingFromEmail):
            incident.snooze(incident, duration=duration)
Esempio n. 9
0
    def test_note_invalid_from_email(self, m):
        """Coverage for invalid from email for notes."""
        query = {
            'limit': 1,
            'offset': 0,
        }
        url = self.url + '?{}'.format(urlencode(query))
        m.register_uri('GET', url, json=self.query_datas[0], complete_qs=True)
        incident = Incident.find_one(api_key=self.api_key)
        content = 'Some notes, derp.'

        with self.assertRaises(MissingFromEmail):
            incident.create_note(None, content=content)
        with self.assertRaises(MissingFromEmail):
            incident.create_note(1, content=content)
        with self.assertRaises(MissingFromEmail):
            incident.create_note(incident, content=content)
Esempio n. 10
0
    def test_snooze_invalid_from_email(self, m):
        """Coverage for invalid from email for snooze."""
        query = {
            'limit': 1,
            'offset': 0,
        }
        url = self.url + '?{}'.format(urlencode(query))
        m.register_uri('GET', url, json=self.query_datas[0], complete_qs=True)
        incident = Incident.find_one(api_key=self.api_key)
        duration = 3600

        with self.assertRaises(MissingFromEmail):
            incident.snooze(None, duration=duration)
        with self.assertRaises(MissingFromEmail):
            incident.snooze(1, duration=duration)
        with self.assertRaises(MissingFromEmail):
            incident.snooze(incident, duration=duration)
    def test_note_invalid_from_email(self, m):
        """Coverage for invalid from email for notes."""
        query = {
            'limit': 1,
            'offset': 0,
        }
        url = self.url + '?{}'.format(urlencode(query))
        m.register_uri('GET', url, json=self.query_datas[0], complete_qs=True)
        incident = Incident.find_one(api_key=self.api_key)
        content = 'Some notes, derp.'

        with self.assertRaises(MissingFromEmail):
            incident.create_note(None, content=content)
        with self.assertRaises(MissingFromEmail):
            incident.create_note(1, content=content)
        with self.assertRaises(MissingFromEmail):
            incident.create_note(incident, content=content)
Esempio n. 12
0
    def test_resolve_valid(self, m):
        """Coverage for using a valid (cheaply validated) email."""
        query = {
            'limit': 1,
            'offset': 0,
        }
        url = self.url + '?{}'.format(urlencode(query))
        m.register_uri('GET', url, json=self.query_datas[0], complete_qs=True)
        incident = Incident.find_one(api_key=self.api_key)
        path = os.path.join(self.base_path,
                            'sample_incident_resolve_response.json')
        with open(path) as f:
            resolve_response = json.load(f)
            resolution = resolve_response['incidents'][0]['resolve_reason']

        url = '{0}/{1}'.format(self.url, incident['id'])
        m.register_uri('PUT', url, json=resolve_response, complete_qs=True)
        response = incident.resolve('*****@*****.**', resolution=resolution)
        self.assertEqual(incident['id'], response['incidents'][0]['id'])
Esempio n. 13
0
    def test_resolve_invalid_from_email(self, m):
        """Coverage for using an invalid (cheaply validated) from email."""
        query = {
            'limit': 1,
            'offset': 0,
        }
        url = self.url + '?{}'.format(urlencode(query))
        m.register_uri('GET', url, json=self.query_datas[0], complete_qs=True)
        incident = Incident.find_one(api_key=self.api_key)
        resolution = 'Incident was resolved manually.'

        with self.assertRaises(MissingFromEmail):
            incident.resolve(None)
        with self.assertRaises(MissingFromEmail):
            incident.resolve(None, resolution=resolution)
        with self.assertRaises(MissingFromEmail):
            incident.resolve(1, resolution=resolution)
        with self.assertRaises(MissingFromEmail):
            incident.resolve(incident, resolution=resolution)
    def test_resolve_invalid_from_email(self, m):
        """Coverage for using an invalid (cheaply validated) from email."""
        query = {
            'limit': 1,
            'offset': 0,
        }
        url = self.url + '?{}'.format(urlencode(query))
        m.register_uri('GET', url, json=self.query_datas[0], complete_qs=True)
        incident = Incident.find_one(api_key=self.api_key)
        resolution = 'Incident was resolved manually.'

        with self.assertRaises(MissingFromEmail):
            incident.resolve(None)
        with self.assertRaises(MissingFromEmail):
            incident.resolve(None, resolution=resolution)
        with self.assertRaises(MissingFromEmail):
            incident.resolve(1, resolution=resolution)
        with self.assertRaises(MissingFromEmail):
            incident.resolve(incident, resolution=resolution)
Esempio n. 15
0
    def test_reassign_invalid_user_id(self, m):
        """Coverage for using an invalid (cheaply validated) assignee."""
        query = {
            'limit': 1,
            'offset': 0,
        }
        url = self.url + '?{}'.format(urlencode(query))
        m.register_uri('GET', url, json=self.query_datas[0], complete_qs=True)
        incident = Incident.find_one(api_key=self.api_key)

        with self.assertRaises(InvalidArguments):
            incident.reassign('*****@*****.**', None)
        with self.assertRaises(InvalidArguments):
            incident.reassign('*****@*****.**', 1)
        with self.assertRaises(InvalidArguments):
            incident.reassign('*****@*****.**', 'foo')
        with self.assertRaises(InvalidArguments):
            incident.reassign('*****@*****.**', [None])
        with self.assertRaises(InvalidArguments):
            incident.reassign('*****@*****.**', [1])
Esempio n. 16
0
    def test_create_note_valid(self, m):
        """Coverage for valid snooze."""
        query = {
            'limit': 1,
            'offset': 0,
        }
        url = self.url + '?{}'.format(urlencode(query))
        m.register_uri('GET', url, json=self.query_datas[0], complete_qs=True)
        incident = Incident.find_one(api_key=self.api_key)
        path = os.path.join(self.base_path,
                            'sample_incident_create_note_response.json')
        with open(path) as f:
            create_response = json.load(f)
            content = create_response['note']['content']

        url = '{0}/{1}/notes'.format(self.url, incident['id'])
        m.register_uri('POST', url, json=create_response, complete_qs=True)
        note = incident.create_note('*****@*****.**', content=content)
        self.assertNotEqual(incident['id'], note['id'])
        self.assertEqual(content, note['content'])
Esempio n. 17
0
    def test_snooze_valid(self, m):
        """Coverage for valid snooze."""
        query = {
            'limit': 1,
            'offset': 0,
        }
        url = self.url + '?{}'.format(urlencode(query))
        m.register_uri('GET', url, json=self.query_datas[0], complete_qs=True)
        incident = Incident.find_one(api_key=self.api_key)
        path = os.path.join(self.base_path,
                            'sample_incident_snooze_response.json')
        duration = 3600
        with open(path) as f:
            snooze_response = json.load(f)

        url = '{0}/{1}/snooze'.format(self.url, incident['id'])
        m.register_uri('POST', url, json=snooze_response, complete_qs=True)
        snoozed_incident = incident.snooze('*****@*****.**',
                                           duration=duration)
        self.assertEqual(incident['id'], snoozed_incident['id'])
    def test_reassign_invalid_user_id(self, m):
        """Coverage for using an invalid (cheaply validated) assignee."""
        query = {
            'limit': 1,
            'offset': 0,
        }
        url = self.url + '?{}'.format(urlencode(query))
        m.register_uri('GET', url, json=self.query_datas[0], complete_qs=True)
        incident = Incident.find_one(api_key=self.api_key)

        with self.assertRaises(InvalidArguments):
            incident.reassign('*****@*****.**', None)
        with self.assertRaises(InvalidArguments):
            incident.reassign('*****@*****.**', 1)
        with self.assertRaises(InvalidArguments):
            incident.reassign('*****@*****.**', 'foo')
        with self.assertRaises(InvalidArguments):
            incident.reassign('*****@*****.**', [None])
        with self.assertRaises(InvalidArguments):
            incident.reassign('*****@*****.**', [1])
    def test_resolve_valid(self, m):
        """Coverage for using a valid (cheaply validated) email."""
        query = {
            'limit': 1,
            'offset': 0,
        }
        url = self.url + '?{}'.format(urlencode(query))
        m.register_uri('GET', url, json=self.query_datas[0], complete_qs=True)
        incident = Incident.find_one(api_key=self.api_key)
        path = os.path.join(
            self.base_path,
            'sample_incident_resolve_response.json'
        )
        with open(path) as f:
            resolve_response = json.load(f)
            resolution = resolve_response['incidents'][0]['resolve_reason']

        url = '{0}/{1}'.format(self.url, incident['id'])
        m.register_uri('PUT', url, json=resolve_response, complete_qs=True)
        response = incident.resolve('*****@*****.**', resolution=resolution)
        self.assertEqual(incident['id'], response['incidents'][0]['id'])
    def test_snooze_valid(self, m):
        """Coverage for valid snooze."""
        query = {
            'limit': 1,
            'offset': 0,
        }
        url = self.url + '?{}'.format(urlencode(query))
        m.register_uri('GET', url, json=self.query_datas[0], complete_qs=True)
        incident = Incident.find_one(api_key=self.api_key)
        path = os.path.join(
            self.base_path,
            'sample_incident_snooze_response.json'
        )
        duration = 3600
        with open(path) as f:
            snooze_response = json.load(f)

        url = '{0}/{1}/snooze'.format(self.url, incident['id'])
        m.register_uri('POST', url, json=snooze_response, complete_qs=True)
        snoozed_incident = incident.snooze(
            '*****@*****.**',
            duration=duration
        )
        self.assertEqual(incident['id'], snoozed_incident['id'])