Пример #1
0
def test_admin_can_edit_existing_officer(mockdata, client, session):
    with current_app.test_request_context():
        login_admin(client)
        department = random.choice(dept_choices())
        form = AddOfficerForm(first_name='Test',
                              last_name='Testerinski',
                              middle_initial='T',
                              race='WHITE',
                              gender='M',
                              star_no=666,
                              rank='COMMANDER',
                              department=department.id,
                              birth_year=1990)

        rv = client.post(url_for('main.add_officer'),
                         data=form.data,
                         follow_redirects=True)

        officer = Officer.query.filter_by(last_name='Testerinski').one()

        form = EditOfficerForm(last_name='Changed')

        rv = client.post(url_for('main.edit_officer', officer_id=officer.id),
                         data=form.data,
                         follow_redirects=True)

        assert 'Changed' in rv.data
        assert 'Testerinski' not in rv.data
Пример #2
0
def test_ac_can_add_new_officer_in_their_dept(mockdata, client, session):
    with current_app.test_request_context():
        login_ac(client)
        department = Department.query.filter_by(id=AC_DEPT).first()
        first_name = 'Testy'
        last_name = 'OTester'
        middle_initial = 'R'
        race = random.choice(RACE_CHOICES)[0]
        gender = random.choice(GENDER_CHOICES)[0]
        form = AddOfficerForm(first_name=first_name,
                              last_name=last_name,
                              middle_initial=middle_initial,
                              race=race,
                              gender=gender,
                              star_no=666,
                              rank='COMMANDER',
                              department=department.id,
                              birth_year=1990)

        rv = client.post(url_for('main.add_officer'),
                         data=form.data,
                         follow_redirects=True)

        assert rv.status_code == 200
        assert last_name in rv.data

        # Check the officer was added to the database
        officer = Officer.query.filter_by(last_name=last_name).one()
        assert officer.first_name == first_name
        assert officer.race == race
        assert officer.gender == gender
Пример #3
0
def test_ac_cannot_add_new_officer_not_in_their_dept(mockdata, client,
                                                     session):
    with current_app.test_request_context():
        login_ac(client)
        department = Department.query.except_(
            Department.query.filter_by(id=AC_DEPT)).first()
        first_name = 'Sam'
        last_name = 'Augustus'
        middle_initial = 'H'
        race = random.choice(RACE_CHOICES)[0]
        gender = random.choice(GENDER_CHOICES)[0]
        form = AddOfficerForm(first_name=first_name,
                              last_name=last_name,
                              middle_initial=middle_initial,
                              race=race,
                              gender=gender,
                              star_no=666,
                              rank='COMMANDER',
                              department=department.id,
                              birth_year=1990)

        client.post(url_for('main.add_officer'),
                    data=form.data,
                    follow_redirects=True)

        officer = Officer.query.filter_by(last_name=last_name).first()
        assert officer is None
Пример #4
0
def test_admin_adds_officer_with_letter_in_badge_no(mockdata, client, session):
    with current_app.test_request_context():
        login_admin(client)

        department = random.choice(dept_choices())
        form = AddOfficerForm(first_name='Test',
                              last_name='Testersly',
                              middle_initial='T',
                              race='WHITE',
                              gender='M',
                              star_no='T666',
                              rank='COMMANDER',
                              department=department.id,
                              birth_year=1990)
        data = process_form_data(form.data)

        rv = client.post(url_for('main.add_officer'),
                         data=data,
                         follow_redirects=True)

        assert 'New Officer Testersly added' in rv.data.decode('utf-8')

        # Check the officer was added to the database
        officer = Officer.query.filter_by(last_name='Testersly').one()
        assert officer.first_name == 'Test'
        assert officer.race == 'WHITE'
        assert officer.gender == 'M'
        assert officer.assignments[0].star_no == 'T666'
Пример #5
0
def test_admin_can_add_new_officer(mockdata, client, session):
    with current_app.test_request_context():
        login_admin(client)
        department = random.choice(dept_choices())
        form = AddOfficerForm(first_name='Test',
                              last_name='McTesterson',
                              middle_initial='T',
                              race='WHITE',
                              gender='M',
                              star_no=666,
                              rank='COMMANDER',
                              department=department.id,
                              birth_year=1990)

        rv = client.post(url_for('main.add_officer'),
                         data=form.data,
                         follow_redirects=True)

        assert 'McTesterson' in rv.data

        # Check the officer was added to the database
        officer = Officer.query.filter_by(last_name='McTesterson').one()
        assert officer.first_name == 'Test'
        assert officer.race == 'WHITE'
        assert officer.gender == 'M'
