Skip to content

Commit 03d68bf

Browse files
fix code style
1 parent fa64b64 commit 03d68bf

File tree

4 files changed

+50
-33
lines changed

4 files changed

+50
-33
lines changed

openedx_events/exceptions.py

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
"""
2-
Custom exceptions thrown by Open edX events tooling. These exceptions are raised
3-
there is an error initializing or sending a signal.
2+
Custom exceptions thrown by Open edX events tooling.
43
"""
54

65

76
class HookEventException(Exception):
87
"""
98
Base class for Open edX Events exceptions.
10-
11-
Arguments:
12-
- message (str): message describing why the exception was raised.
139
"""
1410

1511
def __init__(self, message=""):
12+
"""
13+
Init method for HookEventException base class.
14+
15+
Arguments:
16+
message (str): message describing why the exception was raised.
17+
"""
1618
super().__init__()
1719
self.message = message
1820

1921
def __str__(self):
2022
"""
21-
Shows string representation of HookEventException using its message.
23+
Show string representation of HookEventException using its message.
2224
"""
2325
return self.message
2426

@@ -30,12 +32,16 @@ class InstantiationException(HookEventException):
3032
This exception is raised when there's an error instantiating an Open edX
3133
event, it can be that a required argument for the event definition is
3234
missing.
33-
34-
Arguments:
35-
- event_type (str): name of the event raising the exception.
3635
"""
3736

3837
def __init__(self, event_type="", message=""):
38+
"""
39+
Init method for InstantiationException custom exception class.
40+
41+
Arguments:
42+
event_type (str): name of the event raising the exception.
43+
message (str): message describing why the exception was raised.
44+
"""
3945
super().__init__(
4046
message="There was an error while instantiating {event_type}: {message}".format(
4147
event_type=event_type, message=message
@@ -46,12 +52,16 @@ def __init__(self, event_type="", message=""):
4652
class SenderValidationException(HookEventException):
4753
"""
4854
Describes errors that occur while validating arguments of send methods.
49-
50-
Arguments:
51-
- message (str): message describing why the exception was raised.
5255
"""
5356

5457
def __init__(self, event_type="", message=""):
58+
"""
59+
Init method for SenderValidationException custom exception class.
60+
61+
Arguments:
62+
event_type (str): name of the event raising the exception.
63+
message (str): message describing why the exception was raised.
64+
"""
5565
super().__init__(
5666
message="There was an error while validating the arguments of the event: {event_type}: {message}".format(
5767
event_type=event_type, message=message

openedx_events/tests/test_tooling.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
EventsToolingTest: Test events tooling.
55
"""
66

7+
from unittest.mock import Mock
8+
79
from django.test import TestCase
8-
from mock import Mock
910

1011

1112
class OpenEdxPublicSignalTest(TestCase):
@@ -15,7 +16,7 @@ class OpenEdxPublicSignalTest(TestCase):
1516

1617
def test_get_signal_metadata(self):
1718
"""
18-
This methods tests getting generated metadata for an event.
19+
This methods tests getting the generated metadata for an event.
1920
2021
Expected behavior:
2122
Returns the metadata containing information about the event.

openedx_events/tooling.py

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,17 @@
1515
class OpenEdxPublicSignal(Signal):
1616
"""
1717
Custom class used to create Open edX events.
18-
19-
Arguments:
20-
- event_type (str): name of the event.
21-
- data (dict): attributes passed to the event.
22-
- minor_version (str): version of the event type.
2318
"""
2419

2520
def __init__(self, event_type=None, data=None, minor_version="0.0"):
21+
"""
22+
Init method for OpenEdxPublicSignal definition class.
23+
24+
Arguments:
25+
event_type (str): name of the event.
26+
data (dict): attributes passed to the event.
27+
minor_version (str): version of the event type.
28+
"""
2629
if not event_type or not data:
2730
raise InstantiationException(
2831
event_type=event_type, message="Missing required argument."
@@ -33,11 +36,14 @@ def __init__(self, event_type=None, data=None, minor_version="0.0"):
3336
super().__init__()
3437

3538
def __repr__(self):
39+
"""
40+
Represent OpenEdxPublicSignal as a string.
41+
"""
3642
return "<OpenEdxPublicSignal: {event_type}>".format(event_type=self.event_type)
3743

3844
def get_signal_metadata(self):
3945
"""
40-
Used to set signal extra metadata when an event is sent.
46+
Get signal extra metadata when an event is sent.
4147
4248
These fields are generated on the fly and are a subset of the Event
4349
Message defined in the OEP-41.
@@ -47,28 +53,28 @@ def get_signal_metadata(self):
4753

4854
def get_current_time():
4955
"""
50-
Helper function used to get timestamp when the event ocurred.
56+
Getter function used to get timestamp when the event ocurred.
5157
"""
5258
return str(datetime.utcnow().isoformat()) + "Z"
5359

5460
def get_source():
5561
"""
56-
Helper function used to get logical source of an event.
62+
Getter function used to get logical source of an event.
5763
"""
5864
return "openedx/{service}/web".format(
5965
service=getattr(settings, "SERVICE_VARIANT", "")
6066
)
6167

6268
def get_source_host():
6369
"""
64-
Helper function used to get physical source of the event.
70+
Getter function used to get physical source of the event.
6571
"""
6672
current_request = crum.get_current_request()
6773
return current_request.get_host() if current_request else None
6874

6975
def get_spec_version():
7076
"""
71-
Helper function used to get the Open edX Events version.
77+
Getter function used to get the Open edX Events version.
7278
"""
7379
return openedx_events.__version__
7480

@@ -83,31 +89,31 @@ def get_spec_version():
8389

8490
def send_event(self, send_robust=True, **kwargs):
8591
"""
86-
Custom method that sends events to all connected receivers.
92+
Send events to all connected receivers.
8793
88-
Used to send events just like Django signals are sent. In addition, runs
89-
validations on the arguments sent and generates relevant metadata
90-
that can be used for logging or debugging purposes. Besides this
91-
behavior, send_event behaves just like the send method.
94+
Used to send events just like Django signals are sent. In addition,
95+
some validations are run on the arguments, and then relevant metadata
96+
that can be used for logging or debugging purposes is generated.
97+
Besides this behavior, send_event behaves just like the send method.
9298
9399
Example usage:
94100
95101
Keyword arguments:
96-
- send_robust (bool):
102+
send_robust (bool):
97103
98104
Returns:
99-
- list: response of each receiver following the format
105+
list: response of each receiver following the format
100106
[(receiver, response), ... ]
101107
102108
Exceptions raised:
103-
- SenderValidationException: raised when there's a mismatch between
109+
SenderValidationException: raised when there's a mismatch between
104110
arguments passed to this method and arguments used to initialize
105111
the event.
106112
"""
107113

108114
def validate_sender():
109115
"""
110-
Helper method used to run validations over the send arguments.
116+
Run validations over the send arguments.
111117
"""
112118
if len(kwargs) != len(self.init_data):
113119
raise SenderValidationException(

tests/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)