Skip to content

Commit

Permalink
Add AzureTest framework (#967)
Browse files Browse the repository at this point in the history
* Initial commit for AzureTest.

* AzureTest DVR commit.

* Rename "AzureTestClient" to "ResourceUtilityClient". Eliminate MSAL dependency for AzureTest.

* Add util function to AzureTest to get environment variables (moved out of Chat).

* DVR updates. (#896)

* Update DVR references to point to fork rather than venmo (#903)

* Update DVR references to point to fork rather than venmo.

* Remove static linkage to DVR.

* Recordings on a per-test basis (#904)

* Feature/recording location (#907)

* Environment Variable for sdk root

* Revert project.pbxproj

* Edit to outputDirectory construction

* Env Variable TEST_MODE works as expected (#909)

* Environment Variable for sdk root

Enforce that DVR record-playback honors environment variables

* Environment Variables work as intended with the new DVR updates

* Undo Podfile Changes

Local Changes that need to be removed

* Slight edit to record mode

Co-authored-by: Jair Myree <t-jairmyree@microsoft.com>

* Automated means of creating test resources (#912)

* Add resource group delete operation.

* Progress.

* Project setting fixes.

* Add test-resources.bicep file.

* Update bicep file.

* Target python script in test resource deploy post-script.

* Remove ResourceUtil files and dependencies.

* Revert to previous output style.

* Remove empty environment variable. (#919)

* Injectable test settings  (#924)

* Commit test-settings.plist and git-ignore.

* TestSettings protocol.

* Update Podfile for DVR

* Don't use local DVR

* Chat test updates.

* Add recordings to project.

* Update prepare_chat_tests.py

* Update deployment targets.

* Add podspec.

* Add readme.

* Fix hard-coded links.

* Scrub headings and commit chat test recordings. (#935)

* Remove headers.

* Add scrubbed recordings.

* Feature/scrub subscription ids (#932)

* Major edits toward scrubbing subscription IDs

* Minor edits on scrubbing

* Update sdk/test/AzureTest/Scrubbing.swift

Co-authored-by: Travis Prescott <tjprescott@users.noreply.github.com>

* Update sdk/test/AzureTest/Scrubbing.swift

Co-authored-by: Travis Prescott <tjprescott@users.noreply.github.com>

* Update sdk/test/AzureTest/Scrubbing.swift

Co-authored-by: Travis Prescott <tjprescott@users.noreply.github.com>

* Update sdk/test/AzureTest/Scrubbing.swift

Co-authored-by: Travis Prescott <tjprescott@users.noreply.github.com>

* Recommit: Files changes got left out of last commit

* Requested Draft PR changes

* Clean up after rebase

* Testing response scrubbing in progress

* Finished Scrubbing SubscriptionIDs

* Adjustments made to PR based on review comments.

* Edits to PR based on review comments

* Update sdk/test/AzureTest/AzureTestTests/AzureTestTests.swift

Co-authored-by: Travis Prescott <tjprescott@users.noreply.github.com>

* More edits based of pr review

* More edits to pr based off of review comments

* More edits to PR based off suggestions in review

* More edits to PR from review comments

* Removed unused functions and extensions

* Edits to PR based off review comments

* Edits to PR from review comments

* Edits based off PR review comments

Co-authored-by: Jair Myree <t-jairmyree@microsoft.com>
Co-authored-by: Travis Prescott <tjprescott@users.noreply.github.com>

* RPF: RecordableXCTestCase (#963)

* Add base class for recordable tests.

* Run swiftformat.

* CI fixes.

* Fix podspec source_files.

* Fix project structure.

* Fixes

* Fix broken links.

* CI fixes.

* Remove test-settings.plist reference.

* Re-record tests.

* Fix tests for playback.

Co-authored-by: Jair <67484440+jairmyree@users.noreply.github.com>
Co-authored-by: Jair Myree <t-jairmyree@microsoft.com>
  • Loading branch information
3 people committed Jul 27, 2021
1 parent 1f2e57a commit b72da16
Show file tree
Hide file tree
Showing 46 changed files with 3,891 additions and 666 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,4 @@ fastlane/test_output
.Trashes
Icon?
*.bak
test-settings.plist
20 changes: 15 additions & 5 deletions AzureSDK.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 33 additions & 8 deletions Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ use_frameworks!
platform :ios, '12.0'
workspace 'AzureSDK'

# update with local repo location
$dvr_path = '~/repos/DVR'
$use_local_dvr = false

target 'AzureTemplate' do
project 'sdk/template/AzureTemplate/AzureTemplate'
end

target 'AzureCommunicationCommon' do
project 'sdk/communication/AzureCommunicationCommon/AzureCommunicationCommon'

Expand All @@ -44,6 +52,12 @@ target 'AzureCommunicationChat' do
inherit! :search_paths
pod 'OHHTTPStubs/Swift'
pod 'Trouter', '0.0.1-beta.5'
pod 'MSAL', '1.1.15'
if $use_local_dvr
pod 'DVR', :path => $dvr_path
else
pod 'DVR', :git => 'https://github.com/tjprescott/DVR.git'
end
end

target 'AzureCommunicationChatUnitTests' do
Expand Down Expand Up @@ -81,14 +95,6 @@ target 'AzureStorageBlob' do
end
end

target 'AzureTemplate' do
project 'sdk/template/AzureTemplate/AzureTemplate'

target 'AzureTemplateTests' do
inherit! :search_paths
end
end

target 'AzureSDKDemoSwift' do
project 'examples/AzureSDKDemoSwift/AzureSDKDemoSwift'
pod 'MSAL', '1.1.15'
Expand All @@ -104,6 +110,25 @@ target 'AzureSDKDemoSwiftUI' do
pod 'MSAL', '1.1.15'
end

target 'AzureTest' do
project 'sdk/test/AzureTest/AzureTest'

if $use_local_dvr
pod 'DVR', :path => $dvr_path
else
pod 'DVR', :git => 'https://github.com/tjprescott/DVR.git'
end

target 'AzureTestTests' do
inherit! :search_paths
if $use_local_dvr
pod 'DVR', :path => $dvr_path
else
pod 'DVR', :git => 'https://github.com/tjprescott/DVR.git'
end
end
end

post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
Expand Down
43 changes: 28 additions & 15 deletions eng/scripts/prepare_chat_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,49 @@
1) Run `pip install azure.communication.administration` prior to running.
2) Set the `AZURE_COMMUNICATION_CS` environment variable
2) Run the script: `python prepare_chat_tests.py <CONNECTION_STRING>`
3) Run the script.
4) Copy the values to the AzureCommunicationChat scheme's testing environment variables and set `TEST_MODE` to
3) Copy the values to the AzureCommunicationChat scheme's testing environment variables and set `TEST_MODE` to
"record".
"""

import os
import sys
import plistlib
import urllib
import xml
from azure.communication.administration import CommunicationIdentityClient

connection_string = os.environ['AZURE_COMMUNICATION_CS']
connection_string = sys.argv[1]
identity_client = CommunicationIdentityClient.from_connection_string(connection_string)

items = { key:val for (key, val) in (x.split('=', 1) for x in connection_string.split(';')) }
endpoint = items['endpoint']

user1 = identity_client.create_user()
user2 = identity_client.create_user()

token = identity_client.issue_token(user1, scopes=["chat"]).token
data = {
'endpoint': items['endpoint'],
'user1': user1.identifier,
'user2': user2.identifier,
'token': identity_client.issue_token(user1, scopes=["chat"]).token
}

cwd = os.getcwd()
path = os.path.join(cwd, 'sdk', 'communication', 'AzureCommunicationChat', 'Tests', 'test-settings.plist')

print('\n== AZURE_COMMUNICATION_ENDPOINT ==')
print(endpoint)
print(f'Settings path: {path}')

print('\n== AZURE_COMMUNICATION_USER_ID_1 ==')
print(user1.identifier)
# update or create plist file
try:
with open(path, 'rb') as fp:
plist = plistlib.load(fp)
plist.update(data)
except (IOError, plistlib.InvalidFileException, xml.parsers.expat.ExpatError):
plist = data

print('\n== AZURE_COMMUNICATION_USER_ID_2 ==')
print(user2.identifier)
# save plist file
with open(path, 'wb') as fp:
plistlib.dump(plist, fp)

print('\n== AZURE_COMMUNICATION_TOKEN ==')
print(token)
print('==PLIST UPDATED SUCCESSFULLY==')
Loading

0 comments on commit b72da16

Please sign in to comment.