Skip to content

Commit 3c09b32

Browse files
committed
Adding in test-apps
1 parent 95d267d commit 3c09b32

File tree

21 files changed

+321
-0
lines changed

21 files changed

+321
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
APP_FILE = service.py
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# In this file you can add files/folders to ignore when deploying
2+
# Works similar to a .gitignore file
3+
4+
# Ignore the .git folder to not only use committed code
5+
.git/
6+
7+
# Test directory is not needed in production
8+
tests/
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Daeploy project: my_project
2+
3+
## Creating the service
4+
5+
The ```service.py``` contains an example service and shows how to use the daeploy SDK.
6+
7+
This example shows:
8+
9+
- How to initiate a daeploy service
10+
- How to register changeable parameters
11+
- How to register functions as entrypoints
12+
- How to log from the service
13+
- How to send notifications from the service
14+
- How to start the service
15+
16+
If the service requires external packages, they should be specified in the `requirements.txt` file.
17+
18+
## Deploying the service
19+
20+
The service can be deployed using the daeploy command-line interface:
21+
22+
From a local directory or tarball (.tar.gz):
23+
24+
```daeploy deploy myservice 0.0.1 <path_to_project>```
25+
26+
From a git repository:
27+
28+
```daeploy deploy myservice 0.0.1 --git <git_url>```
29+
30+
## Documentation
31+
32+
Full documentation of the SDK and the CLI can be found here: [https://vikinganalytics.github.io/daeploy-docs/](https://vikinganalytics.github.io/daeploy-docs/)
33+
34+
## Extra
35+
36+
If you want to change name of the service file ```service.py```, or deploy another file as the
37+
daeploy service then you have to change the ```APP_FILE``` key in the ```.s2i/environment``` file.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
daeploy
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import logging
2+
from daeploy import service
3+
4+
logger = logging.getLogger(__name__)
5+
6+
service.add_parameter("greeting_phrase", "Hello")
7+
8+
9+
@service.entrypoint
10+
def hello(name: str) -> str:
11+
greeting_phrase = service.get_parameter("greeting_phrase")
12+
logger.info(f"Greeting someone with the name: {name}")
13+
return f"{greeting_phrase} {name}"
14+
15+
16+
if __name__ == "__main__":
17+
service.run()
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from pathlib import Path
2+
3+
# Change import if you have changed name of service.py
4+
import service as app
5+
6+
# Read service source file
7+
SERVICE_DIR = Path(__file__).parent.parent
8+
service_path = (SERVICE_DIR / app.__name__).with_suffix(".py")
9+
with service_path.open("r") as file_handle:
10+
service_code = file_handle.read()
11+
12+
13+
def test_service_run():
14+
run_statement = "service.run()"
15+
run_row = ""
16+
17+
for item in service_code.split("\n"):
18+
if run_statement in item:
19+
run_row = item
20+
21+
assert (
22+
run_statement in run_row
23+
), f"For the service to run, the service code must end with {run_statement}"
24+
25+
run = run_row.find(run_statement)
26+
comment = run_row.find("#")
27+
assert comment == -1 or comment > run, f"{run_statement} commented out"
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Change import if you have changed name of service.py
2+
from daeploy.testing import patch
3+
import service
4+
5+
# Test functions should always start with test_...
6+
# Daeploy tests use the pytest package
7+
8+
# Example tests:
9+
10+
11+
def test_hello():
12+
# Test that service.hello("Bob") returns what is expected
13+
assert service.hello("Bob") == "Hello Bob"
14+
15+
16+
# Add your tests here
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
APP_FILE = service.py
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# In this file you can add files/folders to ignore when deploying
2+
# Works similar to a .gitignore file
3+
4+
# Ignore the .git folder to not only use committed code
5+
.git/
6+
7+
# Test directory is not needed in production
8+
tests/
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Daeploy project: my_project
2+
3+
## Creating the service
4+
5+
The ```service.py``` contains an example service and shows how to use the daeploy SDK.
6+
7+
This example shows:
8+
9+
- How to initiate a daeploy service
10+
- How to register changeable parameters
11+
- How to register functions as entrypoints
12+
- How to log from the service
13+
- How to send notifications from the service
14+
- How to start the service
15+
16+
If the service requires external packages, they should be specified in the `requirements.txt` file.
17+
18+
## Deploying the service
19+
20+
The service can be deployed using the daeploy command-line interface:
21+
22+
From a local directory or tarball (.tar.gz):
23+
24+
```daeploy deploy myservice 0.0.1 <path_to_project>```
25+
26+
From a git repository:
27+
28+
```daeploy deploy myservice 0.0.1 --git <git_url>```
29+
30+
## Documentation
31+
32+
Full documentation of the SDK and the CLI can be found here: [https://vikinganalytics.github.io/daeploy-docs/](https://vikinganalytics.github.io/daeploy-docs/)
33+
34+
## Extra
35+
36+
If you want to change name of the service file ```service.py```, or deploy another file as the
37+
daeploy service then you have to change the ```APP_FILE``` key in the ```.s2i/environment``` file.

0 commit comments

Comments
 (0)