Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
Final syntax fixes from suggested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
myoung34 committed Oct 27, 2020
1 parent 066acf6 commit 269e5fe
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
15 changes: 7 additions & 8 deletions tests/test_webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ def test_webhook_delay_minutes(
'method': 'GET',
}


wh = webhook.Webhook(config=config)
# On init, we load delay_minutes from config
assert wh.delay_minutes == 3
Expand All @@ -154,7 +153,7 @@ def test_webhook_delay_minutes(
now = datetime.datetime.now(datetime.timezone.utc)
assert wh.delay_minutes == 3
# delay_until should be set for about 3 minutes from now
delay_until = wh.delay_until.get(black_tilt_uuid)
delay_until = wh.delay_until.get('black')
assert delay_until is not None and delay_until >= now
# emitted twice, but the second returned before actually sending a request.
assert mock_requests.mock_calls == [
Expand All @@ -166,17 +165,17 @@ def test_webhook_delay_minutes(
]

# enxure that the blue tilt can send while the black one is waiting
delay_until = wh.delay_until.get(blue_tilt_uuid)
delay_until = wh.delay_until.get('blue')
assert delay_until is None
wh.emit({
'color': 'blue',
'gravity': 99,
'mac': '00:0a:95:9d:68:17',
'temp': 99,
'timestamp': 155559999,
'uuid': blue_tilt_uuid
'uuid': 'a495bb60c5b14b44b5121370f02d74de',
})
delay_until = wh.delay_until.get(blue_tilt_uuid)
delay_until = wh.delay_until.get('blue')
assert delay_until is not None and delay_until >= now
assert mock_requests.mock_calls == [
mock.call.get('GET'),
Expand All @@ -192,17 +191,17 @@ def test_webhook_delay_minutes(

# move the clock forward by setting delay_until to the past, which should
# allow a request to process again
wh.delay_until[black_tilt_uuid] = now - datetime.timedelta(minutes=1)
wh.delay_until['black'] = now - datetime.timedelta(minutes=1)
wh.emit({
'color': 'black',
'gravity': 3,
'mac': '00:0a:95:9d:68:16',
'temp': 34,
'timestamp': 155558899,
'uuid': black_tilt_uuid
'uuid': 'a495bb30c5b14b44b5121370f02d74de',
})
# delay_until is once again about 3 minutes in the future
delay_until = wh.delay_until.get(black_tilt_uuid)
delay_until = wh.delay_until.get('black')
assert delay_until is not None and delay_until >= now
# we now see the request that was made after the delay timeout
assert mock_requests.mock_calls == [
Expand Down
3 changes: 2 additions & 1 deletion tilty/emitters/webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@ def __init__(self, config: dict) -> None:
self.delay_minutes: Union[int, None] = delay_minutes
self.headers: dict = json.loads(config['headers'])
self.template: Template = Template(config['payload_template'])
self.delay_until_identifier = config.get(
self.delay_until_identifier: str = config.get(
'delay_until_identifier',
'color'
)
self.delay_until: Dict[str, datetime.datetime] = dict()

def emit(self, tilt_data: dict) -> None:
""" Initializer
Expand Down

0 comments on commit 269e5fe

Please sign in to comment.