def getUpdatesChangelog(self):
        r = get(self.basePath+'/update/changelog')

        schema = UpdateSchema(many=True)
        updates = schema.load(json.loads(r)['message']['updates'])

        log.info("Gathered %d updates", len(updates))
        return updates
Exemple #2
0
    def test_get_request_connection_errors(self):
        with pytest.raises(AthomAPIConnectionError,
                           match=r'.*Connection refused.*') as e:
            get('http://localhost/api/2',
                params={
                    'param1': 'foobar',
                    'param2': 2
                })

        responses.add(responses.GET,
                      'http://localhost/api/changelog',
                      body=SSLError())
        with pytest.raises(AthomAPIConnectionError) as e:
            get('http://localhost/api/changelog',
                params={
                    'param1': 'foobar',
                    'param2': 2
                })
Exemple #3
0
    def test_get_request_api_errors(self):
        data = {
            'code': 503,
            'error': 'unknown',
            'error_description': 'unknown error'
        }
        responses.add(responses.GET,
                      'http://localhost/api',
                      body=json.dumps(data),
                      status=503)

        with pytest.raises(AthomCloudUnknownAPIError,
                           match=r'\[503\].*unknown error.*'):
            get('http://localhost/api',
                params={
                    'param1': 'foobar',
                    'param2': 2
                })

        assert responses.calls[
            0].request.url == 'http://localhost/api?param1=foobar&param2=2'

        responses.add(responses.GET,
                      'http://localhost/api2',
                      body='Bad Gateway',
                      status=502)
        with pytest.raises(AthomCloudGateWayAPIError,
                           match=r'\[502\].*bad gateway.*'):
            get('http://localhost/api2',
                params={
                    'param1': 'foobar',
                    'param2': 2
                })

        assert responses.calls[
            1].request.url == 'http://localhost/api2?param1=foobar&param2=2'
Exemple #4
0
    def test_get_request_authentication_errors(self, mock_token):
        data = {
            'code': 401,
            'error': 'invalid_auth',
            'error_description': 'Invalid authentication'
        }
        responses.add(responses.GET,
                      'http://localhost/api',
                      status=401,
                      body=json.dumps(data))

        # Test authentication issues without token and refresh
        with pytest.raises(AthomCloudAuthenticationError,
                           match=r'\[401\].*Invalid authentication.*'):
            get('http://localhost/api',
                refresh=False,
                params={
                    'param1': 'foobar',
                    'param2': 2
                })

        assert responses.calls[
            0].request.url == 'http://localhost/api?param1=foobar&param2=2'
        assert not mock_token.refresh.called

        # Test authenitcation issues with token without refresh
        with pytest.raises(AthomCloudAuthenticationError,
                           match=r'\[401\].*Invalid authentication.*'):
            get('http://localhost/api',
                token=mock_token,
                refresh=False,
                params={
                    'param1': 'foobar',
                    'param2': 2
                })

        assert responses.calls[
            1].request.url == 'http://localhost/api?param1=foobar&param2=2'
        assert not mock_token.refresh.called

        # Test authentication with token and refresh enabled
        with pytest.raises(AthomCloudAuthenticationError,
                           match=r'\[401\].*Invalid authentication.*'):
            get('http://localhost/api',
                token=mock_token,
                params={
                    'param1': 'foobar',
                    'param2': 2
                })

        assert responses.calls[
            2].request.url == 'http://localhost/api?param1=foobar&param2=2'
        assert responses.calls[
            3].request.url == 'http://localhost/api?param1=foobar&param2=2'
        assert mock_token.refresh.called_once
Exemple #5
0
 def test_get_request(self):
     # Test normal GET request
     responses.add(responses.GET, 'http://localhost/api')
     get('http://localhost/api', params={'param1': 'foobar', 'param2': 2})
     assert responses.calls[
         0].request.url == 'http://localhost/api?param1=foobar&param2=2'