-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconftest.py
103 lines (88 loc) · 2.68 KB
/
conftest.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import argparse
import os
import pathlib
import shutil
import tempfile
from uuid import uuid4
import pytest
import requests_mock
from src.action import Action
SERVER = os.getenv("SERVER")
LOGIN = os.getenv("LOGIN")
KEY = os.getenv("KEY")
@pytest.fixture
def tmp_folder():
folder = tempfile.mkdtemp()
yield folder
shutil.rmtree(folder)
@pytest.fixture()
def action():
action = Action()
yield action
@pytest.fixture(scope="session")
def action_logged_mocked(args):
with requests_mock.Mocker() as mock_request:
action = Action()
action.args = args
secrets = {
'server': 'https://testing.com',
'login': '123',
'key': '123',
}
mock_request.get(f'{secrets["server"]}/api/v2/maestro/version', json={'version': '2.0'})
mock_request.post(f'{secrets["server"]}/api/v2/workspace/login', json={'accessToken': '123'})
mock_request.get(f'{secrets["server"]}/api/v2/bot?botId={args.botId}', json=[{'botId': args.botId}])
mock_request.post(f'{secrets["server"]}/api/v2/bot/upload/{args.botId}/version/{args.version}', json={})
mock_request.post(f'{secrets["server"]}/api/v2/bot', json={})
mock_request.post(f'{secrets["server"]}/api/v2/bot/release', json={})
mock_request.delete(f'{secrets["server"]}/api/v2/bot/{args.botId}/version/{args.version}', json={})
action.maestro = action._get_maestro(secrets=secrets)
action.headers = {
"Content-Type": "application/json",
"token": action.maestro.access_token,
"organization": action.maestro.organization
}
action.filepath = action._get_file_path()
yield action
@pytest.fixture(scope="session")
def bot_id():
return f'Test-Action-{uuid4()}'
@pytest.fixture(scope="session")
def args(bot_id):
print(bot_id)
args = argparse.Namespace()
args.update = False
args.deploy = False
args.release = False
args.version = '1.0'
args.path = pathlib.Path().absolute()
args.botId = bot_id
args.technology = "python"
args.actionPath = pathlib.Path().absolute()
args.botPath = './bot.zip'
args.repositoryLabel = "DEFAULT"
return args
@pytest.fixture()
def args_mocked(args):
args_mocked = [
"main",
"--update",
'true',
"--deploy",
'true',
"--release",
'true',
"--version",
args.version,
"--path",
str(pathlib.Path().absolute()),
"--botPath",
'./bot.zip',
"--botId",
args.botId,
"--technology",
'python',
"--actionPath",
str(pathlib.Path().absolute()),
]
return args_mocked