def test_format_counts(): """ Document.format_counts() """ d1 = Document.create(path="1") d2 = Document.create(path="2") d3 = Document.create(path="3") d4 = Document.create(path="4") d5 = Document.create(path="5") d6 = Document.create(path="6") # 1 doc with 'format1'. f1 = Document_Format.create(document=d1, format="format1") # 2 docs with 'format2'. f2 = Document_Format.create(document=d2, format="format2") f3 = Document_Format.create(document=d3, format="format2") # 3 docs with 'format3'. f4 = Document_Format.create(document=d4, format="format3") f5 = Document_Format.create(document=d5, format="format3") f6 = Document_Format.create(document=d6, format="format3") assert Document_Format.format_counts() == [("format3", 3), ("format2", 2), ("format1", 1)]
def test_format_counts(): """ Document.format_counts() """ d1 = Document.create(path='1') d2 = Document.create(path='2') d3 = Document.create(path='3') d4 = Document.create(path='4') d5 = Document.create(path='5') d6 = Document.create(path='6') # 1 doc with 'format1'. f1 = Document_Format.create(document=d1, format='format1') # 2 docs with 'format2'. f2 = Document_Format.create(document=d2, format='format2') f3 = Document_Format.create(document=d3, format='format2') # 3 docs with 'format3'. f4 = Document_Format.create(document=d4, format='format3') f5 = Document_Format.create(document=d5, format='format3') f6 = Document_Format.create(document=d6, format='format3') assert Document_Format.format_counts() == [('format3', 3), ('format2', 2), ('format1', 1)]
def format_counts(): """ Print a table of file format -> count. """ t = PrettyTable(['File Type', 'Doc Count']) t.align = 'l' for c in Document_Format.format_counts(): t.add_row(c) click.echo(t)
def test_read_format(mock_osp): """ read_format() should write the format to the `document_format` table. """ # Add a file, create a document row. path = mock_osp.add_file() document = Document.create(path=path) ext_format(document.id) # Pop out the new row. row = Document_Format.get(Document_Format.document == document) assert row.format == 'text/plain'
def test_read_format(mock_osp): """ read_format() should write the format to the `document_format` table. """ # Add a file, create a document row. path = mock_osp.add_file() document = Document.create(path=path) ext_format(document.id) # Pop out the new row. row = Document_Format.get(Document_Format.document==document) assert row.format == 'text/plain'
def ext_format(doc_id): """ Write the libmagic file format. Args: doc_id (int): The document id. """ doc = Document.get(Document.id==doc_id) return Document_Format.create( format=doc.syllabus.libmagic_file_type, document=doc )