Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions novem/group/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
from novem.exceptions import Novem403, Novem404, raise_on_response

from ..api_ref import NovemAPI
from .profile import NovemGroupProfile
from .config import NovemGroupConfig
from .roles import NovemRoles


class NovemGroupAPI(NovemAPI):
roles: Optional[NovemRoles] = None
profile: Optional[NovemGroupProfile] = None
config: Optional[NovemGroupConfig] = None
id: str

_type: str = "NA"
Expand All @@ -34,10 +34,10 @@ def __init__(self, **kwargs: Any) -> None:
self.api_create("")

self.roles = NovemRoles(self)
self.profile = NovemGroupProfile(self, type=self._type)
self.config = NovemGroupConfig(self, type=self._type)

if "profile" in kwargs:
self.profile.set(kwargs["profile"])
if "config" in kwargs:
self.config.set(kwargs["config"])

if "roles" in kwargs:
self.roles.set(kwargs["roles"])
Expand All @@ -51,7 +51,7 @@ def _parse_kwargs(self, **kwargs: Any) -> None:

# get a list of valid properties
props = [
x for x in dir(self) if x[0] != "_" and x not in ["data", "read", "delete", "write", "roles", "profile"]
x for x in dir(self) if x[0] != "_" and x not in ["data", "read", "delete", "write", "roles", "config"]
]

for k, v in kwargs.items():
Expand All @@ -63,8 +63,8 @@ def _parse_kwargs(self, **kwargs: Any) -> None:
def __setattr__(self, name: str, value: Any) -> None:
if name == "roles" and self.roles:
self.roles.set(value)
if name == "profile" and self.profile:
self.profile.set(value)
if name == "config" and self.config:
self.config.set(value)
else:
super().__setattr__(name, value)

Expand Down
39 changes: 20 additions & 19 deletions novem/group/profile.py → novem/group/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@ def __init__(self, api: "NovemGroupAPI") -> None:
"""Initialize organization options with API reference"""
self.api: "NovemGroupAPI" = api

def set(self, profile: Dict[str, Any]) -> None:
def set(self, options: Dict[str, Any]) -> None:
"""
Set profile options
Set config options
"""

props = [x for x in dir(self) if x not in ["api", "set"] and x[0] != "_"]

for k in profile.keys():
for k in options.keys():
if k not in props:
continue
v = profile[k]
v = options[k]
setattr(self, k, v)

@property
def is_open(self) -> bool:
res = self.api.api_read("/profile/options/is_open")
if res.lower() == "yes":
if res.strip().lower() == "yes":
return True
return False

Expand All @@ -37,7 +37,7 @@ def is_open(self, value: bool) -> None:
@property
def show_description(self) -> bool:
res = self.api.api_read("/profile/options/show_description")
if res.lower() == "yes":
if res.strip().lower() == "yes":
return True
return False

Expand All @@ -49,7 +49,7 @@ def show_description(self, value: bool) -> None:
@property
def show_members(self) -> bool:
res = self.api.api_read("/profile/options/show_members")
if res.lower() == "yes":
if res.strip().lower() == "yes":
return True
return False

Expand All @@ -61,7 +61,7 @@ def show_members(self, value: bool) -> None:
@property
def show_profile(self) -> bool:
res = self.api.api_read("/profile/options/show_profile")
if res.lower() == "yes":
if res.strip().lower() == "yes":
return True
return False

Expand All @@ -76,7 +76,7 @@ class OrgOptions(GroupOptions):
def enable_subdomain(self) -> bool:
res = self.api.api_read("/profile/options/enable_subdomain")

if res.lower() == "yes":
if res.strip().lower() == "yes":
return True
return False

Expand All @@ -91,7 +91,7 @@ class OrgGroupOptions(GroupOptions):
def allow_inbound_mail(self) -> bool:
res = self.api.api_read("/profile/options/allow_inbound_mail")

if res.lower() == "yes":
if res.strip().lower() == "yes":
return True
return False

Expand All @@ -104,7 +104,7 @@ def allow_inbound_mail(self, value: bool) -> None:
def mail_verify_dkim(self) -> bool:
res = self.api.api_read("/profile/options/mail_verify_dkim")

if res.lower() == "yes":
if res.strip().lower() == "yes":
return True
return False

Expand All @@ -117,7 +117,7 @@ def mail_verify_dkim(self, value: bool) -> None:
def mail_verify_spf(self) -> bool:
res = self.api.api_read("/profile/options/mail_verify_spf")

if res.lower() == "yes":
if res.strip().lower() == "yes":
return True
return False

Expand All @@ -127,9 +127,10 @@ def mail_verify_spf(self, value: bool) -> None:
return self.api.api_write("/profile/options/mail_verify_spf", val)


class NovemGroupProfile(object):
class NovemGroupConfig(object):
"""
Novem group profile
Novem group config: the group's name, description and options, stored
under ``/profile`` in the API
"""

options: GroupOptions
Expand All @@ -143,20 +144,20 @@ def __init__(self, api: "NovemGroupAPI", type: str = "group") -> None:
elif type == "org_group":
self.options = OrgGroupOptions(api)

