Skip to content

Commit

Permalink
refactore logic
Browse files Browse the repository at this point in the history
  • Loading branch information
devketanpro committed Jul 19, 2024
1 parent 4ed19fb commit 50aa3b0
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 10 deletions.
3 changes: 2 additions & 1 deletion newsroom/am_news/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ async def item(_id):
item = get_entity_or_404(_id, "items")
set_permissions(item, "am_news")
ui_config_service = UiConfigResourceService()
display_char_count = await ui_config_service.get_section_config("am_news").get("char_count", False)
config = await ui_config_service.get_section_config("am_news")
display_char_count = config.get("char_count", False)
if is_json_request(flask.request):
return flask.jsonify(item)
if not item.get("_access"):
Expand Down
3 changes: 2 additions & 1 deletion newsroom/factcheck/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ async def item(_id):
item = get_entity_or_404(_id, "items")
set_permissions(item, "factcheck")
ui_config_service = UiConfigResourceService()
display_char_count = await ui_config_service.get_section_config("factcheck").get("char_count", False)
config = await ui_config_service.get_section_config("factcheck")
display_char_count = config.get("char_count", False)
if is_json_request(flask.request):
return flask.jsonify(item)
if not item.get("_access"):
Expand Down
3 changes: 2 additions & 1 deletion newsroom/market_place/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ async def item(_id):
item = get_entity_or_404(_id, "items")
set_permissions(item, "aapX")
ui_config_service = UiConfigResourceService()
display_char_count = await ui_config_service.get_section_config(SECTION_ID).get("char_count", False)
config = await ui_config_service.get_section_config(SECTION_ID)
display_char_count = config.get("char_count", False)
if is_json_request(flask.request):
return flask.jsonify(item)
if not item.get("_access"):
Expand Down
2 changes: 2 additions & 0 deletions newsroom/media_releases/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ async def item(_id):
set_permissions(item, "media_releases")
ui_config_service = UiConfigResourceService()
display_char_count = await ui_config_service.get_section_config("media_releases").get("char_count", False)
config = await ui_config_service.get_section_config("factcheck")
display_char_count = config.get("char_count", False)
if is_json_request(flask.request):
return flask.jsonify(item)
if not item.get("_access"):
Expand Down
3 changes: 2 additions & 1 deletion newsroom/wire/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,8 @@ async def item(_id):
False if flask.request.args.get("ignoreLatest") == "false" else True,
)
ui_config_service = UiConfigResourceService()
display_char_count = await ui_config_service.get_section_config("wire").get("char_count", False)
config = await ui_config_service.get_section_config("wire")
display_char_count = config.get("char_count", False)
if is_json_request(flask.request):
return flask.jsonify(item)
if not item.get("_access"):
Expand Down
6 changes: 3 additions & 3 deletions tests/core/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,9 @@ def test_login_fails_for_not_approved_user(app, client):
assert "Account has not been approved" in response.get_data(as_text=True)


def test_login_fails_for_many_times_gets_limited(client, app):
async def test_login_fails_for_many_times_gets_limited(client, app):
for i in range(1, 100):
response = client.post(
response = await client.post(
url_for("auth.login"),
data={"email": "xyz{}@abc.org".format(i), "password": "abc"},
follow_redirects=True,
Expand Down Expand Up @@ -291,7 +291,7 @@ def test_account_appears_locked_for_non_existing_user(client):
assert "Your account has been locked" in response.get_data(as_text=True)


def test_login_with_remember_me_selected_creates_permanent_session(app, client):
async def test_login_with_remember_me_selected_creates_permanent_session(app, client):
# Register a new account
app.data.insert(
"users",
Expand Down
2 changes: 1 addition & 1 deletion tests/core/test_auth_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def init(app):
)


def test_password_auth_denies_other_auth_types(app, client):
async def test_password_auth_denies_other_auth_types(app, client):
logout(client)
users_service = get_resource_service("users")
user_id = ObjectId()
Expand Down
4 changes: 2 additions & 2 deletions tests/core/test_home.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from newsroom.tests.fixtures import PUBLIC_USER_ID


def test_personal_dashboard_data(client, app, company_products):
async def test_personal_dashboard_data(client, app, company_products):
with app.test_request_context():
server_session["user"] = str(PUBLIC_USER_ID)
server_session["user_type"] = "public"
Expand All @@ -29,7 +29,7 @@ def test_personal_dashboard_data(client, app, company_products):
user,
)

data = get_home_data()
data = await get_home_data()

assert "personalizedDashboards" in data
dashboard_data = data["personalizedDashboards"][0]
Expand Down

0 comments on commit 50aa3b0

Please sign in to comment.