コード例 #1
0
    def test_get_view(self):
        with app.test_request_context('/'), \
                app.test_client():
            url = request.host_url
            resp = requests.get(url, verify=False)

        assert resp.status_code == http.HTTPStatus.OK
コード例 #2
0
    def test_get_view_employees_with_db_param_more(self):
        with app.test_request_context('/'), \
                app.test_client() as client:
            params = '?more=True'
            url = request.host_url[:-1] + f'{TestViews.port}/' + params
            resp = client.get(url, follow_redirects=True)

        assert resp.status_code == http.HTTPStatus.OK
コード例 #3
0
    def test_get_view_employees_with_db_between_dates(self):
        with app.test_request_context('/'), \
                app.test_client() as client:
            params = '?date_picker1=1985-07-22&date_picker2=1992-07-22'
            url = request.host_url[:-1] + f'{TestViews.port}/' + params
            resp = client.get(url, follow_redirects=True)

        assert resp.status_code == http.HTTPStatus.OK
コード例 #4
0
    def test_delete_view_department_with_db(self):
        with app.test_request_context('/'), \
                app.test_client() as client:
            url = request.host_url[:-1] + f'{TestViews.port}/' + 'departments/' + f'delete/{TestViews.temp_id_dep}'
            resp = client.get(url, follow_redirects=True)
            message = get_flashed_messages()

        assert message[0] == "Department Deleted Successfully"
        assert resp.status_code == http.HTTPStatus.OK
コード例 #5
0
    def test_drop_all(self):
        with app.test_request_context('/'), \
                app.test_client() as client:
            url = request.host_url[:-1] + f'{TestViews.port}/' + 'drop-all'
            resp = client.get(url, follow_redirects=True)
            message = get_flashed_messages()

        assert message[0] == "DB successfully dropped"
        assert resp.status_code == http.HTTPStatus.OK
コード例 #6
0
    def test_get_view_employees_with_db_between_dates_bad_data(self):
        with app.test_request_context('/'), \
                app.test_client() as client:
            params = '?date_picker1=19850722&date_picker2=19920722'
            url = request.host_url[:-1] + f'{TestViews.port}/' + params
            resp = client.get(url, follow_redirects=True)
            message = get_flashed_messages()

        assert message[0] == "time data '19850722' does not match format '%Y-%m-%d'"
        assert resp.status_code == http.HTTPStatus.OK
コード例 #7
0
    def test_get_view_employees_with_db_between_dates_date1_bigger_date2(self):
        with app.test_request_context('/'), \
                app.test_client() as client:
            params = '?date_picker1=1997-07-22&date_picker2=1992-07-22'
            url = request.host_url[:-1] + f'{TestViews.port}/' + params
            resp = client.get(url, follow_redirects=True)
            message = get_flashed_messages()

        assert message[0] == "Value error 'the first date must be less than the second'"
        assert resp.status_code == http.HTTPStatus.OK
コード例 #8
0
    def test_populate_db2_over_limit(self):
        id = 200000
        with app.test_request_context('/'), \
                app.test_client() as client:
            url = request.host_url[:-1] + f'{TestViews.port}/' + f'populate2/{id}'
            resp = client.get(url, follow_redirects=True)
            message = get_flashed_messages()

        assert message[0] == f"DB not populated by {id} records, please request less 1000 records"
        assert resp.status_code == http.HTTPStatus.OK
コード例 #9
0
    def test_populate_db_with_error_connection(self):
        id = 20
        with app.test_request_context('/'), \
                app.test_client() as client:
            url = request.host_url[:-1] + f'{TestViews.port}/' + f'populate/{id}'
            default = app.config['SQLALCHEMY_DATABASE_URI']
            app.config['SQLALCHEMY_DATABASE_URI'] = "mysql://root:@localhost/finalproject1235"
            resp = client.get(url, follow_redirects=True)

        assert resp.status_code == http.HTTPStatus.INTERNAL_SERVER_ERROR
        app.config['SQLALCHEMY_DATABASE_URI'] = default
コード例 #10
0
    def test_post_view_department_with_db(self):
        data = {
            "name": "Fake Department"
        }
        with app.test_request_context('/'), \
                app.test_client() as client:
            url = request.host_url[:-1] + f'{TestViews.port}/' + 'departments/' + 'insert'
            resp = client.post(url, data=data, follow_redirects=True)
            message = get_flashed_messages()

        assert message[0] == "Department Inserted Successfully"
        assert resp.status_code == http.HTTPStatus.OK
コード例 #11
0
    def test_post_view_department_with_db_empty_field(self):
        data = {
            "name": ""
        }
        with app.test_request_context('/'), \
                app.test_client() as client:
            url = request.host_url[:-1] + f'{TestViews.port}/' + 'departments/' + 'insert'
            resp = client.post(url, data=data, follow_redirects=True)
            message = get_flashed_messages()

        assert message[0] == "Validation error, field name must not be empty"
        assert resp.status_code == http.HTTPStatus.OK
コード例 #12
0
    def test_populate_db(self):
        id = 20
        with app.test_request_context('/'), \
                app.test_client() as client:
            url = request.host_url[:-1] + f'{TestViews.port}/' + f'populate/{id}'
            resp = client.get(url, follow_redirects=True)
            message = get_flashed_messages()

        assert message[0] == f"DB successfully populated by {id} records"
        assert resp.status_code == http.HTTPStatus.OK
        TestViews.temp_id_emp = db.session.query(Employee).all()[-1].id
        TestViews.temp_id_dep = db.session.query(Department).all()[-1].id
