Beispiel #1
0
    def test_finish_authenticate_error(self):
        response = mocked_response('something_terrible', status_code=400)
        (flexmock(requests)
            .should_receive('get')
            .with_args('https://www.box.com/api/1.0/rest', params={
                'action': 'get_auth_token',
                'api_key': 'my_api_key',
                'ticket': 'golden_ticket'
            })
            .and_return(response))

        with self.assertRaises(BoxAuthenticationException) as expected_exception:
            finish_authenticate_v1('my_api_key', 'golden_ticket')

        self.assertEqual('something_terrible', expected_exception.exception.message)

        response = mocked_response('<response><status>something_terrible</status></response>')
        (flexmock(requests)
            .should_receive('get')
            .with_args('https://www.box.com/api/1.0/rest', params={
                'action': 'get_auth_token',
                'api_key': 'my_api_key',
                'ticket': 'golden_ticket'
            })
            .and_return(response))

        with self.assertRaises(BoxAuthenticationException) as expected_exception:
            finish_authenticate_v1('my_api_key', 'golden_ticket')

        self.assertEqual('something_terrible', expected_exception.exception.message)
Beispiel #2
0
    def test_finish_authenticate_error(self):
        response = mocked_response('something_terrible', status_code=400)
        (flexmock(requests).should_receive('get').with_args(
            'https://www.box.com/api/1.0/rest',
            params={
                'action': 'get_auth_token',
                'api_key': 'my_api_key',
                'ticket': 'golden_ticket'
            }).and_return(response))

        with self.assertRaises(
                BoxAuthenticationException) as expected_exception:
            finish_authenticate_v1('my_api_key', 'golden_ticket')

        self.assertEqual('something_terrible',
                         expected_exception.exception.message)

        response = mocked_response(
            '<response><status>something_terrible</status></response>')
        (flexmock(requests).should_receive('get').with_args(
            'https://www.box.com/api/1.0/rest',
            params={
                'action': 'get_auth_token',
                'api_key': 'my_api_key',
                'ticket': 'golden_ticket'
            }).and_return(response))

        with self.assertRaises(
                BoxAuthenticationException) as expected_exception:
            finish_authenticate_v1('my_api_key', 'golden_ticket')

        self.assertEqual('something_terrible',
                         expected_exception.exception.message)
Beispiel #3
0
    def test_finish_authenticate_v1(self):
        response = mocked_response("""<response><status>get_auth_token_ok</status>
        <auth_token>123456</auth_token>
        <user>
            <name>test_name</name>
        </user>
        </response>""")
        (flexmock(requests)
            .should_receive('get')
            .with_args('https://www.box.com/api/1.0/rest', params={
                'action': 'get_auth_token',
                'api_key': 'my_api_key',
                'ticket': 'golden_ticket'
            })
            .and_return(response))

        self.assertDictEqual(finish_authenticate_v1('my_api_key', 'golden_ticket'), {
            'token': '123456',
            'user': {
                'name': 'test_name'
            }
        })
Beispiel #4
0
    def test_finish_authenticate_v1(self):
        response = mocked_response(
            """<response><status>get_auth_token_ok</status>
        <auth_token>123456</auth_token>
        <user>
            <name>test_name</name>
        </user>
        </response>""")
        (flexmock(requests).should_receive('get').with_args(
            'https://www.box.com/api/1.0/rest',
            params={
                'action': 'get_auth_token',
                'api_key': 'my_api_key',
                'ticket': 'golden_ticket'
            }).and_return(response))

        self.assertDictEqual(
            finish_authenticate_v1('my_api_key', 'golden_ticket'), {
                'token': '123456',
                'user': {
                    'name': 'test_name'
                }
            })