当前位置: 首页>>代码示例>>Python>>正文


Python models.Department类代码示例

本文整理汇总了Python中comport.department.models.Department的典型用法代码示例。如果您正苦于以下问题:Python Department类的具体用法?Python Department怎么用?Python Department使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Department类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_only_department_user_can_access_non_public_datasets

    def test_only_department_user_can_access_non_public_datasets(self, testapp):
        # create a department
        department = Department.create(name="IM Police Department", short_name="IMPD", load_defaults=True)
        department.is_public_citizen_complaints = False
        department.is_public_use_of_force_incidents = False
        department.is_public_officer_involved_shootings = False
        department.is_public_assaults_on_officers = False

        # log in under a different department, datasets should not be accessible
        bad_department = Department.create(name="B Police Department", short_name="BPD", load_defaults=False)
        create_and_log_in_user(testapp, bad_department)

        testapp.get("/department/{}/complaints/".format(department.short_name), status=403)
        testapp.get("/department/{}/schema/complaints/".format(department.short_name), status=403)
        testapp.get("/department/{}/complaints.csv".format(department.id), status=403)

        testapp.get("/department/{}/useofforce/".format(department.short_name), status=403)
        testapp.get("/department/{}/schema/useofforce/".format(department.short_name), status=403)
        testapp.get("/department/{}/uof.csv".format(department.id), status=403)

        testapp.get("/department/{}/officerinvolvedshootings/".format(department.short_name), status=403)
        testapp.get("/department/{}/schema/officerinvolvedshootings/".format(department.short_name), status=403)
        testapp.get("/department/{}/ois.csv".format(department.id), status=403)

        testapp.get("/department/{}/assaultsonofficers/".format(department.short_name), status=403)
        testapp.get("/department/{}/schema/assaultsonofficers/".format(department.short_name), status=403)
        testapp.get("/department/{}/assaultsonofficers.csv".format(department.id), status=403)
开发者ID:codeforamerica,项目名称:comport,代码行数:27,代码来源:test_functional.py

示例2: test_department_name_unique_required

    def test_department_name_unique_required(self, db):
        Department.create(name="name")
        # Enters username that is already registered
        form = NewDepartmentForm(department_name="name")

        assert form.validate() is False
        assert 'Department name already registered.' in form.department_name.errors
开发者ID:webmaven,项目名称:comport,代码行数:7,代码来源:test_admin_forms.py

示例3: test_department_short_name_unique_required

 def test_department_short_name_unique_required(self, db):
     ''' The form won't allow creation of a duplicate department short name.
     '''
     test_name = "Any Police Department"
     test_short_name = "APD"
     Department.create(name=test_name, short_name=test_short_name)
     form = NewDepartmentForm(department_name="Another Police Department", department_short_name=test_short_name)
     assert form.validate() is False
     assert 'The department short name "{}" is already registered.'.format(test_short_name) in form.department_short_name.errors
开发者ID:carolynjoneslee,项目名称:comport,代码行数:9,代码来源:test_admin_forms.py

示例4: add_department

def add_department():
    form = NewDepartmentForm(request.form)
    if request.method == 'POST':
        if form.validate_on_submit():
            Department.create(name=form.department_name.data)
            flash('Department %s created.' % form.department_name.data, 'info')
            return redirect(url_for('admin.admin_dashboard'))
        else:
            flash_errors(form)
    return render_template("admin/newDepartment.html", form=form)
开发者ID:webmaven,项目名称:comport,代码行数:10,代码来源:views.py

示例5: test_multiple_depts_display

    def test_multiple_depts_display(self, testapp):
        impd = Department.create(name="I Police Department", short_name="IMPD", is_public=True)
        UseOfForceIncidentIMPD.create(department_id=impd.id, opaque_id="12345abcde")
        bpd = Department.create(name="B Police Department", short_name="BPD", is_public=True)
        UseOfForceIncidentBPD.create(department_id=bpd.id, opaque_id="12345abcde")
        lmpd = Department.create(name="LM Police Department", short_name="LMPD", is_public=False)
        UseOfForceIncidentLMPD.create(department_id=lmpd.id, opaque_id="12345abcde")

        response = testapp.get("/", status=200)
        soup = BeautifulSoup(response.text)
        assert soup.find("a", href="/department/IMPD/useofforce") is not None
        assert soup.find("a", href="/department/BPD/useofforce") is not None
        assert soup.find("a", href="/department/LMPD/useofforce") is None
