Esempio n. 1
0
def list(request):
    # Handle file upload
    if request.method == 'POST':
        form = DocumentForm(request.POST, request.FILES)
        
        tests=Detail.objects.all()
        for test in tests:
			if test.is_active==True:
				testset=test.test_id
        if form.is_valid():
            newdoc = Document(docfile = request.FILES['docfile'], user=User.objects.get(username=request.user.username), test_set=Detail.objects.get(test_id=testset))
            newdoc.save()

            # Redirect to the document list after POST
            return HttpResponseRedirect(reverse('uploads.views.list'))
    else:
        form = DocumentForm() # A empty, unbound form

    # Load documents for the list page
    documents = Document.objects.all()

    # Render list page with the documents and the form
    return render_to_response(
        'list.html',
        {'documents': documents, 'form': form},
        context_instance=RequestContext(request))
class TestAddDocMetaView(unittest.TestCase): 
    def setUp(self):
        self.client = Client()
        self.existing_document  = Document(court='nysd', casenum='1234', docnum='1', subdocnum='0')
        self.existing_document.save()
        self.adddocparams =  { 'court': 'nysd', 'casenum': '1234', 
                               'docnum': '1', 'de_seq_num': '1111',
                               'dm_id': '2222', 'docid': '3330'}
    def tearDown(self):
        Document.objects.all().delete()


    
    def test_adddoc_only_post_requests_allowed(self):
        response = self.client.get('/recap/adddocmeta/')
        self.assertEquals("adddocmeta: Not a POST request.", response.content)
    
    def test_adddoc_request_data_missing(self):
        response = self.client.post('/recap/adddocmeta/', {'docid': '1234'})
        self.assertTrue(response.content.startswith("adddocmeta: \"Key 'court' not found"))

    def test_adddoc_updates_meta(self):
        self.assertEquals(None, self.existing_document.docid)
        response = self.client.post('/recap/adddocmeta/', self.adddocparams)
        self.assertEquals("adddocmeta: DB updated for docid=3330", response.content)
        query = Document.objects.filter(court='nysd', casenum='1234', 
                                        docnum='1', subdocnum='0')

        saved_document = query[0]
        self.assertEquals(1111, saved_document.de_seq_num)
        self.assertEquals(2222, saved_document.dm_id)
        self.assertEquals('3330', saved_document.docid)
    
    def test_adddoc_coerces_doc_id(self):
        self.adddocparams['docid'] = '123456789'
        response = self.client.post('/recap/adddocmeta/', self.adddocparams)
        query = Document.objects.filter(court='nysd', casenum='1234', 
                                        docnum='1', subdocnum='0')

        saved_document = query[0]
        self.assertEquals('123056789', saved_document.docid)
    
    def test_adddoc_creates_new_document(self):
        query = Document.objects.filter(court='nysd', casenum='5678', 
                                        docnum='1', subdocnum='0')

        self.adddocparams['casenum'] = '5678'
        self.assertEquals(0, query.count()) 
        response = self.client.post('/recap/adddocmeta/', self.adddocparams)
        self.assertEquals(1, query.count()) 
        created_doc = query[0]
        created_doc.docid = self.adddocparams['docid']
    
    def test_adddoc_responds_with_document_dict(self):
        self.adddocparams['add_case_info'] = True
        response = self.client.post('/recap/adddocmeta/', self.adddocparams)
        response_dict = simplejson.loads(response.content)
        self.assertEquals(1, len(response_dict['documents']))
        self.assertTrue(self.adddocparams['docid'] in response_dict['documents'])
Esempio n. 3
0
    def test_heartbeat_correct_key_with_db_connection(self):

        document = Document(court='cand', casenum='215270', docnum='1', subdocnum='0')
        document.save()

        response = self.client.get('/recap/heartbeat/', {'key' : config['API_KEYS'][0]})
        self.assertEquals(200, response.status_code)
        self.assertEquals("It's Alive!", response.content)
Esempio n. 4
0
    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_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)
