-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #56 from QualiSystems/wip/adam.s/179924_support_token
Wip/adam.s/179924 support token
- Loading branch information
Showing
13 changed files
with
187 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
cloudshell-shell-core>=3.1.0,<3.2.0 | ||
cloudshell-cm-customscript>=1.5.0,<1.6.0 | ||
cloudshell-cm-customscript>=1.6.0,<1.7.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
1.5.0 | ||
1.6.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
nose | ||
mock | ||
unittest2 | ||
unittest2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,47 @@ | ||
|
||
class Any(object): | ||
def __init__(self, predicate=None): | ||
self.predicate = predicate | ||
def __eq__(self, other): | ||
return not self.predicate or self.predicate(other) | ||
|
||
def mocked_requests_get(*args, **kwargs): | ||
''' | ||
Helper method for mocking requests for test_script_downloader | ||
''' | ||
repo_dict = { | ||
"public": 'https://raw.repocontentservice.com/SomeUser/SomePublicRepo/master/bashScript.sh', | ||
"private_token": 'https://raw.repocontentservice.com/SomeUser/SomePrivateTokenRepo/master/bashScript.sh', | ||
"private_cred": 'https://raw.repocontentservice.com/SomeUser/SomePrivateCredRepo/master/bashScript.sh', | ||
"content": 'SomeBashScriptContent' | ||
} | ||
|
||
class MockResponse: | ||
def __init__(self, json_data, status_code, headers, url): | ||
self.json_data = json_data | ||
self.status_code = status_code | ||
self.headers = headers | ||
self.url = url | ||
|
||
def json(self): | ||
return self.json_data | ||
|
||
def iter_content(self, chunk): | ||
return self.json_data | ||
|
||
if args[0] == repo_dict['public']: | ||
response = MockResponse(repo_dict['content'], 200, {"Content-Type": "text/plain"}, repo_dict['public']) | ||
return response | ||
|
||
if args[0] == repo_dict['private_token']: | ||
if 'headers' in kwargs: | ||
if kwargs["headers"]["Authorization"] == 'Bearer 551e48b030e1a9f334a330121863e48e43f58c55': | ||
response = MockResponse(repo_dict['content'], 200, {"Content-Type": "text/plain"}, repo_dict['private_token']) | ||
return response | ||
|
||
if args[0] == repo_dict['private_cred']: | ||
if 'auth' in kwargs and kwargs["auth"] is not None: | ||
if kwargs["auth"][0] == 'SomeUser' and kwargs["auth"][1] == 'SomePassword': | ||
response = MockResponse(repo_dict['content'], 200, {"Content-Type": "text/plain"}, repo_dict['private_cred']) | ||
return response | ||
|
||
return MockResponse(None, 404, None, None) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
from unittest import TestCase | ||
|
||
from cloudshell.cm.customscript.domain.script_executor import ExcutorConnectionError | ||
from mock import patch, Mock | ||
import mock | ||
from cloudshell.cm.customscript.customscript_shell import CustomScriptShell | ||
from cloudshell.cm.customscript.domain.reservation_output_writer import ReservationOutputWriter | ||
from cloudshell.cm.customscript.domain.script_configuration import ScriptConfiguration | ||
from cloudshell.cm.customscript.domain.script_file import ScriptFile | ||
from cloudshell.cm.customscript.domain.script_downloader import ScriptDownloader, HttpAuth | ||
from cloudshell.cm.customscript.domain.script_configuration import ScriptRepository | ||
from tests.helpers import mocked_requests_get | ||
|
||
from tests.helpers import Any | ||
|
||
def print_logs(message): | ||
print(message) | ||
|
||
class TestScriptDownloader(TestCase): | ||
|
||
def setUp(self): | ||
self.logger = Mock() | ||
self.cancel_sampler = Mock() | ||
self.logger_patcher = patch('cloudshell.cm.customscript.customscript_shell.LoggingSessionContext') | ||
self.logger_patcher.start() | ||
self.script_repo = ScriptRepository() | ||
pass | ||
|
||
@mock.patch('cloudshell.cm.customscript.domain.script_downloader.requests.get', side_effect=mocked_requests_get) | ||
def test_download_as_public(self, mock_requests): | ||
# public - url, no credentials | ||
public_repo_url = 'https://raw.repocontentservice.com/SomeUser/SomePublicRepo/master/bashScript.sh' | ||
self.auth = HttpAuth('','','') | ||
|
||
# set downloaded and downaload | ||
self.logger.info = print_logs | ||
script_downloader = ScriptDownloader(self.logger, self.cancel_sampler) | ||
script_file = script_downloader.download(public_repo_url, self.auth) | ||
|
||
# assert name and content | ||
self.assertEqual(script_file.name, "bashScript.sh") | ||
self.assertEqual(script_file.text, "SomeBashScriptContent") | ||
|
||
@mock.patch('cloudshell.cm.customscript.domain.script_downloader.requests.get', side_effect=mocked_requests_get) | ||
def test_download_as_private_with_token(self, mocked_requests_get): | ||
# private - url, with token | ||
private_repo_url = 'https://raw.repocontentservice.com/SomeUser/SomePrivateTokenRepo/master/bashScript.sh' | ||
self.auth = HttpAuth('','','551e48b030e1a9f334a330121863e48e43f58c55') | ||
|
||
# set downloaded and downaload | ||
self.logger.info = print_logs | ||
script_downloader = ScriptDownloader(self.logger, self.cancel_sampler) | ||
script_file = script_downloader.download(private_repo_url, self.auth) | ||
|
||
# assert name and content | ||
self.assertEqual(script_file.name, "bashScript.sh") | ||
self.assertEqual(script_file.text, "SomeBashScriptContent") | ||
|
||
@mock.patch('cloudshell.cm.customscript.domain.script_downloader.requests.get', side_effect=mocked_requests_get) | ||
def test_download_as_private_with_credentials_and_failed_token(self, mocked_requests_get): | ||
# private - url, with token that fails and user\password. note - this is will not work on GitHub repo, they require token | ||
private_repo_url = 'https://raw.repocontentservice.com/SomeUser/SomePrivateCredRepo/master/bashScript.sh' | ||
self.auth = HttpAuth('SomeUser','SomePassword','551e48b030e1a9f334a330121863e48e43f0000') | ||
|
||
# set downloaded and downaload | ||
self.logger.info = print_logs | ||
script_downloader = ScriptDownloader(self.logger, self.cancel_sampler) | ||
script_file = script_downloader.download(private_repo_url, self.auth) | ||
|
||
# assert name and content | ||
self.assertEqual(script_file.name, "bashScript.sh") | ||
self.assertEqual(script_file.text, "SomeBashScriptContent") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
1.5.0 | ||
1.6.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
1.5.0 | ||
1.6.0 |