def set(self, profile: Dict[str, Any]) -> None:
def set(self, config: Dict[str, Any]) -> None:
"""
Set profile options
Set config options
"""

props = [x for x in dir(self) if x in ["name", "description", "options"]]

for k in profile.keys():
for k in config.keys():
if k not in props:
continue

v = profile[k]
v = config[k]
if k == "options":
self.options.set(profile[k])
self.options.set(config[k])
else:
setattr(self, k, v)

Expand Down
70 changes: 35 additions & 35 deletions tests/test_org.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from novem import Org


def test_org_profile_prop(requests_mock):
def test_org_config_prop(requests_mock):
org_id = "test_org"
org_name = "long test name"
org_description = "long test description"
Expand Down Expand Up @@ -61,7 +61,7 @@ def verify_create(request, context):
text=verify_create,
)

# basic profile settings
# basic config settings
requests_mock.register_uri(
"post",
f"{api_root}admin/orgs/{org_id}/profile/name",
Expand All @@ -85,7 +85,7 @@ def verify_create(request, context):
text=partial(verify_read, "desc", org_description),
)

# basic profile options
# basic config options
for opt in ["is_open", "enable_subdomain", "show_description", "show_members", "show_profile"]:
requests_mock.register_uri(
"post", f"{api_root}admin/orgs/{org_id}/profile/options/{opt}", text=partial(verify_write, opt, "yes")
Expand All @@ -100,35 +100,35 @@ def verify_create(request, context):
config_path=config_file,
)

assert n.profile.name == "NA"
assert n.profile.description == "NA"
assert n.config.name == "NA"
assert n.config.description == "NA"

# Test basic properties
n.profile.name = org_name
n.profile.description = org_description
n.config.name = org_name
n.config.description = org_description

assert n.profile.name == org_name
assert n.profile.description == org_description
assert n.config.name == org_name
assert n.config.description == org_description

assert n.profile.options.is_open is False
n.profile.options.is_open = True
assert n.profile.options.is_open is True
assert n.config.options.is_open is False
n.config.options.is_open = True
assert n.config.options.is_open is True

assert n.profile.options.enable_subdomain is False
n.profile.options.enable_subdomain = True
assert n.profile.options.enable_subdomain is True
assert n.config.options.enable_subdomain is False
n.config.options.enable_subdomain = True
assert n.config.options.enable_subdomain is True

assert n.profile.options.show_members is False
n.profile.options.show_members = True
assert n.profile.options.show_members is True
assert n.config.options.show_members is False
n.config.options.show_members = True
assert n.config.options.show_members is True

assert n.profile.options.show_description is False
n.profile.options.show_description = True
assert n.profile.options.show_description is True
assert n.config.options.show_description is False
n.config.options.show_description = True
assert n.config.options.show_description is True

assert n.profile.options.show_profile is False
n.profile.options.show_profile = True
assert n.profile.options.show_profile is True
assert n.config.options.show_profile is False
n.config.options.show_profile = True
assert n.config.options.show_profile is True

# Verify all operations were performed
for k, v in gcheck.items():
Expand All @@ -137,7 +137,7 @@ def verify_create(request, context):
assert n._api_root == "https://api.novem.io/v1/"


def test_org_profile_dict(requests_mock):
def test_org_config_dict(requests_mock):
org_id = "test_org"
org_name = "long test name"
org_description = "long test description"
Expand Down Expand Up @@ -191,7 +191,7 @@ def verify_create(request, context):
text=verify_create,
)

# basic profile settings
# basic config settings
requests_mock.register_uri(
"post",
f"{api_root}admin/orgs/{org_id}/profile/name",
Expand All @@ -215,7 +215,7 @@ def verify_create(request, context):
text=partial(verify_read, "desc", org_description),
)

# basic profile options
# basic config options
for opt in ["is_open", "enable_subdomain", "show_description", "show_members", "show_profile"]:
requests_mock.register_uri(
"post", f"{api_root}admin/orgs/{org_id}/profile/options/{opt}", text=partial(verify_write, opt, "yes")
Expand All @@ -228,7 +228,7 @@ def verify_create(request, context):
n = Org(
org_id,
config_path=config_file,
profile={
config={
"name": org_name,
"description": org_description,
"options": {
Expand All @@ -241,13 +241,13 @@ def verify_create(request, context):
},
)

assert n.profile.name == org_name
assert n.profile.description == org_description
assert n.profile.options.is_open is True
assert n.profile.options.enable_subdomain is True
assert n.profile.options.show_members is True
assert n.profile.options.show_description is True
assert n.profile.options.show_profile is True
assert n.config.name == org_name
assert n.config.description == org_description
assert n.config.options.is_open is True
assert n.config.options.enable_subdomain is True
assert n.config.options.show_members is True
assert n.config.options.show_description is True
assert n.config.options.show_profile is True

# Verify all operations were performed
for k, v in gcheck.items():
Expand Down
Loading
Loading