Skip to content

Commit 72e4cd0

Browse files
Initial commit WIP
1 parent 8077171 commit 72e4cd0

12 files changed

Lines changed: 30 additions & 31 deletions

hello/service.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import re
2-
from dataclasses import dataclass
2+
from dataclasses import dataclass, field
33

44

55
@dataclass
66
class ServiceInfo:
77
name: str
88
role: str
9-
url: str
9+
urls: dict[str, str] = field(default_factory=dict)
1010

1111

1212
@dataclass

tests/advertizerIntegrationTest.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@
1515

1616

1717
class AdvertizerIntegrationTest(TestCase):
18-
SERVICE_INFO = ServiceInfo('test-service', 'test-role', 'http://localhost:8080')
18+
SERVICE_INFO = ServiceInfo('test-service', 'test-role', {'test': 'http://localhost:8080'})
1919

2020
@classmethod
2121
def setUpClass(cls):
2222
setup_logging('hello', 'DEBUG', warn_on_overwrite=False)
2323

2424
def setUp(self):
2525
print()
26-
self.SERVICE_INFO = ServiceInfo('test-service', 'test-role', 'http://localhost:8080')
26+
self.SERVICE_INFO = ServiceInfo('test-service', 'test-role', {'test': 'http://localhost:8080'})
2727

2828
def test_sends_hello_when_advertises_service(self):
2929
# Given
@@ -90,7 +90,7 @@ def test_sends_hello_when_info_changed_and_query_received(self):
9090

9191
wait_for_assertion(0.1, lambda: self.assertEqual(2, len(messages)))
9292

93-
self.SERVICE_INFO.url = 'http://localhost:9090'
93+
self.SERVICE_INFO.urls['test'] = 'http://localhost:9090'
9494
advertizer.advertise(self.SERVICE_INFO)
9595

9696
# When
@@ -100,10 +100,10 @@ def test_sends_hello_when_info_changed_and_query_received(self):
100100

101101
# Then
102102
self.assertEqual([
103-
{'name': 'test-service', 'role': 'test-role', 'url': 'http://localhost:8080'},
104-
{'name': 'test-service', 'role': 'test-role', 'url': 'http://localhost:8080'},
105-
{'name': 'test-service', 'role': 'test-role', 'url': 'http://localhost:9090'},
106-
{'name': 'test-service', 'role': 'test-role', 'url': 'http://localhost:9090'}
103+
{'name': 'test-service', 'role': 'test-role', 'urls': {'test': 'http://localhost:8080'}},
104+
{'name': 'test-service', 'role': 'test-role', 'urls': {'test': 'http://localhost:8080'}},
105+
{'name': 'test-service', 'role': 'test-role', 'urls': {'test': 'http://localhost:9090'}},
106+
{'name': 'test-service', 'role': 'test-role', 'urls': {'test': 'http://localhost:9090'}}
107107
], messages)
108108

109109
def test_sends_hello_when_schedules_advertisement_once(self):

tests/apiIntegrationTest.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
ACCESS_URL = 'udp://239.0.0.1:5555'
1111
GROUP_NAME = 'test-group'
1212
GROUP = Group(GROUP_NAME)
13-
SERVICE_INFO = ServiceInfo('test-service', 'test-role', 'http://localhost:8080')
13+
SERVICE_INFO = ServiceInfo('test-service', 'test-role', {'test': 'http://localhost:8080'})
1414
SERVICE_QUERY = ServiceQuery('test-service', 'test-role')
1515

1616

@@ -22,7 +22,6 @@ def setUpClass(cls):
2222

2323
def setUp(self):
2424
print()
25-
self.SERVICE_INFO = ServiceInfo('test-service', 'test-role', 'http://localhost:8080')
2625

2726
def test_discoverer_caches_advertised_service(self):
2827
# Given
@@ -39,7 +38,7 @@ def test_discoverer_caches_advertised_service(self):
3938
wait_for_assertion(0.1, lambda: self.assertEqual(1, len(discoverer.get_services())))
4039

4140
# Then
42-
self.assertEqual({self.SERVICE_INFO.name: self.SERVICE_INFO}, discoverer.get_services())
41+
self.assertEqual({SERVICE_INFO.name: SERVICE_INFO}, discoverer.get_services())
4342

