Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

context: use autogenerated name to improve multi-tenancy #404

Merged
merged 39 commits into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
72be025
context: use autogenerated name
bloom1 Jul 7, 2023
9c61349
changelog: context now use autogenerated name
bloom1 Jul 7, 2023
4a1f810
context: remove unused test
bloom1 Jul 10, 2023
69e60a4
voicemail: use label for context generation
bloom1 Jul 10, 2023
984f721
voicemail: fix context-related test
bloom1 Jul 13, 2023
f42bbc5
user_voicemail: fix context-related tests
bloom1 Jul 13, 2023
a8de755
users: fix context-related tests
bloom1 Jul 13, 2023
5d80d1b
sync_db: fix context-related tests
bloom1 Jul 14, 2023
49ab6fd
queue_extension: fix context-related tests
bloom1 Jul 14, 2023
b5e2e76
parking_lot_extension: fix context-related tests
bloom1 Jul 14, 2023
43254c1
outcall_extension: fix context-related tests
bloom1 Jul 14, 2023
997e11b
lines: fix context-related tests
bloom1 Jul 14, 2023
cd1f7c4
line_extension: fix context-related tests
bloom1 Jul 14, 2023
39cc7cd
line_endpoint_sip: fix context-related tests
bloom1 Jul 14, 2023
ce1b5ec
line_endpoint_sccp: fix context-related tests
bloom1 Jul 14, 2023
8c896f5
line_endpoint_custom: fix context-related tests
bloom1 Jul 14, 2023
284ec41
line_application: fix context-related tests
bloom1 Jul 14, 2023
5fe94a2
incall_extension: fix context-related tests
bloom1 Jul 14, 2023
8519354
group_extension: fix context-related tests
bloom1 Jul 14, 2023
bc11b12
extensions: fix context-related tests
bloom1 Jul 14, 2023
f10ebc8
devices: fix context-related tests
bloom1 Jul 14, 2023
70819de
contexts: fix length validator
bloom1 Jul 14, 2023
4108a8f
conference_extension: fix context-related tests
bloom1 Jul 14, 2023
cf0c369
user_voicemail: fix test
bloom1 Jul 14, 2023
7d11940
run black
bloom1 Jul 14, 2023
6bb1756
trunks: fix context-related tests
bloom1 Jul 14, 2023
0b563c4
contexts: test name deprecated field
bloom1 Jul 25, 2023
b3806ec
preprocess_subroutine: set maximum to 79 characters
bloom1 Jul 25, 2023
ecf8268
run black
bloom1 Jul 26, 2023
efb5113
context: add UUID column
bloom1 Jul 26, 2023
40af39e
helpers: fix context-related regex
bloom1 Jul 27, 2023
ab0d1d4
context: bump deprecated version notice
fblackburn1 Jul 28, 2023
29c5906
context: remove unused uniquefield validator
fblackburn1 Jul 28, 2023
dec3352
fix destination tests to allow context until 79 char
fblackburn1 Jul 28, 2023
0e73db9
tenants: fix tests for context name
bloom1 Aug 3, 2023
08ebf58
sync_db: fix voicemail test w/ what's on master
bloom1 Aug 3, 2023
bbb747c
context: add context type inside autogenerated name
fblackburn1 Aug 14, 2023
b076575
rebase version for context changelog and notice
fblackburn1 Aug 14, 2023
1d2e0a4
test: exclude some helper methods from nosetests
fblackburn1 Aug 14, 2023
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 23.10

* A context now has a read-only auto-generated `name` and a required `label` instead
of a user-provided `name` and optional `label`. For compatibility purposes, if a context is
created using only a `name`, it will be used as the `label` and auto-generated.

## 23.04

* PUT on `/users?recursive=true` updated, to provide a way to update lines, switchboards, agent, voicemail and incalls for a specific user.
Expand Down
4 changes: 2 additions & 2 deletions integration_tests/suite/base/test_agents.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2018-2022 The Wazo Authors (see the AUTHORS file)
# Copyright 2018-2023 The Wazo Authors (see the AUTHORS file)
# SPDX-License-Identifier: GPL-3.0-or-later

