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
2adb03ec
Commit
2adb03ec
authored
Jan 28, 2017
by
Renzo Lucioni
Committed by
GitHub
Jan 28, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #14417 from edx/renzo/update-catalog-factories
Update catalog factories
parents
1e929897
87ff585e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
81 additions
and
54 deletions
+81
-54
openedx/core/djangoapps/catalog/tests/factories.py
+81
-54
No files found.
openedx/core/djangoapps/catalog/tests/factories.py
View file @
2adb03ec
"""Factories for generating fake catalog data."""
from
uuid
import
uuid4
# pylint: disable=missing-docstring, invalid-name
from
random
import
randint
import
factory
from
fa
ctory.fuzzy
import
FuzzyText
from
fa
ker
import
Faker
class
Organization
(
factory
.
Factory
):
"""
Factory for stubbing Organization resources from the catalog API.
"""
class
Meta
(
object
):
model
=
dict
fake
=
Faker
()
name
=
FuzzyText
(
prefix
=
'Organization '
)
key
=
FuzzyText
(
suffix
=
'X'
)
def
generate_course_key
():
return
'+'
.
join
(
fake
.
words
(
2
))
class
CourseRun
(
factory
.
Factory
):
"""
Factory for stubbing CourseRun resources from the catalog API.
"""
class
Meta
(
object
):
model
=
dict
key
=
FuzzyText
(
prefix
=
'org/'
,
suffix
=
'/run'
)
marketing_url
=
FuzzyText
(
prefix
=
'https://www.example.com/marketing/'
)
def
generate_course_run_key
():
return
'course-v1:'
+
'+'
.
join
(
fake
.
words
(
3
)
)
class
Course
(
factory
.
Factory
):
def
generate_zulu_datetime
(
):
"""
Factory for stubbing Course resources from the catalog API.
The catalog returns UTC datetimes formatted using Z, the zone designator
for the zero UTC offset, not the +00:00 offset. For more, see
https://en.wikipedia.org/wiki/ISO_8601#UTC.
"""
return
fake
.
date_time
()
.
isoformat
()
+
'Z'
class
DictFactory
(
factory
.
Factory
):
class
Meta
(
object
):
model
=
dict
title
=
FuzzyText
(
prefix
=
'Course '
)
key
=
FuzzyText
(
prefix
=
'course+'
)
owners
=
[
Organization
()]
course_runs
=
[
CourseRun
()
for
__
in
range
(
3
)]
class
ImageFactory
(
DictFactory
):
height
=
factory
.
Faker
(
'random_int'
)
width
=
factory
.
Faker
(
'random_int'
)
class
BannerImage
(
factory
.
Factory
):
"""
Factory for stubbing BannerImage resources from the catalog API.
class
Image
(
ImageFactory
):
"""
class
Meta
(
object
):
model
=
dict
For constructing dicts mirroring the catalog's serialized representation of ImageFields.
url
=
FuzzyText
(
prefix
=
'https://www.somecdn.com/media/programs/banner_images/'
,
suffix
=
'.jpg'
)
See https://github.com/edx/course-discovery/blob/master/course_discovery/apps/api/fields.py.
"""
description
=
factory
.
Faker
(
'sentence'
)
src
=
factory
.
Faker
(
'image_url'
)
class
Program
(
factory
.
Factory
):
class
StdImage
(
Image
Factory
):
"""
Factory for stubbing Program resources from the catalog API.
For constructing dicts mirroring the catalog's serialized representation of StdImageFields.
See https://github.com/edx/course-discovery/blob/master/course_discovery/apps/api/fields.py.
"""
class
Meta
(
object
):
model
=
dict
url
=
factory
.
Faker
(
'image_url'
)
uuid
=
str
(
uuid4
())
title
=
FuzzyText
(
prefix
=
'Program '
)
subtitle
=
FuzzyText
(
prefix
=
'Subtitle '
)
type
=
'FooBar'
marketing_slug
=
FuzzyText
(
prefix
=
'slug_'
)
authoring_organizations
=
[
Organization
()]
courses
=
[
Course
()
for
__
in
range
(
3
)]
banner_image
=
{
size
:
BannerImage
()
for
size
in
[
'large'
,
'medium'
,
'small'
,
'x-small'
]
def
generate_sized_stdimage
():
return
{
size
:
StdImage
()
for
size
in
[
'large'
,
'medium'
,
'small'
,
'x-small'
]
}
class
ProgramType
(
factory
.
Factory
):
"""
Factory for stubbing ProgramType resources from the catalog API.
"""
class
Meta
(
object
):
model
=
dict
class
Organization
(
DictFactory
):
key
=
factory
.
Faker
(
'word'
)
name
=
factory
.
Faker
(
'company'
)
uuid
=
factory
.
Faker
(
'uuid4'
)
class
CourseRun
(
DictFactory
):
end
=
factory
.
LazyFunction
(
generate_zulu_datetime
)
enrollment_end
=
factory
.
LazyFunction
(
generate_zulu_datetime
)
enrollment_start
=
factory
.
LazyFunction
(
generate_zulu_datetime
)
image
=
Image
()
key
=
factory
.
LazyFunction
(
generate_course_run_key
)
marketing_url
=
factory
.
Faker
(
'url'
)
pacing_type
=
'self_paced'
short_description
=
factory
.
Faker
(
'sentence'
)
start
=
factory
.
LazyFunction
(
generate_zulu_datetime
)
title
=
factory
.
Faker
(
'catch_phrase'
)
type
=
'verified'
uuid
=
factory
.
Faker
(
'uuid4'
)
name
=
FuzzyText
()
logo_image
=
FuzzyText
(
prefix
=
'https://example.com/program/logo'
)
class
Course
(
DictFactory
):
course_runs
=
[
CourseRun
()
for
__
in
range
(
randint
(
3
,
5
))]
image
=
Image
()
key
=
factory
.
LazyFunction
(
generate_course_key
)
owners
=
[
Organization
()]
title
=
factory
.
Faker
(
'catch_phrase'
)
uuid
=
factory
.
Faker
(
'uuid4'
)
class
Program
(
DictFactory
):
authoring_organizations
=
[
Organization
()]
banner_image
=
factory
.
LazyFunction
(
generate_sized_stdimage
)
card_image_url
=
factory
.
Faker
(
'image_url'
)
courses
=
[
Course
()
for
__
in
range
(
randint
(
3
,
5
))]
marketing_slug
=
factory
.
Faker
(
'slug'
)
marketing_url
=
factory
.
Faker
(
'url'
)
status
=
'active'
subtitle
=
factory
.
Faker
(
'sentence'
)
title
=
factory
.
Faker
(
'catch_phrase'
)
type
=
factory
.
Faker
(
'word'
)
uuid
=
factory
.
Faker
(
'uuid4'
)
class
ProgramType
(
DictFactory
):
name
=
factory
.
Faker
(
'word'
)
logo_image
=
factory
.
LazyFunction
(
generate_sized_stdimage
)
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