开发者ID:codeforamerica,项目名称:comport,代码行数:13,代码来源:test_public_pages.py

示例6: test_delete_records

    def test_delete_records(self):
        """ Delete incidents_updated records using the delete_records method.
        """
        # create a couple of departments
        department_bpd = Department.create(name="B Police Department", short_name="BPD")
        department_impd = Department.create(name="IM Police Department", short_name="IMPD")

        # create some 'incidents updated' records
        uof_type = "uof"
        ois_type = "ois"
        ids_and_types = [
            ("123abc", uof_type, department_bpd.id),
            ("234bcd", uof_type, department_bpd.id),
            ("345cde", ois_type, department_bpd.id),
            ("456def", uof_type, department_impd.id),
            ("567efg", uof_type, department_impd.id),
            ("678fgh", ois_type, department_impd.id),
        ]
        for opaque_id, use_type, department_id in ids_and_types:
            IncidentsUpdated.create(department_id=department_id, opaque_id=opaque_id, incident_type=use_type)

        # verify that the records were saved as expected
        assert len(IncidentsUpdated.query.all()) == len(ids_and_types)
        assert len(IncidentsUpdated.query.filter_by(department_id=department_bpd.id).all()) == 3
        assert len(IncidentsUpdated.query.filter_by(department_id=department_impd.id).all()) == 3
        assert len(IncidentsUpdated.query.filter_by(incident_type=uof_type).all()) == 4
        assert len(IncidentsUpdated.query.filter_by(incident_type=ois_type).all()) == 2

        # delete the impd records
        num_deleted = IncidentsUpdated.delete_records(department_id=department_impd.id)
        assert num_deleted == len(ids_and_types) / 2

        # verify the results
        assert len(IncidentsUpdated.query.all()) == len(ids_and_types) - num_deleted
        assert len(IncidentsUpdated.query.filter_by(department_id=department_bpd.id).all()) == 3
        assert len(IncidentsUpdated.query.filter_by(department_id=department_impd.id).all()) == 0
        assert len(IncidentsUpdated.query.filter_by(incident_type=uof_type).all()) == 2
        assert len(IncidentsUpdated.query.filter_by(incident_type=ois_type).all()) == 1

        # delete the bpd uof records
        num_deleted = IncidentsUpdated.delete_records(department_id=department_bpd.id, incident_type=uof_type)
        assert num_deleted == 2

        # verify the results
        assert len(IncidentsUpdated.query.all()) == 1
        assert len(IncidentsUpdated.query.filter_by(department_id=department_bpd.id).all()) == 1
        assert len(IncidentsUpdated.query.filter_by(incident_type=uof_type).all()) == 0
        assert len(IncidentsUpdated.query.filter_by(incident_type=ois_type).all()) == 1
开发者ID:codeforamerica,项目名称:comport,代码行数:48,代码来源:test_data_models.py

示例7: test_submitting_schema_intro_field_value

    def test_submitting_schema_intro_field_value(self, testapp):
        ''' Submitting the form to edit a schema intro field changes the expected value in the database and not others
        '''
        department = Department.create(name="B Police Department", short_name="BPD", load_defaults=True)

        # set up a user
        create_and_log_in_user(testapp, department)

        # make a request to specific front page
        response = testapp.get("/department/{}/edit/schema/complaints".format(department.id))
        assert response.status_code == 200

        assert 'editIntro' in response.forms
        form = response.forms['editIntro']
        new_content = "A Short Definition of this Data Field"
        form['chart_content'] = new_content
        checkblock = ChartBlock.query.filter_by(slug="complaints-schema-introduction", department_id=department.id).first()
        title = checkblock.title
        order = checkblock.order
        response = form.submit().follow()

        assert response.status_code == 200

        checkblock2 = ChartBlock.query.filter_by(slug="complaints-schema-introduction", department_id=department.id).first()

        assert checkblock.content == new_content
        assert title == checkblock2.title
        assert order == checkblock2.order