コード例 #13
0
    def test_leases_template(self):
        with self.captured_templates(app) as templates:
            rv = app.test_client().get('/leases/')
            # assert rv.status_code == 200
            # assert len(templates) == 1
            template, context = templates[0]
            with app.test_request_context():
                # print(template.render())
                assert 'Aliquam nunc sapien' in template.render()
                assert 'Hi, Larry!' not in template.render()

                print(template.render())

                print("Templates:", templates[0])
コード例 #14
0
    def test_patch_view_employee_with_db_date_no_valid(self):
        data = {
            "name": "Fake Employee",
            "birthday": "1989.06.10",
            "salary": 785,
            "department_name": "some_department"
        }
        with app.test_request_context('/'), \
                app.test_client() as client:
            url = request.host_url[:-1] + f'{TestViews.port}/' + f'update/{TestViews.temp_id_emp}'

            resp = client.post(url, data=data, follow_redirects=True)
            message = get_flashed_messages()

        assert message[0] == "time data '1989.06.10' does not match format '%Y-%m-%d'"
        assert resp.status_code == http.HTTPStatus.OK
コード例 #15
0
    def test_post_view_employee_with_db_data_out_of_range_on_form(self):
        data = {
            "name": "Fake Employee",
            "birthday": "2016-11-11",
            "salary": 789,
            "department_name": "some_department"
        }
        with app.test_request_context('/'), \
                app.test_client() as client:
            url = request.host_url[:-1] + f'{TestViews.port}/' + 'insert'
            client.post(url, data=data, follow_redirects=True)
            resp = client.post(url, data=data, follow_redirects=True)
            message = get_flashed_messages()

        assert message[0] == "date must be in range between dates 1900-01-01 and 2015-01-01"
        assert resp.status_code == http.HTTPStatus.OK
コード例 #16
0
    def test_post_view_employee_with_db_data_out_of_range(self):
        data = {
            "name": "Fake Employee",
            "birthday": "1900-11-11",
            "salary": 789,
            "department_name": "some_department"
        }
        with app.test_request_context('/'), \
                app.test_client() as client:
            url = request.host_url[:-1] + f'{TestViews.port}/' + 'insert'
            client.post(url, data=data, follow_redirects=True)
            resp = client.post(url, data=data, follow_redirects=True)
            message = get_flashed_messages()

        assert message[0] == "Validation error to post Employee {'name': 'Fake Employee', 'birthday': '1900-11-11', 'salary': '789', 'department_name': 'some_department'} is {'birthday': ['birthday must be greater than 1930.']}"
        assert resp.status_code == http.HTTPStatus.OK
コード例 #17
0
    def test_patch_view_employee_with_db_salary_not_valid(self):
        data = {
            "name": "Fake Employee",
            "birthday": "1989-06-10",
            "salary": 'ert',
            "department_name": "some_department"
        }
        with app.test_request_context('/'), \
                app.test_client() as client:
            url = request.host_url[:-1] + f'{TestViews.port}/' + f'update/{TestViews.temp_id_emp}'

            resp = client.post(url, data=data, follow_redirects=True)
            message = get_flashed_messages()

        assert message[0] == "Value error for update Employee in field salary"
        assert resp.status_code == http.HTTPStatus.OK
コード例 #18
0
    def test_patch_view_employee_with_db_fields_are_empty(self):
        data = {
            "name": " ",
            "birthday": "1989-06-10",
            "salary": '123',
            "department_name": ""
        }
        with app.test_request_context('/'), \
                app.test_client() as client:
            url = request.host_url[:-1] + f'{TestViews.port}/' + f'update/{TestViews.temp_id_emp}'

            resp = client.post(url, data=data, follow_redirects=True)
            message = get_flashed_messages()

        assert message[0] == "Validation error, fields name or department are empty"
        assert resp.status_code == http.HTTPStatus.OK
コード例 #19
0
    def test_post_view_employee_with_db(self):
        data = {
            "name": "Fake Employee",
            "birthday": "1990-11-11",
            "salary": 789,
            "department_name": "some_department"
        }
        with app.test_request_context('/'), \
                app.test_client() as client:
            url = request.host_url[:-1] + f'{TestViews.port}/' + 'insert'
            client.post(url, data=data, follow_redirects=True)
            client.post(url, data=data, follow_redirects=True)
            resp = client.post(url, data=data, follow_redirects=True)
            message = get_flashed_messages()

        assert message[0] == "Employee Inserted Successfully"
        assert resp.status_code == http.HTTPStatus.OK
コード例 #20
0
ファイル: blog.py プロジェクト: Rootex/Blog
    name = "Sot"
    return render_template('profile.html', name = name)


def allowed_filename(filename):
    return '.' in filename and filename.rsplit('.', 1)[1] in ALLOWED_EXTENSIONS


@app.route('/edit', methods=['GET', 'POST'])
def upload_file():
    if request.method == 'POST':
        file = request.files['file']
        if file and allowed_filename(file.filename):
            filename = secure_filename(file.filename)
            file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
            return redirect(url_for('uploaded_file', filename=filename))
    return render_template('edit.html')


@app.route('/uploads/<filename>')
def uploaded_file(filename):
    return send_from_directory(app.config['UPLOAD_FOLDER'], filename)


with app.test_request_context():
    print(url_for('index'))

if __name__ == "__main__":
    app.debug = True
    app.run()
コード例 #21
0
 def test_get_view_employees_with_db(self):
     with app.test_request_context('/'), \
             app.test_client() as client:
         url = request.host_url[:-1] + f'{TestViews.port}/'
         resp = client.get(url)
     assert resp.status_code == http.HTTPStatus.OK