Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_diff_for_humans_other_and_future_years():
with pendulum.test(pendulum.datetime(2012, 1, 1, 1, 2, 3)):
assert "2 years after" == pendulum.now().diff_for_humans(
pendulum.now().subtract(years=2)
)
def test_diff_for_humans_now_and_nearly_future_week():
with pendulum.test(pendulum.datetime(2012, 1, 1, 1, 2, 3)):
assert "in 6 days" == pendulum.now().add(days=6).diff_for_humans()
"bot": False,
"discriminator": "4379",
"username": "Big Nibba"
},
"content": "Idk",
"timestamp": "2019-12-22T02:40:01.531Z",
"edited_timestamp": None,
"attachments": [],
"embeds": [],
"mentions": []
}
])
payload = {
'type': random.choice(list(all_types.keys())),
'url': 'https://example.com/log', # This URL is for testing purposes only
'expires': pendulum.now().add(minutes=10).isoformat()
}
archive_response = self.client.post(reverse('v2:archive'), data=payload)
self.assertEqual(archive_response.status_code, status.HTTP_201_CREATED)
signed_data = archive_response.json()['url'].rsplit('/', 1)[1]
# Test un-archiving
accepts_headers = {**default_headers, 'ACCEPTS': 'application/json'}
un_archive_response = self.client.get(reverse('v2:un-archive', kwargs={'signed_data': signed_data}),
**accepts_headers)
self.assertEqual(un_archive_response.status_code, status.HTTP_302_FOUND)
def test_diff_for_humans_other_and_nearly_future_hour():
with pendulum.test(pendulum.datetime(2012, 1, 1, 1, 2, 3)):
assert "59 minutes after" == pendulum.now().diff_for_humans(
pendulum.now().subtract(minutes=59)
)
def test_determine_final_state_preserves_running_states_when_tasks_still_running(
self,
):
task = Task()
flow = Flow(name="test", tasks=[task])
old_state = Running()
new_state = FlowRunner(flow=flow).get_flow_run_state(
state=old_state,
task_states={task: Retrying(start_time=pendulum.now("utc").add(days=1))},
task_contexts={},
return_tasks=set(),
task_runner_state_handlers=[],
executor=LocalExecutor(),
)
assert new_state is old_state
def test_continue(self, cmd, config, factories):
some_entry = factories.TimeEntryFactory()
start = pendulum.now('utc')
stop = start + pendulum.duration(seconds=10)
last_entry = factories.TimeEntryFactory(start=start, stop=stop)
result = cmd('continue')
assert result.obj.exit_code == 0
continuing_entry = TimeEntry.objects.current(config=config)
assert last_entry.description == continuing_entry.description
assert last_entry.id != continuing_entry.id
continuing_entry.stop_and_save()
result = cmd('continue \'{}\''.format(some_entry.description))
assert result.obj.exit_code == 0
continuing_entry = TimeEntry.objects.current(config=config)
assert continuing_entry.description == some_entry.description
def timestamper(task, old_state, new_state):
"""
Task state handler that timestamps new states
and logs the duration between state changes using
the task's logger.
"""
new_state.timestamp = pendulum.now("utc")
if hasattr(old_state, "timestamp"):
duration = (new_state.timestamp - old_state.timestamp).in_seconds()
task.logger.info(
"{} seconds passed in between state transitions".format(duration)
)
return new_state
Note:
This assumes that the heartbeat was recorded in the same timezone as the current timestamp,
which should be a reasonable assumption given that local file access is required to monitor
these heartbeats.
Args:
deadReceivers (set): Receivers where are currently dead.
Returns:
set: Receivers which are dead (or continue to be) after checking the heartbeats.
"""
for subsystem in parameters["subsystemList"]:
heartbeatTimestamp = getHeartbeat(subsystem)
# The receivers are run in Geneva
# This heartbeat is converted to UTC.
heartbeat = pendulum.from_timestamp(heartbeatTimestamp, tz = "Europe/Zurich")
now = pendulum.now(tz = "UTC")
# If the receiver doesn't have a heartbeat for 5 minutes, then it is considered dead.
subsystemDead = False
if now.diff(heartbeat).in_minutes() >= 5:
subsystemDead = True
if subsystem in deadReceivers:
if subsystemDead is True:
# Reduced notification frequency so we don't overwhelm ourselves with errors.
# Just notify once per hour.
if now.minute == 0:
logger.critical("{subsystem} receiver appears to have been dead since {heartbeat}!".format(subsystem = subsystem,
heartbeat = heartbeat))
else:
deadReceivers.remove(subsystem)
logger.warning("{subsystem} receiver has been revived.".format(subsystem = subsystem))
else:
def _parse(text, **options):
"""
Parses a string with the given options.
:param text: The string to parse.
:type text: str
:rtype: mixed
"""
# Handling special cases
if text == "now":
return pendulum.now()
parsed = base_parse(text, **options)
if isinstance(parsed, datetime.datetime):
return pendulum.datetime(
parsed.year,
parsed.month,
parsed.day,
parsed.hour,
parsed.minute,
parsed.second,
parsed.microsecond,
tz=parsed.tzinfo or options.get("tz", UTC),
)
if isinstance(parsed, datetime.date):
def get_auth_token(self) -> str:
"""
Returns an auth token:
- if no explicit access token is stored, returns the api token
- if there is an access token:
- if there's a refresh token and the access token expires in the next 30 seconds,
then we refresh the access token and store the result
- return the access token
Returns:
- str: the access token
"""
if not self._access_token:
return self._api_token
expiration = self._access_token_expires_at or pendulum.now()
if self._refresh_token and pendulum.now().add(seconds=30) > expiration:
self._refresh_access_token()
return self._access_token