Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
configuration
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
configuration
Commits
8c50ea7d
Commit
8c50ea7d
authored
Aug 18, 2017
by
Shirley He
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix up tests
parent
c27687f8
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
221 additions
and
36 deletions
+221
-36
tests/test_generate_permutations.py
+0
-34
util/course_permutation_tool/README.rst
+0
-0
util/course_permutation_tool/generate_permutations.py
+22
-2
util/course_permutation_tool/permutations.json
+0
-0
util/course_permutation_tool/test_generate_permutations.py
+199
-0
No files found.
tests/test_generate_permutations.py
deleted
100644 → 0
View file @
c27687f8
"""
Unittests for generating permutations file
"""
import
unittest
from
generate_permutations
import
arg_parse
import
sys
class
TestArgParsing
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
parser
=
arg_parse
()
"""
If no arguments passed, should fail with SystemExit
"""
def
test_no_args
(
self
):
with
self
.
assertRaises
(
SystemExit
):
self
.
parser
.
parse_args
([])
def
test_invalid_num_fields
(
self
):
args
=
self
.
parser
.
parse_args
([
'start'
,
'end'
,
'display_name'
,
'mobile_available'
])
command_error
=
"Only a max of 3 fields allowed"
self
.
assertEqual
(
args
,
command_error
)
def
test_invalid_file
(
self
):
sys
.
argv
[
1
:]
=
[
"--seed_data_file"
,
"permutation.json"
]
options
=
arg_parse
()
self
.
assertEquals
(
"permutation.json"
,
options
)
if
__name__
==
'__main__'
:
unittest
.
main
()
util/course
-permutation-
tool/README.rst
→
util/course
_permutation_
tool/README.rst
View file @
8c50ea7d
File moved
util/course
-permutation-
tool/generate_permutations.py
→
util/course
_permutation_
tool/generate_permutations.py
View file @
8c50ea7d
...
...
@@ -36,6 +36,13 @@ def arg_parse():
def
process_field_arguments
(
parser_args
):
"""
Processes field arguments and prepares them for the permutation generator. Prepares
non-field arguments for the generator, as well
Input:
parser_args: the set of command line arguments typed in by the user
"""
try
:
file
=
open
(
parser_args
.
seed_data_file
)
file_data
=
json
.
load
(
file
)
...
...
@@ -78,6 +85,17 @@ def process_field_arguments(parser_args):
def
generate_permutations
(
field_args
,
index
,
results
,
courses_dict
,
field_values_dict
):
"""
Returns a dictionary of course permutation objects. Adds default values to the dict,
and recurses over the array attached to each field to create combinations
Input:
field_args: a dictionary of all the default & permutation fields that will be included in each course
index: iterator for each element in the list of field_args keys
results: the list of all permutation objects
courses_dict: dictionary used to separate "fields" and "enrollment" into different objects
field_values_dict: dictionary to hold each field value iteration result
"""
all_permutations_keys
=
field_args
.
keys
()
permutation_option
=
all_permutations_keys
[
index
]
permutations_values
=
field_args
[
permutation_option
]
...
...
@@ -150,9 +168,11 @@ def calculate_date_value(date_const):
def
start_field_recursion
(
process_field_args
):
return
generate_permutations
(
process_field_args
,
0
,
[],
{},
{})
if
__name__
==
"__main__"
:
def
main
():
args
=
arg_parse
()
process_field_args
=
process_field_arguments
(
args
)
json_file
=
start_field_recursion
(
process_field_args
)
create_courses_json_file
(
json_file
)
if
__name__
==
"__main__"
:
main
()
util/course
-permutation-
tool/permutations.json
→
util/course
_permutation_
tool/permutations.json
View file @
8c50ea7d
File moved
util/course_permutation_tool/test_generate_permutations.py
0 → 100644
View file @
8c50ea7d
"""
Unittests for generating permutations file
"""
import
unittest
import
generate_permutations
class
TestGeneratePermutations
(
unittest
.
TestCase
):
def
test_start_field_recursion
(
self
):
# test display_name permutation
process_field_args
=
{
"audit"
:
[
True
],
"end"
:
[
"future"
],
"mobile_available"
:
[
True
],
"verified"
:
[
True
],
"start"
:
[
"past"
],
"display_name"
:
[
"International Project Management"
,
"Cybersecurity Fundamentals"
,
""
,
None
]}
actual_output
=
generate_permutations
.
start_field_recursion
(
process_field_args
)
expected_output
=
{
"courses"
:
[
{
"partner"
:
"edx"
,
"run"
:
"3T2017"
,
"user"
:
"edx@example.com"
,
"organization"
:
"RITX"
,
"fields"
:
{
"audit"
:
True
,
"start"
:
"2017-06-19 14:07:40.835573+00:00"
,
"verified"
:
True
,
"end"
:
"2018-08-18 14:07:40.835529+00:00"
,
"mobile_available"
:
True
,
"display_name"
:
"International Project Management"
},
"enrollment"
:
{
"credit-provider"
:
"test-credit-provider"
,
"credit"
:
False
},
"number"
:
None
},
{
"partner"
:
"edx"
,
"run"
:
"3T2017"
,
"user"
:
"edx@example.com"
,
"organization"
:
"RITX"
,
"fields"
:
{
"audit"
:
True
,
"start"
:
"2017-06-19 14:07:40.835573+00:00"
,
"verified"
:
True
,
"end"
:
"2018-08-18 14:07:40.835529+00:00"
,
"mobile_available"
:
True
,
"display_name"
:
"Cybersecurity Fundamentals"
},
"enrollment"
:
{
"credit-provider"
:
"test-credit-provider"
,
"credit"
:
False
},
"number"
:
None
},
{
"partner"
:
"edx"
,
"run"
:
"3T2017"
,
"user"
:
"edx@example.com"
,
"organization"
:
"RITX"
,
"fields"
:
{
"audit"
:
True
,
"start"
:
"2017-06-19 14:07:40.835573+00:00"
,
"verified"
:
True
,
"end"
:
"2018-08-18 14:07:40.835529+00:00"
,
"mobile_available"
:
True
,
"display_name"
:
""
},
"enrollment"
:
{
"credit-provider"
:
"test-credit-provider"
,
"credit"
:
False
},
"number"
:
None
},
{
"partner"
:
"edx"
,
"run"
:
"3T2017"
,
"user"
:
"edx@example.com"
,
"organization"
:
"RITX"
,
"fields"
:
{
"audit"
:
True
,
"start"
:
"2017-06-19 14:07:40.835573+00:00"
,
"verified"
:
True
,
"end"
:
"2018-08-18 14:07:40.835529+00:00"
,
"mobile_available"
:
True
,
"display_name"
:
None
},
"enrollment"
:
{
"credit-provider"
:
"test-credit-provider"
,
"credit"
:
False
},
"number"
:
None
},
{
"partner"
:
"edx"
,
"run"
:
"3T2017"
,
"user"
:
"edx@example.com"
,
"organization"
:
"RITX"
,
"fields"
:
{
"audit"
:
True
,
"start"
:
"2017-06-19 14:07:40.835573+00:00"
,
"verified"
:
True
,
"end"
:
"2018-08-18 14:07:40.835529+00:00"
,
"mobile_available"
:
True
,
"display_name"
:
None
},
"enrollment"
:
{
"credit-provider"
:
"test-credit-provider"
,
"credit"
:
False
},
"number"
:
None
},
{
"partner"
:
"edx"
,
"run"
:
"3T2017"
,
"user"
:
"edx@example.com"
,
"organization"
:
"RITX"
,
"fields"
:
{
"audit"
:
True
,
"start"
:
"2017-06-19 14:07:40.835573+00:00"
,
"verified"
:
True
,
"end"
:
"2018-08-18 14:07:40.835529+00:00"
,
"mobile_available"
:
True
,
"display_name"
:
None
},
"enrollment"
:
{
"credit-provider"
:
"test-credit-provider"
,
"credit"
:
False
,
"audit"
:
True
},
"number"
:
None
},
{
"partner"
:
"edx"
,
"run"
:
"3T2017"
,
"user"
:
"edx@example.com"
,
"organization"
:
"RITX"
,
"fields"
:
{
"audit"
:
True
,
"start"
:
"2017-06-19 14:07:40.835573+00:00"
,
"verified"
:
True
,
"end"
:
"2018-08-18 14:07:40.835529+00:00"
,
"mobile_available"
:
True
,
"display_name"
:
None
},
"enrollment"
:
{
"credit-provider"
:
"test-credit-provider"
,
"credit"
:
False
,
"audit"
:
True
},
"number"
:
None
},
{
"partner"
:
"edx"
,
"run"
:
"3T2017"
,
"user"
:
"edx@example.com"
,
"organization"
:
"RITX"
,
"fields"
:
{
"audit"
:
True
,
"start"
:
"2017-06-19 14:07:40.835573+00:00"
,
"verified"
:
True
,
"end"
:
"2018-08-18 14:07:40.835529+00:00"
,
"mobile_available"
:
True
,
"display_name"
:
None
},
"enrollment"
:
{
"credit-provider"
:
"test-credit-provider"
,
"credit"
:
False
},
"number"
:
None
},
{
"partner"
:
"edx"
,
"run"
:
"3T2017"
,
"user"
:
"edx@example.com"
,
"organization"
:
"RITX"
,
"fields"
:
{
"audit"
:
True
,
"start"
:
"2017-06-19 14:07:40.835573+00:00"
,
"verified"
:
True
,
"end"
:
"2018-08-18 14:07:40.835529+00:00"
,
"mobile_available"
:
True
,
"display_name"
:
None
},
"enrollment"
:
{
"credit-provider"
:
"test-credit-provider"
,
"credit"
:
False
,
"audit"
:
True
},
"number"
:
None
}
]
}
self
.
assertEquals
(
actual_output
,
expected_output
)
if
__name__
==
'__main__'
:
unittest
.
main
()
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