1 package com.jetbrains.edu.learning.stepic;
3 import com.intellij.openapi.util.io.FileUtil;
4 import com.intellij.testFramework.PlatformTestUtil;
5 import com.intellij.util.containers.ContainerUtil;
6 import com.jetbrains.edu.learning.courseFormat.AnswerPlaceholder;
7 import com.jetbrains.edu.learning.courseFormat.AnswerPlaceholderSubtaskInfo;
8 import com.jetbrains.edu.learning.courseFormat.TaskFile;
9 import org.jetbrains.annotations.NotNull;
10 import org.junit.Test;
13 import java.io.IOException;
14 import java.util.Collections;
15 import java.util.List;
18 import static org.junit.Assert.*;
21 public class StudyStepicFormatTest {
24 public void fromFirstVersion() throws IOException {
25 doStepOptionsCreationTest("1.json");
29 public void fromSecondVersion() throws IOException {
30 doStepOptionsCreationTest("2.json");
34 public void testWithSubtasks() throws IOException {
35 StepicWrappers.StepOptions stepOptions = doStepOptionsCreationTest("3.json");
36 assertEquals(1, stepOptions.lastSubtaskIndex);
40 private static StepicWrappers.StepOptions doStepOptionsCreationTest(String fileName) throws IOException {
41 String responseString =
42 FileUtil.loadFile(new File(getTestDataPath(), fileName));
43 StepicWrappers.StepSource stepSource =
44 EduStepicClient.deserializeStepicResponse(StepicWrappers.StepContainer.class, responseString).steps.get(0);
45 StepicWrappers.StepOptions options = stepSource.block.options;
46 List<TaskFile> files = options.files;
47 assertTrue("Wrong number of task files", files.size() == 1);
48 List<AnswerPlaceholder> placeholders = files.get(0).getAnswerPlaceholders();
49 assertTrue("Wrong number of placeholders", placeholders.size() == 1);
50 Map<Integer, AnswerPlaceholderSubtaskInfo> infos = placeholders.get(0).getSubtaskInfos();
52 assertEquals(Collections.singletonList("Type your name here."), infos.get(0).getHints());
53 assertEquals("Liana", infos.get(0).getPossibleAnswer());
58 public void testAvailableCourses() throws IOException {
59 String responseString = FileUtil.loadFile(new File(getTestDataPath(), "courses.json"));
60 StepicWrappers.CoursesContainer container =
61 EduStepicClient.deserializeStepicResponse(StepicWrappers.CoursesContainer.class, responseString);
62 assertNotNull(container.courses);
63 assertTrue("Incorrect number of courses", container.courses.size() == 4);
64 List<CourseInfo> filtered = ContainerUtil.filter(container.courses, info -> EduStepicConnector.canBeOpened(info));
65 assertEquals(ContainerUtil.newArrayList("Adaptive Python", "Introduction to Python", "format2"), ContainerUtil.map(filtered, CourseInfo::getName));
69 private static String getTestDataPath() {
70 return FileUtil.join(PlatformTestUtil.getCommunityPath(), "python/educational-core/student/testData/stepic");