1
1
import pytest
2
+ from unittest import mock
2
3
from ReversingLabs .SDK import __version__
3
4
from ReversingLabs .SDK .tiscale import TitaniumScale
4
- from ReversingLabs .SDK .helper import WrongInputError
5
+ from ReversingLabs .SDK .helper import WrongInputError , DEFAULT_USER_AGENT
5
6
6
7
7
8
def test_tiscale_object ():
@@ -22,3 +23,103 @@ def test_tiscale_object():
22
23
23
24
user_agent = tiscale ._headers .get ("User-Agent" )
24
25
assert __version__ in user_agent
26
+
27
+
28
+ @pytest .fixture
29
+ def requests_mock ():
30
+ with mock .patch ('ReversingLabs.SDK.tiscale.requests' , autospec = True ) as requests_mock :
31
+ yield requests_mock
32
+
33
+
34
+ class TestTitaniumScale :
35
+ host = "https://my.host"
36
+ token = "token"
37
+
38
+ @classmethod
39
+ def setup_class (cls ):
40
+ cls .tiscale = TitaniumScale (cls .host , token = cls .token )
41
+
42
+ def test_list_tasks (self , requests_mock ):
43
+ self .tiscale .list_processing_tasks (age = 10 , custom_token = "custom" )
44
+
45
+ query_params = {
46
+ "age" : 10 ,
47
+ "token" : "Token custom"
48
+ }
49
+
50
+ expected_url = f"{ self .host } /api/tiscale/v1/task"
51
+
52
+ requests_mock .get .assert_called_with (
53
+ url = expected_url ,
54
+ verify = True ,
55
+ proxies = None ,
56
+ headers = {"User-Agent" : DEFAULT_USER_AGENT , "Authorization" : f"Token { self .token } " },
57
+ params = query_params
58
+ )
59
+
60
+ def test_task_info (self , requests_mock ):
61
+ self .tiscale .get_processing_task_info (
62
+ task_id = 1 ,
63
+ full = True
64
+ )
65
+
66
+ query_params = {
67
+ "full" : "true" ,
68
+ "v13" : "false"
69
+ }
70
+
71
+ expected_url = f"{ self .host } /api/tiscale/v1/task/1"
72
+
73
+ requests_mock .get .assert_called_with (
74
+ url = expected_url ,
75
+ verify = True ,
76
+ proxies = None ,
77
+ headers = {"User-Agent" : DEFAULT_USER_AGENT , "Authorization" : f"Token { self .token } " },
78
+ params = query_params
79
+ )
80
+
81
+ def test_delete_task (self , requests_mock ):
82
+ self .tiscale .delete_processing_task (
83
+ task_id = 1
84
+ )
85
+
86
+ expected_url = f"{ self .host } /api/tiscale/v1/task/1"
87
+
88
+ requests_mock .delete .assert_called_with (
89
+ url = expected_url ,
90
+ verify = True ,
91
+ proxies = None ,
92
+ headers = {"User-Agent" : DEFAULT_USER_AGENT , "Authorization" : f"Token { self .token } " }
93
+ )
94
+
95
+ def test_wrong_task_id (self , requests_mock ):
96
+ with pytest .raises (WrongInputError , match = r"task_id parameter must be integer." ):
97
+ self .tiscale .delete_processing_task (task_id = "123" )
98
+
99
+ assert not requests_mock .delete .called
100
+
101
+ def test_delete_multiple (self , requests_mock ):
102
+ self .tiscale .delete_multiple_tasks (age = 10 )
103
+
104
+ query_params = {"age" : 10 }
105
+
106
+ expected_url = f"{ self .host } /api/tiscale/v1/task"
107
+
108
+ requests_mock .delete .assert_called_with (
109
+ url = expected_url ,
110
+ verify = True ,
111
+ proxies = None ,
112
+ headers = {"User-Agent" : DEFAULT_USER_AGENT , "Authorization" : f"Token { self .token } " },
113
+ params = query_params
114
+ )
115
+
116
+ def test_yara_id (self , requests_mock ):
117
+ self .tiscale .get_yara_id ()
118
+
119
+ requests_mock .get .assert_called_with (
120
+ url = f"{ self .host } /api/tiscale/v1/yara" ,
121
+ verify = True ,
122
+ proxies = None ,
123
+ headers = {"User-Agent" : DEFAULT_USER_AGENT , "Authorization" : f"Token { self .token } " }
124
+ )
125
+
0 commit comments