-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathe2e_test.py
More file actions
43 lines (35 loc) · 1.5 KB
/
e2e_test.py
File metadata and controls
43 lines (35 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env python3
"""E2E tests against real Codewire infrastructure.
Requires: CODEWIRE_API_KEY, CODEWIRE_ORG_ID
Optional: CODEWIRE_BASE_URL
"""
import unittest
from codewire import Codewire
class E2EFirstParty(unittest.TestCase):
def test_full_lifecycle(self):
with Codewire(timeout=300) as cw:
env = cw.environments.create(template_slug="python", wait=True, wait_timeout=300)
try:
result = env.exec(command=["python3", "--version"])
self.assertEqual(result["exit_code"], 0)
self.assertIn("Python", result["stdout"])
env.files.upload(b"hello", "/workspace/test.txt")
files = env.files.list("/workspace")
names = [f["name"] for f in files]
self.assertIn("test.txt", names)
data = env.files.download("/workspace/test.txt")
self.assertEqual(data, b"hello")
finally:
env.remove()
class E2EArbitraryImage(unittest.TestCase):
def test_exec_on_arbitrary_image(self):
with Codewire(timeout=300) as cw:
env = cw.environments.create(image="python:3.12-slim", wait=True, wait_timeout=300)
try:
result = env.exec(command=["python3", "-c", "print(1+1)"])
self.assertEqual(result["exit_code"], 0)
self.assertEqual(result["stdout"].strip(), "2")
finally:
env.remove()
if __name__ == "__main__":
unittest.main()