Ejemplo n.º 1
0
class TestEVE(unittest.TestCase):
    def setUp(self):
        self.api = EVE(
            client_id=1,
            redirect_uri='http://localhost:8000/complete/eveonline/')

    def test_endpoint_default(self):
        self.assertEqual(self.api._endpoint, 'https://crest-tq.eveonline.com/')
        self.assertEqual(self.api._image_server,
                         'https://imageserver.eveonline.com/')
        self.assertEqual(self.api._oauth_endpoint,
                         'https://login.eveonline.com/oauth')

    def test_endpoint_testing(self):
        api = EVE(testing=True)
        self.assertEqual(api._endpoint, 'https://api-sisi.testeveonline.com/')
        # imageserver. is given an 302 redirect to image. on testeveonline.com
        #   we might just as well keep using the old URL for now
        self.assertEqual(api._image_server, 'https://image.testeveonline.com/')
        self.assertEqual(api._oauth_endpoint,
                         'https://sisilogin.testeveonline.com/oauth')

    def test_auth_uri(self):
        self.assertEqual(
            self.api.auth_uri(),
            'https://login.eveonline.com/oauth/authorize?response_type=code&r'
            'edirect_uri=http%3A%2F%2Flocalhost%3A8000%2Fcomplete%2Feveonline'
            '%2F&client_id=1')

    def test_authorize(self):

        with httmock.HTTMock(*all_httmocks):
            self.api.authorize(code='code')

    def test_authorize_non_200(self):
        @httmock.all_requests
        def mock_login(url, request):
            return httmock.response(status_code=204, content='{}')

        with httmock.HTTMock(mock_login):
            self.assertRaises(APIException, self.api.authorize, code='code')

    def test_refr_authorize(self):
        with httmock.HTTMock(*all_httmocks):
            self.api.refr_authorize('refresh_token')

    def test_temptoken_authorize(self):
        with httmock.HTTMock(*all_httmocks):
            self.api.temptoken_authorize(access_token='access_token',
                                         expires_in=300,
                                         refresh_token='refresh_token')
Ejemplo n.º 2
0
class TestAuthedConnection(unittest.TestCase):

    def setUp(self):
        with httmock.HTTMock(*all_httmocks):
            self.api = EVE()

        with httmock.HTTMock(*all_httmocks):
            self.authed = self.api.authorize(code='code')

    def test_call(self):
        with httmock.HTTMock(*all_httmocks):
            self.authed()

    def test_whoami(self):
        with httmock.HTTMock(*all_httmocks):
            self.authed.whoami()

    def test_refresh(self):
        with httmock.HTTMock(*all_httmocks):
            self.authed.refresh()

    def test_refresh_on_get(self):
        self.authed.expires = 0
        with httmock.HTTMock(*all_httmocks):
            self.authed()
Ejemplo n.º 3
0
class TestAuthedConnection(unittest.TestCase):

    def setUp(self):
        with httmock.HTTMock(*all_httmocks):
            self.api = EVE()

        with httmock.HTTMock(*all_httmocks):
            self.authed = self.api.authorize(code='code')

    def test_call(self):
        with httmock.HTTMock(*all_httmocks):
            self.authed()

    def test_whoami(self):
        with httmock.HTTMock(*all_httmocks):
            self.authed.whoami()

    def test_refresh(self):
        with httmock.HTTMock(*all_httmocks):
            self.authed.refresh()

    def test_refresh_on_get(self):
        self.authed.expires = 0
        with httmock.HTTMock(*all_httmocks):
            self.authed()
Ejemplo n.º 4
0
class TestEVE(unittest.TestCase):

    def setUp(self):
        self.api = EVE(
            client_id=1,
            redirect_uri='http://localhost:8000/complete/eveonline/')

    def test_endpoint_default(self):
        self.assertEqual(
            self.api._endpoint,
            'https://crest-tq.eveonline.com/')
        self.assertEqual(
            self.api._image_server,
            'https://imageserver.eveonline.com/')
        self.assertEqual(
            self.api._oauth_endpoint,
            'https://login.eveonline.com/oauth')

    def test_endpoint_testing(self):
        api = EVE(testing=True)
        self.assertEqual(
            api._endpoint,
            'https://api-sisi.testeveonline.com/')
        # imageserver. is given an 302 redirect to image. on testeveonline.com
        #   we might just as well keep using the old URL for now
        self.assertEqual(
            api._image_server,
            'https://image.testeveonline.com/')
        self.assertEqual(
            api._oauth_endpoint,
            'https://sisilogin.testeveonline.com/oauth')

    def test_auth_uri(self):
        self.assertEqual(
            self.api.auth_uri(),
            'https://login.eveonline.com/oauth/authorize?response_type=code&r'
            'edirect_uri=http%3A%2F%2Flocalhost%3A8000%2Fcomplete%2Feveonline'
            '%2F&client_id=1')

    def test_authorize(self):

        with httmock.HTTMock(*all_httmocks):
            self.api.authorize(code='code')

    def test_authorize_non_200(self):

        @httmock.all_requests
        def mock_login(url, request):
            return httmock.response(status_code=204)

        with httmock.HTTMock(mock_login):
            self.assertRaises(APIException, self.api.authorize, code='code')

    def test_refr_authorize(self):
        with httmock.HTTMock(*all_httmocks):
            self.api.refr_authorize('refresh_token')

    def test_temptoken_authorize(self):
        with httmock.HTTMock(*all_httmocks):
            self.api.temptoken_authorize(access_token='access_token',
                                         expires_in=300,
                                         refresh_token='refresh_token')