Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
cb2ac424
Commit
cb2ac424
authored
Apr 22, 2016
by
Calen Pennington
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use separate git repos for separate TestCases
parent
3402c657
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
141 additions
and
62 deletions
+141
-62
lms/djangoapps/dashboard/git_import.py
+95
-34
lms/djangoapps/dashboard/management/commands/tests/test_git_add_course.py
+37
-24
lms/djangoapps/dashboard/sysadmin.py
+2
-1
lms/djangoapps/dashboard/tests/test_sysadmin.py
+7
-3
No files found.
lms/djangoapps/dashboard/git_import.py
View file @
cb2ac424
This diff is collapsed.
Click to expand it.
lms/djangoapps/dashboard/management/commands/tests/test_git_add_course.py
View file @
cb2ac424
...
@@ -7,7 +7,7 @@ import shutil
...
@@ -7,7 +7,7 @@ import shutil
import
StringIO
import
StringIO
import
subprocess
import
subprocess
import
unittest
import
unittest
from
uuid
import
uuid4
from
nose.plugins.attrib
import
attr
from
nose.plugins.attrib
import
attr
from
django.conf
import
settings
from
django.conf
import
settings
...
@@ -17,7 +17,14 @@ from django.test.utils import override_settings
...
@@ -17,7 +17,14 @@ from django.test.utils import override_settings
from
opaque_keys.edx.locations
import
SlashSeparatedCourseKey
from
opaque_keys.edx.locations
import
SlashSeparatedCourseKey
import
dashboard.git_import
as
git_import
import
dashboard.git_import
as
git_import
from
dashboard.git_import
import
GitImportError
from
dashboard.git_import
import
(
GitImportError
,
GitImportErrorNoDir
,
GitImportErrorUrlBad
,
GitImportErrorCannotPull
,
GitImportErrorBadRepo
,
GitImportErrorRemoteBranchMissing
,
)
from
xmodule.modulestore
import
ModuleStoreEnum
from
xmodule.modulestore
import
ModuleStoreEnum
from
xmodule.modulestore.django
import
modulestore
from
xmodule.modulestore.django
import
modulestore
from
xmodule.modulestore.tests.django_utils
import
SharedModuleStoreTestCase
from
xmodule.modulestore.tests.django_utils
import
SharedModuleStoreTestCase
...
@@ -37,7 +44,10 @@ FEATURES_WITH_SSL_AUTH['AUTH_USE_CERTIFICATES'] = True
...
@@ -37,7 +44,10 @@ FEATURES_WITH_SSL_AUTH['AUTH_USE_CERTIFICATES'] = True
@attr
(
'shard_3'
)
@attr
(
'shard_3'
)
@override_settings
(
MONGODB_LOG
=
TEST_MONGODB_LOG
)
@override_settings
(
MONGODB_LOG
=
TEST_MONGODB_LOG
,
GIT_REPO_DIR
=
settings
.
TEST_ROOT
/
"course_repos_{}"
.
format
(
uuid4
()
.
hex
)
)
@unittest.skipUnless
(
settings
.
FEATURES
.
get
(
'ENABLE_SYSADMIN_DASHBOARD'
),
@unittest.skipUnless
(
settings
.
FEATURES
.
get
(
'ENABLE_SYSADMIN_DASHBOARD'
),
"ENABLE_SYSADMIN_DASHBOARD not set"
)
"ENABLE_SYSADMIN_DASHBOARD not set"
)
class
TestGitAddCourse
(
SharedModuleStoreTestCase
):
class
TestGitAddCourse
(
SharedModuleStoreTestCase
):
...
@@ -49,10 +59,13 @@ class TestGitAddCourse(SharedModuleStoreTestCase):
...
@@ -49,10 +59,13 @@ class TestGitAddCourse(SharedModuleStoreTestCase):
TEST_COURSE
=
'MITx/edx4edx/edx4edx'
TEST_COURSE
=
'MITx/edx4edx/edx4edx'
TEST_BRANCH
=
'testing_do_not_delete'
TEST_BRANCH
=
'testing_do_not_delete'
TEST_BRANCH_COURSE
=
SlashSeparatedCourseKey
(
'MITx'
,
'edx4edx_branch'
,
'edx4edx'
)
TEST_BRANCH_COURSE
=
SlashSeparatedCourseKey
(
'MITx'
,
'edx4edx_branch'
,
'edx4edx'
)
GIT_REPO_DIR
=
settings
.
GIT_REPO_DIR
ENABLED_CACHES
=
[
'default'
,
'mongo_metadata_inheritance'
,
'loc_cache'
]
ENABLED_CACHES
=
[
'default'
,
'mongo_metadata_inheritance'
,
'loc_cache'
]
def
setUp
(
self
):
super
(
TestGitAddCourse
,
self
)
.
setUp
()
self
.
git_repo_dir
=
settings
.
GIT_REPO_DIR
def
assertCommandFailureRegexp
(
self
,
regex
,
*
args
):
def
assertCommandFailureRegexp
(
self
,
regex
,
*
args
):
"""
"""
Convenience function for testing command failures
Convenience function for testing command failures
...
@@ -72,40 +85,40 @@ class TestGitAddCourse(SharedModuleStoreTestCase):
...
@@ -72,40 +85,40 @@ class TestGitAddCourse(SharedModuleStoreTestCase):
'blah'
,
'blah'
,
'blah'
,
'blah'
)
'blah'
,
'blah'
,
'blah'
,
'blah'
)
# Not a valid path.
# Not a valid path.
self
.
assertCommandFailureRegexp
(
self
.
assertCommandFailureRegexp
(
'Path {0} doesn
\'
t exist, please create it,'
.
format
(
self
.
GIT_REPO_DIR
),
'Path {0} doesn
\'
t exist, please create it,'
.
format
(
self
.
git_repo_dir
),
'blah'
)
'blah'
)
# Test successful import from command
# Test successful import from command
if
not
os
.
path
.
isdir
(
self
.
GIT_REPO_DIR
):
if
not
os
.
path
.
isdir
(
self
.
git_repo_dir
):
os
.
mkdir
(
self
.
GIT_REPO_DIR
)
os
.
mkdir
(
self
.
git_repo_dir
)
self
.
addCleanup
(
shutil
.
rmtree
,
self
.
GIT_REPO_DIR
)
self
.
addCleanup
(
shutil
.
rmtree
,
self
.
git_repo_dir
)
# Make a course dir that will be replaced with a symlink
# Make a course dir that will be replaced with a symlink
# while we are at it.
# while we are at it.
if
not
os
.
path
.
isdir
(
self
.
GIT_REPO_DIR
/
'edx4edx'
):
if
not
os
.
path
.
isdir
(
self
.
git_repo_dir
/
'edx4edx'
):
os
.
mkdir
(
self
.
GIT_REPO_DIR
/
'edx4edx'
)
os
.
mkdir
(
self
.
git_repo_dir
/
'edx4edx'
)
call_command
(
'git_add_course'
,
self
.
TEST_REPO
,
call_command
(
'git_add_course'
,
self
.
TEST_REPO
,
directory_path
=
self
.
GIT_REPO_DIR
/
'edx4edx_lite'
)
directory_path
=
self
.
git_repo_dir
/
'edx4edx_lite'
)
# Test with all three args (branch)
# Test with all three args (branch)
call_command
(
'git_add_course'
,
self
.
TEST_REPO
,
call_command
(
'git_add_course'
,
self
.
TEST_REPO
,
directory_path
=
self
.
GIT_REPO_DIR
/
'edx4edx_lite'
,
directory_path
=
self
.
git_repo_dir
/
'edx4edx_lite'
,
repository_branch
=
self
.
TEST_BRANCH
)
repository_branch
=
self
.
TEST_BRANCH
)
def
test_add_repo
(
self
):
def
test_add_repo
(
self
):
"""
"""
Various exit path tests for test_add_repo
Various exit path tests for test_add_repo
"""
"""
with
self
.
assertRaises
Regexp
(
GitImportError
,
GitImportError
.
NO_DIR
):
with
self
.
assertRaises
(
GitImportErrorNoDir
):
git_import
.
add_repo
(
self
.
TEST_REPO
,
None
,
None
)
git_import
.
add_repo
(
self
.
TEST_REPO
,
None
,
None
)
os
.
mkdir
(
self
.
GIT_REPO_DIR
)
os
.
mkdir
(
self
.
git_repo_dir
)
self
.
addCleanup
(
shutil
.
rmtree
,
self
.
GIT_REPO_DIR
)
self
.
addCleanup
(
shutil
.
rmtree
,
self
.
git_repo_dir
)
with
self
.
assertRaises
Regexp
(
GitImportError
,
GitImportError
.
URL_BAD
):
with
self
.
assertRaises
(
GitImportErrorUrlBad
):
git_import
.
add_repo
(
'foo'
,
None
,
None
)
git_import
.
add_repo
(
'foo'
,
None
,
None
)
with
self
.
assertRaises
Regexp
(
GitImportError
,
GitImportError
.
CANNOT_PULL
):
with
self
.
assertRaises
(
GitImportErrorCannotPull
):
git_import
.
add_repo
(
'file:///foobar.git'
,
None
,
None
)
git_import
.
add_repo
(
'file:///foobar.git'
,
None
,
None
)
# Test git repo that exists, but is "broken"
# Test git repo that exists, but is "broken"
...
@@ -115,14 +128,14 @@ class TestGitAddCourse(SharedModuleStoreTestCase):
...
@@ -115,14 +128,14 @@ class TestGitAddCourse(SharedModuleStoreTestCase):
subprocess
.
check_output
([
'git'
,
'--bare'
,
'init'
,
],
stderr
=
subprocess
.
STDOUT
,
subprocess
.
check_output
([
'git'
,
'--bare'
,
'init'
,
],
stderr
=
subprocess
.
STDOUT
,
cwd
=
bare_repo
)
cwd
=
bare_repo
)
with
self
.
assertRaises
Regexp
(
GitImportError
,
GitImportError
.
BAD_REPO
):
with
self
.
assertRaises
(
GitImportErrorBadRepo
):
git_import
.
add_repo
(
'file://{0}'
.
format
(
bare_repo
),
None
,
None
)
git_import
.
add_repo
(
'file://{0}'
.
format
(
bare_repo
),
None
,
None
)
def
test_detached_repo
(
self
):
def
test_detached_repo
(
self
):
"""
"""
Test repo that is in detached head state.
Test repo that is in detached head state.
"""
"""
repo_dir
=
self
.
GIT_REPO_DIR
repo_dir
=
self
.
git_repo_dir
# Test successful import from command
# Test successful import from command
try
:
try
:
os
.
mkdir
(
repo_dir
)
os
.
mkdir
(
repo_dir
)
...
@@ -133,21 +146,21 @@ class TestGitAddCourse(SharedModuleStoreTestCase):
...
@@ -133,21 +146,21 @@ class TestGitAddCourse(SharedModuleStoreTestCase):
subprocess
.
check_output
([
'git'
,
'checkout'
,
'HEAD~2'
,
],
subprocess
.
check_output
([
'git'
,
'checkout'
,
'HEAD~2'
,
],
stderr
=
subprocess
.
STDOUT
,
stderr
=
subprocess
.
STDOUT
,
cwd
=
repo_dir
/
'edx4edx_lite'
)
cwd
=
repo_dir
/
'edx4edx_lite'
)
with
self
.
assertRaises
Regexp
(
GitImportError
,
GitImportError
.
CANNOT_PULL
):
with
self
.
assertRaises
(
GitImportErrorCannotPull
):
git_import
.
add_repo
(
self
.
TEST_REPO
,
repo_dir
/
'edx4edx_lite'
,
None
)
git_import
.
add_repo
(
self
.
TEST_REPO
,
repo_dir
/
'edx4edx_lite'
,
None
)
def
test_branching
(
self
):
def
test_branching
(
self
):
"""
"""
Exercise branching code of import
Exercise branching code of import
"""
"""
repo_dir
=
self
.
GIT_REPO_DIR
repo_dir
=
self
.
git_repo_dir
# Test successful import from command
# Test successful import from command
if
not
os
.
path
.
isdir
(
repo_dir
):
if
not
os
.
path
.
isdir
(
repo_dir
):
os
.
mkdir
(
repo_dir
)
os
.
mkdir
(
repo_dir
)
self
.
addCleanup
(
shutil
.
rmtree
,
repo_dir
)
self
.
addCleanup
(
shutil
.
rmtree
,
repo_dir
)
# Checkout non existent branch
# Checkout non existent branch
with
self
.
assertRaises
Regexp
(
GitImportError
,
GitImportError
.
REMOTE_BRANCH_MISSING
):
with
self
.
assertRaises
(
GitImportErrorRemoteBranchMissing
):
git_import
.
add_repo
(
self
.
TEST_REPO
,
repo_dir
/
'edx4edx_lite'
,
'asdfasdfasdf'
)
git_import
.
add_repo
(
self
.
TEST_REPO
,
repo_dir
/
'edx4edx_lite'
,
'asdfasdfasdf'
)
# Checkout new branch
# Checkout new branch
...
@@ -185,13 +198,13 @@ class TestGitAddCourse(SharedModuleStoreTestCase):
...
@@ -185,13 +198,13 @@ class TestGitAddCourse(SharedModuleStoreTestCase):
cwd
=
bare_repo
)
cwd
=
bare_repo
)
# Build repo dir
# Build repo dir
repo_dir
=
self
.
GIT_REPO_DIR
repo_dir
=
self
.
git_repo_dir
if
not
os
.
path
.
isdir
(
repo_dir
):
if
not
os
.
path
.
isdir
(
repo_dir
):
os
.
mkdir
(
repo_dir
)
os
.
mkdir
(
repo_dir
)
self
.
addCleanup
(
shutil
.
rmtree
,
repo_dir
)
self
.
addCleanup
(
shutil
.
rmtree
,
repo_dir
)
rdir
=
'{0}/bare'
.
format
(
repo_dir
)
rdir
=
'{0}/bare'
.
format
(
repo_dir
)
with
self
.
assertRaises
Regexp
(
GitImportError
,
GitImportError
.
BAD_REPO
):
with
self
.
assertRaises
(
GitImportErrorBadRepo
):
git_import
.
add_repo
(
'file://{0}'
.
format
(
bare_repo
),
None
,
None
)
git_import
.
add_repo
(
'file://{0}'
.
format
(
bare_repo
),
None
,
None
)
# Get logger for checking strings in logs
# Get logger for checking strings in logs
...
...
lms/djangoapps/dashboard/sysadmin.py
View file @
cb2ac424
...
@@ -346,7 +346,8 @@ class Courses(SysadminDashboardView):
...
@@ -346,7 +346,8 @@ class Courses(SysadminDashboardView):
# Try the data dir, then try to find it in the git import dir
# Try the data dir, then try to find it in the git import dir
if
not
gdir
.
exists
():
if
not
gdir
.
exists
():
gdir
=
path
(
git_import
.
GIT_REPO_DIR
)
/
cdir
git_repo_dir
=
getattr
(
settings
,
'GIT_REPO_DIR'
,
git_import
.
DEFAULT_GIT_REPO_DIR
)
gdir
=
path
(
git_repo_dir
/
cdir
)
if
not
gdir
.
exists
():
if
not
gdir
.
exists
():
return
info
return
info
...
...
lms/djangoapps/dashboard/tests/test_sysadmin.py
View file @
cb2ac424
...
@@ -6,6 +6,7 @@ import os
...
@@ -6,6 +6,7 @@ import os
import
re
import
re
import
shutil
import
shutil
import
unittest
import
unittest
from
uuid
import
uuid4
from
util.date_utils
import
get_time_display
,
DEFAULT_DATE_TIME_FORMAT
from
util.date_utils
import
get_time_display
,
DEFAULT_DATE_TIME_FORMAT
from
nose.plugins.attrib
import
attr
from
nose.plugins.attrib
import
attr
...
@@ -18,7 +19,7 @@ import mongoengine
...
@@ -18,7 +19,7 @@ import mongoengine
from
opaque_keys.edx.locations
import
SlashSeparatedCourseKey
from
opaque_keys.edx.locations
import
SlashSeparatedCourseKey
from
dashboard.models
import
CourseImportLog
from
dashboard.models
import
CourseImportLog
from
dashboard.git_import
import
GitImportError
from
dashboard.git_import
import
GitImportError
NoDir
from
datetime
import
datetime
from
datetime
import
datetime
from
student.roles
import
CourseStaffRole
,
GlobalStaff
from
student.roles
import
CourseStaffRole
,
GlobalStaff
from
student.tests.factories
import
UserFactory
from
student.tests.factories
import
UserFactory
...
@@ -109,7 +110,10 @@ class SysadminBaseTestCase(SharedModuleStoreTestCase):
...
@@ -109,7 +110,10 @@ class SysadminBaseTestCase(SharedModuleStoreTestCase):
@attr
(
'shard_1'
)
@attr
(
'shard_1'
)
@override_settings
(
MONGODB_LOG
=
TEST_MONGODB_LOG
)
@override_settings
(
MONGODB_LOG
=
TEST_MONGODB_LOG
,
GIT_REPO_DIR
=
settings
.
TEST_ROOT
/
"course_repos_{}"
.
format
(
uuid4
()
.
hex
)
)
@unittest.skipUnless
(
settings
.
FEATURES
.
get
(
'ENABLE_SYSADMIN_DASHBOARD'
),
@unittest.skipUnless
(
settings
.
FEATURES
.
get
(
'ENABLE_SYSADMIN_DASHBOARD'
),
"ENABLE_SYSADMIN_DASHBOARD not set"
)
"ENABLE_SYSADMIN_DASHBOARD not set"
)
class
TestSysAdminMongoCourseImport
(
SysadminBaseTestCase
):
class
TestSysAdminMongoCourseImport
(
SysadminBaseTestCase
):
...
@@ -149,7 +153,7 @@ class TestSysAdminMongoCourseImport(SysadminBaseTestCase):
...
@@ -149,7 +153,7 @@ class TestSysAdminMongoCourseImport(SysadminBaseTestCase):
# Create git loaded course
# Create git loaded course
response
=
self
.
_add_edx4edx
()
response
=
self
.
_add_edx4edx
()
self
.
assertIn
(
GitImportError
.
NO_DIR
,
self
.
assertIn
(
GitImportError
NoDir
(
settings
.
GIT_REPO_DIR
)
.
message
,
response
.
content
.
decode
(
'UTF-8'
))
response
.
content
.
decode
(
'UTF-8'
))
def
test_mongo_course_add_delete
(
self
):
def
test_mongo_course_add_delete
(
self
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment