Search in sources :

Example 6 with GradingScale

use of de.tum.in.www1.artemis.domain.GradingScale in project ArTEMiS by ls1intum.

the class GradingScaleIntegrationTest method init.

/**
 * Initialize variables
 */
@BeforeEach
public void init() {
    database.addUsers(0, 0, 0, 1);
    course = database.addEmptyCourse();
    exam = database.addExamWithExerciseGroup(course, true);
    courseGradingScale = new GradingScale();
    courseGradingScale.setCourse(course);
    examGradingScale = new GradingScale();
    examGradingScale.setExam(exam);
    gradeSteps = new HashSet<>();
    courseGradingScale.setGradeSteps(gradeSteps);
    examGradingScale.setGradeSteps(gradeSteps);
}
Also used : GradingScale(de.tum.in.www1.artemis.domain.GradingScale) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 7 with GradingScale

use of de.tum.in.www1.artemis.domain.GradingScale in project ArTEMiS by ls1intum.

the class GradingScaleIntegrationTest method testSaveGradingScaleForCourse.

/**
 * Test post request for grading scale
 *
 * @throws Exception
 */
@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void testSaveGradingScaleForCourse() throws Exception {
    gradeSteps = database.generateGradeStepSet(courseGradingScale, true);
    courseGradingScale.setGradeSteps(gradeSteps);
    GradingScale savedGradingScale = request.postWithResponseBody("/api/courses/" + course.getId() + "/grading-scale", courseGradingScale, GradingScale.class, HttpStatus.CREATED);
    assertThat(savedGradingScale.getGradeSteps()).hasSameSizeAs(courseGradingScale.getGradeSteps());
    assertThat(savedGradingScale.getGradeSteps()).allMatch(gradeStep -> isGradeStepInSet(courseGradingScale.getGradeSteps(), gradeStep));
    assertThat(savedGradingScale).usingRecursiveComparison().ignoringFields("id", "exam", "course", "gradeSteps").ignoringCollectionOrder().isEqualTo(courseGradingScale);
}
Also used : GradingScale(de.tum.in.www1.artemis.domain.GradingScale) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test)

Example 8 with GradingScale

use of de.tum.in.www1.artemis.domain.GradingScale in project ArTEMiS by ls1intum.

the class GradingScaleIntegrationTest method testGetGradingScaleForExam.

/**
 * Test get request for grading scale
 *
 * @throws Exception
 */
@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void testGetGradingScaleForExam() throws Exception {
    examGradingScale.setGradeSteps(Set.of());
    gradingScaleRepository.save(examGradingScale);
    GradingScale foundGradingScale = request.get("/api/courses/" + course.getId() + "/exams/" + exam.getId() + "/grading-scale", HttpStatus.OK, GradingScale.class);
    assertThat(foundGradingScale).usingRecursiveComparison().ignoringFields("id", "course", "exam").isEqualTo(examGradingScale);
}
Also used : GradingScale(de.tum.in.www1.artemis.domain.GradingScale) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test)

Example 9 with GradingScale

use of de.tum.in.www1.artemis.domain.GradingScale in project ArTEMiS by ls1intum.

the class GradeStepResource method getGradeStepByPercentageForExam.

/**
 * GET /courses/{courseId}/exams/{examId}/grading-scale/grade-steps/match-grade-step : Find a grade step for the grading scale of a course by grade percentage
 *
 * @param courseId the course to which the exam belongs
 * @param examId the exam to which the grading scale belongs
 * @param gradePercentage the grade percentage the has to be mapped to a grade step
 * @return ResponseEntity with status 200 (Ok) with body the grade if the grading scale and grade step exist and 404 (Not found) otherwise
 */
