Skip to content

Commit

Permalink
Merge pull request #37 from Onemind-Services-LLC/management.Account
Browse files Browse the repository at this point in the history
added management.Account
  • Loading branch information
abhi1693 authored Dec 24, 2023
2 parents 775b366 + c0248e4 commit 2e0176d
Show file tree
Hide file tree
Showing 4 changed files with 246 additions and 0 deletions.
5 changes: 5 additions & 0 deletions docs/management.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,8 @@ Management
:members:
:undoc-members:
:show-inheritance:

.. automodule:: jelastic.api.management._Account
:members:
:undoc-members:
:show-inheritance:
119 changes: 119 additions & 0 deletions jelastic/api/management/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,122 @@

class Management(ClientAbstract):
_endpoint1 = "management"

@property
def Account(self) -> "_Account":
"""
>>> from jelastic import Jelastic
>>> jelastic = Jelastic('https://jca.xapp.cloudmydc.com', token='d6f4e314a5b5fefd164995169f28ae32d987704f')
>>> jelastic.management.Account
Ref: https://docs.jelastic.com/api/private/#!/api/management.Account
"""
return _Account(
session=self._session,
token=self._token,
debug=self._debug,
)


class _Account(Management):
"""
Ref: https://docs.jelastic.com/api/private/#!/api/management.Account
"""

_endpoint2 = "account"

def AddPrivateSSHKey(self, title: str, ssh_key: str):
"""
:param title: title of the ssh key.
:param sshKey: value of the ssh key.
"""
return self._get(
"AddPrivateSSHKey",
params={"title": title, "sshKey": ssh_key},
)

def AddPublicSSHKey(self, title: str, ssh_key: str):
"""
:param title: title of the ssh key.
:param sshKey: value of the ssh key.
"""
return self._get(
"AddPublicSSHKey",
params={"title": title, "sshKey": ssh_key},
)

def AddSSHKey(self, title: str, ssh_key: str, is_private: bool):
"""
:param title: title of the ssh key.
:param sshKey: value of the ssh key.
"""
return self._get(
"AddSSHKey",
params={"title": title, "sshKey": ssh_key, "isPrivate": is_private},
)

def AdjustContainersLimitsForAllUsers(
self,
):
return self._get(
"AdjustContainersLimitsForAllUsers",
params={},
)

def CleanQuotasCache(
self,
uid: int,
):
return self._get(
"CleanQuotasCache",
params={
"uid": uid,
},
)

def DeleteSSHKey(self, id: int):
"""
:param id: unique identifier of the ssh key.
"""
return self._get(
"DeleteSSHKey",
params={
"id": id,
},
)

def GetQuotasByIpAddress(
self,
ip_address: str,
quotasnames: str,
):
return self._get(
"GetQuotasByIpAddress",
params={
"ipAddress": ip_address,
"quotasnames": quotasnames,
},
)

def GetSSHKeys(self, is_private: bool):
"""
:param isPrivate: defines whether to return the account's private (true) or public (false) SSH keys.
"""
return self._get(
"GetSSHKeys",
params={"isPrivate": is_private},
)

def GetSSHKeysInner(
self,
uid: int,
):
"""
:param uid: unique identifier of the user (key owner).
"""
return self._get(
"GetSSHKeysInner",
params={
"uid": uid,
},
)
19 changes: 19 additions & 0 deletions tests/unit/test_api/test_management/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import datetime
from unittest.mock import patch, Mock

import pytest

from jelastic.api import Management

CURRENT_DATETIME = datetime.datetime.now()
success_response = {"error": "", "reason": 0, "result": 0, "source": "billing"}

__all__ = ("client", "success_response", "CURRENT_DATETIME")


@pytest.fixture
def client():
with patch("jelastic.api.abstract.ClientAbstract._get") as mock_get:
jc = Management(session=Mock(), token="token")
jc._get = mock_get
yield jc
103 changes: 103 additions & 0 deletions tests/unit/test_api/test_management/test_account.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
from . import *


def test_add_private_ssh_key(client):
client._get.return_value = success_response
response = client.Account.AddPrivateSSHKey("title", "ssh_key")
client._get.assert_called_with(
"AddPrivateSSHKey",
params={"title": "title", "sshKey": "ssh_key"},
)
assert response == success_response


def test_add_public_ssh_key(client):
client._get.return_value = success_response
response = client.Account.AddPublicSSHKey("title", "ssh_key")
client._get.assert_called_with(
"AddPublicSSHKey",
params={"title": "title", "sshKey": "ssh_key"},
)
assert response == success_response


def test_add_ssh_key(client):
client._get.return_value = success_response
response = client.Account.AddSSHKey("title", "ssh_key", False)
client._get.assert_called_with(
"AddSSHKey",
params={"title": "title", "sshKey": "ssh_key", "isPrivate": False},
)
assert response == success_response


def test_adjust_containers_limits_or_all_users(client):
client._get.return_value = success_response
response = client.Account.AdjustContainersLimitsForAllUsers()
client._get.AdjustContainersLimitsForAllUsers(
"AddSSHKey",
params={},
)
assert response == success_response


def test_clean_quotas_cache(client):
client._get.return_value = success_response
response = client.Account.CleanQuotasCache(1)
client._get.assert_called_with(
"CleanQuotasCache",
params={
"uid": 1,
},
)
assert response == success_response


def test_delete_ssh_key(client):
client._get.return_value = success_response
response = client.Account.DeleteSSHKey(1)
client._get.assert_called_with(
"DeleteSSHKey",
params={
"id": 1,
},
)
assert response == success_response


def test_get_quotas_by_ip_address(client):
client._get.return_value = success_response
response = client.Account.GetQuotasByIpAddress(
"address",
"quotas_names",
)
client._get.assert_called_with(
"GetQuotasByIpAddress",
params={
"ipAddress": "address",
"quotasnames": "quotas_names",
},
)
assert response == success_response


def test_get_ssh_keys(client):
client._get.return_value = success_response
response = client.Account.GetSSHKeys(False)
client._get.assert_called_with(
"GetSSHKeys",
params={"isPrivate": False},
)
assert response == success_response


def test_get_ssh_keys_inner(client):
client._get.return_value = success_response
response = client.Account.GetSSHKeysInner(1)
client._get.assert_called_with(
"GetSSHKeysInner",
params={
"uid": 1,
},
)
assert response == success_response

0 comments on commit 2e0176d

Please sign in to comment.