def test_fetch_one_from_service(self, m):
        # setup mocked request uris
        integration_id = 'P1ONR10'
        service_url = '{0}/services/{1}'.format(
            self.base_url,
            self.service_id,
        )

        integration_data = self.integration_data[0]

        integration_url = '{0}/integrations/{1}'.format(
            service_url, integration_data['id'])

        m.register_uri('GET',
                       integration_url,
                       json={'integration': integration_data},
                       complete_qs=False)

        m.register_uri('GET',
                       service_url,
                       json=self.service_data,
                       complete_qs=False)

        service = Service.fetch(self.service_id, api_key=self.api_key)
        integration = service.get_integration(integration_id)
        self.assertEqual(integration['service']['id'], service.id)
        self.assertEqual(
            integration['type'],
            'event_transformer_api_inbound_integration_reference')
        Integration.validate(integration._data)
        self.assertDictEqual(integration._data, integration_data)
    def test_delete_and_remove(self, m):
        integration_id = 'P1ONR10'
        service_url = '{0}/services/{1}'.format(
            self.base_url,
            self.service_id,
        )
        integration_data = self.integration_data[0]

        integration_url = '{0}/integrations/{1}'.format(
            service_url,
            integration_data['id']
        )

        m.register_uri(
            'GET',
            integration_url,
            json={'integration': integration_data},
            complete_qs=False
        )

        integration = Integration.fetch(integration_id,
                                        service=self.service_id)

        with self.assertRaises(InvalidEndpoint):
            Integration.delete(integration_id)

        with self.assertRaises(InvalidEndpointOperation):
            integration.remove()
    def test_validate_valid(self, m):
        integration_data = self.integration_data[0]
        Integration.validate(integration_data)

        for allowed_type in Integration.ALLOWED_INTEGRATION_TYPES:
            data = integration_data.copy()
            data['type'] = allowed_type
            Integration.validate(data)
    def test_validate_valid(self, m):
        integration_data = self.integration_data[0]
        Integration.validate(integration_data)

        for allowed_type in Integration.ALLOWED_INTEGRATION_TYPES:
            data = integration_data.copy()
            data['type'] = allowed_type
            Integration.validate(data)
    def test_validate_invalid(self, m):
        integration_data = self.integration_data[0].copy()
        integration_data['type'] = 'invalidtype'

        with self.assertRaises(AssertionError):
            Integration.validate(integration_data)

        with self.assertRaises(AssertionError):
            Integration.validate(None)
    def test_validate_invalid(self, m):
        integration_data = self.integration_data[0].copy()
        integration_data['type'] = 'invalidtype'

        with self.assertRaises(AssertionError):
            Integration.validate(integration_data)

        with self.assertRaises(AssertionError):
            Integration.validate(None)
    def test_fetch_with_service(self, m):
        # setup mocked request uris
        integration_id = 'P1ONR10'
        service_url = '{0}/services/{1}'.format(
            self.base_url,
            self.service_id,
        )

        integration_data = self.integration_data[0]

        integration_url = '{0}/integrations/{1}'.format(
            service_url, integration_data['id'])

        m.register_uri('GET',
                       integration_url,
                       json={'integration': integration_data},
                       complete_qs=False)

        m.register_uri('GET',
                       service_url,
                       json=self.service_data,
                       complete_qs=False)

        service = Service.fetch(self.service_id, api_key=self.api_key)
        integration = Integration.fetch(integration_id, service=service)
        self.assertDictEqual(integration._data, integration_data)
    def test_fetch_with_service(self, m):
        # setup mocked request uris
        integration_id = 'P1ONR10'
        service_url = '{0}/services/{1}'.format(
            self.base_url,
            self.service_id,
        )

        integration_data = self.integration_data[0]

        integration_url = '{0}/integrations/{1}'.format(
            service_url,
            integration_data['id']
        )

        m.register_uri(
            'GET',
            integration_url,
            json={'integration': integration_data},
            complete_qs=False
        )

        m.register_uri(
            'GET',
            service_url,
            json=self.service_data,
            complete_qs=False
        )

        service = Service.fetch(self.service_id, api_key=self.api_key)
        integration = Integration.fetch(integration_id, service=service)
        self.assertDictEqual(integration._data, integration_data)
    def test_create_valid(self, m):
        integration_data = self.integration_data[0].copy()
        integration_data.pop('created_at', None)
        integration_data.pop('id', None)

        service_url = '{0}/services/{1}'.format(
            self.base_url,
            self.service_id,
        )
        create_url = '{0}/integrations'.format(service_url)

        m.register_uri('POST',
                       create_url,
                       json={'integration': integration_data},
                       complete_qs=False)

        Integration.create(service=self.service_id, data=integration_data)
    def test_create_invalid(self, m):
        integration_data = self.integration_data[0]

        service_url = '{0}/services/{1}'.format(
            self.base_url,
            self.service_id,
        )

        integration_url = '{0}/integrations/{1}'.format(
            service_url, integration_data['id'])

        m.register_uri('POST',
                       integration_url,
                       json={'integration': integration_data},
                       complete_qs=False)

        with self.assertRaises(InvalidArguments):
            Integration.create(service=None, data=integration_data)
    def test_create_valid(self, m):
        integration_data = self.integration_data[0].copy()
        integration_data.pop('created_at', None)
        integration_data.pop('id', None)

        service_url = '{0}/services/{1}'.format(
            self.base_url,
            self.service_id,
        )
        create_url = '{0}/integrations'.format(service_url)

        m.register_uri(
            'POST',
            create_url,
            json={'integration': integration_data},
            complete_qs=False
        )

        Integration.create(service=self.service_id, data=integration_data)
    def test_create_invalid(self, m):
        integration_data = self.integration_data[0]

        service_url = '{0}/services/{1}'.format(
            self.base_url,
            self.service_id,
        )

        integration_url = '{0}/integrations/{1}'.format(
            service_url,
            integration_data['id']
        )

        m.register_uri(
            'POST',
            integration_url,
            json={'integration': integration_data},
            complete_qs=False
        )

        with self.assertRaises(InvalidArguments):
            Integration.create(service=None, data=integration_data)
    def test_fetch_one_from_service(self, m):
        # setup mocked request uris
        integration_id = 'P1ONR10'
        service_url = '{0}/services/{1}'.format(
            self.base_url,
            self.service_id,
        )

        integration_data = self.integration_data[0]

        integration_url = '{0}/integrations/{1}'.format(
            service_url,
            integration_data['id']
        )

        m.register_uri(
            'GET',
            integration_url,
            json={'integration': integration_data},
            complete_qs=False
        )

        m.register_uri(
            'GET',
            service_url,
            json=self.service_data,
            complete_qs=False
        )

        service = Service.fetch(self.service_id, api_key=self.api_key)
        integration = service.get_integration(integration_id)
        self.assertEqual(integration['service']['id'], service.id)
        self.assertEqual(
            integration['type'],
            'event_transformer_api_inbound_integration_reference'
        )
        Integration.validate(integration._data)
        self.assertDictEqual(integration._data, integration_data)
    def test_delete_and_remove(self, m):
        integration_id = 'P1ONR10'
        service_url = '{0}/services/{1}'.format(
            self.base_url,
            self.service_id,
        )
        integration_data = self.integration_data[0]

        integration_url = '{0}/integrations/{1}'.format(
            service_url, integration_data['id'])

        m.register_uri('GET',
                       integration_url,
                       json={'integration': integration_data},
                       complete_qs=False)

        integration = Integration.fetch(integration_id,
                                        service=self.service_id)

        with self.assertRaises(InvalidEndpoint):
            Integration.delete(integration_id)

        with self.assertRaises(InvalidEndpointOperation):
            integration.remove()