Exemplo n.º 1
0
    def test_execute_with_unknown_exception(self):
        message = 'Unit test message'
        room = 'unit_room'
        actor = hipchat.Message('Unit Test Action', {
            'message': message,
            '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()
Exemplo n.º 2
0
    def test_build_potential_args(self):
        potential_args = {
            'foo': 'bar',
            'baz': 'bat',
        }
        expected_args = dict(potential_args)
        expected_args['auth_token'] = hipchat.TOKEN
        expected_args['from'] = hipchat.NAME

        expected_dry_args = dict(expected_args)
        expected_dry_args['auth_test'] = True

        message = 'Unit test message'
        room = 'Operations'
        actor = hipchat.Message(
            'Unit Test Action',
            {'message': message, 'room': room})

        # Regular run
        args = actor._build_potential_args(potential_args)
        self.assertEquals(args, expected_args)

        # Now in dry mode
        actor._dry = True
        args = actor._build_potential_args(potential_args)
        self.assertEquals(args, expected_dry_args)
Exemplo n.º 3
0
    def test_execute_with_403(self):
        message = 'Unit test message'
        room = 'unit_room'
        actor = hipchat.Message('Unit Test Action', {
            'message': message,
            'room': room
        })

        # Valid response test
        response_dict = {
            'error': {
                'code': 403,
                'type': 'Forbidden',
                'message': 'Hit the rate limit'
            }
        }
        response_body = json.dumps(response_dict)
        http_response = httpclient.HTTPError(code=403, 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.InvalidCredentials):
                yield actor._execute()
Exemplo n.º 4
0
    def test_execute_dry_mode_response(self):
        message = 'Unit test message'
        room = 'unit_room'
        actor = hipchat.Message('Unit Test Action', {
            'message': message,
            '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)
Exemplo n.º 5
0
 def test_init_without_environment_creds(self):
     # Un-set the token now and make sure the init fails
     hipchat.TOKEN = None
     with self.assertRaises(exceptions.InvalidCredentials):
         hipchat.Message('Unit Test Action', {
             'room': 'test',
             'message': 'test'
         })
Exemplo n.º 6
0
    def test_validate_from_name(self):
        message = 'Unit test message'
        room = 'Operations'
        actor = hipchat.Message(
            'Unit Test Action',
            {'message': message, 'room': room})

        # Regular run
        self.assertEquals('Foo Bar', actor._validate_from_name('Foo Bar'))
Exemplo n.º 7
0
 def integration_test_execute_real(self):
     message = 'Unit test message'
     room = 'Operations'
     actor = hipchat.Message('Unit Test Action', {
         'message': message,
         'room': room
     },
                             dry=True)
     res = yield actor.execute()
     self.assertEqual(res, None)
Exemplo n.º 8
0
    def integration_test_execute_with_invalid_creds(self):
        message = 'Unit test message'
        room = 'unit_room'
        actor = hipchat.Message('Unit Test Action', {
            'message': message,
            'room': room
        },
                                dry=True)

        # Valid response test
        actor._token = 'Invalid'
        with self.assertRaises(exceptions.InvalidCredentials):
            yield actor.execute()
Exemplo n.º 9
0
    def test_execute_with_empty_response(self):
        message = 'Unit test message'
        room = 'unit_room'
        actor = hipchat.Message(
            'Unit Test Action',
            {'message': message, 'room': room})

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

        with self.assertRaises(exceptions.RecoverableActorFailure):
            yield actor._execute()
Exemplo n.º 10
0
    def integration_test_init_without_environment_creds(self):
        message = 'Unit test message'
        room = 'Operations'

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

        # Reload the hipchat library to re-get the token
        importlib.reload(hipchat)
Exemplo n.º 11
0
    def test_execute(self):
        message = 'Unit test message'
        room = 'unit_room'
        actor = hipchat.Message(
            'Unit Test Action',
            {'message': message, '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)
Exemplo n.º 12
0
 def test_init_with_missing_options(self):
     with self.assertRaises(exceptions.InvalidOptions):
         hipchat.Message('Unit Test Action', {})