开发者ID:codeforamerica,项目名称:comport,代码行数:28,代码来源:test_admin_forms.py

示例8: test_changing_schema_field_order_reorders_other_fields

    def test_changing_schema_field_order_reorders_other_fields(self, testapp):
        ''' Changing the order value of a schema field will re-order the other fields to make room.
        '''
        department = Department.create(name="B Police Department", short_name="BPD", load_defaults=True)

        # set up a user
        create_and_log_in_user(testapp, department)

        for incident_type in [("complaints", "complaints"), ("assaults", "assaultsonofficers"), ("ois", "ois"), ("uof", "useofforce")]:
            # make a request to specific front page
            response = testapp.get("/department/{}/edit/schema/{}".format(department.id, incident_type[1]))
            assert response.status_code == 200

            schema_field_prefix = "{}-schema-field-".format(incident_type[0])
            schema_fields = department.get_blocks_by_slug_startswith(schema_field_prefix)

            assert schema_fields[0].order < schema_fields[1].order
            assert schema_fields[1].order < schema_fields[2].order
            assert schema_fields[2].order < schema_fields[3].order

            form_name = "edit{}TitleContentAndOrder".format(schema_fields[2].slug.replace(schema_field_prefix, "").replace("-", " ").title().replace(" ", ""))
            assert form_name in response.forms
            form = response.forms[form_name]
            new_order = schema_fields[0].order
            form['chart_order'] = new_order
            response = form.submit().follow()
            assert response.status_code == 200

            check_fields = department.get_blocks_by_slug_startswith(schema_field_prefix)
            assert check_fields[0].order < check_fields[1].order
            assert check_fields[1].order < check_fields[2].order
            assert check_fields[2].order < check_fields[3].order
开发者ID:codeforamerica,项目名称:comport,代码行数:32,代码来源:test_admin_forms.py

示例9: test_assaults_schema_edit_forms_exist

    def test_assaults_schema_edit_forms_exist(self, testapp):
        ''' Edit forms exist for the complaints schema page.
        '''
        department = Department.create(name="B Police Department", short_name="BPD", load_defaults=True)

        # set up a user
        create_and_log_in_user(testapp, department)

        # make a request to specific front page
        response = testapp.get("/department/{}/edit/schema/assaultsonofficers".format(department.id))
        assert response.status_code == 200

        # assert that the intro, footer, disclaimer forms are there
        assert 'editIntro' in response.forms
        assert 'editFooter' in response.forms
        assert 'editDisclaimer' in response.forms

        # assert that the field forms are there
        assert 'editIdTitleContentAndOrder' in response.forms
        assert 'editOfficerIdentifierTitleContentAndOrder' in response.forms
        assert 'editServiceTypeTitleContentAndOrder' in response.forms
        assert 'editForceTypeTitleContentAndOrder' in response.forms
        assert 'editAssignmentTitleContentAndOrder' in response.forms
        assert 'editArrestMadeTitleContentAndOrder' in response.forms
        assert 'editOfficerInjuredTitleContentAndOrder' in response.forms
        assert 'editReportFiledTitleContentAndOrder' in response.forms
开发者ID:codeforamerica,项目名称:comport,代码行数:26,代码来源:test_admin_forms.py

