-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_methods.py
More file actions
112 lines (94 loc) · 3.32 KB
/
test_methods.py
File metadata and controls
112 lines (94 loc) · 3.32 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
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
104
105
106
107
108
109
110
111
112
import typing
import unittest
from unittest.mock import Mock, patch
from max_api_client_python.API import GreenAPI
from max_api_client_python.response import Response
api = GreenAPI("", "")
path = "examples/data/rates.png"
class MethodsTestCase(unittest.TestCase):
@patch("max_api_client_python.API.Session.request")
def test_methods(self, mock_request):
mock_request.return_value = Mock(
status_code=200, text="""{"example": {"key": "value"}}"""
)
methods = [
*self.account_methods,
*self.group_methods,
*self.log_methods,
*self.queue_methods,
*self.read_mark_methods,
*self.receiving_methods,
*self.sending_methods,
*self.service_methods
]
for response in methods:
self.assertEqual(response.code, 200)
self.assertEqual(response.data, {"example": {"key": "value"}})
self.assertEqual(mock_request.call_count, len(methods))
@property
def account_methods(self) -> typing.List[Response]:
return [
api.account.getSettings(),
api.account.getAccountSettings(),
api.account.setSettings({}),
api.account.getStateInstance(),
api.account.reboot(),
api.account.logout(),
api.account.qr(),
api.account.setProfilePicture(path)
]
@property
def group_methods(self) -> typing.List[Response]:
return [
api.groups.createGroup("", []),
api.groups.updateGroupName("", ""),
api.groups.getGroupData(""),
api.groups.addGroupParticipant("", ""),
api.groups.removeGroupParticipant("", ""),
api.groups.setGroupAdmin("", ""),
api.groups.removeAdmin("", ""),
api.groups.setGroupPicture("", path),
api.groups.leaveGroup("")
]
@property
def log_methods(self) -> typing.List[Response]:
return [
api.journals.getChatHistory(""),
api.journals.getMessage("", ""),
api.journals.lastIncomingMessages(),
api.journals.lastOutgoingMessages()
]
@property
def queue_methods(self) -> typing.List[Response]:
return [
api.queues.showMessagesQueue(),
api.queues.clearMessagesQueue()
]
@property
def read_mark_methods(self) -> typing.List[Response]:
return [api.marking.readChat("")]
@property
def receiving_methods(self) -> typing.List[Response]:
return [
api.receiving.receiveNotification(),
api.receiving.deleteNotification(0),
api.receiving.downloadFile("", "")
]
@property
def sending_methods(self) -> typing.List[Response]:
return [
api.sending.sendMessage("", ""),
api.sending.sendFileByUpload("", path),
api.sending.sendFileByUrl("", "", ""),
api.sending.uploadFile(path)
]
@property
def service_methods(self) -> typing.List[Response]:
return [
api.serviceMethods.checkAccount(0),
api.serviceMethods.getAvatar(""),
api.serviceMethods.getContacts(),
api.serviceMethods.getContactInfo("")
]
if __name__ == '__main__':
unittest.main()