from hamcrest import (
Expand Down Expand Up @@ -81,7 +81,7 @@ def error_checks(url):
yield s.check_bogus_field_returns_error, url, 'preprocess_subroutine', 123
yield s.check_bogus_field_returns_error, url, 'preprocess_subroutine', True
yield s.check_bogus_field_returns_error, url, 'preprocess_subroutine', s.random_string(
40
80
)
yield s.check_bogus_field_returns_error, url, 'preprocess_subroutine', []
yield s.check_bogus_field_returns_error, url, 'preprocess_subroutine', {}
Expand Down
94 changes: 50 additions & 44 deletions integration_tests/suite/base/test_conference_extension.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2016-2020 The Wazo Authors (see the AUTHORS file)
# Copyright 2016-2023 The Wazo Authors (see the AUTHORS file)
# SPDX-License-Identifier: GPL-3.0-or-later

from hamcrest import assert_that, contains, has_entries
Expand Down Expand Up @@ -47,37 +47,40 @@ def test_associate(extension, conference):
@fixtures.conference(wazo_tenant=SUB_TENANT)
@fixtures.context(
wazo_tenant=MAIN_TENANT,
name='main-internal',
label='main-internal',
conference_room_ranges=[{'start': '4000', 'end': '4999'}],
)
@fixtures.context(
wazo_tenant=SUB_TENANT,
name='sub-internal',
label='sub-internal',
conference_room_ranges=[{'start': '4000', 'end': '4999'}],
)
@fixtures.extension(context='main-internal', exten=gen_conference_exten())
@fixtures.extension(context='sub-internal', exten=gen_conference_exten())
def test_associate_multi_tenant(main, sub, _, __, main_exten, sub_exten):
response = (
confd.conferences(sub['id'])
.extensions(main_exten['id'])
.put(wazo_tenant=SUB_TENANT)
)
response.assert_match(404, e.not_found('Extension'))

response = (
confd.conferences(main['id'])
.extensions(sub_exten['id'])
.put(wazo_tenant=SUB_TENANT)
)
response.assert_match(404, e.not_found('Conference'))

response = (
confd.conferences(main['id'])
.extensions(sub_exten['id'])
.put(wazo_tenant=MAIN_TENANT)
)
response.assert_match(400, e.different_tenant())
def test_associate_multi_tenant(main, sub, main_ctx, sub_ctx):
@fixtures.extension(context=main_ctx['name'], exten=gen_conference_exten())
@fixtures.extension(context=sub_ctx['name'], exten=gen_conference_exten())
def aux(main_exten, sub_exten):
response = (
confd.conferences(sub['id'])
.extensions(main_exten['id'])
.put(wazo_tenant=SUB_TENANT)
)
response.assert_match(404, e.not_found('Extension'))

response = (
confd.conferences(main['id'])
.extensions(sub_exten['id'])
.put(wazo_tenant=SUB_TENANT)
)
response.assert_match(404, e.not_found('Conference'))

response = (
confd.conferences(main['id'])
.extensions(sub_exten['id'])
.put(wazo_tenant=MAIN_TENANT)
)
response.assert_match(400, e.different_tenant())

aux()


@fixtures.conference()
Expand Down Expand Up @@ -159,30 +162,33 @@ def test_dissociate(conference, extension):
@fixtures.conference(wazo_tenant=SUB_TENANT)
@fixtures.context(
wazo_tenant=MAIN_TENANT,
name='main-internal',
label='main-internal',
conference_room_ranges=[{'start': '4000', 'end': '4999'}],
)
@fixtures.context(
wazo_tenant=SUB_TENANT,
name='sub-internal',
label='sub-internal',
conference_room_ranges=[{'start': '4000', 'end': '4999'}],
)
@fixtures.extension(context='main-internal', exten=gen_conference_exten())
@fixtures.extension(context='sub-internal', exten=gen_conference_exten())
def test_dissociate_multi_tenant(main, sub, _, __, main_exten, sub_exten):
response = (
confd.conferences(sub['id'])
.extensions(main_exten['id'])
.delete(wazo_tenant=SUB_TENANT)
)
response.assert_match(404, e.not_found('Extension'))

response = (
confd.conferences(main['id'])
.extensions(sub_exten['id'])
.delete(wazo_tenant=SUB_TENANT)
)
response.assert_match(404, e.not_found('Conference'))
def test_dissociate_multi_tenant(main, sub, main_ctx, sub_ctx):
@fixtures.extension(context=main_ctx['name'], exten=gen_conference_exten())
@fixtures.extension(context=sub_ctx['name'], exten=gen_conference_exten())
def aux(main_exten, sub_exten):
response = (
confd.conferences(sub['id'])
.extensions(main_exten['id'])
.delete(wazo_tenant=SUB_TENANT)
)
response.assert_match(404, e.not_found('Extension'))

response = (
confd.conferences(main['id'])
.extensions(sub_exten['id'])
.delete(wazo_tenant=SUB_TENANT)
)
response.assert_match(404, e.not_found('Conference'))

aux()


@fixtures.conference()
Expand Down
4 changes: 2 additions & 2 deletions integration_tests/suite/base/test_conferences.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2016-2022 The Wazo Authors (see the AUTHORS file)
# Copyright 2016-2023 The Wazo Authors (see the AUTHORS file)
# SPDX-License-Identifier: GPL-3.0-or-later

from hamcrest import (
Expand Down Expand Up @@ -59,7 +59,7 @@ def error_checks(url):
yield s.check_bogus_field_returns_error, url, 'preprocess_subroutine', True
yield s.check_bogus_field_returns_error, url, 'preprocess_subroutine', 123
yield s.check_bogus_field_returns_error, url, 'preprocess_subroutine', s.random_string(
40
80
)
yield s.check_bogus_field_returns_error, url, 'preprocess_subroutine', []
yield s.check_bogus_field_returns_error, url, 'preprocess_subroutine', {}
Expand Down
118 changes: 53 additions & 65 deletions integration_tests/suite/base/test_contexts.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2016-2022 The Wazo Authors (see the AUTHORS file)
# Copyright 2016-2023 The Wazo Authors (see the AUTHORS file)
# SPDX-License-Identifier: GPL-3.0-or-later

from hamcrest import (
Expand Down Expand Up @@ -34,24 +34,23 @@ def test_post_errors():
for check in error_checks(url):
yield check

yield s.check_bogus_field_returns_error, url, 'name', 123
yield s.check_bogus_field_returns_error, url, 'name', True
yield s.check_bogus_field_returns_error, url, 'name', None
yield s.check_bogus_field_returns_error, url, 'name', 'with space'
yield s.check_bogus_field_returns_error, url, 'name', ''
yield s.check_bogus_field_returns_error, url, 'name', 'authentication'
yield s.check_bogus_field_returns_error, url, 'name', 'general'
yield s.check_bogus_field_returns_error, url, 'name', 'global'
yield s.check_bogus_field_returns_error, url, 'name', 'globals'
yield s.check_bogus_field_returns_error, url, 'name', 'parkedcalls'
yield s.check_bogus_field_returns_error, url, 'name', 'xivo-features'
yield s.check_bogus_field_returns_error, url, 'name', 'zonemessages'
yield s.check_bogus_field_returns_error, url, 'name', s.random_string(40)
yield s.check_bogus_field_returns_error, url, 'name', []
yield s.check_bogus_field_returns_error, url, 'name', {}
fblackburn1 marked this conversation as resolved.
Show resolved Hide resolved

for check in unique_error_checks(url):
yield check
yield s.check_bogus_field_returns_error, url, 'label', 123
yield s.check_bogus_field_returns_error, url, 'label', True
yield s.check_bogus_field_returns_error, url, 'label', None
yield s.check_bogus_field_returns_error, url, 'label', ''
yield s.check_bogus_field_returns_error, url, 'label', s.random_string(129)
yield s.check_bogus_field_returns_error, url, 'label', []
yield s.check_bogus_field_returns_error, url, 'label', {}

yield s.check_bogus_field_returns_error, url, 'name', 123, None, 'label'
yield s.check_bogus_field_returns_error, url, 'name', True, None, 'label'
yield s.check_bogus_field_returns_error, url, 'name', None, None, 'label'
yield s.check_bogus_field_returns_error, url, 'name', '', None, 'label'
yield s.check_bogus_field_returns_error, url, 'name', s.random_string(
129
), None, 'label'
yield s.check_bogus_field_returns_error, url, 'name', [], None, 'label'
yield s.check_bogus_field_returns_error, url, 'name', {}, None, 'label'


@fixtures.context()
Expand All @@ -67,6 +66,13 @@ def error_checks(url):
yield s.check_bogus_field_returns_error, url, 'label', s.random_string(129)
yield s.check_bogus_field_returns_error, url, 'label', []
yield s.check_bogus_field_returns_error, url, 'label', {}
yield s.check_bogus_field_returns_error, url, 'name', 123, None, 'label'
yield s.check_bogus_field_returns_error, url, 'name', True, None, 'label'
yield s.check_bogus_field_returns_error, url, 'name', s.random_string(
129
), None, 'label'
yield s.check_bogus_field_returns_error, url, 'name', [], None, 'label'
yield s.check_bogus_field_returns_error, url, 'name', {}, None, 'label'
yield s.check_bogus_field_returns_error, url, 'type', 123
yield s.check_bogus_field_returns_error, url, 'type', 'invalid'
yield s.check_bogus_field_returns_error, url, 'type', True
Expand Down Expand Up @@ -168,27 +174,19 @@ def error_checks(url):
]


@fixtures.context(name='unique')
def unique_error_checks(url, context):
yield s.check_bogus_field_returns_error, url, 'name', context['name']


@fixtures.context(
name='name_search',
label='label_search',
type='internal',
description='desc_search',
)
@fixtures.context(
name='hidden',
label='hidden',
type='incall',
description='hidden',
)
def test_search(context, hidden):
url = confd.contexts
searches = {
'name': 'name_search',
'label': 'label_search',
'type': 'internal',
'description': 'desc_search',
Expand Down Expand Up @@ -221,15 +219,15 @@ def test_list_multi_tenant(main, sub):
assert_that(response.items, has_items(main, sub))


@fixtures.context(name='sort1', description='sort1')
@fixtures.context(name='sort2', description='sort2')
@fixtures.context(label='sort1', description='sort1')
@fixtures.context(label='sort2', description='sort2')
def test_sorting_offset_limit(context1, context2):
url = confd.contexts.get
yield s.check_sorting, url, context1, context2, 'name', 'sort'
yield s.check_sorting, url, context1, context2, 'label', 'sort'
yield s.check_sorting, url, context1, context2, 'description', 'sort'

yield s.check_offset, url, context1, context2, 'name', 'sort'
yield s.check_limit, url, context1, context2, 'name', 'sort'
yield s.check_offset, url, context1, context2, 'label', 'sort'
yield s.check_limit, url, context1, context2, 'label', 'sort'


@fixtures.context()
Expand All @@ -256,7 +254,7 @@ def test_get(context):


def test_create_minimal_parameters():
response = confd.contexts.post(name='MyContext')
response = confd.contexts.post(label='MyContext')
response.assert_created('contexts')

assert_that(response.item, has_entries(id=not_(empty()), tenant_uuid=MAIN_TENANT))
Expand All @@ -266,21 +264,20 @@ def test_create_minimal_parameters():

def test_create_out_of_tree_tenant():
response = confd.contexts.post(
name='MyContext', wazo_tenant='00000000-0000-0000-0000-000000000000'
label='MyContext', wazo_tenant='00000000-0000-0000-0000-000000000000'
)
response.assert_status(401)


def test_create_in_authorized_tenant():
response = confd.contexts.post(name='ZContext', wazo_tenant=SUB_TENANT)
response = confd.contexts.post(label='Context', wazo_tenant=SUB_TENANT)
response.assert_created('context')

assert_that(response.item, has_entries(tenant_uuid=SUB_TENANT))


def test_create_all_parameters():
parameters = {
'name': 'MyContext',
'label': 'Context Power',
'type': 'outcall',
'user_ranges': [{'start': '1000', 'end': '1999'}],
Expand Down Expand Up @@ -327,15 +324,6 @@ def test_edit_all_parameters(context):
assert_that(response.item, has_entries(parameters))


@fixtures.context(name='OriginalName')
def test_edit_name_unavailable(context):
response = confd.contexts(context['id']).put(name='ModifiedName')
response.assert_updated()

response = confd.contexts(context['id']).get()
assert_that(response.item, has_entries(name=context['name']))


@fixtures.context()
def test_delete(context):
response = confd.contexts(context['id']).delete()
Expand All @@ -344,32 +332,32 @@ def test_delete(context):
response.assert_match(404, e.not_found(resource='Context'))


@fixtures.context(name='error')
@fixtures.extension(context='error')
def test_delete_when_extension_associated(context, extension):
response = confd.contexts(context['id']).delete()
response.assert_match(400, e.resource_associated('Context', 'Extension'))
@fixtures.context(label='error')
def test_delete_when_extension_associated(context):
with fixtures.extension(context=context['name']):
response = confd.contexts(context['id']).delete()
response.assert_match(400, e.resource_associated('Context', 'Extension'))


@fixtures.context(name='error')
@fixtures.trunk(context='error')
def test_delete_when_trunk_associated(context, trunk):
response = confd.contexts(context['id']).delete()
response.assert_match(400, e.resource_associated('Context', 'Trunk'))
@fixtures.context(label='error')
def test_delete_when_trunk_associated(context):
with fixtures.trunk(context=context['name']):
response = confd.contexts(context['id']).delete()
response.assert_match(400, e.resource_associated('Context', 'Trunk'))


@fixtures.context(name='error')
@fixtures.voicemail(context='error')
def test_delete_when_voicemail_associated(context, voicemail):
response = confd.contexts(context['id']).delete()
response.assert_match(400, e.resource_associated('Context', 'Voicemail'))
@fixtures.context(label='error')
def test_delete_when_voicemail_associated(context):
with fixtures.voicemail(context=context['name']):
response = confd.contexts(context['id']).delete()
response.assert_match(400, e.resource_associated('Context', 'Voicemail'))


@fixtures.context(name='error')
@fixtures.agent_login_status(context='error')
def test_delete_when_agent_is_logged(context, agent_login_status):
response = confd.contexts(context['id']).delete()
response.assert_match(400, e.resource_associated('Context', 'AgentLoginStatus'))
@fixtures.context(label='error')
def test_delete_when_agent_is_logged(context):
with fixtures.agent_login_status(context=context['name']):
response = confd.contexts(context['id']).delete()
response.assert_match(400, e.resource_associated('Context', 'AgentLoginStatus'))


@fixtures.context()
Expand Down
Loading