def redirect_by_date(request, label_id, year, month, day): """If a user requests a date as the version, find the version which was current as of that date""" date_versions = [] client = ApiReader() for struct in client.regversions(label_id.split('-')[0])['versions']: if 'by_date' in struct: date_versions.append((struct['by_date'], struct['version'])) date_versions = sorted(date_versions) last_version = None date_str = '%s-%s-%s' % (year, month, day) while date_versions and date_versions[0][0] <= date_str: last_version = date_versions[0][1] date_versions = date_versions[1:] label_parts = label_id.split('-') if last_version and len(label_parts) == 2: return redirect('chrome_section_view', label_id, last_version) elif last_version and label_parts[-1] == 'Interp': return redirect('chrome_section_view', label_id, last_version) elif last_version and len(label_parts) == 1: return redirect('chrome_regulation_view', label_id, last_version) elif last_version: return redirect('chrome_paragraph_view', label_id, last_version) else: return handle_generic_404(request)
def test_regversion(self, fetch): to_return = {} fetch.return_value = to_return reader = ApiReader() self.assertEqual(to_return, reader.regversions('765')) self.assertTrue(fetch.called) param = fetch.call_args[0][0] self.assertTrue('765' in param)
def test_regversion(self, api_client): to_return = {} api_client.ApiClient.return_value.get.return_value = to_return reader = ApiReader() self.assertEqual(to_return, reader.regversions('765')) get = api_client.ApiClient.return_value.get self.assertTrue(get.called) param = get.call_args[0][0] self.assertTrue('765' in param)