4443
def test_discoverer_caches_advertised_service_when_scheduled_once(self):
4544
# Given
@@ -56,7 +55,7 @@ def test_discoverer_caches_advertised_service_when_scheduled_once(self):
5655
wait_for_assertion(0.1, lambda: self.assertEqual(1, len(discoverer.get_services())))
5756

5857
# Then
59-
self.assertEqual({self.SERVICE_INFO.name: self.SERVICE_INFO}, discoverer.get_services())
58+
self.assertEqual({SERVICE_INFO.name: SERVICE_INFO}, discoverer.get_services())
6059

6160
def test_discoverer_caches_advertised_service_when_scheduled_periodically(self):
6261
# Given
@@ -73,7 +72,7 @@ def test_discoverer_caches_advertised_service_when_scheduled_periodically(self):
7372
wait_for_assertion(0.1, lambda: self.assertEqual(1, len(discoverer.get_services())))
7473

7574
# Then
76-
self.assertEqual({self.SERVICE_INFO.name: self.SERVICE_INFO}, discoverer.get_services())
75+
self.assertEqual({SERVICE_INFO.name: SERVICE_INFO}, discoverer.get_services())
7776

7877
def test_discoverer_caches_discovery_response_service(self):
7978
# Given
@@ -90,7 +89,7 @@ def test_discoverer_caches_discovery_response_service(self):
9089
wait_for_assertion(0.2, lambda: self.assertEqual(1, len(discoverer.get_services())))
9190

9291
# Then
93-
self.assertEqual({self.SERVICE_INFO.name: self.SERVICE_INFO}, discoverer.get_services())
92+
self.assertEqual({SERVICE_INFO.name: SERVICE_INFO}, discoverer.get_services())
9493

9594

9695
if __name__ == '__main__':

tests/defaultAdvertizerTest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
ACCESS_URL = 'udp://239.0.0.1:5555'
1010
GROUP_NAME = 'test-group'
1111
GROUP = Group(GROUP_NAME)
12-
SERVICE_INFO = ServiceInfo('test-service', 'test-role', 'http://localhost:8080')
12+
SERVICE_INFO = ServiceInfo('test-service', 'test-role', {'test': 'http://localhost:8080'})
1313

1414

1515
class DefaultAdvertizerTest(TestCase):
@@ -84,7 +84,7 @@ def test_sends_last_info_when_passed_at_start_and_at_advertise(self):
8484
# Given
8585
sender = MagicMock(spec=Sender)
8686
advertizer = DefaultAdvertizer(sender)
87-
advertizer.start(ACCESS_URL, GROUP, ServiceInfo('test-service', 'test-role', 'http://localhost:9090'))
87+
advertizer.start(ACCESS_URL, GROUP, ServiceInfo('test-service', 'test-role', {'test': 'http://localhost:9090'}))
8888

8989
# When
9090
advertizer.advertise(SERVICE_INFO)

tests/defaultDiscovererTest.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
GROUP_NAME = 'test-group'
1212
GROUP = Group(GROUP_NAME)
1313
SERVICE_QUERY = ServiceQuery('test-.*', 'test-.*')
14-
SERVICE_INFO = ServiceInfo('test-service', 'test-role', 'http://localhost:8080')
14+
SERVICE_INFO = ServiceInfo('test-service', 'test-role', {'test': 'http://localhost:8080'})
1515

1616

1717
class DefaultDiscovererTest(TestCase):
@@ -117,7 +117,7 @@ def test_updates_service_and_calls_handler_when_receives_matching_info(self):
117117
discoverer.register(handler)
118118
discoverer._handle_message(SERVICE_INFO.__dict__)
119119
handler.reset_mock()
120-
new_service_info = ServiceInfo(SERVICE_INFO.name, SERVICE_INFO.role, 'http://localhost:9090')
120+
new_service_info = ServiceInfo(SERVICE_INFO.name, SERVICE_INFO.role, {'test': 'http://localhost:9090'})
121121

122122
# When
123123
discoverer._handle_message(new_service_info.__dict__)
@@ -180,7 +180,7 @@ def test_does_not_cache_service_when_info_not_matching_query(self):
180180
discoverer = DefaultDiscoverer(sender, receiver)
181181
discoverer.start(ACCESS_URL, GROUP, SERVICE_QUERY)
182182

183-
non_matching_info = ServiceInfo('other-service', 'test-role', 'http://localhost:8080')
183+
non_matching_info = ServiceInfo('other-service', 'test-role', {'test': 'http://localhost:8080'})
184184

185185
# When
186186
discoverer._handle_message(non_matching_info.__dict__)

tests/defaultScheduledAdvertizerTest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
ACCESS_URL = 'udp://239.0.0.1:5555'
1111
GROUP_NAME = 'test-group'
1212
GROUP = Group(GROUP_NAME)
13-
SERVICE_INFO = ServiceInfo('test-service', 'test-role', 'http://localhost:8080')
13+
SERVICE_INFO = ServiceInfo('test-service', 'test-role', {'test': 'http://localhost:8080'})
1414

1515

1616
class DefaultScheduledAdvertizerTest(TestCase):

tests/discovererIntegrationTest.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@
1515

1616

1717
class DiscovererIntegrationTest(TestCase):
18-
SERVICE_INFO = ServiceInfo('test-service', 'test-role', 'http://localhost:8080')
18+
SERVICE_INFO = ServiceInfo('test-service', 'test-role', {'test': 'http://localhost:8080'})
1919

2020
@classmethod
2121
def setUpClass(cls):
2222
setup_logging('hello', 'DEBUG', warn_on_overwrite=False)
2323

2424
def setUp(self):
2525
print()
26-
self.SERVICE_INFO = ServiceInfo('test-service', 'test-role', 'http://localhost:8080')
26+
self.SERVICE_INFO = ServiceInfo('test-service', 'test-role', {'test': 'http://localhost:8080'})
2727

2828
def test_discovers_service_when_hello_received(self):
2929
# Given
@@ -58,18 +58,18 @@ def test_updates_service_when_info_changed(self):
5858
wait_for_assertion(0.1, lambda: self.assertEqual(1, len(discoverer.get_services())))
5959

6060
# When
61-
self.SERVICE_INFO.url = 'http://localhost:9090'
61+
self.SERVICE_INFO.urls['test'] = 'http://localhost:9090'
6262
test_sender.send(self.SERVICE_INFO)
6363

6464
wait_for_assertion(0.1, lambda: self.assertEqual(
6565
'http://localhost:9090',
66-
discoverer.get_services()[self.SERVICE_INFO.name].url
66+
discoverer.get_services()[self.SERVICE_INFO.name].urls['test']
6767
))
6868

6969
# Then
7070
self.assertEqual(
7171
'http://localhost:9090',
72-
discoverer.get_services()[self.SERVICE_INFO.name].url
72+
discoverer.get_services()[self.SERVICE_INFO.name].urls['test']
7373
)
7474

7575
def test_sends_query(self):

tests/dishReceiverTest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
ACCESS_URL = 'udp://239.0.0.1:5555'
1212
GROUP_NAME = 'test-group'
1313
GROUP = Group(GROUP_NAME)
14-
SERVICE_INFO = ServiceInfo('test-service', 'test-role', 'http://localhost:8080')
14+
SERVICE_INFO = ServiceInfo('test-service', 'test-role', {'test': 'http://localhost:8080'})
1515

1616

1717
class DishReceiverTest(TestCase):

tests/radioSenderTest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
ACCESS_URL = 'udp://239.0.0.1:5555'
1212
GROUP_NAME = 'test-group'
1313
GROUP = Group(GROUP_NAME)
14-
SERVICE_INFO = ServiceInfo('test-service', 'test-role', 'http://localhost:8080')
14+
SERVICE_INFO = ServiceInfo('test-service', 'test-role', {'test': 'http://localhost:8080'})
1515

1616

1717
class RadioSenderTest(TestCase):

tests/receiverIntegrationTest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
ACCESS_URL = 'udp://239.0.0.1:5555'
1111
GROUP_NAME = 'test-group'
1212
GROUP = Group(GROUP_NAME)
13-
SERVICE_INFO = ServiceInfo('test-service', 'test-role', 'http://localhost:8080')
13+
SERVICE_INFO = ServiceInfo('test-service', 'test-role', {'test': 'http://localhost:8080'})
1414

1515

1616
class ReceiverIntegrationTest(TestCase):

0 commit comments

Comments
 (0)