Skip to content

Commit

Permalink
test: add test serializers test
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian2012 committed Mar 5, 2024
1 parent 8e7fb01 commit 480ef53
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 4 deletions.
2 changes: 1 addition & 1 deletion platform_plugin_aspects/sinks/course_overview_sink.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

from opaque_keys.edx.keys import CourseKey

from platform_plugin_aspects.sinks.serializers import CourseOverviewSerializer
from platform_plugin_aspects.sinks.base_sink import ModelBaseSink
from platform_plugin_aspects.sinks.serializers import CourseOverviewSerializer
from platform_plugin_aspects.utils import get_detached_xblock_types, get_modulestore

# Defaults we want to ensure we fail early on bulk inserts
Expand Down
2 changes: 1 addition & 1 deletion platform_plugin_aspects/sinks/external_id_sink.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""User profile sink"""

from platform_plugin_aspects.sinks.serializers import UserExternalIDSerializer
from platform_plugin_aspects.sinks.base_sink import ModelBaseSink
from platform_plugin_aspects.sinks.serializers import UserExternalIDSerializer


class ExternalIdSink(ModelBaseSink): # pylint: disable=abstract-method
Expand Down
82 changes: 82 additions & 0 deletions platform_plugin_aspects/sinks/tests/test_serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import json
from unittest.mock import Mock

from django.test import TestCase

from platform_plugin_aspects.sinks.serializers import (
BaseSinkSerializer,
CourseOverviewSerializer,
)


class TestBaseSinkSerializer(TestCase):
"""
Test BaseSinkSerializer
"""

def setUp(self):
self.serializer = BaseSinkSerializer()

def test_to_representation(self):
"""
Test to_representation
"""
self.assertEqual(
list(self.serializer.to_representation({}).keys()),
["dump_id", "time_last_dumped"],
)


class TestCourseOverviewSerializer(TestCase):
"""
Test CourseOverviewSerializer
"""

def setUp(self):
self.serializer = CourseOverviewSerializer()

def test_get_course_data_json(self):
"""
Test to_representation
json_fields = {
"advertised_start": getattr(overview, "advertised_start", ""),
"announcement": getattr(overview, "announcement", ""),
"lowest_passing_grade": float(
getattr(overview, "lowest_passing_grade", 0.0)
),
"invitation_only": getattr(overview, "invitation_only", ""),
"max_student_enrollments_allowed": getattr(
overview, "max_student_enrollments_allowed", None
),
"effort": getattr(overview, "effort", ""),
"enable_proctored_exams": getattr(overview, "enable_proctored_exams", ""),
"entrance_exam_enabled": getattr(overview, "entrance_exam_enabled", ""),
"external_id": getattr(overview, "external_id", ""),
"language": getattr(overview, "language", ""),
}
"""
json_fields = {
"advertised_start": "2018-01-01T00:00:00Z",
"announcement": "announcement",
"lowest_passing_grade": 0.0,
"invitation_only": "invitation_only",
"max_student_enrollments_allowed": None,
"effort": "effort",
"enable_proctored_exams": "enable_proctored_exams",
"entrance_exam_enabled": "entrance_exam_enabled",
"external_id": "external_id",
"language": "language",
}
mock_overview = Mock(**json_fields)
self.assertEqual(
self.serializer.get_course_data_json(mock_overview), json.dumps(json_fields)
)

def test_get_course_key(self):
"""
Test get_course_key
"""
mock_id = Mock()
mock_overview = Mock(id=mock_id)
self.assertEqual(self.serializer.get_course_key(mock_overview), str(mock_id))
2 changes: 1 addition & 1 deletion platform_plugin_aspects/sinks/user_profile_sink.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""User profile sink"""

from platform_plugin_aspects.sinks.serializers import UserProfileSerializer
from platform_plugin_aspects.sinks.base_sink import ModelBaseSink
from platform_plugin_aspects.sinks.serializers import UserProfileSerializer


class UserProfileSink(ModelBaseSink): # pylint: disable=abstract-method
Expand Down
2 changes: 1 addition & 1 deletion platform_plugin_aspects/sinks/user_retire_sink.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import requests
from django.conf import settings

from platform_plugin_aspects.sinks.serializers import UserRetirementSerializer
from platform_plugin_aspects.sinks.base_sink import ModelBaseSink
from platform_plugin_aspects.sinks.serializers import UserRetirementSerializer


class UserRetirementSink(ModelBaseSink): # pylint: disable=abstract-method
Expand Down

0 comments on commit 480ef53

Please sign in to comment.