Add unit test for highlights in instruments
This commit is contained in:
parent
de77eeaff3
commit
3c8a74c746
|
|
@ -18,7 +18,7 @@ urlpatterns = [
|
||||||
re_path(r"^statistics/", include("statistics.urls", namespace="statistics")),
|
re_path(r"^statistics/", include("statistics.urls", namespace="statistics")),
|
||||||
# wagtail
|
# wagtail
|
||||||
re_path(r"^cms/autocomplete/", include(autocomplete_admin_urls)),
|
re_path(r"^cms/autocomplete/", include(autocomplete_admin_urls)),
|
||||||
re_path(r"^cms/pages/(\d+)/$", override_wagtailadmin_explore_default_ordering),
|
# re_path(r"^cms/pages/(\d+)/$", override_wagtailadmin_explore_default_ordering),
|
||||||
re_path(r"^cms/", include(wagtailadmin_urls)),
|
re_path(r"^cms/", include(wagtailadmin_urls)),
|
||||||
re_path(r"^documents/", include(wagtaildocs_urls)),
|
re_path(r"^documents/", include(wagtaildocs_urls)),
|
||||||
# graphql backend
|
# graphql backend
|
||||||
|
|
|
||||||
|
|
@ -305,6 +305,8 @@ class AddHighlight(relay.ClientIDMutation):
|
||||||
page = Module.objects.get(id=page_id)
|
page = Module.objects.get(id=page_id)
|
||||||
elif page_type == "ChapterNode":
|
elif page_type == "ChapterNode":
|
||||||
page = Chapter.objects.get(id=page_id)
|
page = Chapter.objects.get(id=page_id)
|
||||||
|
elif page_type == "InstrumentNode":
|
||||||
|
page = BasicKnowledge.objects.get(id=page_id)
|
||||||
else:
|
else:
|
||||||
raise Exception("wrong type")
|
raise Exception("wrong type")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,10 @@
|
||||||
import pytest
|
import pytest
|
||||||
from books.factories import ChapterFactory, ContentBlockFactory, ModuleFactory
|
from books.factories import (
|
||||||
|
ChapterFactory,
|
||||||
|
ContentBlockFactory,
|
||||||
|
InstrumentFactory,
|
||||||
|
ModuleFactory,
|
||||||
|
)
|
||||||
from books.models.contentblock import ContentBlock
|
from books.models.contentblock import ContentBlock
|
||||||
from graphql_relay import to_global_id
|
from graphql_relay import to_global_id
|
||||||
|
|
||||||
|
|
@ -121,6 +126,20 @@ module_query = (
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
|
||||||
|
instrument_query = (
|
||||||
|
fragment
|
||||||
|
+ """
|
||||||
|
query InstrumentQuery($id: ID!) {
|
||||||
|
instrument(id:$id) {
|
||||||
|
id
|
||||||
|
highlights {
|
||||||
|
...HighlightLegacyParts
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures("create_users")
|
@pytest.mark.usefixtures("create_users")
|
||||||
class TestAddHighlight:
|
class TestAddHighlight:
|
||||||
|
|
@ -186,7 +205,40 @@ class TestAddHighlight:
|
||||||
assert result.errors is not None
|
assert result.errors is not None
|
||||||
|
|
||||||
def test_add_highlight_in_instrument(self, teacher, get_client):
|
def test_add_highlight_in_instrument(self, teacher, get_client):
|
||||||
assert 1 == 0
|
instrument = InstrumentFactory()
|
||||||
|
client = get_client(teacher)
|
||||||
|
iid = to_global_id("InstrumentNode", instrument.id)
|
||||||
|
result = client.execute(
|
||||||
|
add_highlight_mutation,
|
||||||
|
variables={
|
||||||
|
"input": {
|
||||||
|
"highlight": {
|
||||||
|
"page": iid,
|
||||||
|
"paragraphIndex": 0,
|
||||||
|
"text": "Hallo",
|
||||||
|
"startPosition": 0,
|
||||||
|
"selectionLength": 10,
|
||||||
|
"color": "alpha",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
assert result.errors is None
|
||||||
|
|
||||||
|
highlight = result.data.get("addHighlight").get("highlight")
|
||||||
|
logger.debug(highlight)
|
||||||
|
logger.debug(iid)
|
||||||
|
assert highlight.get("text") == "Hallo"
|
||||||
|
assert highlight.get("page").get("id") == iid
|
||||||
|
|
||||||
|
client = get_client(teacher)
|
||||||
|
result = client.execute(instrument_query, variables={"id": iid})
|
||||||
|
assert result.errors is None
|
||||||
|
instrument = result.data.get("instrument")
|
||||||
|
logger.debug(instrument)
|
||||||
|
assert instrument.get("id") == iid
|
||||||
|
assert instrument.get("highlights")[0].get("color") == "alpha"
|
||||||
|
assert instrument.get("highlights")[0].get("page").get("id") == iid
|
||||||
|
|
||||||
def test_add_highlight_in_module(self, teacher, get_client):
|
def test_add_highlight_in_module(self, teacher, get_client):
|
||||||
module = ModuleFactory()
|
module = ModuleFactory()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue