Skip to content

Commit

Permalink
Lint
Browse files Browse the repository at this point in the history
  • Loading branch information
rodriguesk committed Nov 22, 2023
1 parent a2fa74b commit 3403dd7
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 18 deletions.
2 changes: 1 addition & 1 deletion app/analytics/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

bp = Blueprint("analytics", __name__)

from app.analytics import routes
from app.analytics import routes
9 changes: 6 additions & 3 deletions app/analytics/analytics_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
from datetime import datetime, timezone



def log_user_a_event(session_uuid, category, action, label, event_value, event_timestamp, page_url):
def log_user_a_event(
session_uuid, category, action, label, event_value, event_timestamp, page_url
):
"""
Log an event in the user a analytics data table.
"""
Expand All @@ -19,7 +20,9 @@ def log_user_a_event(session_uuid, category, action, label, event_value, event_t
event_to_add.action = action
event_to_add.label = label
event_to_add.value = event_value
event_to_add.event_timestamp = datetime.strptime(str(event_timestamp), '%Y-%m-%d %H:%M:%S')
event_to_add.event_timestamp = datetime.strptime(
str(event_timestamp), "%Y-%m-%d %H:%M:%S"
)
event_to_add.page_url = page_url
# event_to_add.event_timestamp = datetime.now(timezone.utc)
db.session.add(event_to_add)
Expand Down
14 changes: 9 additions & 5 deletions app/analytics/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from app.models import AnalyticsData



@bp.route("/analytics", methods=["POST"])
@cross_origin()
def post_user_a_event():
Expand All @@ -39,11 +38,16 @@ def post_user_a_event():
json_data = request.get_json(force=True, silent=True)
schema = AnalyticsSchema()
result_data = schema.load(json_data)
log_user_a_event(session_uuid,result_data["category"],result_data["action"],result_data["label"],result_data["event_value"],result_data["event_timestamp"],result_data["page_url"])
log_user_a_event(
session_uuid,
result_data["category"],
result_data["action"],
result_data["label"],
result_data["event_value"],
result_data["event_timestamp"],
result_data["page_url"],
)

response = {"message": "User event logged."}

return jsonify(response), 201



15 changes: 6 additions & 9 deletions app/analytics/tests/test_analytics_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ def test_add_event(client, accept_json):
session = SessionsFactory()
session_header = [("X-Session-Id", session.session_uuid)]
ok_data = {
"category": faker.pystr(20, 50),
"action": faker.pystr(20, 50),
"label": faker.pystr(20, 50),
"eventValue": faker.pystr(20, 50),
"eventTimestamp": str(faker.date_time()),
"pageUrl": faker.pystr(20, 255),
"category": faker.pystr(20, 50),
"action": faker.pystr(20, 50),
"label": faker.pystr(20, 50),
"eventValue": faker.pystr(20, 50),
"eventTimestamp": str(faker.date_time()),
"pageUrl": faker.pystr(20, 255),
}

url = url_for("analytics.post_user_a_event")
Expand All @@ -38,6 +38,3 @@ def test_add_event(client, accept_json):
json=ok_data,
)
assert response.status_code == 201, "User event logged."



0 comments on commit 3403dd7

Please sign in to comment.