def test_upload_document_failure(self):
        docket = DocketXML('nysd', '1234')
        docnum, subdocnum = self.docmap.keys()[0].split('-')
        docket.add_document(docnum, subdocnum)
        # Sanity Check
        self.assertFalse(docket.get_document_metadict(docnum, subdocnum).get('available'))

        success, msg = ia_uploader._upload_documents(docket, self.docmap)
        self.assertFalse(success)
        self.assertEquals("0", docket.get_document_metadict(docnum, subdocnum)['available'])
    def test_upload_document_success(self):
        docket = DocketXML('nysd', '1234')
        docnum, subdocnum = self.docmap.keys()[0].split('-')
        docket.add_document(docnum, subdocnum)
        # Sanity Check
        self.assertFalse(docket.get_document_metadict(docnum, subdocnum).get('available'))

        success, msg = ia_uploader._upload_documents(docket, self.docmap)
        self.assertTrue(success)
        self.assertEquals("1", docket.get_document_metadict(docnum, subdocnum)['available'])
        #sha1 of "documentfilebits"
        self.assertEquals("0fff5bc4b311d46f0bad0c840a59ec6859276265",
                          docket.get_document_metadict(docnum, subdocnum)['sha1'])
示例#3
0
class TestDocketXml(unittest.TestCase):

    def setUp(self):
        self.doc_xml = DocketXML('test_court', '1234')

    
    def test_object_creation(self):
        self.assertEquals('test_court', self.doc_xml.get_court())
        self.assertEquals('1234', self.doc_xml.get_casenum())
        self.assertEquals([], self.doc_xml.parties)
        self.assertEquals({}, self.doc_xml.documents)
        self.assertFalse(self.doc_xml.nonce == None)

    def test_add_document(self):
        meta_dict = {'test_key': 'test_value'}
        self.doc_xml.add_document('1', '2', meta_dict)
        docs = self.doc_xml.documents

        self.assertEquals(['1-2'], docs.keys())

        meta_dict['doc_num'] = '1'
        meta_dict['attachment_num'] = '2'
        self.assertEquals(meta_dict, docs['1-2'])
    
    def test_add_document_object(self):
        d1 = Document(court='nysd', casenum='1234', 
                      docnum='2', subdocnum='3',
                      de_seq_num='20', dm_id='12',
                      docid='789',
                      sha1='hash', available='1', 
                      free_import=1,
                      lastdate='lastdate', modified='1')

        expected_dict = {'doc_num': '2', 'attachment_num': '3',
                         'pacer_doc_id': '789', 
                         'pacer_de_seq_num': '20',
                         'pacer_dm_id': '12',
                         'upload_date': 'lastdate',
                         'available': '1',
                         'free_import': '1',
                         'sha1': 'hash'}

        self.doc_xml.add_document_object(d1)
        actual_dict = self.doc_xml.get_document_metadict('2','3')
        self.assertEquals(expected_dict, actual_dict)

    def test_set_document_available(self):
        meta_dict = {'test_key': 'test_value'}
        self.doc_xml.add_document('1', '2', meta_dict)
        self.doc_xml.set_document_available('1', '2', '0')
        doc_dict = self.doc_xml.get_document_metadict('1','2')
        self.assertEquals("0", doc_dict['available'])
    
    def test_set_document_available_no_preexiting_document(self):
        self.doc_xml.set_document_available('1', '2', '0')
        doc_dict = self.doc_xml.get_document_metadict('1','2')
        self.assertEquals("0", doc_dict['available'])
    
    def test_get_document_sha1(self):
        meta_dict = {'sha1': 'sha1test'}
        self.doc_xml.add_document('1', '2', meta_dict)
        actual_sha1 = self.doc_xml.get_document_sha1('1', '2')
        self.assertEquals('sha1test', actual_sha1)
    
    def test_remove_document(self):
        self.doc_xml.add_document('1', '2')
        self.doc_xml.remove_document('1', '2')
        self.assertEquals({}, self.doc_xml.documents)

    def test_add_party(self):
        party = {'name': 'Dhruv'}
        self.doc_xml.add_party(party)
        self.assertEquals([party], self.doc_xml.parties)

    def test_update_parties_simple(self):
        party_list= [{'name': 'Dhruv'}]

        #Test updates when no pre-existing parties
        self.doc_xml.update_parties(party_list)
        self.assertEquals(party_list, self.doc_xml.parties)

        # Test that equivalent updates change nothing
        self.doc_xml.update_parties(party_list)
        self.assertEquals(party_list, self.doc_xml.parties)
    
    def test_update_parties_same_name(self):
        party = {'name': 'Dhruv'}
        self.doc_xml.add_party(party)
        party_update = {'name': 'Dhruv', 'phone': '1234'}

        self.doc_xml.update_parties([party_update])

        self.assertEquals([party_update], self.doc_xml.parties)
    
    def test_update_parties_different_name(self):
        party = {'name': 'Dhruv'}
        self.doc_xml.add_party(party)
        party_update = {'name': 'Harlan', 'phone': '1234'}

        self.doc_xml.update_parties([party_update])

        self.assertEquals([party, party_update], self.doc_xml.parties)

    def test_update_case(self):
        new_casemeta = {'Nature of Suit': 'Something'}
        self.doc_xml.update_case(new_casemeta)
        new_casemeta['pacer_case_num'] = '1234'
        new_casemeta['court'] = 'test_court'
        self.assertEquals(new_casemeta, self.doc_xml.casemeta)

    def test_get_root(self):
        # TODO: there's a lot of logic in this method, but
        #       testing it is overkill for now
        #       we should refactor it to make it easier to test

        xml_obj = self.doc_xml.get_root()
        self.assertFalse(xml_obj == None)

    def test_to_xml(self):
        # TODO: better test here (after refactoring get_root)
        meta_dict = {'free_import': 1}
        self.doc_xml.add_document('1', '2', meta_dict)
        xml_text = self.doc_xml.to_xml()
        self.assertFalse(xml_text == None)
        self.assertTrue(xml_text.find('free_import') > 0)
    
    def test_to_html(self):
        # TODO: better test here (after refactoring get_root)
        html_text = self.doc_xml.to_html()
        self.assertFalse(html_text == None)

    def test_parse_xml_string(self):
        meta_dict = {'free_import': 1}
        self.doc_xml.add_document('1', '2', meta_dict)
        xml_text = self.doc_xml.to_xml()
        parsed_docket, msg = parse_xml_string(xml_text)

        self.assertEquals(1, len(parsed_docket.documents))
        self.assertEquals('1', parsed_docket.documents['1-2']['free_import'])
