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
class MyPrint: | |
def __init__(self): | |
pass | |
def myPrint(self): | |
for item in range(10): | |
print("This is the item at " + str(item) + " .") | |
return True |
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
import socket | |
import requests | |
# ...snippet | |
def call_api(url): | |
try: | |
requests.get(url="url") | |
except: | |
socket.error as e: |
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
import socket | |
import inject_exception | |
import requests | |
from mock import patch | |
import nose.tools | |
# ...snippet | |
def test_api_call(): | |
with patch.object(requests, "get") as get_mock: |
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
import socket | |
# ...snippet | |
class ExceededRetries(StopIteration): | |
pass | |
def call_api(url): | |
try: | |
requests.get(url="url") |
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
import socket | |
import inject_exception2 | |
import requests | |
from mock import patch | |
import nose.tools | |
# ...snippet | |
def test_api_call(): | |
with patch.object(requests, "get") as get_mock: |
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
class APIWrapper: | |
#snippet... | |
def poll_api(self, tries, initial_delay, delay, backoff, success_list, apifunction, *args): | |
time.sleep(initial_delay) | |
for n in range(tries): | |
try: | |
status = self.get_status() | |
if status not in success_list: |
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
import requests | |
import json | |
class AbstractDataProvider(): | |
"""A list of methods that data providers should implement or extend.""" | |
def __init__(self, base_url, username=None, password=None): | |
self.base_url = base_url.rstrip('/') | |
self.username = username | |
self.password = password |
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
import json | |
import jsonschema | |
import requests | |
def get_valid_json(self, data, json_schema_url): | |
""" | |
Validates a json artifact against a published schema. | |
""" | |
s = requests.get(url=json_schema_url) | |
schema = s.json() |
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
import jsonschema | |
import json | |
import nose.tools | |
def test_schema_generator(): | |
test_setup_data = [ | |
{"schema": "../schema/1.0/build-manifest.json", "tests": "build-manifest-validtests.json", "assert_function": nose.tools.assert_true}, | |
{"schema": "../schema/1.0/build-manifest.json", "tests": "build-manifest-invalidtests.json", "assert_function": nose.tools.assert_false}] | |
for test_setup in test_setup_data: |
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
def create_build_info(self, build_name, build_number, dependencies, build_dependencies): | |
""" | |
Returns a build info dictionary which is formated to correctly deploy | |
a new build to artifactory. | |
Make a put request with this build info to api/build | |
""" | |
build_info = {'version': '1.0.1', | |
'name': build_name, | |
'number': str(build_number), | |
'type': 'GENERIC', |
OlderNewer