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_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']
        )