Esempio n. 7
0
def update_local_db(docket, ignore_available=1):

    court = docket.casemeta["court"]
    casenum = docket.casemeta["pacer_case_num"]
    for docmeta in docket.documents.values():

        docnum = docmeta["doc_num"]
        subdocnum = docmeta["attachment_num"]

        docquery = Document.objects.filter(court=court, casenum=casenum, docnum=docnum, subdocnum=subdocnum)

        try:
            docentry = docquery[0]
        except IndexError:
            # Add this new document to our DB
            docentry = Document(court=court, casenum=casenum, docnum=docnum, subdocnum=subdocnum)
        try:
            docentry.docid = docmeta["pacer_doc_id"]
        except KeyError:
            pass
        try:
            docentry.de_seq_num = docmeta["pacer_de_seq_num"]
        except KeyError:
            pass
        try:
            docentry.dm_id = docmeta["pacer_dm_id"]
        except KeyError:
            pass
        try:
            docentry.sha1 = docmeta["sha1"]
        except KeyError:
            pass
        if not ignore_available:
            try:
                docentry.available = docmeta["available"]
            except KeyError:
                pass
        try:
            docentry.lastdate = docmeta["upload_date"]
        except KeyError:
            pass

        try:
            docentry.free_import = docmeta["free_import"]
        except KeyError:
            pass

        try:
            docentry.save()
        except IntegrityError:
            logging.error("update_local_db: could not save %s %s %s %s" % (court, casenum, docnum, subdocnum))
Esempio n. 8
0
def handle_adddocmeta(docid, court, casenum, de_seq_num, dm_id, docnum,
                      subdocnum):
    docid = ParsePacer.coerce_docid(docid)

    query = Document.objects.filter(court=court,
                                    casenum=casenum,
                                    docnum=docnum,
                                    subdocnum=subdocnum)

    try:
        doc = query[0]
    except IndexError:
        doc = Document(docid=docid,
                       court=court,
                       casenum=casenum,
                       de_seq_num=de_seq_num,
                       dm_id=dm_id,
                       docnum=docnum,
                       subdocnum=subdocnum)
    else:
        doc.de_seq_num = de_seq_num
        doc.dm_id = dm_id
        doc.docnum = docnum
        doc.docid = docid

    try:
        doc.save()
    except IntegrityError:
        logging.error("handle_adddocmeta: could not save docid %s" % (docid))
Esempio n. 9
0
    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)
Esempio n. 10
0
    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 setUp(self):
     self.client = Client()
     self.existing_document  = Document(court='nysd', casenum='1234', docnum='1', subdocnum='0')
     self.existing_document.save()
     self.adddocparams =  { 'court': 'nysd', 'casenum': '1234', 
                            'docnum': '1', 'de_seq_num': '1111',
                            'dm_id': '2222', 'docid': '3330'}
Esempio n. 12
0
def handle_adddocmeta(docid, court, casenum, de_seq_num, dm_id, docnum, subdocnum):

    docid = ParsePacer.coerce_docid(docid)

    query = Document.objects.filter(court=court, casenum=casenum, docnum=docnum, subdocnum=subdocnum)

    try:
        doc = query[0]
    except IndexError:
        doc = Document(
            docid=docid,
            court=court,
            casenum=casenum,
            de_seq_num=de_seq_num,
            dm_id=dm_id,
            docnum=docnum,
            subdocnum=subdocnum,
        )
    else:
        doc.de_seq_num = de_seq_num
        doc.dm_id = dm_id
        doc.docnum = docnum
        doc.docid = docid

    try:
        doc.save()
    except IntegrityError:
        logging.error("handle_adddocmeta: could not save docid %s" % (docid))
Esempio n. 13
0
    def setUp(self):
        self.client = Client()
        self.not_avail_doc = Document(
            court="nysd", casenum="1234", docnum="1", subdocnum="0", dm_id="1234", de_seq_num="111", docid="12304213"
        )
        self.not_avail_doc.save()

        self.available_doc = Document(
            court="nysd", casenum="1234", docnum="2", subdocnum="0", dm_id="1234", de_seq_num="111", docid="1230445"
        )
        self.available_doc.available = "1"
        self.available_doc.lastdate = datetime.datetime.now()
        self.available_doc.save()

        self.docs = [self.not_avail_doc, self.available_doc]

        self.valid_params = {"court": "nysd", "urls": [self._show_doc_url_for_document(d) for d in self.docs]}

        self.valid_params_doc1 = {"court": "nysd", "urls": [self._doc1_url_for_document(d) for d in self.docs]}
 def setUp(self):
     self.client = Client()
     self.valid_params = {'court': 'nysd', 
                          'casenum' : '1234'} 
     
     self.available_doc = Document(court='nysd', casenum='1234', docnum='2', subdocnum='0', 
                                     dm_id = '1234', de_seq_num = '111', docid = '1230445')
     self.available_doc.available = '1'
     self.available_doc.lastdate = datetime.datetime.now()
     self.available_doc.save()
