Skip to content

Commit 8d09504

Browse files
Update tests to use new fields
1 parent 70ba141 commit 8d09504

5 files changed

Lines changed: 76 additions & 10 deletions

File tree

.idea/.gitignore

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/cameraServiceExample.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ def main() -> None:
2424
service = Service(uuid=uuid4(), name='er-sniper-camera-1', role='camera', address=if_address, urls={
2525
'api': f'grpc://{if_address}:50051',
2626
'stream': f'http://{if_address}:8000/video_feed'
27+
}, info={
28+
'site': 'er-sniper-site-1',
29+
'range': 'er-sniper-range-1'
2730
})
2831

2932
# Use a scheduled advertizer to periodically announce the camera service

tests/apiIntegrationTest.py

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,14 @@
99
from hello import Service, Group, ServiceQuery, Hello, HelloConfig
1010

1111
GROUP = Group('test-group', 'udp://239.0.0.1:5555')
12-
SERVICE = Service(uuid4(), 'test-service', 'test-role', {'test': 'http://localhost:8080'})
12+
SERVICE = Service(
13+
uuid4(),
14+
'test-service',
15+
'test-role',
16+
{'test': 'http://localhost:8080'},
17+
{'site': 'test-site', 'range': 'test-range'},
18+
'192.168.1.100'
19+
)
1320
SERVICE_QUERY = ServiceQuery('test-service', 'test-role')
1421

1522

@@ -46,8 +53,22 @@ def test_discoverer_caches_advertised_services(self):
4653
with (Hello.builder(config).advertizer().default() as advertizer1,
4754
Hello.builder(config).advertizer().default() as advertizer2,
4855
Hello.builder(config).discoverer().default() as discoverer):
49-
service1 = Service(uuid4(), 'test-service1', 'test-role', {'test': 'http://localhost:8080'})
50-
service2 = Service(uuid4(), 'test-service2', 'test-role', {'test': 'http://localhost:8080'})
56+
service1 = Service(
57+
uuid4(),
58+
'test-service1',
59+
'test-role',
60+
{'test': 'http://localhost:8080'},
61+
{'site': 'site1', 'range': 'range1'},
62+
'192.168.1.101'
63+
)
64+
service2 = Service(
65+
uuid4(),
66+
'test-service2',
67+
'test-role',
68+
{'test': 'http://localhost:8080'},
69+
{'site': 'site2', 'range': 'range2'},
70+
'192.168.1.102'
71+
)
5172
advertizer1.start(GROUP, service1)
5273
advertizer2.start(GROUP, service2)
5374
discoverer.start(GROUP, ServiceQuery('test-service.+', 'test-role'))
@@ -123,8 +144,22 @@ def test_discoverer_caches_discovery_response_services(self):
123144
with (Hello.builder(config).advertizer().default() as advertizer1,
124145
Hello.builder(config).advertizer().default() as advertizer2,
125146
Hello.builder(config).discoverer().default() as discoverer):
126-
service1 = Service(uuid4(), 'test-service1', 'test-role', {'test': 'http://localhost:8080'})
127-
service2 = Service(uuid4(), 'test-service2', 'test-role', {'test': 'http://localhost:8080'})
147+
service1 = Service(
148+
uuid4(),
149+
'test-service1',
150+
'test-role',
151+
{'test': 'http://localhost:8080'},
152+
{'site': 'site1', 'range': 'range1'},
153+
'192.168.1.101'
154+
)
155+
service2 = Service(
156+
uuid4(),
157+
'test-service2',
158+
'test-role',
159+
{'test': 'http://localhost:8080'},
160+
{'site': 'site2', 'range': 'range2'},
161+
'192.168.1.102'
162+
)
128163
advertizer1.start(GROUP, service1)
129164
advertizer2.start(GROUP, service2)
130165
discoverer.start(GROUP, ServiceQuery('test-service.+', 'test-role'))

tests/defaultDiscovererTest.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,17 @@
99
from hello import Service, Group, ServiceQuery, DefaultDiscoverer, Sender, Receiver, OnDiscoveryEvent, \
1010
DiscoveryEventType, DiscoveryEvent
1111

12+
1213
GROUP = Group('test-group', 'udp://239.0.0.1:5555')
1314
SERVICE_QUERY = ServiceQuery('test-.*', 'test-.*')
14-
SERVICE = Service(uuid4(), 'test-service', 'test-role', {'test': 'http://localhost:8080'})
15+
SERVICE = Service(
16+
uuid4(),
17+
'test-service',
18+
'test-role',
19+
{'test': 'http://localhost:8080'},
20+
{'site': 'test-site', 'range': 'test-range'},
21+
'192.168.1.100'
22+
)
1523

1624

1725
class DefaultDiscovererTest(TestCase):
@@ -153,7 +161,12 @@ def test_updates_service_and_calls_handler_when_receives_matching_service(self):
153161
discoverer._handle_message(SERVICE.to_dict())
154162
handler.reset_mock()
155163
new_service = Service(
156-
SERVICE.uuid, SERVICE.name, SERVICE.role, {'test': 'http://localhost:9090'}
164+
SERVICE.uuid,
165+
SERVICE.name,
166+
SERVICE.role,
167+
{'test': 'http://localhost:9090'},
168+
{'site': 'test-site', 'range': 'test-range', 'updated': True},
169+
'192.168.1.101'
157170
)
158171

159172
# When
@@ -221,7 +234,14 @@ def test_does_not_cache_service_when_info_not_matching_query(self):
221234
discoverer = DefaultDiscoverer(sender, receiver)
222235
discoverer.start(GROUP, SERVICE_QUERY)
223236

224-
non_matching_info = Service(uuid4(), 'other-service', 'test-role', {'test': 'http://localhost:8080'})
237+
non_matching_info = Service(
238+
uuid4(),
239+
'other-service',
240+
'test-role',
241+
{'test': 'http://localhost:8080'},
242+
{'site': 'other-site'},
243+
'192.168.1.102'
244+
)
225245

226246
# When
227247
discoverer._handle_message(non_matching_info.to_dict())

tests/scheduledAdvertizerTest.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,14 @@
1010
from hello import Service, Group, ScheduledAdvertizer, Advertizer
1111

1212
GROUP = Group('test-group', 'udp://239.0.0.1:5555')
13-
SERVICE = Service(uuid4(), 'test-service', 'test-role', {'test': 'http://localhost:8080'})
13+
SERVICE = Service(
14+
uuid4(),
15+
'test-service',
16+
'test-role',
17+
{'test': 'http://localhost:8080'},
18+
{'site': 'test-site', 'range': 'test-range'},
19+
'192.168.1.100'
20+
)
1421

1522

1623
class ScheduledAdvertizerTest(TestCase):

0 commit comments

Comments
 (0)