Пример #6
0
def test_admin_can_add_new_officer_with_suffix(mockdata, client, session):
    with current_app.test_request_context():
        login_admin(client)
        department = random.choice(dept_choices())
        links = [
            LinkForm(url='http://www.pleasework.com', link_type='link').data,
            LinkForm(url='http://www.avideo/?v=2345jk', link_type='video').data
        ]
        form = AddOfficerForm(first_name='Testy',
                              last_name='McTesty',
                              middle_initial='T',
                              suffix='Jr',
                              race='WHITE',
                              gender='M',
                              star_no=666,
                              rank='COMMANDER',
                              department=department.id,
                              birth_year=1990,
                              links=links)

        data = process_form_data(form.data)

        rv = client.post(url_for('main.add_officer'),
                         data=data,
                         follow_redirects=True)

        assert 'New Officer McTesty added' in rv.data.decode('utf-8')

        # Check the officer was added to the database
        officer = Officer.query.filter_by(last_name='McTesty').one()
        assert officer.first_name == 'Testy'
        assert officer.race == 'WHITE'
        assert officer.gender == 'M'
        assert officer.suffix == 'Jr'
def test_admin_adds_officer_without_middle_initial(mockdata, client, session):
    with current_app.test_request_context():
        login_admin(client)

        department = random.choice(dept_choices())
        form = AddOfficerForm(first_name='Test',
                              last_name='McTesty',
                              race='WHITE',
                              gender='M',
                              star_no=666,
                              rank='COMMANDER',
                              department=department.id,
                              birth_year=1990,
                              # because of encoding error, link_type must be set for tests
                              links=[LinkForm(link_type='link').data])
        data = process_form_data(form.data)

        rv = client.post(
            url_for('main.add_officer'),
            data=data,
            follow_redirects=True
        )

        assert 'McTesty' in rv.data

        # Check the officer was added to the database
        officer = Officer.query.filter_by(
            last_name='McTesty').one()
        assert officer.first_name == 'Test'
        assert officer.middle_initial == ''
        assert officer.race == 'WHITE'
        assert officer.gender == 'M'
def test_ac_can_edit_officer_in_their_dept(mockdata, client, session):
    with current_app.test_request_context():
        login_ac(client)
        department = Department.query.filter_by(id=AC_DEPT).first()
        first_name = 'Testier'
        last_name = 'OTester'
        middle_initial = 'R'
        suffix = ''
        race = random.choice(RACE_CHOICES)[0]
        gender = random.choice(GENDER_CHOICES)[0]
        form = AddOfficerForm(first_name=first_name,
                              last_name=last_name,
                              middle_initial=middle_initial,
                              suffix=suffix,
                              race=race,
                              gender=gender,
                              star_no=666,
                              rank='COMMANDER',
                              department=department.id,
                              birth_year=1990,
                              # because of encoding error, link_type must be set for tests
                              links=[LinkForm(link_type='link').data])

        data = process_form_data(form.data)

        rv = client.post(
            url_for('main.add_officer'),
            data=data,
            follow_redirects=True
        )

        officer = Officer.query.filter_by(
            last_name=last_name).one()

        new_last_name = 'Shiny'
        form = EditOfficerForm(
            first_name=first_name,
            last_name=new_last_name,
            suffix=suffix,
            race=race,
            gender=gender,
            department=department.id,
            # because of encoding error, link_type must be set for tests
            links=[LinkForm(link_type='link').data]
        )
        data = process_form_data(form.data)

        rv = client.post(
            url_for('main.edit_officer', officer_id=officer.id),
            data=data,
            follow_redirects=True
        )

        assert new_last_name in rv.data
        assert last_name not in rv.data

        # Check the changes were added to the database
        officer = Officer.query.filter_by(
            id=officer.id).one()
        assert officer.last_name == new_last_name
def test_officer_csv(mockdata, client, session):
    with current_app.test_request_context():
        login_admin(client)
        department = random.choice(dept_choices())
        links = [
            LinkForm(url='http://www.pleasework.com', link_type='link').data,
        ]
        form = AddOfficerForm(first_name='CKtVwe2gqhAIc',
                              last_name='FVkcjigWUeUyA',
                              middle_initial='T',
                              suffix='Jr',
                              race='WHITE',
                              gender='M',
                              star_no=90009,
                              rank='PO',
                              department=department.id,
                              birth_year=1910,
                              links=links)
        # add the officer
        rv = client.post(
            url_for('main.add_officer'),
            data=process_form_data(form.data),
            follow_redirects=True
        )
        # dump officer csv
        rv = client.get(
            url_for('main.download_dept_csv', department_id=department.id),
            follow_redirects=True
        )
        # get csv entry matching officer last n"createdame
        csv = list(filter(lambda row: form.last_name.data in row, rv.data.decode('utf-8').split("\n")))
        assert len(csv) == 1
        assert form.first_name.data in csv[0]
        assert form.last_name.data in csv[0]
        assert form.rank.data in csv[0]
