-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add BaseFacade static class to allow access to API from anywhere (#15)
* Add Facade to allow for access to API and options * Set version to 0.8.0
- Loading branch information
Showing
6 changed files
with
82 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
"""Hold static information that can be accessed by any part of the package. | ||
A facade is an object that serves as a front-facing interface masking more complex | ||
underlying or structural code. | ||
""" | ||
from argparse import Namespace | ||
|
||
from drf_client.connection import Api as RestApi | ||
|
||
|
||
class BaseFacade: | ||
"""Stores key static information used across the package.""" | ||
|
||
api: RestApi or None = None | ||
api_options: dict or None = None | ||
cmd_args: Namespace or None = None | ||
|
||
@staticmethod | ||
def initialize_api(api_options: dict, cmd_args: Namespace = None): | ||
"""Initialize API with the given options.""" | ||
if BaseFacade.api is None: | ||
# Only initialize ones | ||
BaseFacade.api_options = api_options.copy() | ||
BaseFacade.api = RestApi(api_options) | ||
BaseFacade.cmd_args = cmd_args |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
"""test Resource class.""" | ||
import argparse | ||
import unittest | ||
|
||
from drf_client.helpers.base_facade import BaseFacade | ||
|
||
|
||
class FacadeTestCase(unittest.TestCase): | ||
"""Test static facade class.""" | ||
|
||
def test_initialize_facade(self): | ||
"""Test Initializer.""" | ||
BaseFacade.initialize_api({"DOMAIN": "https://example.com"}) | ||
assert BaseFacade.api_options["DOMAIN"] == "https://example.com" | ||
assert BaseFacade.api is not 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