def test_api_returns_200_if_document_is_found(self): from hambar.model import Document with db_session(self.app) as session: session.add(Document(code='mof1_2007_0123')) resp = self.client.get('/api/document/mof1_2007_0123') self.assertEqual(resp.status_code, 200)
def test_document_is_created_on_save(self): from hambar.mof_import import save_document_acts from hambar.model import Document with self.app.app_context(): save_document_acts([], 'mof1_2007_0123') with db_session(self.app) as session: [doc] = session.query(Document).all() self.assertEqual(doc.code, 'mof1_2007_0123')
def test_api_returns_act_information(self): from hambar.model import Document, Act, ActType with db_session(self.app) as session: council = ActType(code='counc', label="Revolutionary council") doc = Document(code='mof1_2007_0123') act1 = Act(document=doc, type=council, ident='13', headline="Proclamation", title="Independence", text="We hereby proclaim!") session.add_all([council, doc, act1]) resp = self.client.get('/api/document/mof1_2007_0123') data = json.loads(resp.data) self.assertEqual(data['acts'][0]['authority'], "Revolutionary council") self.assertEqual(data['acts'][0]['number'], "13") self.assertEqual(data['acts'][0]['title'], "Independence") self.assertEqual(data['acts'][0]['body'], "We hereby proclaim!") self.assertEqual(data['acts'][0]['headline'], "Proclamation")
def test_act_is_created_on_save(self): from hambar.mof_import import save_document_acts from hambar.model import Document acts = [{ 'section': 'hg', 'number': '13', 'title': "HG 13 !!!", 'body': "hello world!", 'headline': "Hotarare de guvern", }] with self.app.app_context(): save_document_acts(acts, 'mof1_2007_0123') with db_session(self.app) as session: [doc] = session.query(Document).all() [act13] = doc.acts self.assertEqual(act13.title, "HG 13 !!!") self.assertEqual(act13.ident, '13') self.assertEqual(act13.type.code, 'hg') self.assertEqual(act13.text, "hello world!") self.assertEqual(act13.headline, "Hotarare de guvern")