@GetMapping("/courses/{courseId}/exams/{examId}/grading-scale/match-grade-step")
@PreAuthorize("hasRole('USER')")
public ResponseEntity<GradeDTO> getGradeStepByPercentageForExam(@PathVariable Long courseId, @PathVariable Long examId, @RequestParam Double gradePercentage) {
    log.debug("REST request to get grade step for grade percentage {} for exam: {}", gradePercentage, examId);
    User user = userRepository.getUserWithGroupsAndAuthorities();
    Course course = courseRepository.findByIdElseThrow(courseId);
    Exam exam = examRepository.findByIdElseThrow(examId);
    Optional<GradingScale> gradingScale = gradingScaleRepository.findByExamId(examId);
    authCheckService.checkHasAtLeastRoleInCourseElseThrow(Role.STUDENT, course, user);
    boolean isInstructor = authCheckService.isAtLeastInstructorInCourse(course, user);
    if (gradingScale.isEmpty()) {
        return ResponseEntity.ok(null);
    } else if (!isInstructor && !exam.resultsPublished()) {
        throw new AccessForbiddenException();
    }
    GradeStep gradeStep = gradingScaleRepository.matchPercentageToGradeStep(gradePercentage, gradingScale.get().getId());
    GradeDTO gradeDTO = new GradeDTO(gradeStep.getGradeName(), gradeStep.getIsPassingGrade(), gradeStep.getGradingScale().getGradeType());
    return ResponseEntity.ok(gradeDTO);
}
Also used : GradingScale(de.tum.in.www1.artemis.domain.GradingScale) User(de.tum.in.www1.artemis.domain.User) GradeDTO(de.tum.in.www1.artemis.web.rest.dto.GradeDTO) GradeStep(de.tum.in.www1.artemis.domain.GradeStep) Course(de.tum.in.www1.artemis.domain.Course) Exam(de.tum.in.www1.artemis.domain.exam.Exam) AccessForbiddenException(de.tum.in.www1.artemis.web.rest.errors.AccessForbiddenException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 10 with GradingScale

use of de.tum.in.www1.artemis.domain.GradingScale in project ArTEMiS by ls1intum.

the class GradingScaleResource method deleteGradingScaleForExam.

/**
 * DELETE /courses/{courseId}/exams/{examId}/grading-scale : Delete grading scale for course
 *
 * @param courseId the course to which the exam belongs
 * @param examId the exam to which the grading scale belongs
 * @return ResponseEntity with status 200 (Ok) if the grading scale is successfully deleted and 400 (Bad request) otherwise
 */
@DeleteMapping("/courses/{courseId}/exams/{examId}/grading-scale")
@PreAuthorize("hasRole('INSTRUCTOR')")
public ResponseEntity<Void> deleteGradingScaleForExam(@PathVariable Long courseId, @PathVariable Long examId) {
    log.debug("REST request to delete the grading scale for exam: {}", examId);
    Course course = courseRepository.findByIdElseThrow(courseId);
    GradingScale gradingScale = gradingScaleRepository.findByExamIdOrElseThrow(examId);
    authCheckService.checkHasAtLeastRoleInCourseElseThrow(Role.INSTRUCTOR, course, null);
    gradingScaleRepository.delete(gradingScale);
    return ResponseEntity.ok().headers(HeaderUtil.createEntityDeletionAlert(applicationName, true, ENTITY_NAME, "")).build();
}
Also used : GradingScale(de.tum.in.www1.artemis.domain.GradingScale) Course(de.tum.in.www1.artemis.domain.Course) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

GradingScale (de.tum.in.www1.artemis.domain.GradingScale)72 WithMockUser (org.springframework.security.test.context.support.WithMockUser)62 Test (org.junit.jupiter.api.Test)60 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)44 AbstractSpringIntegrationBambooBitbucketJiraTest (de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest)42 GradeStep (de.tum.in.www1.artemis.domain.GradeStep)38 Course (de.tum.in.www1.artemis.domain.Course)28 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)24 Exam (de.tum.in.www1.artemis.domain.exam.Exam)14 BadRequestAlertException (de.tum.in.www1.artemis.web.rest.errors.BadRequestAlertException)10 GradeStepsDTO (de.tum.in.www1.artemis.web.rest.dto.GradeStepsDTO)8 EntityNotFoundException (de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException)6 BeforeEach (org.junit.jupiter.api.BeforeEach)6 de.tum.in.www1.artemis.domain (de.tum.in.www1.artemis.domain)4 User (de.tum.in.www1.artemis.domain.User)4 ExerciseGroup (de.tum.in.www1.artemis.domain.exam.ExerciseGroup)4 StudentExam (de.tum.in.www1.artemis.domain.exam.StudentExam)4 ModelingExercise (de.tum.in.www1.artemis.domain.modeling.ModelingExercise)4 ModelingSubmission (de.tum.in.www1.artemis.domain.modeling.ModelingSubmission)4 StudentParticipation (de.tum.in.www1.artemis.domain.participation.StudentParticipation)4