Skip to content

Commit

Permalink
Addressed comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jorge-beauregard committed Jan 28, 2021
1 parent aa29772 commit d8e0aa7
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
from azure.core.credentials import AccessToken

class FakeTokenCredential(object):
def __init__(self):
self.token = AccessToken("Fake Token", 0)

def get_token(self, *args):
return self.token
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# ------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# -------------------------------------------------------------------------
from .fake_token_credential import FakeTokenCredential
from azure.identity import DefaultAzureCredential

def create_token_credential():
# type: () -> FakeTokenCredential or DefaultAzureCredential
from devtools_testutils import is_live
if not is_live():
return FakeTokenCredential()
return DefaultAzureCredential()
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,12 @@
from phone_number_helper import PhoneNumberUriReplacer
from phone_number_testcase import PhoneNumberCommunicationTestCase
from _shared.testcase import BodyReplacerProcessor
from azure.identity import DefaultAzureCredential
from _shared.utils import create_token_credential
from azure.communication.administration._shared.utils import parse_connection_str

SKIP_PHONE_NUMBER_TESTS = True
PHONE_NUMBER_TEST_SKIP_REASON= "Phone Number Administration live tests infra not ready yet"

class FakeTokenCredential(object):
def __init__(self):
self.token = AccessToken("Fake Token", 0)

def get_token(self, *args):
return self.token
class PhoneNumberAdministrationClientTest(PhoneNumberCommunicationTestCase):
def setUp(self):
super(PhoneNumberAdministrationClientTest, self).setUp()
Expand Down Expand Up @@ -137,11 +131,7 @@ def setUp(self):
@pytest.mark.skipif(SKIP_PHONE_NUMBER_TESTS, reason=PHONE_NUMBER_TEST_SKIP_REASON)
def test_list_all_phone_numbers_from_managed_identity(self):
endpoint, access_key = parse_connection_str(self.connection_str)
from devtools_testutils import is_live
if not is_live():
credential = FakeTokenCredential()
else:
credential = DefaultAzureCredential()
credential = create_token_credential()
phone_number_client = PhoneNumberAdministrationClient(endpoint, credential)
pages = phone_number_client.list_all_phone_numbers()
assert pages.next()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
# license information.
# --------------------------------------------------------------------------
import pytest
from azure.core.credentials import AccessToken
from azure.communication.administration.aio import PhoneNumberAdministrationClient
from azure.communication.administration._shared.utils import parse_connection_str
from azure.communication.administration import (
Expand All @@ -16,18 +15,12 @@
from phone_number_helper import PhoneNumberUriReplacer
from phone_number_testcase_async import AsyncPhoneNumberCommunicationTestCase
from _shared.testcase import BodyReplacerProcessor, ResponseReplacerProcessor
from azure.identity import DefaultAzureCredential
from _shared.utils import create_token_credential
import os

SKIP_PHONE_NUMBER_TESTS = True
PHONE_NUMBER_TEST_SKIP_REASON= "Phone Number Administration live tests infra not ready yet"

class FakeTokenCredential(object):
def __init__(self):
self.token = AccessToken("Fake Token", 0)

def get_token(self, *args):
return self.token
class PhoneNumberAdministrationClientTestAsync(AsyncPhoneNumberCommunicationTestCase):

def setUp(self):
Expand Down Expand Up @@ -140,11 +133,7 @@ def setUp(self):
@pytest.mark.skipif(SKIP_PHONE_NUMBER_TESTS, reason=PHONE_NUMBER_TEST_SKIP_REASON)
async def test_list_all_phone_numbers_from_managed_identity(self):
endpoint, access_key = parse_connection_str(self.connection_str)
from devtools_testutils import is_live
if not is_live():
credential = FakeTokenCredential()
else:
credential = DefaultAzureCredential()
credential = create_token_credential()
phone_number_client = PhoneNumberAdministrationClient(endpoint, credential)
async with phone_number_client:
pages = phone_number_client.list_all_phone_numbers()
Expand Down

0 comments on commit d8e0aa7

Please sign in to comment.