-
Notifications
You must be signed in to change notification settings - Fork 2
/
tests.py
77 lines (58 loc) · 2.34 KB
/
tests.py
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import os
import unittest
from estela_cli.estela_client import EstelaClient
from estela_cli.login import login, DEFAULT_ESTELA_API_HOST
from dotenv import load_dotenv
class TestEstelaClient(unittest.TestCase):
client = None
def __init__(self, *args, **kwargs):
self.client = login()
super().__init__(*args, **kwargs)
def test_wrong_credentials(self):
with self.assertRaises(Exception) as error:
EstelaClient(
DEFAULT_ESTELA_API_HOST,
username="wrong_user",
password="wrong_password",
)
self.assertEqual(
str(error.exception), "['Unable to log in with provided credentials.']"
)
def test_create_project(self):
project_name = "test_project"
project = self.client.create_project(name=project_name)
self.assertIn("pid", project)
self.assertIn("name", project)
self.assertIn("container_image", project)
self.assertEqual(project["name"], project_name)
self.client.delete_project(project["pid"])
def test_get_project(self):
project_name = "test_project"
project = self.client.create_project(name=project_name)
project = self.client.get_project(pid=project["pid"])
self.assertIn("pid", project)
self.assertIn("name", project)
self.assertIn("container_image", project)
self.assertEqual(project["name"], project_name)
self.client.delete_project(project["pid"])
def test_not_found_project(self):
with self.assertRaises(Exception) as error:
self.client.get_project(pid="wrong_pid")
self.assertIn("Not found.", str(error.exception))
def test_get_projects(self):
project_name = "test_project"
project = self.client.create_project(name=project_name)
projects = self.client.get_projects()
project = [
proj
for proj in projects
if proj["name"] == project_name and proj["pid"] == project["pid"]
][0]
self.assertIn("pid", project)
self.assertIn("name", project)
self.assertIn("container_image", project)
self.assertEqual(project["name"], project_name)
self.client.delete_project(project["pid"])
if __name__ == "__main__":
load_dotenv()
unittest.main()