-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract kubernetes mockups to a common py file
Some common mockups are used in the tests of all providers. This PR prevents the duplication of code
- Loading branch information
Showing
3 changed files
with
53 additions
and
95 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from datetime import datetime, timezone, timedelta | ||
|
||
|
||
class MockedKubernetesConfig(): | ||
def load_kube_config(self, *args, **kwargs): | ||
return True | ||
|
||
|
||
class MockedKubernetesClient(): | ||
def __init__(self, jobs=[]): | ||
self.jobs = jobs | ||
self.deleted_jobs = [] | ||
|
||
# pylint: disable=C0103 | ||
def BatchV1Api(self): | ||
return self | ||
|
||
def list_job_for_all_namespaces(self, *args, **kwargs): | ||
return MockedKubernetesResult(self.jobs) | ||
|
||
def delete_namespaced_job(self, name, namespace): | ||
self.deleted_jobs.append(name) | ||
|
||
|
||
class MockedKubernetesResult(): | ||
def __init__(self, items): | ||
self.items = items | ||
|
||
|
||
class MockedKubernetesJobStatus(): | ||
def __init__(self, age): | ||
self.start_time = datetime.now(timezone.utc) - timedelta(days=age) | ||
|
||
|
||
class MockedKubernetesJobMetadata(): | ||
def __init__(self, name): | ||
self.name = name | ||
self.namespace = "default" | ||
|
||
|
||
class MockedKubernetesJob(): | ||
def __init__(self, name, age): | ||
self.status = MockedKubernetesJobStatus(age) | ||
self.metadata = MockedKubernetesJobMetadata(name) | ||
|
||
|
||
class MockedSubprocessReturn(): | ||
def __init__(self, returncode=0, stdout="", stderr=""): | ||
self.returncode = returncode | ||
self.stderr = stderr | ||
self.stdout = stdout |
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