Skip to content
This repository has been archived by the owner on Apr 3, 2024. It is now read-only.

Commit

Permalink
Merge pull request #27 from SoryRawyer/rds/add-graded-to-xblock-json
Browse files Browse the repository at this point in the history
feat: add graded boolean to xblock json (FC-0033)
  • Loading branch information
Ian2012 authored Aug 18, 2023
2 parents f46bfc7 + 2d0986e commit abba0a7
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion event_sink_clickhouse/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
A sink for Open edX events to send them to ClickHouse.
"""

__version__ = '0.1.1'
__version__ = '0.1.2'
1 change: 1 addition & 0 deletions event_sink_clickhouse/sinks/course_published.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ def serialize_xblock(item, index, detached_xblock_types, dump_id, dump_timestamp
'run': course_key.run,
'block_type': block_type,
'detached': 1 if block_type in detached_xblock_types else 0,
'graded': 1 if getattr(item, 'graded', False) else 0,
}

# Core table data, if things change here it's a big deal.
Expand Down
7 changes: 6 additions & 1 deletion test_utils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class FakeXBlock:
"""
Fakes the parameters of an XBlock that we care about.
"""
def __init__(self, identifier, detached_block=False):
def __init__(self, identifier, detached_block=False, graded=False):
self.block_type = "course_info" if detached_block else "vertical"
self.scope_ids = Mock()
self.scope_ids.usage_id.course_key = course_key_factory()
Expand All @@ -61,6 +61,7 @@ def __init__(self, identifier, detached_block=False):
self.display_name_with_default = f"Display name {identifier}"
self.edited_on = datetime.now()
self.children = []
self.graded = graded

def get_children(self):
"""
Expand Down Expand Up @@ -188,6 +189,10 @@ def course_factory():
for i in range(3):
course.append(FakeXBlock(f"Detached {i}", detached_block=True))

# Create some graded blocks at the top level
for i in range(3):
course.append(FakeXBlock(f"Graded {i}", graded=True))

return course


Expand Down
17 changes: 17 additions & 0 deletions tests/test_course_published.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
"""
Tests for the course_published sinks.
"""
import json
import logging
import uuid
from datetime import datetime
from unittest.mock import patch

Expand Down Expand Up @@ -206,3 +208,18 @@ def test_get_last_dump_time():
last_published_date = sink.get_course_last_dump_time(course_key)
dt = datetime.strptime(last_published_date, "%Y-%m-%d %H:%M:%S.%f+00:00")
assert dt


def test_xblock_json_seralization():
course = course_factory()

for index, item in enumerate(course):
block = CoursePublishedSink.serialize_xblock(
item,
index,
mock_detached_xblock_types(),
str(uuid.uuid4()),
str(datetime.now()),
)
block_json = json.loads(block['xblock_data_json'])
assert bool(int(block_json['graded'])) == item.graded

0 comments on commit abba0a7

Please sign in to comment.