-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* api: Shell2HttpAPI.delete method * tests: TestDeletion testcase * example: add deletion.py * docs: info about deletion.py
- Loading branch information
Showing
6 changed files
with
114 additions
and
18 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
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,29 @@ | ||
# web imports | ||
from flask import Flask | ||
from flask_executor import Executor | ||
from flask_shell2http import Shell2HTTP | ||
|
||
# Flask application instance | ||
app = Flask(__name__) | ||
|
||
# application factory | ||
executor = Executor(app) | ||
shell2http = Shell2HTTP(app, executor) | ||
|
||
|
||
shell2http.register_command( | ||
endpoint="sleep", | ||
command_name="sleep", | ||
) | ||
|
||
|
||
# Test Runner | ||
if __name__ == "__main__": | ||
app.testing = True | ||
c = app.test_client() | ||
# request new process | ||
r1 = c.post("/sleep", json={"args": ["10"], "force_unique_key": True}) | ||
print(r1) | ||
# request cancellation | ||
r2 = c.delete(f"/sleep?key={r1.get_json()['key']}") | ||
print(r2) |
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,36 @@ | ||
from examples.deletion import app | ||
|
||
from tests._utils import CustomTestCase | ||
|
||
|
||
class TestDeletion(CustomTestCase): | ||
uri = "/sleep" | ||
|
||
def create_app(self): | ||
app.config["TESTING"] = True | ||
return app | ||
|
||
def test_delete__204(self): | ||
# create command process | ||
r1 = self.client.post(self.uri, json={"args": ["10"], "force_unique_key": True}) | ||
r1_json = r1.get_json() | ||
self.assertStatus(r1, 202) | ||
# request cancellation: correct key | ||
r2 = self.client.delete(f"{self.uri}?key={r1_json['key']}") | ||
self.assertStatus(r2, 204) | ||
|
||
def test_delete__400(self): | ||
# create command process | ||
r1 = self.client.post(self.uri, json={"args": ["10"], "force_unique_key": True}) | ||
self.assertStatus(r1, 202) | ||
# request cancellation: no key | ||
r2 = self.client.delete(f"{self.uri}?key=") | ||
self.assertStatus(r2, 400) | ||
|
||
def test_delete__404(self): | ||
# create command process | ||
r1 = self.client.post(self.uri, json={"args": ["10"], "force_unique_key": True}) | ||
self.assertStatus(r1, 202) | ||
# request cancellation: invalid key | ||
r2 = self.client.delete(f"{self.uri}?key=abcdefg") | ||
self.assertStatus(r2, 404) |