示例#1
0
    def test_execute_with_unknown_exception(self):
        topic = 'Unit test topic'
        room = 'unit_room'
        actor = hipchat.Topic('Unit Test Action', {
            'topic': topic,
            'room': room
        })

        # Valid response test
        response_dict = {
            'error': {
                'code': 123,
                'type': 'Unknown',
                'message': 'Auth token not found'
            }
        }
        response_body = json.dumps(response_dict)
        http_response = httpclient.HTTPError(code=123, response=response_body)

        with mock.patch.object(actor, '_get_http_client') as m:
            m.return_value = FakeExceptionRaisingHTTPClientClass()
            m.return_value.response_value = http_response

            with self.assertRaises(exceptions.RecoverableActorFailure):
                yield actor._execute()
示例#2
0
    def test_execute_dry_mode_response(self):
        topic = 'Unit test topic'
        room = 'unit_room'
        actor = hipchat.Topic('Unit Test Action', {
            'topic': topic,
            'room': room
        })

        # Valid response test
        response_dict = {
            'success': {
                'code': 202,
                'type': 'Accepted',
                'message': 'It worked'
            }
        }
        response_body = json.dumps(response_dict)
        http_response = httpclient.HTTPResponse(
            httpclient.HTTPRequest('/'),
            code=202,
            buffer=io.StringIO(response_body))

        with mock.patch.object(actor, '_get_http_client') as m:
            m.return_value = FakeHTTPClientClass()
            m.return_value.response_value = http_response
            res = yield actor._execute()
            self.assertEqual(res, None)
示例#3
0
 def integration_test_execute_real(self):
     topic = 'Unit test topic'
     room = 'Operations'
     actor = hipchat.Topic('Unit Test Action', {
         'topic': topic,
         'room': room
     },
                           dry=True)
     res = yield actor.execute()
     self.assertEqual(res, None)
示例#4
0
    def integration_test_execute_with_invalid_creds(self):
        topic = 'Unit test topic'
        room = 'unit_room'
        actor = hipchat.Topic('Unit Test Action', {
            'topic': topic,
            'room': room
        },
                              dry=True)

        # Valid response test
        actor._token = 'Invalid'
        with self.assertRaises(exceptions.InvalidCredentials):
            yield actor.execute()
示例#5
0
    def test_execute_with_empty_response(self):
        topic = 'Unit test topic'
        room = 'unit_room'
        actor = hipchat.Topic(
            'Unit Test Action',
            {'topic': topic, 'room': room})

        @gen.coroutine
        def fake_set_topic(*args, **kwargs):
            raise gen.Return(None)
        actor._set_topic = fake_set_topic

        with self.assertRaises(exceptions.RecoverableActorFailure):
            yield actor._execute()
示例#6
0
    def integration_test_init_without_environment_creds(self):
        topic = 'Unit test topic'
        room = 'Operations'

        # Un-set the token now and make sure the init fails
        hipchat.TOKEN = None
        with self.assertRaises(exceptions.InvalidCredentials):
            hipchat.Topic('Unit Test Action', {
                'topic': topic,
                'room': room
            },
                          dry=True)

        # Reload the hipchat library to re-get the token
        importlib.reload(hipchat)
示例#7
0
    def test_execute(self):
        topic = 'Unit test topic'
        room = 'unit_room'
        actor = hipchat.Topic(
            'Unit Test Action',
            {'topic': topic, 'room': room})

        # Valid response test
        response_dict = {'status': 'sent'}
        response_body = json.dumps(response_dict)
        http_response = httpclient.HTTPResponse(
            httpclient.HTTPRequest('/'), code=200,
            buffer=StringIO.StringIO(response_body))

        with mock.patch.object(actor, '_get_http_client') as m:
            m.return_value = FakeHTTPClientClass()
            m.return_value.response_value = http_response
            res = yield actor._execute()
            self.assertEquals(res, None)