示例#4
0
 def setUp(self):
     self.doc_xml = DocketXML('test_court', '1234')
 def setUp(self):
     self.doc_xml = DocketXML('nysd', '1234')
     self.doc_xml.add_document('1', '2')
class TestDocumentManager(unittest.TestCase):

    def setUp(self):
        self.doc_xml = DocketXML('nysd', '1234')
        self.doc_xml.add_document('1', '2')

    def tearDown(self):
        Document.objects.all().delete()

    def test_update_local_db_basic(self):
        DocumentManager.update_local_db(self.doc_xml)
        created_doc = Document.objects.all()[0]

        self.assertEquals(1, Document.objects.count())
        self.assertEquals('nysd', created_doc.court)
        self.assertEquals(1234, created_doc.casenum)
        self.assertEquals(1, created_doc.docnum)
        self.assertEquals(2, created_doc.subdocnum)
    
    def test_update_local_db_updates_existing(self):
        d1 = Document(court='nysd', casenum='1234', docnum='1', subdocnum='2')
        d1.save()
        self.assertEquals(1, Document.objects.count())

        doc_meta = self.doc_xml.get_document_metadict('1', '2')
        doc_meta['pacer_doc_id'] = '12'

        DocumentManager.update_local_db(self.doc_xml)
        created_doc = Document.objects.all()[0]
        self.assertEquals(1, Document.objects.count())
        self.assertEquals('12', created_doc.docid)
    
    def test_update_local_db_doesnt_overwrite_local(self):
        d1 = Document(court='nysd', casenum='1234', 
                      docnum='1', subdocnum='2',
                      docid='120')
        d1.save()
        self.assertEquals(1, Document.objects.count())

        # This document doesn't have docid, but we shouldn't overwrite
        DocumentManager.update_local_db(self.doc_xml)

        created_doc = Document.objects.all()[0]
        self.assertEquals(1, Document.objects.count())
        self.assertEquals('120', created_doc.docid)

    def test_update_local_db_translates_opt_fields_correctly(self):
        i_dict = {'doc_num': '2', 'attachment_num': '3',
                         'pacer_doc_id': '789', 
                         'pacer_de_seq_num': '20',
                         'pacer_dm_id': '12',
                         'upload_date': '2007-12-25',
                         'free_import': 1,
                         'sha1': 'hash'}

        self.doc_xml.remove_document('1', '2')
        self.doc_xml.add_document('2', '3', i_dict)
        DocumentManager.update_local_db(self.doc_xml)
        self.assertEquals(1, Document.objects.count())
        created_doc = Document.objects.all()[0]
        self.assertEquals(int(i_dict['doc_num']), created_doc.docnum)
        self.assertEquals(int(i_dict['attachment_num']), created_doc.subdocnum)
        self.assertEquals(i_dict['pacer_doc_id'], created_doc.docid)
        self.assertEquals(int(i_dict['pacer_de_seq_num']), created_doc.de_seq_num)
        self.assertEquals(int(i_dict['pacer_dm_id']), created_doc.dm_id)
        self.assertEquals(i_dict['sha1'], created_doc.sha1)
        expected_upload_date = datetime.strptime(i_dict['upload_date'], 
                                                "%Y-%m-%d")
        self.assertEquals(expected_upload_date, created_doc.lastdate)
        self.assertEquals(int(i_dict['free_import']), created_doc.free_import)

    
    def test_update_local_db_ignore_available(self):
        doc_meta = self.doc_xml.get_document_metadict('1', '2')
        doc_meta['available'] = '1'
        
        DocumentManager.update_local_db(self.doc_xml)
        created_doc = Document.objects.all()[0]
        self.assertEquals(0, created_doc.available)
        
        DocumentManager.update_local_db(self.doc_xml, ignore_available=0)
        created_doc = Document.objects.all()[0]
        self.assertEquals(1, created_doc.available)