示例10: test_get_blocks_by_slugs_order

    def test_get_blocks_by_slugs_order(self):
        ''' We can get blocks sorted by order or in the order the slugs were passed.
        '''
        department = Department.create(name="IM Police Department", short_name="IMPD", load_defaults=True)

        # get some complaint schema blocks
        blocks = department.get_complaint_schema_blocks()['blocks']
        assert len(blocks) >= 6
        blocks = blocks[:6]

        # make sure our test will be valid
        orders = [b.order for b in blocks]
        assert orders == sorted(orders)

        # make a list of slugs out of order
        ordered_slugs = [b.slug for b in blocks]
        mixedup_slugs = ordered_slugs.copy()
        mixedup_slugs = [ordered_slugs[i] for i in [5, 3, 1, 0, 2, 4]]
        assert ordered_slugs != mixedup_slugs

        # now request an ordered list of chart blocks from the mixed up list
        check_ordered_blocks = department.get_blocks_by_slugs(mixedup_slugs, sort_by_order=True)
        check_ordered_slugs = [b.slug for b in check_ordered_blocks]
        assert len(check_ordered_blocks) == 6
        assert check_ordered_slugs == ordered_slugs
        assert check_ordered_slugs != mixedup_slugs

        # and request a list of chart blocks in the order the slugs are passed
        check_mixedup_blocks = department.get_blocks_by_slugs(mixedup_slugs, sort_by_order=False)
        check_mixedup_slugs = [b.slug for b in check_mixedup_blocks]
        assert len(check_mixedup_slugs) == 6
        assert check_mixedup_slugs != ordered_slugs
        assert check_mixedup_slugs == mixedup_slugs
开发者ID:codeforamerica,项目名称:comport,代码行数:33,代码来源:test_department_models.py

示例11: test_schema_chart_block_order

    def test_schema_chart_block_order(self):
        ''' Set and get complaint chart blocks.
        '''
        department = Department.create(name="IM Police Department", short_name="IMPD", load_defaults=True)

        # get complaint schema blocks
        before_blocks = department.get_complaint_schema_blocks()

        # make sure our test will be valid
        assert len(before_blocks['blocks']) > 2
        assert before_blocks['blocks'][0].order < before_blocks['blocks'][1].order
        assert before_blocks['blocks'][1].order < 100
        assert before_blocks['blocks'][-1].order < 100

        # change the order of the first block to 100
        block = before_blocks['blocks'][0]
        block.order = 100
        block.save()

        # get the blocks again and test the order
        after_blocks = department.get_complaint_schema_blocks()
        assert before_blocks['blocks'][1].order == after_blocks['blocks'][0].order
        assert before_blocks['blocks'][1].slug == after_blocks['blocks'][0].slug
        assert after_blocks['blocks'][-1].order == 100
        assert before_blocks['blocks'][0].slug == after_blocks['blocks'][-1].slug
开发者ID:codeforamerica,项目名称:comport,代码行数:25,代码来源:test_department_models.py

示例12: test_correct_complaint_cap

    def test_correct_complaint_cap (self, testapp):
        ''' New complaint data from the extractor is processed as expected.
        '''
        # Set up the extractor
        department = Department.create(name="IM Police Department", short_name="IMPD", load_defaults=False)
        extractor, envs = Extractor.from_department_and_password(department=department, password="password")

        # Set the correct authorization
        testapp.authorization = ('Basic', (extractor.username, 'password'))

        # Get a generated list of complaint descriptions from the JSON test client
        test_client = JSONTestClient()
        complaint_count = 1
        complaint_data = test_client.get_prebaked_complaints(last=complaint_count)
        complaint_data[0]["allegation"] = "Rude, demeaning, or affronting language"

        # post the json to the complaint URL
        response = testapp.post_json("/data/complaints", params={'month': 0, 'year': 0, 'data': complaint_data})

        # assert that we got the expected reponse
        assert response.status_code == 200
        assert response.json_body['updated'] == 0
        assert response.json_body['added'] == complaint_count

        # check the complaint incident in the database against the data that was sent
        cleaner = Cleaners()
        sent_complaint = cleaner.capitalize_incident(complaint_data[0])
        check_complaint = CitizenComplaintIMPD.query.filter_by(opaque_id=sent_complaint['opaqueId']).first()
        assert check_complaint.allegation == "Rude, Demeaning, or Affronting Language"
        with open("scratch.txt", "w") as text_file:
            text_file.write("Complaint Data: {} ".format(check_complaint.allegation))
开发者ID:codeforamerica,项目名称:comport,代码行数:31,代码来源:test_extractor_api.py

