Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow setting a term when creating a course. #128

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions integration-example.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ token=11537~nqSvdZ55SkdnlqGyAuk7JHspdjlX7tZrXmjrlDMNLDWj2syiIwp4kwbrwJRS0nXC
user=73
# ID of course to use for course related tests.
course=26841
# ID of a term
term=222
88 changes: 88 additions & 0 deletions src/integration-test/java/edu/ksu/canvas/calendar/CoursesIT.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package edu.ksu.canvas.calendar;

import edu.ksu.canvas.CanvasApiFactory;
import edu.ksu.canvas.interfaces.*;
import edu.ksu.canvas.model.CalendarEvent;
import edu.ksu.canvas.model.Course;
import edu.ksu.canvas.model.Section;
import edu.ksu.canvas.oauth.NonRefreshableOauthToken;
import edu.ksu.canvas.requestOptions.DeleteCalendarEventOptions;
import edu.ksu.canvas.requestOptions.GetSingleCourseOptions;
import edu.ksu.canvas.requestOptions.ListCalendarEventsOptions;
import org.junit.Before;
import org.junit.Test;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.*;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

public class CoursesIT {

private CanvasApiFactory canvasApiFactory;
private NonRefreshableOauthToken nonRefreshableOauthToken;
private String course;
private String user;
private String account;
private long term;
private CourseWriter writer;
private CourseReader reader;


@Before
public void setUp() throws IOException {
// Load from root of project
File config = new File("integration.properties");
if (!config.isFile()) {
throw new FileNotFoundException("Failed to find configuration: " + config.getAbsolutePath());
}
Properties properties = new Properties();
properties.load(new FileInputStream(config));

String url = properties.getProperty("url");
Objects.requireNonNull(url, "Property 'url' must be set in config file.");
canvasApiFactory = new CanvasApiFactory(url);

String token = properties.getProperty("token");
Objects.requireNonNull(token, "Property 'token' must be set in config file.");
nonRefreshableOauthToken = new NonRefreshableOauthToken(token);

user = properties.getProperty("user");
Objects.requireNonNull(user, "Property 'user' must be set in config file.");

course = properties.getProperty("course");
Objects.requireNonNull(course, "Property 'course' must be set in config file.");

account = properties.getProperty("account");
Objects.requireNonNull(course, "Property 'account' must be set in config file.");

term = Long.parseLong(properties.getProperty("term"));
Objects.requireNonNull(course, "Property 'term' must be set in config file.");

reader = canvasApiFactory.getReader(CourseReader.class, nonRefreshableOauthToken);
writer = canvasApiFactory.getWriter(CourseWriter.class, nonRefreshableOauthToken);
}

@Test
public void testCreateReadDelete() throws IOException {
Course course = new Course();
course.setSisCourseId(UUID.randomUUID().toString());
course.setName("Integration Course Test");
course.setEnrollmentTermId(term);
Course createdCourse = writer.createCourse(account, course).orElseThrow(RuntimeException::new);

Course readCourse = reader.getSingleCourse(new GetSingleCourseOptions(createdCourse.getId().toString())).orElseThrow(RuntimeException::new);

assertEquals(term, readCourse.getEnrollmentTermId());
assertEquals("Integration Course Test", readCourse.getName());

assertTrue(writer.deleteCourse(createdCourse.getId().toString()));
}

}
11 changes: 1 addition & 10 deletions src/main/java/edu/ksu/canvas/model/Course.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ public class Course extends BaseCanvasModel implements Serializable {
private Boolean allowStudentForumAttachments;
private Boolean openEnrollment;
private Boolean selfEnrollment;
private Boolean termId;
private String timeZone;
private Boolean offer;
private Boolean enrollMe;
Expand All @@ -59,6 +58,7 @@ public class Course extends BaseCanvasModel implements Serializable {
@SerializedName("term")
private EnrollmentTerm enrollmentTerm;

@CanvasField(postKey = "term_id")
public long getEnrollmentTermId() {
return enrollmentTermId;
}
Expand Down Expand Up @@ -340,15 +340,6 @@ public void setSelfEnrollment(Boolean selfEnrollment) {
this.selfEnrollment = selfEnrollment;
}

@CanvasField(postKey = "term_id")
public Boolean getTermId() {
return termId;
}

public void setTermId(Boolean termId) {
this.termId = termId;
}

@CanvasField(postKey = "time_zone")
public String getTimeZone() {
return timeZone;
Expand Down