Esempio n. 15
0
def list(request):
    # Handle file upload
    if request.method == 'POST':
        form = DocumentForm(request.POST, request.FILES)
        if form.is_valid():
            newdoc = Document(docfile = request.FILES['docfile'])
            newdoc.save()

            # Redirect to the document list after POST
            return HttpResponseRedirect('/')
    else:
        form = DocumentForm() # A empty, unbound form

    # Load documents for the list page
    documents = Document.objects.all()

    # Render list page with the documents and the form
    return render_to_response(
        'uploads/list.html',
        {'documents': documents, 'form': form},
        context_instance=RequestContext(request)
    )
Esempio n. 16
0
    def test_valid_query_response_with_subdocuments(self):
        subdoc1 = Document(
            court="nysd", casenum="1234", docnum="2", subdocnum="1", available=1, lastdate=datetime.datetime.now()
        )
        subdoc2 = Document(
            court="nysd", casenum="1234", docnum="2", subdocnum="2", available=1, lastdate=datetime.datetime.now()
        )
        subdoc3 = Document(court="nysd", casenum="1234", docnum="2", subdocnum="3")
        subdoc1.save()
        subdoc2.save()
        subdoc3.save()

        response = self.client.post("/recap/query/", {"json": simplejson.dumps(self.valid_params)})
        output = simplejson.loads(response.content)

        avail_show_doc_url = self._show_doc_url_for_document(self.available_doc)
        self.assertTrue(avail_show_doc_url in output)
        self.assertTrue("subDocuments" in output[avail_show_doc_url])
        subdoc_dict = output[avail_show_doc_url]["subDocuments"]
        self.assertEquals(2, len(subdoc_dict))
        self.assertEquals(self._ia_url_for_doc(subdoc1), subdoc_dict["1"]["filename"])
Esempio n. 17
0
 def test_get_updated_cases_valid_request(self):
     d1 = Document(court='nysd', casenum='1234', docnum='1', subdocnum='0')
     d1.save()
     d2 = Document(court='dcd', casenum='100', docnum='1', subdocnum='0')
     d2.save()
     yesterday = time.time() - 60 * 60 * 24
     response = self.client.post('/recap/get_updated_cases/', {'key' : config['API_KEYS'][0], 
                                                              'tpq' : yesterday})
     self.assertEquals(200, response.status_code)
     self.assertEquals('%s,%s\r\n%s,%s\r\n' % (d1.court, d1.casenum, d2.court, d2.casenum), response.content)
     self.assertEquals({'Content-Type': 'text/csv'}, response.headers)
Esempio n. 18
0
def create_profile(request):
    if request.method == 'POST':
        form = DocumentForm(request.POST, request.FILES)
        employee_id=""

        if form.is_valid():
            image_validator, origin_image, image_drawn = form.cleaned_data['photo']
            #def the uploaded image has 1 face and is valid
            if (image_validator==1):
                record = Document()
                record.photo=origin_image
                record.firstname=form.cleaned_data['firstname']
                record.lastname=form.cleaned_data['lastname']
                record.department=form.cleaned_data['department']

                record.save()
                employee_id=record.employee_id

            buffered = BytesIO()


        #face_no, image_drawn = draw_face(image.file.read())

            image_drawn.save(buffered, format="JPEG")
            b64_img = base64.b64encode((buffered.getvalue()))
            one_face= image_validator==1
            #multi_face = image_validator>1
            no_face = image_validator==0

    


            return render(request, 'view_form.html', {
        'form': form, 'image_drawn':b64_img,'one_face':one_face, 'no_face': no_face, 'employee_id': employee_id
    })

    else:
        form = DocumentForm()
    return render(request, 'create_form.html', {
        'form': form
    })
