Skip to content

Commit

Permalink
Merge pull request #488 from wazo-platform/phone-numbers-main-read-only
Browse files Browse the repository at this point in the history
phone numbers main read only

phone_number: updated PhoneNumber schema for read-only 'main'
integration_tests: phone_number: 'main' number handling in fixture
phone_number: test_phone_numbers: refactored tests

Reviewed-by: Pascal Cadotte Michaud
  • Loading branch information
wazo-community-zuul[bot] authored Nov 7, 2024
2 parents a2915a8 + fd15661 commit c8a4a33
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 35 deletions.
54 changes: 21 additions & 33 deletions integration_tests/suite/base/test_phone_numbers.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,36 @@ def test_delete_errors():
s.check_resource_not_found(fake_phone_number, 'PhoneNumber')


@fixtures.phone_number()
def test_put_errors(phone_number):
def test_put_not_found():
fake_phone_number = confd.phone_numbers(FAKE_UUID).put
s.check_resource_not_found(fake_phone_number, 'PhoneNumber')


@fixtures.phone_number()
def test_put_bogus_fields(phone_number):
url = confd.phone_numbers(phone_number['uuid']).put
error_checks(url)
unique_error_checks_put(phone_number)


def test_post_errors():
@fixtures.phone_number()
@fixtures.phone_number(number='+18005551234', main=True)
def test_put_conflict(phone_number1, phone_number2):
phone_number1['number'] = phone_number2['number']
response = confd.phone_numbers(phone_number1['uuid']).put(**phone_number1)
response.assert_match(400, e.resource_exists(resource='PhoneNumber'))


def test_post_bogus_fields():
url = confd.phone_numbers.post
error_checks(url)
unique_error_checks_post(url)


@fixtures.phone_number(number='+18005551234', main=True)
def test_post_conflict(main_number):
url = confd.phone_numbers.post

response = url(number=main_number['number'])
response.assert_match(400, e.resource_exists(resource='PhoneNumber'))


def error_checks(url):
Expand All @@ -67,39 +83,13 @@ def error_checks(url):
s.check_bogus_field_returns_error(url, 'caller_id_name', True)
s.check_bogus_field_returns_error(url, 'caller_id_name', {})
s.check_bogus_field_returns_error(url, 'caller_id_name', 'a' * 1024)
s.check_bogus_field_returns_error(url, 'main', 123)
s.check_bogus_field_returns_error(url, 'main', '42')
s.check_bogus_field_returns_error(url, 'main', None)
s.check_bogus_field_returns_error(url, 'main', [])
s.check_bogus_field_returns_error(url, 'main', {})
s.check_bogus_field_returns_error(url, 'shared', 123)
s.check_bogus_field_returns_error(url, 'shared', '42')
s.check_bogus_field_returns_error(url, 'shared', None)
s.check_bogus_field_returns_error(url, 'shared', [])
s.check_bogus_field_returns_error(url, 'shared', {})


@fixtures.phone_number(number='+18005551234', main=True)
def unique_error_checks_put(first, second):
first['main'] = True
response = confd.phone_numbers(first['uuid']).put(**first)
response.assert_match(400, e.resource_exists(resource='PhoneNumber'))

first['main'] = False
first['number'] = second['number']
response = confd.phone_numbers(first['uuid']).put(**first)
response.assert_match(400, e.resource_exists(resource='PhoneNumber'))


@fixtures.phone_number(number='+18005551234', main=True)
def unique_error_checks_post(url, existing):
response = url(number='+15551234567', main=True)
response.assert_match(400, e.resource_exists(resource='PhoneNumber'))

response = url(number=existing['number'])
response.assert_match(400, e.resource_exists(resource='PhoneNumber'))


@fixtures.phone_number(
number='+18001235555', main=True, shared=True, caller_id_name='search'
)
Expand Down Expand Up @@ -205,7 +195,6 @@ def test_create_all_parameters():
parameters = {
'number': '+18001235567',
'caller_id_name': 'Here',
'main': True,
'shared': True,
}

Expand Down Expand Up @@ -436,7 +425,6 @@ def test_edit_all_parameters(phone_number):
parameters = {
'number': '+18001235567',
'caller_id_name': 'Here',
'main': True,
'shared': True,
}

Expand Down
8 changes: 7 additions & 1 deletion integration_tests/suite/helpers/helpers/phone_number.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ def delete_phone_number(phone_number_uuid, check=False, **parameters):

def add_phone_number(wazo_tenant=None, **parameters):
response = confd.phone_numbers.post(parameters, wazo_tenant=wazo_tenant)
return response.item
if parameters.get('main', False):
main_response = confd.phone_numbers.main.put(
{'phone_number_uuid': response.item['uuid']}, wazo_tenant=wazo_tenant
)
main_response.assert_updated()

return confd.phone_numbers(response.item['uuid']).get().item


def _random_number(length):
Expand Down
2 changes: 1 addition & 1 deletion wazo_confd/plugins/phone_number/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class PhoneNumberSchema(BaseSchema):
tenant_uuid = fields.String(dump_only=True)
number = number_field(required=True)
caller_id_name = fields.String(validate=Length(min=1, max=256), allow_none=True)
main = StrictBoolean(default=False)
main = StrictBoolean(dump_only=True)
shared = StrictBoolean(default=False)
links = ListLink(Link('phone_numbers', field='uuid'))

Expand Down

0 comments on commit c8a4a33

Please sign in to comment.