Skip to content

Commit

Permalink
Merge pull request #15 from edx/alangsto/fix_json_field
Browse files Browse the repository at this point in the history
fix: remove deserialization of jsonfield
  • Loading branch information
alangsto authored Aug 25, 2023
2 parents f5eccd1 + 9340d50 commit 92d4663
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 15 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ Change Log

.. There should always be an "Unreleased" section for changes pending release.
1.3.2 - 2023-08-25
******************
* Remove deserialization of prompt field, as it is represented in the python
native format

1.3.1 - 2023-08-24
******************
* Remove prompt field
Expand Down
2 changes: 1 addition & 1 deletion learning_assistant/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
Plugin for a learning assistant backend, intended for use within edx-platform.
"""

__version__ = '1.3.1'
__version__ = '1.3.2'

default_app_config = 'learning_assistant.apps.LearningAssistantConfig' # pylint: disable=invalid-name
5 changes: 1 addition & 4 deletions learning_assistant/api.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
"""
Library for the learning_assistant app.
"""
import json

from learning_assistant.models import CoursePrompt


Expand All @@ -12,8 +10,7 @@ def get_deserialized_prompt_content_by_course_id(course_id):
"""
json_prompt = CoursePrompt.get_json_prompt_content_by_course_id(course_id)
if json_prompt:
prompt_messages = json.loads(json_prompt)
return prompt_messages
return json_prompt
return None


Expand Down
8 changes: 3 additions & 5 deletions tests/test_api.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
"""
Test cases for the learning-assistant api module.
"""
import json

from django.test import TestCase

from learning_assistant.api import get_deserialized_prompt_content_by_course_id, get_setup_messages
Expand All @@ -16,7 +14,7 @@ class LearningAssistantAPITests(TestCase):

def setUp(self):
self.course_id = 'course-v1:edx+test+23'
self.prompt = json.dumps('["This is a Prompt", "This is another Prompt"]')
self.prompt = ["This is a Prompt", "This is another Prompt"]
self.course_prompt = CoursePrompt.objects.create(
course_id=self.course_id,
json_prompt_content=self.prompt,
Expand All @@ -25,7 +23,7 @@ def setUp(self):

def test_get_deserialized_prompt_valid_course_id(self):
prompt_content = get_deserialized_prompt_content_by_course_id(self.course_id)
expected_content = json.loads(self.prompt)
expected_content = self.prompt
self.assertEqual(prompt_content, expected_content)

def test_get_deserialized_prompt_invalid_course_id(self):
Expand All @@ -34,7 +32,7 @@ def test_get_deserialized_prompt_invalid_course_id(self):

def test_get_setup_messages(self):
setup_messages = get_setup_messages(self.course_id)
expected_messages = [{'role': 'system', 'content': x} for x in json.loads(self.prompt)]
expected_messages = [{'role': 'system', 'content': x} for x in self.prompt]
self.assertEqual(setup_messages, expected_messages)

def test_get_setup_messages_invalid_course_id(self):
Expand Down
4 changes: 1 addition & 3 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
"""
Tests for the `learning-assistant` models module.
"""
import json

from django.test import TestCase

from learning_assistant.models import CoursePrompt
Expand All @@ -16,7 +14,7 @@ class CoursePromptTests(TestCase):

def setUp(self):
self.course_id = 'course-v1:edx+test+23'
self.prompt = json.dumps('["This is a Prompt", "This is another Prompt"]')
self.prompt = ["This is a Prompt", "This is another Prompt"]
self.course_prompt = CoursePrompt.objects.create(
course_id=self.course_id,
json_prompt_content=self.prompt,
Expand Down
4 changes: 2 additions & 2 deletions tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def test_invalid_messages(self, mock_role, mock_waffle):

CoursePrompt.objects.create(
course_id=self.course_id,
json_prompt_content=json.dumps('["This is a Prompt", "This is another Prompt"]')
json_prompt_content=["This is a Prompt", "This is another Prompt"]
)

test_data = [
Expand All @@ -140,7 +140,7 @@ def test_chat_response(self, mock_role, mock_waffle, mock_chat_response):

CoursePrompt.objects.create(
course_id=self.course_id,
json_prompt_content=json.dumps('["This is a Prompt", "This is another Prompt"]')
json_prompt_content=["This is a Prompt", "This is another Prompt"]
)

test_data = [
Expand Down

0 comments on commit 92d4663

Please sign in to comment.