Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
Muhammad Faraz Maqsood committed Sep 12, 2024
1 parent 19bbca6 commit ea99719
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from . import models, settings, utils
from forum import api as forum_api
from .utils import check_service_enabled, handle_metric_tags, handle_response
from .utils import check_service_enabled, handle_response


log = logging.getLogger(__name__)
Expand Down Expand Up @@ -198,12 +198,6 @@ def unFlagAbuse(self, user, voteable, removeAll):
def pin(self, user, thread_id):
check_service_enabled()
response = forum_api.pin_thread(user.id, thread_id)
handle_metric_tags(
"put",
response["status_code"],
metric_action="thread.pin",
metric_tags=self._metric_tags,
)
response = handle_response(
response,
"put",
Expand All @@ -215,12 +209,6 @@ def pin(self, user, thread_id):
def un_pin(self, user, thread_id):
check_service_enabled()
response = forum_api.unpin_thread(user.id, thread_id)
handle_metric_tags(
"put",
response["status_code"],
metric_action="thread.unpin",
metric_tags=self._metric_tags,
)
response = handle_response(
response,
"put",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from . import models, settings, utils
from forum import api as forum_api
from .utils import check_service_enabled, handle_metric_tags, handle_response
from .utils import check_service_enabled, handle_response

class User(models.Model):

Expand Down Expand Up @@ -152,12 +152,6 @@ def _retrieve(self, *args, **kwargs):
try:
check_service_enabled()
response = forum_api.retrieve_user(self.attributes["id"], retrieve_params)
handle_metric_tags(
"get",
response["status_code"],
metric_action="model.retrieve",
metric_tags=self._metric_tags,
)
response = handle_response(
response, "get", retrieve_params, metric_action="model.retrieve"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,23 +230,6 @@ def check_service_enabled():
raise CommentClientMaintenanceError("service disabled")


def handle_metric_tags(
request_method, status_code, metric_action=None, metric_tags=None
):
if metric_tags is None:
metric_tags = []

metric_tags.append(f"method:{request_method}")
if metric_action:
metric_tags.append(f"action:{metric_action}")

metric_tags.append(f"status_code:{status_code}")
if status_code > 200:
metric_tags.append("result:failure")
else:
metric_tags.append("result:success")


def handle_response(
response,
request_method,
Expand All @@ -273,8 +256,8 @@ def handle_response(
data = response["data"]
except ValueError:
raise CommentClientError( # lint-amnesty, pylint: disable=raise-missing-from
"Invalid JSON response for request to forum v2 method named{forum_v2_method}; first 100 characters: '{content}'".format(
forum_v2_method=metric_action, content=response["text"][:100]
"Invalid JSON response for request to forum v2 method named{metric_action}; first 100 characters: '{content}'".format(
metric_action=metric_action, content=response["text"][:100]
)
)
return data

0 comments on commit ea99719

Please sign in to comment.