Esempio n. 19
0
    def setUp(self):
        self.client = Client()
        self.f = open(TEST_DOCKET_PATH + 'DktRpt_111111.html')
        self.valid_params = {'court': 'nysd', 
                             'casenum' : '1234',
                             'mimetype' : 'text/html',
                             'data': self.f} 
        self.f_pdf = open(TEST_DOCUMENT_PATH + 'gov.uscourts.cand.206019.18.0.pdf')
        self.valid_params_pdf = {'court': 'cand', 
                                 'casenum': '206019',
                                 'mimetype': 'application/pdf',
                                 'url': 'https://ecf.cand.uscourts.gov/doc1/123456', #docid
                                 'data': self.f_pdf} 

        #Doc id is 'coerced', so doesn't match one above
        self.pdf_doc = Document(court='cand', casenum='206019', 
                                docnum='18', subdocnum='0', docid=123056)
        self.pdf_doc.save()
        
        self.f_doc1 = open(TEST_DOC1_PATH + 'ecf.cand.uscourts.gov.03517852828')
        self.valid_params_doc1 = {'court': 'cand', 
                                 'casenum': '206019',
                                 'mimetype': 'text/html',
                                 'data': self.f_doc1} 
def update_local_db(docket, ignore_available=1, team_name=None):
    court = docket.casemeta["court"]
    casenum = docket.casemeta["pacer_case_num"]
    for docmeta in docket.documents.values():

        docnum = docmeta["doc_num"]
        subdocnum = docmeta["attachment_num"]

        docquery = Document.objects.filter(court=court,
                                           casenum=casenum,
                                           docnum=docnum,
                                           subdocnum=subdocnum)

        try:
            docentry = docquery[0]
        except IndexError:
            # New item: Add it to our DB
            docentry = Document(court=court, casenum=casenum,
                                docnum=docnum, subdocnum=subdocnum)
            if team_name is not None:
                # Only add the team_name to new items
                docentry.team_name = team_name
        except OperationalError:
            logging.error("update_local_db: could not save %s %s %s %s"
                          % (court, casenum, docnum, subdocnum))
            return

        try:
            docentry.docid = docmeta["pacer_doc_id"]
        except KeyError:
            pass
        try:
            docentry.de_seq_num = docmeta["pacer_de_seq_num"]
        except KeyError:
            pass
        try:
            docentry.dm_id = docmeta["pacer_dm_id"]
        except KeyError:
            pass
        try:
            docentry.sha1 = docmeta["sha1"]
        except KeyError:
            pass
        if not ignore_available:
            try:
                docentry.available = docmeta["available"]
            except KeyError:
                pass
        try:
            docentry.lastdate = docmeta["upload_date"]
        except KeyError:
            pass

        try:
            docentry.free_import = docmeta["free_import"]
        except KeyError:
            pass

        try:
            docentry.save()
        except IntegrityError:
            logging.error("update_local_db: could not save %s %s %s %s"
                          % (court, casenum, docnum, subdocnum))
