Skip to content

Commit

Permalink
Apply formatting fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
akx committed Oct 12, 2021
1 parent c10da27 commit 9e623ee
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 91 deletions.
53 changes: 26 additions & 27 deletions iron_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ def __init__(self, keystone):
self.token = None
self.local_expires_at_timestamp = 0


def getToken(self):
date_diff = time.mktime(datetime.now().timetuple()) - self.local_expires_at_timestamp
if self.token is None or date_diff > -10:
Expand Down Expand Up @@ -84,34 +83,34 @@ def __init__(self, name, version, product, host=None, project_id=None,
None.
"""
config = {
"host": None,
"protocol": "https",
"port": 443,
"api_version": None,
"project_id": None,
"token": None,
"keystone": None,
"path_prefix": None,
"cloud": None,
"host": None,
"protocol": "https",
"port": 443,
"api_version": None,
"project_id": None,
"token": None,
"keystone": None,
"path_prefix": None,
"cloud": None,
}
products = {
"iron_worker": {
"host": "worker-aws-us-east-1.iron.io",
"version": 2
},
"iron_mq": {
"host": "mq-aws-us-east-1-1.iron.io",
"version": 3
},
"iron_cache": {
"host": "cache-aws-us-east-1.iron.io",
"version": 1
}
"iron_worker": {
"host": "worker-aws-us-east-1.iron.io",
"version": 2
},
"iron_mq": {
"host": "mq-aws-us-east-1-1.iron.io",
"version": 3
},
"iron_cache": {
"host": "cache-aws-us-east-1.iron.io",
"version": 1
}
}
if product in products:
config["host"] = products[product]["host"]
config["api_version"] = products[product]["version"]

try:
config = configFromFile(config,
os.path.expanduser("~/.iron.json"), product)
Expand Down Expand Up @@ -145,8 +144,6 @@ def __init__(self, name, version, product, host=None, project_id=None,
if config["token"] is None and not keystone_configured:
raise ValueError("At least one of token or keystone should be specified.")



self.name = name
self.version = version
self.product = product
Expand All @@ -160,8 +157,8 @@ def __init__(self, name, version, product, host=None, project_id=None,
self.cloud = config["cloud"]

self.headers = {
"Accept": "application/json",
"User-Agent": f"{self.name} (version: {self.version})"
"Accept": "application/json",
"User-Agent": f"{self.name} (version: {self.version})"
}
self.path_prefix = config["path_prefix"]

Expand Down Expand Up @@ -357,6 +354,7 @@ def fromTimestamp(timestamp=None):
return timestamp
return datetime.fromtimestamp(float(timestamp))


def configFromFile(config, path, product=None):
if path is None:
return config
Expand Down Expand Up @@ -396,5 +394,6 @@ def configFromArgs(config, **kwargs):
config[k] = kwargs[k]
return config


def intersect(a, b):
return list(set(a) & set(b))
59 changes: 31 additions & 28 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,39 @@
from setuptools import setup
import sys

setup(
name = "iron-core",
py_modules = ["iron_core"],
install_requires=["requests >= 1.1.0", "python-dateutil"],
version = "1.2.0",
description = "Universal classes and methods for Iron.io API wrappers to build on.",
author = "Iron.io",
author_email = "[email protected]",
url = "https://www.github.com/iron-io/iron_core_python",
keywords = ["Iron.io"],
python_requires=">=3.6",
classifiers = [
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Intended Audience :: Developers",
"Operating System :: OS Independent",
"Development Status :: 2 - Pre-Alpha",
"License :: OSI Approved :: BSD License",
"Natural Language :: English",
"Topic :: Internet",
"Topic :: Internet :: WWW/HTTP",
"Topic :: Software Development :: Libraries :: Python Modules",

],
long_description = """\
LONG_DESCRIPTION = """
Iron.io common library
----------------------
This package offers common functions for Iron.io APIs and services. It does not wrap
This package offers common functions for Iron.io APIs and services. It does not wrap
any APIs or contain API-specific features, but serves as a common base that wrappers
may be built on. Users looking for API wrappers should instead look at
iron_worker_python and iron_worker_mq.""",
may be built on. Users looking for API wrappers should instead look at
iron_worker_python and iron_worker_mq.
""".strip()

setup(
name="iron-core",
py_modules=["iron_core"],
install_requires=["requests >= 1.1.0", "python-dateutil"],
version="1.2.0",
description="Universal classes and methods for Iron.io API wrappers to build on.",
author="Iron.io",
author_email="[email protected]",
url="https://www.github.com/iron-io/iron_core_python",
keywords=["Iron.io"],
python_requires=">=3.6",
classifiers=[
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Intended Audience :: Developers",
"Operating System :: OS Independent",
"Development Status :: 2 - Pre-Alpha",
"License :: OSI Approved :: BSD License",
"Natural Language :: English",
"Topic :: Internet",
"Topic :: Internet :: WWW/HTTP",
"Topic :: Software Development :: Libraries :: Python Modules",

],
long_description=LONG_DESCRIPTION,
)
75 changes: 39 additions & 36 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ def test_fromArgsUseHTTP(self):

def test_fromArgsConfigFileGlobal(self):
test_config = {
"host": "test-config-host",
"protocol": "test-config-protocol",
"port": "test-config-port",
"api_version": "test-config-api-version",
"project_id": "test-config-project-id",
"token": "test-config-token"
"host": "test-config-host",
"protocol": "test-config-protocol",
"port": "test-config-port",
"api_version": "test-config-api-version",
"project_id": "test-config-project-id",
"token": "test-config-token"
}

file = open("test_config.json", "w")
Expand All @@ -95,74 +95,74 @@ def test_fromArgsConfigFileGlobal(self):

def test_fromArgsConfigFileProduct(self):
test_config = {
"iron_worker": {
"host": "test-config-host",
"protocol": "test-config-protocol",
"port": "test-config-port",
"api_version": "test-config-api-version",
"project_id": "test-config-project-id",
"token": "test-config-token"
}
"iron_worker": {
"host": "test-config-host",
"protocol": "test-config-protocol",
"port": "test-config-port",
"api_version": "test-config-api-version",
"project_id": "test-config-project-id",
"token": "test-config-token"
}
}

file = open("test_config.json", "w")
file.write(json.dumps(test_config))
file.close()

client = iron_core.IronClient(name="Test", version="0.1.0",
product="iron_worker", config_file="test_config.json")
product="iron_worker", config_file="test_config.json")

self.assertEqual(client.host, test_config["iron_worker"]["host"])
self.assertEqual(client.protocol,
test_config["iron_worker"]["protocol"])
test_config["iron_worker"]["protocol"])
self.assertEqual(client.port, test_config["iron_worker"]["port"])
self.assertEqual(client.api_version,
test_config["iron_worker"]["api_version"])
test_config["iron_worker"]["api_version"])
self.assertEqual(client.project_id,
test_config["iron_worker"]["project_id"])
test_config["iron_worker"]["project_id"])
self.assertEqual(client.token, test_config["iron_worker"]["token"])

os.remove("test_config.json")

def test_fromArgsConfigFileMixed(self):
test_config = {
"host": "test-config-host-global",
"protocol": "test-config-protocol-global",
"port": "test-config-port-global",
"project_id": "test-config-project-id-global",
"iron_worker": {
"api_version": "test-config-api-version-product",
"project_id": "test-config-project-id-product",
"token": "test-config-token-product"
}
"host": "test-config-host-global",
"protocol": "test-config-protocol-global",
"port": "test-config-port-global",
"project_id": "test-config-project-id-global",
"iron_worker": {
"api_version": "test-config-api-version-product",
"project_id": "test-config-project-id-product",
"token": "test-config-token-product"
}
}

file = open("test_config.json", "w")
file.write(json.dumps(test_config))
file.close()

client = iron_core.IronClient(name="Test", version="0.1.0",
product="iron_worker", config_file="test_config.json")
product="iron_worker", config_file="test_config.json")

self.assertEqual(client.host, test_config["host"])
self.assertEqual(client.protocol, test_config["protocol"])
self.assertEqual(client.port, test_config["port"])
self.assertEqual(client.api_version,
test_config["iron_worker"]["api_version"])
test_config["iron_worker"]["api_version"])
self.assertEqual(client.project_id,
test_config["iron_worker"]["project_id"])
test_config["iron_worker"]["project_id"])
self.assertEqual(client.token, test_config["iron_worker"]["token"])

os.remove("test_config.json")

def test_fromArgsAndArgsConfigFile(self):
test_config = {
"host": "test-config-host",
"protocol": "test-config-protocol",
"port": "test-config-port",
"api_version": "test-config-api-version",
"project_id": "test-config-project-id",
"token": "test-config-token"
"host": "test-config-host",
"protocol": "test-config-protocol",
"port": "test-config-port",
"api_version": "test-config-api-version",
"project_id": "test-config-project-id",
"token": "test-config-token"
}

file = open("test_config.json", "w")
Expand Down Expand Up @@ -255,13 +255,16 @@ def test_checkTrailingSlash(self):
keystone = iron_core.KeystoneTokenProvider(keystone_data)
self.assertEqual("http://localhost/", keystone.server)


def create_test_config(filename, content):
file = open(filename, "w")
file.write(json.dumps(content))
file.close()


def remove_test_config(filename):
os.remove(filename)


if __name__ == "__main__":
unittest.main()

0 comments on commit 9e623ee

Please sign in to comment.