def get_performance_data(self, date_from: datetime.date,
                             date_to: datetime.date):
        api_client = get_api_session()

        date_range = {'week__gte': date_from, 'week__lt': date_to}
        data = api_client.get(api_url('performance/data'), params=date_range)
        return data.json()
 def assertFormValid(self, form):  # noqa: N802
     with mock.patch.object(self.form_class, 'get_api_session') as mock_session, responses.RequestsMock() as rsps:
         mock_session.side_effect = lambda reconnect: get_api_session()
         mock_auth(rsps)
         rsps.add(
             rsps.GET,
             api_url(f'/prisoner_account_balances/{form.prisoner_number}'),
             json={
                 'combined_account_balance': 3000
             },
             status=200,
         )
         self.assertTrue(form.is_valid(), msg='\n\n%s' % form.errors.as_text())
Ejemplo n.º 3
0
 def get_prison_list(cls):
     prison_list = cache.get('prison_list')
     if not prison_list:
         try:
             session = get_api_session()
             prison_list = retrieve_all_pages_for_path(
                 session, '/prisons/', exclude_empty_prisons=True)
             prison_list = [
                 prison['name'] for prison in sorted(
                     prison_list, key=lambda prison: prison['short_name'])
             ]
             if not prison_list:
                 raise ValueError('Empty prison list')
             cache.set('prison_list', prison_list, timeout=60 * 60)
         except (RequestException, OAuth2Error, ValueError):
             logger.exception('Could not look up prison list')
     return prison_list
 def get_api_session(cls, reconnect=False):
     with cls.shared_api_session_lock:
         if reconnect or not cls.shared_api_session:
             cls.shared_api_session = get_api_session()
         return cls.shared_api_session
Ejemplo n.º 5
0
 def api_session(self):
     return get_api_session()