def test_logout(client): actions = AuthActions(client) actions.register_and_login() rv = client.get("/auth/logout/") assert rv.status_code == 302 assert rv.headers["Location"] == "http://localhost/auth/login/" rv = client.get("/") assert rv.status_code == 302 assert rv.headers["Location"] == r"http://localhost/auth/login/?next=%2F"
def test_current(client: FlaskClient, auth: AuthActions): response = client.get('/api/user/current') assert response.status_code == 403 auth.login() response = client.get('/api/user/current') assert response.status_code == 200 assert response.json['reference'] == 'Person/fa1636df'
def test_current(client: FlaskClient, auth: AuthActions): response = client.get('/api/treatment/current') assert response.status_code == 403 auth.login() response = client.get('/api/treatment/current') assert response.status_code == 200 assert response.json['id'] == 2
def test_all(client: FlaskClient, auth: AuthActions): response = client.get('/api/treatment/all') assert response.status_code == 403 auth.login() response = client.get('/api/treatment/all') assert response.status_code == 200 assert len(response.json['treatments']) == 4
def test_per_user_task_separation(client): _clean_set_up(client) client.get("/tasktest/10/") task = Task.query.filter_by(user_id=1).first() assert task # logout default test user AuthActions(client).logout() actions = AuthActions( client, username="******", password="******", email="*****@*****.**" ) actions.register_and_login() task = Task.query.filter_by(user_id=2).first() assert not task
def test_register_existing_users(client): actions = AuthActions(client) actions.register() user_data = { # same as test user "username": "******", "email": "*****@*****.**", "password": "******", "password2": "test", } for _ in range(5): rv = client.post("/auth/register/", data={**user_data}) assert rv.status_code == 200 users = User.query.filter_by(username="******").all() assert len(users) == 1
def test_index(client: FlaskClient, auth: AuthActions): response = client.get("/") assert response.status_code == 302 assert response.headers['Location'] == 'http://localhost/index.html' response = client.get('index.html') print(response) assert response.status_code == 403 auth.login() response = client.get('index.html') print(response) assert response.status_code == 200
def test_post_blog(client: FlaskClient, auth: AuthActions): user_response = auth.login() user_response_status = user_response.status_code user_response_json = user_response.json assert user_response_status == 200 access_token = user_response_json["access_token"] filename = "test_image.jpg" filepath = f"tests/{filename}" blog_data = { "title": "Test Blog", "content": "Test content", "thumbnail": (open(filepath, "rb"), "test_image.jpg"), "is_published": True } blog_headers = { "Authorization": f"Bearer {access_token}" } blog_response = client.post("/blog/", data=blog_data, headers=blog_headers) assert blog_response.status_code == 201
def test_get_index_should_return_200(client): actions = AuthActions(client) actions.register_and_login() rv = client.get("/") assert rv.status_code == 200
def _clean_set_up(client): actions = AuthActions(client) actions.register_and_login() Task.query.delete() db.session.commit()
def test_login_when_authenticated(client): actions = AuthActions(client) actions.register_and_login() rv = client.get("/auth/login/") assert rv.status_code == 302 assert rv.headers["Location"] == "http://localhost/"
def test_known_user_should_authenticate(client): actions = AuthActions(client) actions.register_and_login() # try getting login-required page rv = client.get("/") assert rv.status_code == 200
def test_register(auth: AuthActions): auth.register() assert User.query.get(1)