示例#7
0
 def setUp(self):
     self.doc_xml = DocketXML('nysd', '1234')
     self.doc_xml.add_document('1', '2')
示例#8
0
class TestDocumentManager(unittest.TestCase):
    def setUp(self):
        self.doc_xml = DocketXML('nysd', '1234')
        self.doc_xml.add_document('1', '2')

    def tearDown(self):
        Document.objects.all().delete()

    def test_update_local_db_basic(self):
        DocumentManager.update_local_db(self.doc_xml)
        created_doc = Document.objects.all()[0]

        self.assertEquals(1, Document.objects.count())
        self.assertEquals('nysd', created_doc.court)
        self.assertEquals(1234, created_doc.casenum)
        self.assertEquals(1, created_doc.docnum)
        self.assertEquals(2, created_doc.subdocnum)

    def test_update_local_db_updates_existing(self):
        d1 = Document(court='nysd', casenum='1234', docnum='1', subdocnum='2')
        d1.save()
        self.assertEquals(1, Document.objects.count())

        doc_meta = self.doc_xml.get_document_metadict('1', '2')
        doc_meta['pacer_doc_id'] = '12'

        DocumentManager.update_local_db(self.doc_xml)
        created_doc = Document.objects.all()[0]
        self.assertEquals(1, Document.objects.count())
        self.assertEquals('12', created_doc.docid)

    def test_update_local_db_doesnt_overwrite_local(self):
        d1 = Document(court='nysd',
                      casenum='1234',
                      docnum='1',
                      subdocnum='2',
                      docid='120')
        d1.save()
        self.assertEquals(1, Document.objects.count())

        # This document doesn't have docid, but we shouldn't overwrite
        DocumentManager.update_local_db(self.doc_xml)

        created_doc = Document.objects.all()[0]
        self.assertEquals(1, Document.objects.count())
        self.assertEquals('120', created_doc.docid)

    def test_update_local_db_translates_opt_fields_correctly(self):
        i_dict = {
            'doc_num': '2',
            'attachment_num': '3',
            'pacer_doc_id': '789',
            'pacer_de_seq_num': '20',
            'pacer_dm_id': '12',
            'upload_date': '2007-12-25',
            'free_import': 1,
            'sha1': 'hash'
        }

        self.doc_xml.remove_document('1', '2')
        self.doc_xml.add_document('2', '3', i_dict)
        DocumentManager.update_local_db(self.doc_xml)
        self.assertEquals(1, Document.objects.count())
        created_doc = Document.objects.all()[0]
        self.assertEquals(int(i_dict['doc_num']), created_doc.docnum)
        self.assertEquals(int(i_dict['attachment_num']), created_doc.subdocnum)
        self.assertEquals(i_dict['pacer_doc_id'], created_doc.docid)
        self.assertEquals(int(i_dict['pacer_de_seq_num']),
                          created_doc.de_seq_num)
        self.assertEquals(int(i_dict['pacer_dm_id']), created_doc.dm_id)
        self.assertEquals(i_dict['sha1'], created_doc.sha1)
        expected_upload_date = datetime.strptime(i_dict['upload_date'],
                                                 "%Y-%m-%d")
        self.assertEquals(expected_upload_date, created_doc.lastdate)
        self.assertEquals(int(i_dict['free_import']), created_doc.free_import)

    def test_update_local_db_ignore_available(self):
        doc_meta = self.doc_xml.get_document_metadict('1', '2')
        doc_meta['available'] = '1'

        DocumentManager.update_local_db(self.doc_xml)
        created_doc = Document.objects.all()[0]
        self.assertEquals(0, created_doc.available)

        DocumentManager.update_local_db(self.doc_xml, ignore_available=0)
        created_doc = Document.objects.all()[0]
        self.assertEquals(1, created_doc.available)
