1
|
|
|
# -*- coding: utf-8 -*- |
|
|
|
|
2
|
|
|
# MIT License |
3
|
|
|
# |
4
|
|
|
# Copyright (c) 2021 Pincer |
5
|
|
|
# |
6
|
|
|
# Permission is hereby granted, free of charge, to any person obtaining |
7
|
|
|
# a copy of this software and associated documentation files |
8
|
|
|
# (the "Software"), to deal in the Software without restriction, |
9
|
|
|
# including without limitation the rights to use, copy, modify, merge, |
10
|
|
|
# publish, distribute, sublicense, and/or sell copies of the Software, |
11
|
|
|
# and to permit persons to whom the Software is furnished to do so, |
12
|
|
|
# subject to the following conditions: |
13
|
|
|
# |
14
|
|
|
# The above copyright notice and this permission notice shall be |
15
|
|
|
# included in all copies or substantial portions of the Software. |
16
|
|
|
# |
17
|
|
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
18
|
|
|
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
19
|
|
|
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
20
|
|
|
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
21
|
|
|
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
22
|
|
|
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
23
|
|
|
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
24
|
|
|
|
25
|
|
|
from pincer.core.dispatch import GatewayDispatch |
26
|
|
|
|
27
|
|
|
|
28
|
|
|
class TestDispatch: |
|
|
|
|
29
|
|
|
op = 123 |
30
|
|
|
data = { |
31
|
|
|
"foo": "bar", |
32
|
|
|
"bar": "foo" |
33
|
|
|
} |
34
|
|
|
seq = 456 |
35
|
|
|
event_name = "test_event" |
36
|
|
|
|
37
|
|
|
dispatch_string = ( |
38
|
|
|
'{"op": 123, "d": {"foo": "bar", "bar": "foo"}, ' |
39
|
|
|
'"s": 456, "t": "test_event"}' |
40
|
|
|
) |
41
|
|
|
|
42
|
|
|
dispatch = GatewayDispatch(op, data, seq, event_name) |
43
|
|
|
|
44
|
|
|
def test_string_fmt(self): |
45
|
|
|
""" |
46
|
|
|
Tests whether or not the dispatch class its string conversion |
47
|
|
|
is correct. |
48
|
|
|
""" |
49
|
|
|
assert str(self.dispatch) == self.dispatch_string |
50
|
|
|
|
51
|
|
|
def test_from_string(self): |
52
|
|
|
""" |
53
|
|
|
Tests whether or not the from_string function is properly |
54
|
|
|
parsing the string and creating a GatewayDispatch instance. |
55
|
|
|
""" |
56
|
|
|
assert ( |
57
|
|
|
str(GatewayDispatch.from_string(self.dispatch_string)) |
58
|
|
|
== self.dispatch_string |
59
|
|
|
) |
60
|
|
|
|
|
|
|
|
61
|
|
|
|