-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathtest_methods.py
More file actions
144 lines (124 loc) · 4.61 KB
/
test_methods.py
File metadata and controls
144 lines (124 loc) · 4.61 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import typing
import unittest
from unittest.mock import Mock, patch
from whatsapp_api_client_python.API import GreenAPI
from whatsapp_api_client_python.response import Response
api = GreenAPI("", "")
path = "examples/data/rates.png"
class MethodsTestCase(unittest.TestCase):
@patch("whatsapp_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.device_methods,
*self.group_methods,
*self.status_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.getWaSettings(),
api.account.setSettings({}),
api.account.getStateInstance(),
api.account.getStatusInstance(),
api.account.reboot(),
api.account.logout(),
api.account.qr(),
api.account.setProfilePicture(path),
api.account.getAuthorizationCode(0)
]
@property
def device_methods(self) -> typing.List[Response]:
return [api.device.getDeviceInfo()]
@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 status_methods(self) -> typing.List[Response]:
return [
api.statuses.sendTextStatus(""),
api.statuses.sendVoiceStatus("", ""),
api.statuses.sendMediaStatus("", ""),
api.statuses.deleteStatus(""),
api.statuses.getStatusStatistic(""),
api.statuses.getIncomingStatuses(),
api.statuses.getOutgoingStatuses()
]
@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.sendButtons("", "", []),
api.sending.sendTemplateButtons("", "", []),
api.sending.sendListMessage("", "", "", []),
api.sending.sendFileByUpload("", path),
api.sending.sendFileByUrl("", "", ""),
api.sending.uploadFile(path),
api.sending.sendLocation("", 0.0, 0.0),
api.sending.sendContact("", {}),
api.sending.sendLink("", ""),
api.sending.forwardMessages("", "", []),
api.sending.sendPoll("", "", [])
]
@property
def service_methods(self) -> typing.List[Response]:
return [
api.serviceMethods.checkWhatsapp(0),
api.serviceMethods.getAvatar(""),
api.serviceMethods.getContacts(),
api.serviceMethods.getContactInfo(""),
api.serviceMethods.deleteMessage("", ""),
api.serviceMethods.archiveChat(""),
api.serviceMethods.unarchiveChat(""),
api.serviceMethods.setDisappearingChat("")
]
if __name__ == '__main__':
unittest.main()