class TestQueryCasesView(unittest.TestCase):
    def setUp(self):
        self.client = Client()
        self.valid_params = {'court': 'nysd', 
                             'casenum' : '1234'} 
        
        self.available_doc = Document(court='nysd', casenum='1234', docnum='2', subdocnum='0', 
                                        dm_id = '1234', de_seq_num = '111', docid = '1230445')
        self.available_doc.available = '1'
        self.available_doc.lastdate = datetime.datetime.now()
        self.available_doc.save()
    
    def tearDown(self):
        Document.objects.all().delete()

    def test_query_cases_post_request_only(self):
        response = self.client.get('/recap/query_cases/', {'blah' : 'foo'})
        self.assertEquals('query_cases: Not a POST request.', response.content)
    
    def test_query_cases_no_params(self):
        response = self.client.post('/recap/query_cases/')
        self.assertEquals("query_cases: no 'json' POST argument", response.content)
    
    def test_query_cases_missing_court_param(self):
        del self.valid_params['court']
        response = self.client.post('/recap/query_cases/', {'json': simplejson.dumps(self.valid_params)})
        self.assertEquals("query_cases: missing json 'court' argument.", response.content)
    
    def test_query_cases_missing_casenum_param(self):
        del self.valid_params['casenum']
        response = self.client.post('/recap/query_cases/', {'json': simplejson.dumps(self.valid_params)})
        self.assertEquals("query_cases: missing json 'casenum' argument.", response.content)

    def test_valid_query_cases_response_no_match(self):

        response = self.client.post('/recap/query_cases/', {'json': simplejson.dumps(self.valid_params)})
        self.assertEquals("{}", response.content)
    
    def test_valid_query_cases_response_no_match(self):
        self.valid_params['casenum'] = '99999'
        response = self.client.post('/recap/query_cases/', {'json': simplejson.dumps(self.valid_params)})
        self.assertEquals("{}", response.content)
    
    def test_valid_query_cases_response_available_doc_match(self):
        response = self.client.post('/recap/query_cases/', {'json': simplejson.dumps(self.valid_params)})
        output= simplejson.loads(response.content)

        self.assertEquals(2, len(output))
        self.assertEquals(self.available_doc.lastdate.strftime("%m/%d/%y"), output['timestamp'])
        self.assertEquals(IACommon.get_dockethtml_url('nysd', '1234'), output['docket_url'])
    
    def test_valid_query_cases_response_unavailable_doc_currently_uploading(self):
        self.available_doc.available = 0
        self.available_doc.save()
        ppquery = PickledPut(filename=IACommon.get_docketxml_name('nysd', '1234'))
        ppquery.save()
        response = self.client.post('/recap/query_cases/', {'json': simplejson.dumps(self.valid_params)})
        self.assertEquals("{}", response.content)
        PickledPut.objects.all().delete()
    
    def test_valid_query_cases_response_old_doc_currently_uploading(self):
        self.available_doc.available = 0
        two_days_ago = datetime.datetime.now() - datetime.timedelta(2)
        self.available_doc.modified= two_days_ago
        self.available_doc.save()

        ppquery = PickledPut(filename=IACommon.get_docketxml_name('nysd', '1234'))
        ppquery.save()
        response = self.client.post('/recap/query_cases/', {'json': simplejson.dumps(self.valid_params)})
        
        output= simplejson.loads(response.content)

        self.assertEquals(2, len(output))
        self.assertEquals(self.available_doc.lastdate.strftime("%m/%d/%y"), output['timestamp'])
        self.assertEquals(IACommon.get_dockethtml_url('nysd', '1234'), output['docket_url'])
        PickledPut.objects.all().delete()
