本文整理汇总了Python中badges.tests.factories.BadgeClassFactory类的典型用法代码示例。如果您正苦于以下问题:Python BadgeClassFactory类的具体用法?Python BadgeClassFactory怎么用?Python BadgeClassFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BadgeClassFactory类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_assertions
def test_get_assertions(self, check_course, wildcard):
"""
Verify we can get assertions via the badge class and username.
"""
badge_class = self.create_badge_class(check_course)
for dummy in range(3):
BadgeAssertionFactory.create(user=self.user, badge_class=badge_class)
if badge_class.course_id:
# Also create a version of this badge under a different course.
alt_class = BadgeClassFactory.create(
slug=badge_class.slug,
issuing_component=badge_class.issuing_component,
course_id=CourseFactory.create().location.course_key,
)
BadgeAssertionFactory.create(user=self.user, badge_class=alt_class)
# Same badge class, but different user. Should not show up in the list.
for dummy in range(5):
BadgeAssertionFactory.create(badge_class=badge_class)
# Different badge class AND different user. Certainly shouldn't show up in the list!
for dummy in range(6):
BadgeAssertionFactory.create()
response = self.get_json(self.url(), data=self.get_qs_args(check_course, wildcard, badge_class))
if wildcard:
expected_length = 4
else:
expected_length = 3
# pylint: disable=no-member
self.assertEqual(len(response["results"]), expected_length)
unused_class = self.create_badge_class(check_course, slug="unused_slug", issuing_component="unused_component")
response = self.get_json(self.url(), data=self.get_qs_args(check_course, wildcard, unused_class))
# pylint: disable=no-member
self.assertEqual(len(response["results"]), 0)
示例2: test_award
def test_award(self, mock_award):
"""
Verify that the award command calls the award function on the backend with the right parameters.
"""
user = UserFactory.create()
badge_class = BadgeClassFactory.create()
badge_class.award(user, evidence_url='http://example.com/evidence')
self.assertTrue(mock_award.called)
mock_award.assert_called_with(badge_class, user, evidence_url='http://example.com/evidence')
示例3: test_get_for_user
def test_get_for_user(self):
"""
Make sure we can get an assertion for a user if there is one.
"""
user = UserFactory.create()
badge_class = BadgeClassFactory.create()
self.assertFalse(badge_class.get_for_user(user))
assertion = BadgeAssertionFactory.create(badge_class=badge_class, user=user)
self.assertEqual(list(badge_class.get_for_user(user)), [assertion])
示例4: test_assertion_structure
def test_assertion_structure(self):
"""
Verify the badge assertion structure is as expected when a course is involved.
"""
course_key = self.course.location.course_key
badge_class = BadgeClassFactory.create(course_id=course_key)
assertion = BadgeAssertionFactory.create(badge_class=badge_class, user=self.user)
response = self.get_json(self.url())
self.check_assertion_structure(assertion, response['results'][0])
示例5: setUp
def setUp(self):
"""
Create a course and user to test with.
"""
super(BadgrBackendTestCase, self).setUp()
# Need key to be deterministic to test slugs.
self.course = CourseFactory.create(
org='edX', course='course_test', run='test_run', display_name='Badged',
start=datetime(year=2015, month=5, day=19),
end=datetime(year=2015, month=5, day=20)
)
self.user = UserFactory.create(email='[email protected]')
CourseEnrollmentFactory.create(user=self.user, course_id=self.course.location.course_key, mode='honor')
# Need to empty this on each run.
BadgrBackend.badges = []
self.badge_class = BadgeClassFactory.create(course_id=self.course.location.course_key)
self.legacy_badge_class = BadgeClassFactory.create(
course_id=self.course.location.course_key, issuing_component=''
)
self.no_course_badge_class = BadgeClassFactory.create()
示例6: test_get_badge_class
def test_get_badge_class(self):
runtime = self.create_runtime()
badge_service = runtime.service(self.mock_block, 'badging')
premade_badge_class = BadgeClassFactory.create()
# Ignore additional parameters. This class already exists.
# We should get back the first class we created, rather than a new one.
badge_class = badge_service.get_badge_class(
slug='test_slug', issuing_component='test_component', description='Attempted override',
criteria='test', display_name='Testola', image_file_handle=get_image('good')
)
# These defaults are set on the factory.
self.assertEqual(badge_class.criteria, 'https://example.com/syllabus')
self.assertEqual(badge_class.display_name, 'Test Badge')
self.assertEqual(badge_class.description, "Yay! It's a test badge.")
# File name won't always be the same.
self.assertEqual(badge_class.image.path, premade_badge_class.image.path)
示例7: test_get_badge_class_preexisting
def test_get_badge_class_preexisting(self):
"""
Verify fetching a badge first grabs existing badges.
"""
premade_badge_class = BadgeClassFactory.create()
# Ignore additional parameters. This class already exists.
badge_class = BadgeClass.get_badge_class(
slug='test_slug', issuing_component='test_component', description='Attempted override',
criteria='test', display_name='Testola', image_file_handle=get_image('good')
)
# These defaults are set on the factory.
self.assertEqual(badge_class.criteria, 'https://example.com/syllabus')
self.assertEqual(badge_class.display_name, 'Test Badge')
self.assertEqual(badge_class.description, "Yay! It's a test badge.")
# File name won't always be the same.
self.assertEqual(badge_class.image.path, premade_badge_class.image.path)
示例8: test_unique_for_course
def test_unique_for_course(self):
"""
Verify that the course_id is used in fetching existing badges or creating new ones.
"""
course_key = CourseFactory.create().location.course_key
premade_badge_class = BadgeClassFactory.create(course_id=course_key)
badge_class = BadgeClass.get_badge_class(
slug='test_slug', issuing_component='test_component', description='Attempted override',
criteria='test', display_name='Testola', image_file_handle=get_image('good')
)
course_badge_class = BadgeClass.get_badge_class(
slug='test_slug', issuing_component='test_component', description='Attempted override',
criteria='test', display_name='Testola', image_file_handle=get_image('good'),
course_id=course_key,
)
self.assertNotEqual(badge_class.id, course_badge_class.id)
self.assertEqual(course_badge_class.id, premade_badge_class.id)
示例9: test_get_assertions
def test_get_assertions(self):
"""
Verify we can get assertions via the course_id and username.
"""
course_key = self.course.location.course_key
badge_class = BadgeClassFactory.create(course_id=course_key)
for dummy in range(3):
BadgeAssertionFactory.create(user=self.user, badge_class=badge_class)
# Should not be included, as they don't share the target badge class.
for dummy in range(3):
BadgeAssertionFactory.create(user=self.user)
# Also should not be included, as they don't share the same user.
for dummy in range(6):
BadgeAssertionFactory.create(badge_class=badge_class)
response = self.get_json(self.url(), data={'course_id': course_key})
self.assertEqual(len(response['results']), 3)
unused_course = CourseFactory.create()
response = self.get_json(self.url(), data={'course_id': unused_course.location.course_key})
self.assertEqual(len(response['results']), 0)