Пример #10
0
def test_admin_adds_officer_with_letter_in_badge_no(mockdata, client, session):
    with current_app.test_request_context():
        login_admin(client)

        form = AddOfficerForm(first_name='Test',
                              last_name='Testersly',
                              middle_initial='T',
                              race='WHITE',
                              gender='M',
                              star_no='T666',
                              rank='COMMANDER',
                              birth_year=1990)

        rv = client.post(url_for('main.add_officer'),
                         data=form.data,
                         follow_redirects=True)

        assert 'Testersly' in rv.data

        # Check the officer was added to the database
        officer = Officer.query.filter_by(last_name='Testersly').one()
        assert officer.first_name == 'Test'
        assert officer.race == 'WHITE'
        assert officer.gender == 'M'
        assert officer.assignments[0].star_no == 'T666'
Пример #11
0
def test_browse_filtering_allows_good(client, mockdata, session):
    with current_app.test_request_context():
        department_id = Department.query.first().id

        # Add a officer with a specific race, gender, rank and age to the first page
        login_admin(client)
        links = [
            LinkForm(url='http://www.pleasework.com', link_type='link').data,
            LinkForm(url='http://www.avideo/?v=2345jk', link_type='video').data
        ]
        form = AddOfficerForm(first_name='A',
                              last_name='A',
                              middle_initial='A',
                              race='WHITE',
                              gender='M',
                              star_no=666,
                              rank='COMMANDER',
                              department=department_id,
                              birth_year=1990,
                              links=links)

        data = process_form_data(form.data)

        rv = client.post(url_for('main.add_officer'),
                         data=data,
                         follow_redirects=True)

        assert 'A' in rv.data.decode('utf-8')

        # Check the officer was added to the database
        officer = Officer.query.filter_by(last_name='A').one()
        assert officer.first_name == 'A'
        assert officer.race == 'WHITE'
        assert officer.gender == 'M'

        # Check that added officer appears when filtering for this race, gender, rank and age
        form = BrowseForm(race='WHITE',
                          gender='M',
                          rank='COMMANDER',
                          min_age=datetime.now().year - 1991,
                          max_age=datetime.now().year - 1989)

        data = process_form_data(form.data)

        rv = client.get(url_for('main.list_officer',
                                department_id=department_id),
                        data=data,
                        follow_redirects=True)

        filter_list = rv.data.decode('utf-8').split("<dt>Race</dt>")[1:]
        assert any("<dd>White</dd>" in token for token in filter_list)

        filter_list = rv.data.decode('utf-8').split("<dt>Rank</dt>")[1:]
        assert any("<dd>COMMANDER</dd>" in token for token in filter_list)

        filter_list = rv.data.decode('utf-8').split("<dt>Gender</dt>")[1:]
        assert any("<dd>M</dd>" in token for token in filter_list)
def test_admin_can_edit_existing_officer(mockdata, client, session):
    with current_app.test_request_context():
        login_admin(client)
        department = random.choice(dept_choices())
        link_url0 = 'http://pleasework.com'
        link_url1 = 'http://avideo/?v=2345jk'
        links = [
            LinkForm(url=link_url0, link_type='link').data,
            LinkForm(url=link_url0, link_type='video').data
        ]
        form = AddOfficerForm(first_name='Test',
                              last_name='Testerinski',
                              middle_initial='T',
                              race='WHITE',
                              gender='M',
                              star_no=666,
                              rank='COMMANDER',
                              department=department.id,
                              birth_year=1990,
                              links=links)
        data = process_form_data(form.data)

        rv = client.post(
            url_for('main.add_officer'),
            data=data,
            follow_redirects=True
        )

        officer = Officer.query.filter_by(
            last_name='Testerinski').one()

        form = EditOfficerForm(last_name='Changed', links=links[:1])
        data = process_form_data(form.data)

        rv = client.post(
            url_for('main.edit_officer', officer_id=officer.id),
            data=data,
            follow_redirects=True
        )

        assert 'Changed' in rv.data
        assert 'Testerinski' not in rv.data
        assert link_url0 in rv.data
        assert link_url1 not in rv.data