Esempio n. 22
0
class TestQueryView(unittest.TestCase):
    def setUp(self):
        self.client = Client()
        self.not_avail_doc = Document(
            court="nysd", casenum="1234", docnum="1", subdocnum="0", dm_id="1234", de_seq_num="111", docid="12304213"
        )
        self.not_avail_doc.save()

        self.available_doc = Document(
            court="nysd", casenum="1234", docnum="2", subdocnum="0", dm_id="1234", de_seq_num="111", docid="1230445"
        )
        self.available_doc.available = "1"
        self.available_doc.lastdate = datetime.datetime.now()
        self.available_doc.save()

        self.docs = [self.not_avail_doc, self.available_doc]

        self.valid_params = {"court": "nysd", "urls": [self._show_doc_url_for_document(d) for d in self.docs]}

        self.valid_params_doc1 = {"court": "nysd", "urls": [self._doc1_url_for_document(d) for d in self.docs]}

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

    def _show_doc_url_for_document(self, doc):
        show_doc_url = "".join(
            [
                "/cgi-bin/show_doc.pl?",
                "caseid=%(casenum)s",
                "&de_seq_num=%(de_seq_num)s",
                "&dm_id=%(dm_id)s",
                "&doc_num=%(docnum)s",
                "&pdf_header=2",
            ]
        )
        show_doc_dict = {"casenum": doc.casenum, "de_seq_num": doc.de_seq_num, "dm_id": doc.dm_id, "docnum": doc.docnum}

        return show_doc_url % show_doc_dict

    def _doc1_url_for_document(self, doc):
        return "/doc1/%s" % doc.docid

    def _ia_url_for_doc(self, doc):
        return IACommon.get_pdf_url(doc.court, doc.casenum, doc.docnum, doc.subdocnum)

    def test_query_post_request_only(self):
        response = self.client.get("/recap/query/", {"blah": "foo"})
        self.assertEquals("query: Not a POST request.", response.content)

    def test_query_no_params(self):
        response = self.client.post("/recap/query/")
        self.assertEquals("query: no 'json' POST argument", response.content)

    def test_query_invalid_json(self):
        response = self.client.post("/recap/query/", {"json": "dkkfkdk"})
        self.assertEquals("query: malformed 'json' POST argument", response.content)

    def test_query_missing_court_param(self):
        del self.valid_params["court"]
        response = self.client.post("/recap/query/", {"json": simplejson.dumps(self.valid_params)})
        self.assertEquals("query: missing json 'court' argument.", response.content)

    def test_query_missing_url_param(self):
        del self.valid_params["urls"]
        response = self.client.post("/recap/query/", {"json": simplejson.dumps(self.valid_params)})
        self.assertEquals("query: missing json 'urls' argument.", response.content)

    def test_valid_show_doc_query_response(self):
        response = self.client.post("/recap/query/", {"json": simplejson.dumps(self.valid_params)})

        output = simplejson.loads(response.content)
        avail_show_doc_url = self._show_doc_url_for_document(self.available_doc)
        self.assertTrue(avail_show_doc_url in output)
        self.assertFalse(self._show_doc_url_for_document(self.not_avail_doc) in output)
        self.assertEquals(self.available_doc.lastdate.strftime("%m/%d/%y"), output[avail_show_doc_url]["timestamp"])
        self.assertEquals(self._ia_url_for_doc(self.available_doc), output[avail_show_doc_url]["filename"])

    def test_valid_doc1_url_query_response(self):
        response = self.client.post("/recap/query/", {"json": simplejson.dumps(self.valid_params_doc1)})
        output = simplejson.loads(response.content)

        avail_show_doc_url = self._doc1_url_for_document(self.available_doc)
        self.assertFalse(self._doc1_url_for_document(self.not_avail_doc) in output)
        self.assertEquals(self.available_doc.lastdate.strftime("%m/%d/%y"), output[avail_show_doc_url]["timestamp"])
        self.assertEquals(self._ia_url_for_doc(self.available_doc), output[avail_show_doc_url]["filename"])

    def test_valid_query_response_with_subdocuments(self):
        subdoc1 = Document(
            court="nysd", casenum="1234", docnum="2", subdocnum="1", available=1, lastdate=datetime.datetime.now()
        )
        subdoc2 = Document(
            court="nysd", casenum="1234", docnum="2", subdocnum="2", available=1, lastdate=datetime.datetime.now()
        )
        subdoc3 = Document(court="nysd", casenum="1234", docnum="2", subdocnum="3")
        subdoc1.save()
        subdoc2.save()
        subdoc3.save()

        response = self.client.post("/recap/query/", {"json": simplejson.dumps(self.valid_params)})
        output = simplejson.loads(response.content)

        avail_show_doc_url = self._show_doc_url_for_document(self.available_doc)
        self.assertTrue(avail_show_doc_url in output)
        self.assertTrue("subDocuments" in output[avail_show_doc_url])
        subdoc_dict = output[avail_show_doc_url]["subDocuments"]
        self.assertEquals(2, len(subdoc_dict))
        self.assertEquals(self._ia_url_for_doc(subdoc1), subdoc_dict["1"]["filename"])
