示例#1
0
    def loginButtonClicked(self):
        loginBoxValue = self.loginTextBox.text()
        passwordBoxValue = self.passwordTextBox.text()

        if (not loginBoxValue) or (not passwordBoxValue):
            FunnyClassForErrorMsg().showMsg(self, "Type Login and Password")
        else:
            self.username = self.loginTextBox.text()
            self.passwd = self.passwordTextBox.text()

            s = Connection().getSocket()
            req = request.AuthRequest(user=self.username, passwd=self.passwd)
            transfer.send(s, req)
            resp = response.AuthResponse.fromJSON(transfer.recieve(s))
            if resp.type == MessageType.ERR:
                FunnyClassForErrorMsg().showMsg(self, resp.description)
            else:
                if self.operatingWindow is None:
                    self.operatingWindow = OperatingWindow(self.username)
                    self.operatingWindow.set_connection(s)
                    self.operatingWindow.refreshFileList()
                    self.operatingWindow.show()
                    self.hide()
                else:
                    self.operatingWindow.close()
                    self.operatingWindow = None
示例#2
0
 def __init__(self, hostname):
     """
     :param string hostname: Node hostname. Examples: `http://127.0.0.1:4002` or
         `http://my.domain.io/api/`. This is to allow people to server the api
         on whatever url they want.
     """
     self.connection = Connection(hostname)
     self._import_api()
def test_request_get_calls_connection_get_with_correct_params(mocker):
    get_mock = mocker.patch.object(Connection, 'get')
    connection = Connection('http://127.0.0.1:4003')

    resource = Resource(connection)
    resource.request_get('spongebob', params={'foo': 'bar'})

    get_mock.assert_called_once_with('spongebob', params={'foo': 'bar'})
def test_request_delete_calls_connection_delete_with_correct_params(mocker):
    delete_mock = mocker.patch.object(Connection, 'delete')
    connection = Connection('http://127.0.0.1:4003', '2')

    resource = Resource(connection)
    resource.request_delete('spongebob', params={'foo': 'bar'})

    delete_mock.assert_called_once_with('spongebob', params={'foo': 'bar'})
def test_handle_response_retuns_body_from_request():
    responses.add(responses.GET,
                  'http://127.0.0.1:4003/spongebob',
                  json={'success': True},
                  status=200)

    connection = Connection('http://127.0.0.1:4003')
    response = requests.get('http://127.0.0.1:4003/spongebob')
    body = connection._handle_response(response)
    assert body == {'success': True}
def test_handle_response_raises_for_no_content_in_response():
    responses.add(responses.GET, 'http://127.0.0.1:4003/spongebob', status=404)

    connection = Connection('http://127.0.0.1:4003')
    response = requests.get('http://127.0.0.1:4003/spongebob')
    with pytest.raises(ArkHTTPException) as exception:
        connection._handle_response(response)

    assert str(exception.value) == 'No content in response'
    assert exception.value.response == response
def test_connection_raises_for_request_retry_failure():
    responses.add(responses.GET,
                  'http://127.0.0.1:4003/spongebob',
                  body=requests.exceptions.RequestException())

    connection = Connection('http://127.0.0.1:4003')

    with pytest.raises(ArkHTTPException) as exception:
        connection.get('spongebob')

    assert len(responses.calls) == 3
def test_http_methods_call_correct_url_and_return_correct_response(
        method, func_name):
    responses.add(method,
                  'http://127.0.0.1:4003/spongebob',
                  json={'success': True},
                  status=200)

    connection = Connection('http://127.0.0.1:4003')
    data = getattr(connection, func_name)('spongebob')
    assert data == {'success': True}
    assert len(responses.calls) == 1
    assert responses.calls[0].request.url == 'http://127.0.0.1:4003/spongebob'
def test_request_post_calls_connection_post_with_correct_params(mocker):
    post_mock = mocker.patch.object(Connection, 'post')
    connection = Connection('http://127.0.0.1:4003')

    resource = Resource(connection)
    resource.request_post('spongebob',
                          data={'one': 'two'},
                          params={'foo': 'bar'})

    post_mock.assert_called_once_with('spongebob',
                                      data={'one': 'two'},
                                      params={'foo': 'bar'})
示例#10
0
def test_handle_response_raises_for_success_false_in_response():
    responses.add(
        responses.GET,
        'http://127.0.0.1:4003/spongebob',
        json={'success': False, 'error': 'Best error ever'},
        status=404
    )

    connection = Connection('http://127.0.0.1:4003')
    response = requests.get('http://127.0.0.1:4003/spongebob')
    with pytest.raises(PhantomHTTPException) as exception:
        connection._handle_response(response)

    assert str(exception.value) == 'GET 404 http://127.0.0.1:4003/spongebob - Best error ever'
    assert exception.value.response == response
示例#11
0
    def __init__(self, hostname, api_version='v2'):
        """
        :param string hostname: Node hostname. Examples: `http://127.0.0.1:4002` or
            `http://my.domain.io/api/`. NOTE: For v1 of the client, hostname needs to include
            url to the API, meaning that because v1 API is accessible on `/api/` url, hostname
            needs to be `http://127.0.0.1:4002/api/`. This is to allow people to server the api
            on whatever url they want.
        :param string api_version: Version of the API you want to use. Defaults to v2.
        """
        if api_version not in ['v1', 'v2']:
            raise ArkParameterException(
                'Only versions "v1" and "v2" are supported')

        self.api_version = api_version

        self.connection = Connection(hostname, api_version.replace('v', ''))
        self._import_api()
def test_connection_request_retry_successful():
    responses.add(responses.GET,
                  'http://127.0.0.1:4003/spongebob',
                  body=requests.exceptions.RequestException())
    responses.add(responses.GET,
                  'http://127.0.0.1:4003/spongebob',
                  body=requests.exceptions.RequestException())
    responses.add(responses.GET,
                  'http://127.0.0.1:4003/spongebob',
                  json={'success': True},
                  status=200)

    connection = Connection('http://127.0.0.1:4003')

    data = connection.get('spongebob')
    assert data == {'success': True}
    assert len(responses.calls) == 3
    assert responses.calls[0].request.url == 'http://127.0.0.1:4003/spongebob'
示例#13
0
def test_connection_creation_sets_default_session_headers_and_variables():
    connection = Connection('http://127.0.0.1:4003')
    assert connection.hostname == 'http://127.0.0.1:4003'
    assert isinstance(connection.session, requests.Session)
    assert connection.session.headers['Content-Type'] == 'application/json'
    assert connection.session.headers['API-Version'] == '2'
示例#14
0
def test_build_url_correctly_builds_url():
    connection = Connection('http://127.0.0.1:4003', '2')
    url = connection._build_url('spongebob')
    assert url == 'http://127.0.0.1:4003/spongebob'
示例#15
0
def test_connection_creation_raises_with_wrong_api_version_number(
        version_number):
    with pytest.raises(Exception) as error:
        Connection('http://127.0.0.1:4003', version_number)
    assert 'Only versions "1" and "2" are supported' in str(error.value)
示例#16
0
def test_connection_creation_sets_default_session_headers_and_variables():
    connection = Connection('http://127.0.0.1:4003', '2')
    assert connection.hostname == 'http://127.0.0.1:4003'
    assert isinstance(connection.session, requests.Session)
    assert connection.session.headers['port'] == '1'
    assert connection.session.headers['API-Version'] == '2'