-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_P2PNode.py
54 lines (47 loc) · 1.29 KB
/
test_P2PNode.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
import sys
import time
import json
import unittest
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from P2PNode import P2PNode
class testP2PNode(unittest.TestCase):
def setUp(self):
pass
def test_connections(self):
picture = QImage()
node1 = P2PNode("localhost", 7777, picture)
node2 = P2PNode("localhost", 8888, picture)
#node1.start()
#node2.start()
time.sleep(1)
node1.connect_with_node("localhost", 8888)
time.sleep(1)
if(len(node1.nodes_outbound)==1):
node1.stop()
node2.stop()
assert True
node1.stop()
node2.stop()
assert False
def test_disconnections(self):
picture = QImage()
node1 = P2PNode("localhost", 7777, picture)
node2 = P2PNode("localhost", 8888, picture)
#node1.start()
#node2.start()
time.sleep(1)
node1.connect_with_node("localhost", 8888)
time.sleep(1)
node1.disconnect_with_node(node2)
time.sleep(1)
if(len(node1.nodes_outbound)==0):
node1.stop()
node2.stop()
assert True
node1.stop()
node2.stop()
assert False
if __name__ == '__main__':
unittest.main()