Esempio n. 23
0
def update_local_db(docket, ignore_available=1, team_name=None):
    court = docket.casemeta["court"]
    casenum = docket.casemeta["pacer_case_num"]
    for docmeta in docket.documents.values():

        docnum = docmeta["doc_num"]
        subdocnum = docmeta["attachment_num"]

        docquery = Document.objects.filter(court=court,
                                           casenum=casenum,
                                           docnum=docnum,
                                           subdocnum=subdocnum)

        try:
            docentry = docquery[0]
        except IndexError:
            # New item: Add it to our DB
            docentry = Document(court=court,
                                casenum=casenum,
                                docnum=docnum,
                                subdocnum=subdocnum)
            if team_name is not None:
                # Only add the team_name to new items
                docentry.team_name = team_name
        except OperationalError:
            logging.error("update_local_db: could not save %s %s %s %s" %
                          (court, casenum, docnum, subdocnum))
            return

        try:
            docentry.docid = docmeta["pacer_doc_id"]
        except KeyError:
            pass
        try:
            docentry.de_seq_num = docmeta["pacer_de_seq_num"]
        except KeyError:
            pass
        try:
            docentry.dm_id = docmeta["pacer_dm_id"]
        except KeyError:
            pass
        try:
            docentry.sha1 = docmeta["sha1"]
        except KeyError:
            pass
        if not ignore_available:
            try:
                docentry.available = docmeta["available"]
            except KeyError:
                pass
        try:
            docentry.lastdate = docmeta["upload_date"]
        except KeyError:
            pass

        try:
            docentry.free_import = docmeta["free_import"]
        except KeyError:
            pass

        try:
            docentry.save()
        except IntegrityError:
            logging.error("update_local_db: could not save %s %s %s %s" %
                          (court, casenum, docnum, subdocnum))
