Files
edx-platform/lms/djangoapps/teams/tests/test_services.py
Kyle McCormick 151bd13666 Use full names for common.djangoapps imports; warn when using old style (#25477)
* Generate common/djangoapps import shims for LMS
* Generate common/djangoapps import shims for Studio
* Stop appending project root to sys.path
* Stop appending common/djangoapps to sys.path
* Import from common.djangoapps.course_action_state instead of course_action_state
* Import from common.djangoapps.course_modes instead of course_modes
* Import from common.djangoapps.database_fixups instead of database_fixups
* Import from common.djangoapps.edxmako instead of edxmako
* Import from common.djangoapps.entitlements instead of entitlements
* Import from common.djangoapps.pipline_mako instead of pipeline_mako
* Import from common.djangoapps.static_replace instead of static_replace
* Import from common.djangoapps.student instead of student
* Import from common.djangoapps.terrain instead of terrain
* Import from common.djangoapps.third_party_auth instead of third_party_auth
* Import from common.djangoapps.track instead of track
* Import from common.djangoapps.util instead of util
* Import from common.djangoapps.xblock_django instead of xblock_django
* Add empty common/djangoapps/__init__.py to fix pytest collection
* Fix pylint formatting violations
* Exclude import_shims/ directory tree from linting
2020-11-10 07:02:01 -05:00

58 lines
2.0 KiB
Python

# -*- coding: utf-8 -*-
"""
Tests for any Teams app services
"""
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from openedx.core.djangoapps.catalog.tests.factories import CourseRunFactory
from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory
from lms.djangoapps.teams.services import TeamsService
from lms.djangoapps.teams.tests.factories import CourseTeamFactory
class TeamsServiceTests(ModuleStoreTestCase):
""" Tests for the TeamsService """
def setUp(self):
super(TeamsServiceTests, self).setUp()
self.course_run = CourseRunFactory.create()
self.course_key = self.course_run['key']
self.team = CourseTeamFactory.create(course_id=self.course_key)
self.service = TeamsService()
self.user = UserFactory.create()
CourseEnrollmentFactory.create(user=self.user, course_id=self.course_key)
self.team.add_user(self.user)
def test_get_team_by_team_id(self):
team = self.service.get_team_by_team_id('NONEXISTANCE')
self.assertIsNone(team)
team = self.service.get_team_by_team_id(self.team.team_id)
self.assertEqual(team, self.team)
def test_get_team(self):
user_team = self.service.get_team(self.user, self.course_key, self.team.topic_id)
self.assertEqual(user_team, self.team)
user2 = UserFactory.create()
user2_team = self.service.get_team(user2, self.course_key, self.team.topic_id)
self.assertIsNone(user2_team)
def test_get_team_detail_url(self):
# edx.org/courses/blah/teams/#teams/topic_id/team_id
team_detail_url = self.service.get_team_detail_url(self.team)
split_url = team_detail_url.split('/')
self.assertEqual(
split_url[1:],
[
'courses',
str(self.course_run['key']),
'teams',
'#teams',
self.team.topic_id,
self.team.team_id,
]
)