Skip to content

Commit

Permalink
Merge 4fc9450 into 6500058
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Pannell committed Jan 23, 2019
2 parents 6500058 + 4fc9450 commit 39350d0
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 14 deletions.
69 changes: 59 additions & 10 deletions teamwork/apps/courses/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@
from teamwork.apps.courses.models import *
from teamwork.apps.profiles.models import *

def create_user(username, email, password):
return User.objects.create_user(username, email, password)

def create_course(name, slug, creator):
return Course.objects.create(name=name, slug=slug, creator=creator)

def create_course_enrollment(user, course, role):
return Enrollment.objects.create(user=user, course=course, role=role)

def create_project_membership(user, project, invite_reason):
return Membership.objects.create(user=user, project=project, invite_reason=invite_reason)

class CourseTestCase(TestCase):
"""
Expand All @@ -26,24 +37,62 @@ def setUp(self):
"""
# Create a test user as an attribute of ProjectTestCase, for future use
# (we're not testing user or profile methods here)
self.user1 = User.objects.create_user('user_test1', 'test1@test.com', 'groupthink')
self.user1 = create_user('user_test1', 'test1@test.com', 'groupthink')

# create a dummy course (with no M2M relationships) that will be associated with user1
course1 = Course.objects.create(name="Test Course", info="Testing course", slug="test1-slug",
creator=self.user1)
self.course1 = create_course('Test Course 1', 'test1-slug', self.user1)
self.course2 = create_course('Test Course 2', 'test2-slug', self.user1)

# Create a membership object between user1 and project1
Enrollment.objects.create(user=self.user1, course=course1)
self.enrollment1 = create_course_enrollment(self.user1, self.course1, 'professor')
self.enrollment2 = create_course_enrollment(self.user1, self.course2, 'professor')

# TODO:
def tearDown(self):
pass

def test_get_user_courses(self):
"""All courses associated with a user are returned"""
my_courses = Course.get_my_courses(self.user1)
for c in my_courses:
# Test fails if any unexpected course name is returned.
self.assertEqual(c.name, 'Test Course')
self.assertTrue(self.course1 in my_courses)
self.assertTrue(self.course2 in my_courses)

def test_get_my_created_courses(self):
"""All created courses associated with a user are returned"""
my_created_courses = Course.get_my_created_courses(self.user1)
for c in my_created_courses:
# Test fails if any unexpected course name is returned
self.assertEqual(c.name, 'Test Course')
self.assertTrue(self.course1 in my_created_courses)
self.assertTrue(self.course2 in my_created_courses)

def test_get_active_courses(self):
# call get active, initially both courses should be active
active_courses = get_user_active_courses(self.user1)
self.assertTrue(self.course1 in active_courses)
self.assertTrue(self.course2 in active_courses)

# inactivate course2, ensure course1 is only returned as active
self.course2.disable = True
self.course2.save()

active_courses = get_user_active_courses(self.user1)
self.assertTrue(self.course1 in active_courses)
self.assertTrue(self.course2 not in active_courses)

def test_get_inactive_courses(self):
# call get inactive, initially neither courses should be inactive
inactive_courses = get_user_disabled_courses(self.user1)
self.assertTrue(self.course1 not in inactive_courses)
self.assertTrue(self.course2 not in inactive_courses)

# deactivate course2, ensure course2 is only returned as inactive
self.course2.disable = True
self.course2.save()

inactive_courses = get_user_disabled_courses(self.user1)
self.assertTrue(self.course1 not in inactive_courses)
self.assertTrue(self.course2 in inactive_courses)

def test_delete_course(self):
"""
TODO: once delete is moved to Course model
"""
pass
2 changes: 1 addition & 1 deletion teamwork/apps/courses/views/EditCourseView.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,9 @@ def edit_course(request, slug):
def delete_course(request, slug):
"""
Delete course method
TODO: delete should be moved to Course model ie: Course.DeleteGraph()
"""
course = get_object_or_404(Course, slug=slug)
#students = course.students.all()
projects = course.projects.all()
assignments = course.assignments.all()
course_updates = course.get_updates()
Expand Down
8 changes: 5 additions & 3 deletions teamwork/apps/projects/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,17 @@ def setUp(self):
self.user2 = create_user("test2", "test2@test.com", "test2")
self.user3 = create_user("test3", "test3@test.com", "test3")
self.course1 = create_course("course1", "slug1", self.user1)
self.membership1 = create_course_enrollment(self.user1, self.course1, "student")
self.membership2 = create_course_enrollment(self.user2, self.course1, "student")
self.enrollment1 = create_course_enrollment(self.user1, self.course1, "student")
self.enrollment2 = create_course_enrollment(self.user2, self.course1, "student")
self.project1 = create_project(self.user1, self.user1, self.user1, self.course1, "slug1")
self.enrollment1 = create_project_membership(self.user1, self.project1, "invite reason")
self.membership1 = create_project_membership(self.user1, self.project1, "invite reason")
self.client = Client()

# TODO:
def tearDown(self):
pass

# TODO:
def test_add_member(self):
"""
- Successfully add a member
Expand Down

0 comments on commit 39350d0

Please sign in to comment.