Esempio n. 24
0
class TestUploadView(unittest.TestCase):
    def setUp(self):
        self.client = Client()
        self.f = open(TEST_DOCKET_PATH + 'DktRpt_111111.html')
        self.valid_params = {'court': 'nysd', 
                             'casenum' : '1234',
                             'mimetype' : 'text/html',
                             'data': self.f} 
        self.f_pdf = open(TEST_DOCUMENT_PATH + 'gov.uscourts.cand.206019.18.0.pdf')
        self.valid_params_pdf = {'court': 'cand', 
                                 'casenum': '206019',
                                 'mimetype': 'application/pdf',
                                 'url': 'https://ecf.cand.uscourts.gov/doc1/123456', #docid
                                 'data': self.f_pdf} 

        #Doc id is 'coerced', so doesn't match one above
        self.pdf_doc = Document(court='cand', casenum='206019', 
                                docnum='18', subdocnum='0', docid=123056)
        self.pdf_doc.save()
        
        self.f_doc1 = open(TEST_DOC1_PATH + 'ecf.cand.uscourts.gov.03517852828')
        self.valid_params_doc1 = {'court': 'cand', 
                                 'casenum': '206019',
                                 'mimetype': 'text/html',
                                 'data': self.f_doc1} 

    def tearDown(self):
        self.f.close()
        self.f_pdf.close()
        self.f_doc1.close()
        for p in PickledPut.objects.all():
            IA.delete_pickle(p.filename)
            p.delete()
        Document.objects.all().delete()
    
    def test_upload_post_request_only(self):
        response = self.client.get('/recap/upload/', {'blah' : 'foo'})
        self.assertEquals('upload: Not a POST request.', response.content)
    
    def test_upload_no_params(self):
        response = self.client.post('/recap/upload/')
        self.assertEquals("upload: No request.FILES attribute.", response.content)
    
    def test_upload_docket_no_court_param(self):
        del self.valid_params['court']
        response = self.client.post('/recap/upload/', self.valid_params)
        self.assertEquals("upload: No POST 'court' attribute.", response.content)
    
    def test_upload_docket_invalid_casenum_param(self):
        self.valid_params['casenum'] = 'garbage_data'
        response = self.client.post('/recap/upload/', self.valid_params)
        self.assertEquals("upload: 'casenum' invalid: garbage_data", response.content)
    
    def test_upload_docket_no_casenum_param(self):
        del self.valid_params['casenum']
        response = self.client.post('/recap/upload/', self.valid_params)
        self.assertEquals("upload: docket has no casenum.", response.content)
    
    def test_upload_docket_no_mimetype_param(self):
        del self.valid_params['mimetype']
        response = self.client.post('/recap/upload/', self.valid_params)
        self.assertEquals("upload: No POST 'mimetype' attribute.", response.content)
    
    def test_upload_docket_report(self):
        response = self.client.post('/recap/upload/', self.valid_params)
        output = simplejson.loads(response.content)
        self.assertEquals(3, len(output))
        self.assertEquals("DktRpt successfully parsed.", output['message'])
        # After upload, a pickled put should be created
        # If this fails, make sure you've created a picklejar directory
        self.assertEquals(1, PickledPut.objects.all().count())
        pp = PickledPut.objects.all()[0]
        self.assertEquals(1, pp.ready)
    
    def test_upload_docket_report_for_unlocked_bucket(self):
        # Setup - Upload a docket
        response = self.client.post('/recap/upload/', self.valid_params)
        # After upload, a pickled put should be created
        self.assertEquals(1, PickledPut.objects.all().count())

        #Do it again, to test whether merges are handled correctly
        response = self.client.post('/recap/upload/', self.valid_params)
        output = simplejson.loads(response.content)
        self.assertEquals("DktRpt successfully parsed.", output['message'])
        self.assertEquals(1, PickledPut.objects.all().count())
        pp = PickledPut.objects.all()[0]
        self.assertEquals(1, pp.ready)
    
    #TK: This case seems wrong, we discard the newer docket if an old docket
    # on the same case is being uploaded. Might be too edge casey to worry about
    # The function test behavior is the same as the one above, so going to leave it 
    # unimplemented for now
    def test_upload_docket_report_for_locked_bucket(self):
        pass
    
    def test_upload_document_without_url(self):
        del self.valid_params_pdf['url']
        response = self.client.post('/recap/upload/', self.valid_params_pdf)
        self.assertEquals('upload: pdf failed. no url supplied.', response.content)
    
    #TK: Handle this case better? Most likely isn't possible
    def test_upload_document_no_associated_document_with_docid(self):
        self.pdf_doc.delete()
        response = self.client.post('/recap/upload/', self.valid_params_pdf)
        self.assertEquals('upload: pdf ignored.', response.content)
    
    def test_upload_document_no_record_of_docid(self):
        self.pdf_doc.docid=99999
        self.pdf_doc.save()
        response = self.client.post('/recap/upload/', self.valid_params_pdf)
        self.assertEquals('upload: pdf ignored.', response.content)
    
    def test_upload_document_metadata_mismatch(self):
        self.valid_params_pdf['court'] = 'azb'
        response = self.client.post('/recap/upload/', self.valid_params_pdf)
        self.assertEquals('upload: pdf metadata mismatch.', response.content)
    
    def test_upload_document(self):
        response = self.client.post('/recap/upload/', self.valid_params_pdf)
        output = simplejson.loads(response.content)
        self.assertEquals('pdf uploaded.', output['message'])
        self.assertEquals(2, PickledPut.objects.all().count())
        self.pdf_doc = Document.objects.all()[0]
        self.assertTrue(self.pdf_doc.sha1 != None)
        self.assertEquals("5741373aff552f22fa2f14f2bd39fea4564aa49c", self.pdf_doc.sha1)
    
    def test_upload_document_no_sha1_difference(self):
        #set the sha1 to what we know it to be
        self.pdf_doc.sha1 = "5741373aff552f22fa2f14f2bd39fea4564aa49c"
        self.pdf_doc.save()
        response = self.client.post('/recap/upload/', self.valid_params_pdf)
        output = simplejson.loads(response.content)
        self.assertEquals('pdf uploaded.', output['message'])
        # we only upload a docket update if the doc is the same
        self.assertEquals(1, PickledPut.objects.all().count())
    
    # have to do some patching to get around the filename issue
    @patch('uploads.UploadHandler.is_doc1_html', Mock(return_value=True))
    @patch('uploads.UploadHandler.docid_from_url_name', Mock(return_value='9999999'))
    def test_upload_doc1_no_matching_docid(self):
        response = self.client.post('/recap/upload/', self.valid_params_doc1)
        self.assertEquals('upload: doc1 ignored.', response.content)
    
    # have to do some patching to get around the filename issue
    @patch('uploads.UploadHandler.is_doc1_html', Mock(return_value=True))
    @patch('uploads.UploadHandler.docid_from_url_name', Mock(return_value='123056'))
    def test_upload_doc1(self):
        response = self.client.post('/recap/upload/', self.valid_params_doc1)
        output = simplejson.loads(response.content)
        self.assertEquals('doc1 successfully parsed.', output['message'])
        self.assertTrue('cases' in output)