This repository has been archived by the owner on Oct 3, 2020. It is now read-only.
forked from kelproject/pykube
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
46 additions
and
0 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 |
---|---|---|
|
@@ -9,3 +9,4 @@ dist/ | |
.pytest_cache/ | ||
.tox/ | ||
docs/_build | ||
htmlcov/ |
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,42 @@ | ||
import pytest | ||
|
||
from unittest.mock import MagicMock | ||
|
||
from pykube import Pod, ObjectDoesNotExist | ||
|
||
from pykube.query import Query | ||
|
||
|
||
@pytest.fixture | ||
def api(): | ||
return MagicMock() | ||
|
||
|
||
def test_get(api): | ||
with pytest.raises(ObjectDoesNotExist): | ||
Query(api, Pod).get(namespace='myns') | ||
|
||
|
||
def test_filter_by_namespace(api): | ||
Query(api, Pod).filter(namespace='myns').execute() | ||
api.get.assert_called_once_with(namespace='myns', url='pods', version='v1') | ||
|
||
|
||
def test_filter_by_labels_eq(api): | ||
Query(api, Pod).filter(selector={'application': 'myapp', 'component': 'backend'}).execute() | ||
api.get.assert_called_once_with(url='pods?labelSelector=application%3Dmyapp%2Ccomponent%3Dbackend', version='v1') | ||
|
||
|
||
def test_filter_by_labels_neq(api): | ||
Query(api, Pod).filter(selector={'application__neq': 'myapp'}).execute() | ||
api.get.assert_called_once_with(url='pods?labelSelector=application+%21%3D+myapp', version='v1') | ||
|
||
|
||
def test_filter_by_labels_in(api): | ||
Query(api, Pod).filter(selector={'application__in': ['foo', 'bar']}).execute() | ||
api.get.assert_called_once_with(url='pods?labelSelector=application+in+%28bar%2Cfoo%29', version='v1') | ||
|
||
|
||
def test_filter_by_labels_notin(api): | ||
Query(api, Pod).filter(selector={'application__notin': ['foo', 'bar']}).execute() | ||
api.get.assert_called_once_with(url='pods?labelSelector=application+notin+%28bar%2Cfoo%29', version='v1') |