-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from zowe/SampleSDK
Sample SDK
- Loading branch information
Showing
9 changed files
with
253 additions
and
4 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 |
---|---|---|
@@ -1,7 +1,38 @@ | ||
# Zowe Python SDK Sample | ||
|
||
## Requirements | ||
|
||
The sample SDK has the following requirements: | ||
``` | ||
black | ||
isort | ||
zowe.core-for-zowe-sdk~=1.0.0.dev | ||
pytest==7.1.2 | ||
``` | ||
You can install the requirements in a virtual environment with following commands: | ||
|
||
```shell | ||
python3 -m venv venv | ||
source venv/bin/activate | ||
pip install -r requirements.txt | ||
``` | ||
|
||
You can clone the repository using `git`: | ||
|
||
``` | ||
git clone https://github.com/zowe/zowe-client-samples.git | ||
``` | ||
|
||
## Quickstart | ||
|
||
After you install the package, import the class SampleSDK from modules. | ||
|
||
Below is a simple script of how to run the sample SDK, assuming the script file is located under the `python-sdk-sample` folder: | ||
|
||
```python | ||
from org.sample_for_zowe_sdk import SampleSdk | ||
|
||
t = SampleSdk() | ||
result = t.create_post({"title": "foo", "body": "bar", "userId": 10}) | ||
print(result) | ||
``` |
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 |
---|---|---|
@@ -1,5 +1,12 @@ | ||
[project] | ||
name = "org_sample-for-zowe-sdk" | ||
version = "0.0.1" | ||
|
||
[tool.black] | ||
line-length = 120 | ||
|
||
[tool.isort] | ||
profile = "black" | ||
|
||
[tool.setuptools.package-dir] | ||
"org.sample_for_zowe_sdk" = "src" |
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
black | ||
isort | ||
zowe.core-for-zowe-sdk~=1.0.0.dev | ||
zowe.core-for-zowe-sdk>=1.0.0-dev16 | ||
pytest==7.1.2 | ||
-e . |
This file was deleted.
Oops, something went wrong.
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 @@ | ||
from .main import SampleSdk |
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
45 changes: 45 additions & 0 deletions
45
python-sdk-sample/tests/integration/test_integration_sample_sdk.py
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,45 @@ | ||
from unittest import TestCase | ||
|
||
import sys | ||
import os | ||
|
||
current_dir = os.path.dirname(os.path.abspath(__file__)) | ||
sys.path.append(os.path.join(current_dir, "../..")) | ||
from src import SampleSdk | ||
|
||
class TestSampleSDK(TestCase): | ||
|
||
def setUp(self): | ||
self.expected = {"title": "foo", "body": "bar", "userId": 10} | ||
|
||
def is_subset(self, dict1, dict2): | ||
for key, value in dict1.items(): | ||
if key not in dict2 or dict2[key] != value: | ||
return False | ||
return True | ||
|
||
def test_create_post(self): | ||
sdk = SampleSdk() | ||
result = sdk.create_post(self.expected) | ||
self.assertTrue(self.is_subset(self.expected, result)) | ||
|
||
def test_get_post(self): | ||
sdk = SampleSdk() | ||
result = sdk.get_post(1) | ||
self.assertEqual(result.get("id"), 1) | ||
|
||
def test_update_post(self): | ||
sdk = SampleSdk() | ||
result = sdk.update_post(1, self.expected) | ||
self.assertTrue(self.is_subset(self.expected, result)) | ||
|
||
def test_delete_post(self): | ||
sdk = SampleSdk() | ||
result = sdk.delete_post(1) | ||
self.assertEqual(result, {}) | ||
|
||
def test_list_post(self): | ||
sdk = SampleSdk() | ||
result = sdk.list_post() | ||
self.assertIsInstance(result, list) | ||
self.assertIsInstance(result[0], dict) |
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,45 @@ | ||
from unittest import TestCase, mock | ||
|
||
import sys | ||
import os | ||
|
||
current_dir = os.path.dirname(os.path.abspath(__file__)) | ||
sys.path.append(os.path.join(current_dir, "../..")) | ||
from src import SampleSdk | ||
|
||
class TestSampleSDK(TestCase): | ||
|
||
@mock.patch("requests.Session.send") | ||
def test_create_post(self, mock_send_request): | ||
mock_send_request.return_value = mock.Mock(headers={"Content-Type": "application/json"}, status_code=201) | ||
post = SampleSdk() | ||
result = post.create_post({"title": "foo", "body": "bar", "userId": 10}) | ||
mock_send_request.assert_called() | ||
|
||
@mock.patch("requests.Session.send") | ||
def test_update_post(self, mock_send_request): | ||
mock_send_request.return_value = mock.Mock(headers={"Content-Type": "application/json"}, status_code=200) | ||
post = SampleSdk() | ||
result = post.update_post(1, {"title": "foo", "body": "bar", "userId": 10}) | ||
mock_send_request.assert_called() | ||
|
||
@mock.patch("requests.Session.send") | ||
def test_get_post(self, mock_send_request): | ||
mock_send_request.return_value = mock.Mock(headers={"Content-Type": "application/json"}, status_code=200) | ||
post = SampleSdk() | ||
result = post.get_post(1) | ||
mock_send_request.assert_called() | ||
|
||
@mock.patch("requests.Session.send") | ||
def test_list_post(self, mock_send_request): | ||
mock_send_request.return_value = mock.Mock(headers={"Content-Type": "application/json"}, status_code=200) | ||
post = SampleSdk() | ||
result = post.list_post() | ||
mock_send_request.assert_called() | ||
|
||
@mock.patch("requests.Session.send") | ||
def test_delete_post(self, mock_send_request): | ||
mock_send_request.return_value = mock.Mock(headers={"Content-Type": "application/json"}, status_code=200) | ||
post = SampleSdk() | ||
result = post.delete_post(1) | ||
mock_send_request.assert_called() |