示例#9
0
 def setUp(self):
     self.doc_xml = DocketXML('test_court', '1234')
示例#10
0
class TestDocketXml(unittest.TestCase):
    def setUp(self):
        self.doc_xml = DocketXML('test_court', '1234')

    def test_object_creation(self):
        self.assertEquals('test_court', self.doc_xml.get_court())
        self.assertEquals('1234', self.doc_xml.get_casenum())
        self.assertEquals([], self.doc_xml.parties)
        self.assertEquals({}, self.doc_xml.documents)
        self.assertFalse(self.doc_xml.nonce == None)

    def test_add_document(self):
        meta_dict = {'test_key': 'test_value'}
        self.doc_xml.add_document('1', '2', meta_dict)
        docs = self.doc_xml.documents

        self.assertEquals(['1-2'], docs.keys())

        meta_dict['doc_num'] = '1'
        meta_dict['attachment_num'] = '2'
        self.assertEquals(meta_dict, docs['1-2'])

    def test_add_document_object(self):
        d1 = Document(court='nysd',
                      casenum='1234',
                      docnum='2',
                      subdocnum='3',
                      de_seq_num='20',
                      dm_id='12',
                      docid='789',
                      sha1='hash',
                      available='1',
                      free_import=1,
                      lastdate='lastdate',
                      modified='1')

        expected_dict = {
            'doc_num': '2',
            'attachment_num': '3',
            'pacer_doc_id': '789',
            'pacer_de_seq_num': '20',
            'pacer_dm_id': '12',
            'upload_date': 'lastdate',
            'available': '1',
            'free_import': '1',
            'sha1': 'hash'
        }

        self.doc_xml.add_document_object(d1)
        actual_dict = self.doc_xml.get_document_metadict('2', '3')
        self.assertEquals(expected_dict, actual_dict)

    def test_set_document_available(self):
        meta_dict = {'test_key': 'test_value'}
        self.doc_xml.add_document('1', '2', meta_dict)
        self.doc_xml.set_document_available('1', '2', '0')
        doc_dict = self.doc_xml.get_document_metadict('1', '2')
        self.assertEquals("0", doc_dict['available'])

    def test_set_document_available_no_preexiting_document(self):
        self.doc_xml.set_document_available('1', '2', '0')
        doc_dict = self.doc_xml.get_document_metadict('1', '2')
        self.assertEquals("0", doc_dict['available'])

    def test_get_document_sha1(self):
        meta_dict = {'sha1': 'sha1test'}
        self.doc_xml.add_document('1', '2', meta_dict)
        actual_sha1 = self.doc_xml.get_document_sha1('1', '2')
        self.assertEquals('sha1test', actual_sha1)

    def test_remove_document(self):
        self.doc_xml.add_document('1', '2')
        self.doc_xml.remove_document('1', '2')
        self.assertEquals({}, self.doc_xml.documents)

    def test_add_party(self):
        party = {'name': 'Dhruv'}
        self.doc_xml.add_party(party)
        self.assertEquals([party], self.doc_xml.parties)

    def test_update_parties_simple(self):
        party_list = [{'name': 'Dhruv'}]

        #Test updates when no pre-existing parties
        self.doc_xml.update_parties(party_list)
        self.assertEquals(party_list, self.doc_xml.parties)

        # Test that equivalent updates change nothing
        self.doc_xml.update_parties(party_list)
        self.assertEquals(party_list, self.doc_xml.parties)

    def test_update_parties_same_name(self):
        party = {'name': 'Dhruv'}
        self.doc_xml.add_party(party)
        party_update = {'name': 'Dhruv', 'phone': '1234'}

        self.doc_xml.update_parties([party_update])

        self.assertEquals([party_update], self.doc_xml.parties)

    def test_update_parties_different_name(self):
        party = {'name': 'Dhruv'}
        self.doc_xml.add_party(party)
        party_update = {'name': 'Harlan', 'phone': '1234'}

        self.doc_xml.update_parties([party_update])

        self.assertEquals([party, party_update], self.doc_xml.parties)

    def test_update_case(self):
        new_casemeta = {'Nature of Suit': 'Something'}
        self.doc_xml.update_case(new_casemeta)
        new_casemeta['pacer_case_num'] = '1234'
        new_casemeta['court'] = 'test_court'
        self.assertEquals(new_casemeta, self.doc_xml.casemeta)

    def test_get_root(self):
        # TODO: there's a lot of logic in this method, but
        #       testing it is overkill for now
        #       we should refactor it to make it easier to test

        xml_obj = self.doc_xml.get_root()
        self.assertFalse(xml_obj == None)

    def test_to_xml(self):
        # TODO: better test here (after refactoring get_root)
        meta_dict = {'free_import': 1}
        self.doc_xml.add_document('1', '2', meta_dict)
        xml_text = self.doc_xml.to_xml()
        self.assertFalse(xml_text == None)
        self.assertTrue(xml_text.find('free_import') > 0)

    def test_to_html(self):
        # TODO: better test here (after refactoring get_root)
        html_text = self.doc_xml.to_html()
        self.assertFalse(html_text == None)

    def test_parse_xml_string(self):
        meta_dict = {'free_import': 1}
        self.doc_xml.add_document('1', '2', meta_dict)
        xml_text = self.doc_xml.to_xml()
        parsed_docket, msg = parse_xml_string(xml_text)

        self.assertEquals(1, len(parsed_docket.documents))
        self.assertEquals('1', parsed_docket.documents['1-2']['free_import'])