def get(self, request, doc_number): preamble, _, _ = notice_data(doc_number) section = first_preamble_section(preamble) if section is None: raise Http404 return redirect('chrome_preamble', paragraphs='/'.join(section['label']))
def get(self, request, *args, **kwargs): notices = ApiReader().notices().get("results", []) context = {} notices_meta = [] for notice in notices: try: if notice.get("document_number"): _, meta, _ = notice_data(notice["document_number"]) notices_meta.append(meta) except Http404: pass notices_meta = sorted(notices_meta, key=itemgetter("publication_date"), reverse=True) context["notices"] = notices_meta # Django templates won't show contents of CommentState as an Enum, so: context["comment_state"] = { state.name: state.value for state in CommentState } template = self.template_name return TemplateResponse(request=request, template=template, context=context)
def get(self, request, doc_number): preamble, _, _ = notice_data(doc_number) section = first_preamble_section(preamble) if section is None: raise Http404 return redirect( 'chrome_preamble', paragraphs='/'.join(section['label']))
def test_comments_open_from_settings(self, ApiReader): """ Mock the PREAMBLE_INTRO data from settings for this test of the comments being open. """ _, meta, _ = preamble.notice_data('1') assert meta['comment_state'] == CommentState.OPEN
def test_notice_data(self, ApiReader): """We should try to fetch data corresponding to both the Preamble and the Notice""" ApiReader.return_value.preamble.return_value = self._mock_preamble ApiReader.return_value.notice.return_value = { 'publication_date': '2002-02-02', 'comments_close': '2003-03-03', 'cfr_title': 21, 'cfr_parts': ['123']} for doc_id in ('123_456', '123-456'): preamble_, meta, notice = preamble.notice_data(doc_id) self.assertEqual(preamble_, self._mock_preamble) assert meta['comment_state'] == CommentState.CLOSED self.assertEqual(meta['cfr_refs'], [{'title': 21, 'parts': ['123']}]) self.assertEqual(ApiReader.return_value.preamble.call_args[0][0], '123_456') self.assertEqual(ApiReader.return_value.notice.call_args[0][0], '123-456')
def get(self, request, *args, **kwargs): notices = ApiReader().notices().get("results", []) context = {} notices_meta = [] for notice in notices: try: if notice.get("document_number"): _, meta, _ = notice_data(notice["document_number"]) notices_meta.append(meta) except Http404: pass notices_meta = sorted(notices_meta, key=itemgetter("publication_date"), reverse=True) context["notices"] = notices_meta # Django templates won't show contents of CommentState as an Enum, so: context["comment_state"] = {state.name: state.value for state in CommentState} template = self.template_name return TemplateResponse(request=request, template=template, context=context)
def test_comments_closed(self, ApiReader): self._setup_mock_response(ApiReader) _, meta, _ = preamble.notice_data('1') assert meta['comment_state'] == CommentState.CLOSED
def test_comments_prepub(self, ApiReader): future = date.today() + timedelta(days=10) self._setup_mock_response(ApiReader, publication_date=future.isoformat()) _, meta, _ = preamble.notice_data('1') assert meta['comment_state'] == CommentState.PREPUB
def test_comments_open(self, ApiReader): future = date.today() + timedelta(days=10) self._setup_mock_response(ApiReader, comments_close=future.isoformat()) _, meta, _ = preamble.notice_data('1') assert meta['comment_state'] == CommentState.OPEN