def test_get_active_officers(self): officer = OfficerFactory(rank='Officer', active=ACTIVE_YES_CHOICE) OfficerFactory(rank='Officer', active=ACTIVE_YES_CHOICE) OfficerFactory(rank='Officer', active=ACTIVE_NO_CHOICE) OfficerFactory(rank='Senior Police Officer') OfficerFactory(rank='') SalaryFactory(rank='Police Officer', officer=officer) expect(Officer.get_active_officers(rank='Officer')).to.have.length(2) expect(Officer.get_active_officers( rank='Police Officer')).to.have.length(0)
def extract_datum(self, datum): return { 'rank': datum, 'tags': ['rank'], 'active_officers_count': Officer.get_active_officers(datum).count(), 'officers_most_complaints': OfficerMostComplaintsSerializer( Officer.get_officers_most_complaints(datum), many=True).data }
def test_get_officers_most_complaints(self): officer123 = OfficerFactory( id=123, rank='Officer', first_name='Jerome', last_name='Finnigan', allegation_count=2, ) officer456 = OfficerFactory( id=456, rank='Officer', first_name='Ellis', last_name='Skol', allegation_count=1, ) OfficerFactory( id=789, rank='Senior Police Officer', first_name='Raymond', last_name='Piwinicki', allegation_count=0, ) expect(list(Officer.get_officers_most_complaints( rank='Officer'))).to.eq([officer123, officer456])
def handle(self, *args, **options): """import tablib from import_export import resources from data.models import Officer from data.models import Complaint from data.admin import OfficerResource from data.admin import ComplaintResource #complaint_resource = ComplaintResource() officer_resource = OfficerResource() dataset = tablib.Dataset() dataset.csv = open('old_officers.csv').read() #dataset.headers = ['file_no','DSN','date','district','complaint_nature','complaint_text'] dataset.headers = ['DSN'] result = officer_resource.import_data(dataset,dry_run=True) """ import csv from data.models import Officer, Complaint with open('complaints_simplified_v2.csv', newline='') as f: reader = csv.reader(f) for row in reader: file_no = row[0] DSN = row[1] date = row[2].split('/') print(date) date = '20' + date[2] + '-' + date[0] + '-' + date[1] print(date) district = row[3] complaint_nature = row[4] complaint_text = row[5] if Complaint.objects.filter(file_no=file_no).count() == 0: try: DSN = int(DSN) if not Officer.objects.filter(DSN=DSN).exists(): officer = Officer(DSN=DSN) officer.save() print(officer) else: officer = Officer.objects.get(DSN=DSN) print(officer) complaint = Complaint( file_no=file_no, officer=officer, date=date, district=district, complaint_nature=complaint_nature, complaint_text=complaint_text) complaint.save() except: complaint = Complaint( file_no=file_no, date=date, district=district, complaint_nature=complaint_nature, complaint_text=complaint_text) complaint.save()
def test_v1_url(self): first = 'first' last = 'last' url = 'domain/officer/first-last/1' expect(Officer(first_name=first, last_name=last, pk=1).v1_url).to.eq(url)
def test_str(self): self.assertEqual(str(Officer(first_name='Daniel', last_name='Abate')), 'Daniel Abate')
def test_str(self): officer = Officer(first_name='Jeffery', last_name='Aaron') expect(str(OfficerBadgeNumber( officer=officer, star='123456'))).to.eq('Jeffery Aaron - 123456')