示例13: test_post_assaults_data

    def test_post_assaults_data(self, testapp):
        ''' New assaults data from the extractor is processed as expected.
        '''
        # Set up the extractor
        department = Department.create(name="IM Police Department", short_name="IMPD", load_defaults=False)
        extractor, envs = Extractor.from_department_and_password(department=department, password="password")

        # Set the correct authorization
        testapp.authorization = ('Basic', (extractor.username, 'password'))

        # Get a generated list of assault descriptions from the JSON test client
        test_client = JSONTestClient()
        assault_count = 1
        assault_data = test_client.get_prebaked_assaults(last=assault_count)
        # post the json to the assault URL
        response = testapp.post_json("/data/assaults", params={'month': 0, 'year': 0, 'data': assault_data})

        # assert that we got the expected reponse
        assert response.status_code == 200
        assert response.json_body['updated'] == 0
        assert response.json_body['added'] == assault_count

        # check the assault incident in the database against the data that was sent
        cleaner = Cleaners()
        sent_assault = cleaner.capitalize_incident(assault_data[0])
        check_assault = AssaultOnOfficerIMPD.query.filter_by(opaque_id=sent_assault['opaqueId']).first()
        assert check_assault.service_type == sent_assault['serviceType']
        assert check_assault.force_type == sent_assault['forceType']
        assert check_assault.assignment == sent_assault['assignment']
        assert check_assault.arrest_made == sent_assault['arrestMade']
        assert check_assault.officer_injured == sent_assault['officerInjured']
        assert check_assault.officer_killed == sent_assault['officerKilled']
        assert check_assault.report_filed == sent_assault['reportFiled']
开发者ID:codeforamerica,项目名称:comport,代码行数:33,代码来源:test_extractor_api.py

示例14: test_editing_useofforce_schema_field_value

    def test_editing_useofforce_schema_field_value(self, testapp):
        ''' Submitting the form to edit a schema field changes the correct value in the database
        '''
        department = Department.create(name="B Police Department", short_name="BPD", load_defaults=True)

        # set up a user
        create_and_log_in_user(testapp, department)

        # make a request to specific front page
        response = testapp.get("/department/{}/edit/schema/useofforce".format(department.id))
        assert response.status_code == 200

        assert 'editShiftTitleContentAndOrder' in response.forms
        form = response.forms['editShiftTitleContentAndOrder']
        new_title = "A New Data Field Title"
        new_content = "A Short Definition of this Data Field"
        new_order = 99
        form['chart_title'] = new_title
        form['chart_content'] = new_content
        form['chart_order'] = new_order
        response = form.submit().follow()
        assert response.status_code == 200

        checkblock = ChartBlock.query.filter_by(slug="uof-schema-field-shift").first()
        assert checkblock.title == new_title
        assert checkblock.content == new_content
        assert checkblock.order == len(department.get_blocks_by_slug_startswith("uof-schema-field-")) - 1
开发者ID:codeforamerica,项目名称:comport,代码行数:27,代码来源:test_admin_forms.py

示例15: test_submitting_schema_edit_form_redirects_to_preview

    def test_submitting_schema_edit_form_redirects_to_preview(self, testapp):
        ''' Submitting the form to edit a schema field changes the correct value in the database
        '''
        department = Department.create(name="B Police Department", short_name="BPD", load_defaults=True)

        # set up a user
        create_and_log_in_user(testapp, department)

        # make a request to specific front page
        response = testapp.get("/department/{}/edit/schema/complaints".format(department.id))
        assert response.status_code == 200

        # submit new title & content
        assert 'editShiftTitleContentAndOrder' in response.forms
        form = response.forms['editShiftTitleContentAndOrder']
        new_title = "A New Data Field Title"
        new_content = "A Short Definition of this Data Field"
        new_order = 99
        form['chart_title'] = new_title
        form['chart_content'] = new_content
        form['chart_order'] = new_order
        response = form.submit()

        # the response should be a redirect
        assert response.status_code == 302
        # the location of the redirect should be the preview page
        parsed = urlparse(response.location)
        assert parsed.path == "/department/{}/preview/schema/complaints".format(department.id)
开发者ID:codeforamerica,项目名称:comport,代码行数:28,代码来源:test_admin_forms.py


注:本文中的comport.department.models.Department类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。