当前位置: 首页>>代码示例>>Python>>正文


Python BadgeClassFactory.create方法代码示例

本文整理汇总了Python中badges.tests.factories.BadgeClassFactory.create方法的典型用法代码示例。如果您正苦于以下问题:Python BadgeClassFactory.create方法的具体用法?Python BadgeClassFactory.create怎么用?Python BadgeClassFactory.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在badges.tests.factories.BadgeClassFactory的用法示例。


在下文中一共展示了BadgeClassFactory.create方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_get_assertions

# 需要导入模块: from badges.tests.factories import BadgeClassFactory [as 别名]
# 或者: from badges.tests.factories.BadgeClassFactory import create [as 别名]
    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)
开发者ID:zhenzhai,项目名称:edx-platform,代码行数:36,代码来源:tests.py

示例2: test_award

# 需要导入模块: from badges.tests.factories import BadgeClassFactory [as 别名]
# 或者: from badges.tests.factories.BadgeClassFactory import create [as 别名]
 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')
开发者ID:mreyk,项目名称:edx-platform,代码行数:11,代码来源:test_models.py

示例3: test_get_for_user

# 需要导入模块: from badges.tests.factories import BadgeClassFactory [as 别名]
# 或者: from badges.tests.factories.BadgeClassFactory import create [as 别名]
 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])
开发者ID:mreyk,项目名称:edx-platform,代码行数:11,代码来源:test_models.py

示例4: test_assertion_structure

# 需要导入模块: from badges.tests.factories import BadgeClassFactory [as 别名]
# 或者: from badges.tests.factories.BadgeClassFactory import create [as 别名]
 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])
开发者ID:mitocw,项目名称:edx-platform,代码行数:11,代码来源:tests.py

示例5: setUp

# 需要导入模块: from badges.tests.factories import BadgeClassFactory [as 别名]
# 或者: from badges.tests.factories.BadgeClassFactory import create [as 别名]
 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()
开发者ID:edx,项目名称:edx-platform,代码行数:22,代码来源:test_badgr_backend.py

示例6: test_get_badge_class

# 需要导入模块: from badges.tests.factories import BadgeClassFactory [as 别名]
# 或者: from badges.tests.factories.BadgeClassFactory import create [as 别名]
 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)
开发者ID:Lektorium-LLC,项目名称:edx-platform,代码行数:18,代码来源:test_runtime.py

示例7: test_get_badge_class_preexisting

# 需要导入模块: from badges.tests.factories import BadgeClassFactory [as 别名]
# 或者: from badges.tests.factories.BadgeClassFactory import create [as 别名]
 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)
开发者ID:mreyk,项目名称:edx-platform,代码行数:18,代码来源:test_models.py

示例8: test_unique_for_course

# 需要导入模块: from badges.tests.factories import BadgeClassFactory [as 别名]
# 或者: from badges.tests.factories.BadgeClassFactory import create [as 别名]
 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)
开发者ID:mreyk,项目名称:edx-platform,代码行数:19,代码来源:test_models.py

示例9: test_get_assertions

# 需要导入模块: from badges.tests.factories import BadgeClassFactory [as 别名]
# 或者: from badges.tests.factories.BadgeClassFactory import create [as 别名]
 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)
开发者ID:mitocw,项目名称:edx-platform,代码行数:21,代码来源:tests.py


注:本文中的badges.tests.factories.BadgeClassFactory.create方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。