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


Python UserFactory.create方法代码示例

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


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

示例1: test_user_submit

# 需要导入模块: from brouwers.users.tests.factories import UserFactory [as 别名]
# 或者: from brouwers.users.tests.factories.UserFactory import create [as 别名]
    def test_user_submit(self):
        """ Test that the user can submit the concept """
        user1 = UserFactory.create()
        user2 = UserFactory.create()

        groupbuild = GroupBuildFactory.create(status=GroupbuildStatuses.concept)
        groupbuild.admins.add(user1, groupbuild.applicant)
        self.assertEqual(groupbuild.admins.count(), 2)

        # test that user2 cannot submit the groupbuilds
        self.client.login(username=user2.username, password='password')
        url = reverse('groupbuilds:submit', kwargs={'slug': groupbuild.slug})
        response = self.client.get(url)
        self.assertEquals(response.status_code, 404)
        self.client.logout

        self.client.login(username=user1, password='password')
        url = reverse('groupbuilds:submit', kwargs={'slug': groupbuild.slug})
        response = self.client.get(url)
        self.assertEquals(response.status_code, 200)

        response = self.client.post(url)
        self.assertEquals(response.status_code, 302)
        groupbuild = GroupBuild.objects.get(slug=groupbuild.slug)
        self.assertEquals(groupbuild.status, GroupbuildStatuses.submitted)
开发者ID:modelbrouwers,项目名称:modelbrouwers,代码行数:27,代码来源:test_flow.py

示例2: setUp

# 需要导入模块: from brouwers.users.tests.factories import UserFactory [as 别名]
# 或者: from brouwers.users.tests.factories.UserFactory import create [as 别名]
    def setUp(self):
        super(SearchTests, self).setUp()
        self.user1 = UserFactory.create(username='BBT')
        self.user2 = UserFactory.create(username='hanjos')

        self.builds_user1 = [
            BuildFactory.create(title='Sopwith Triplane', user=self.user1),
            BuildFactory.create(title='Honda McJugen', user=self.user1)
        ]
        self.builds_user2 = [
            BuildFactory.create(title='Monogram 4wheel drive', user=self.user2),
        ]
        self.url = reverse('api:builds:search')
开发者ID:modelbrouwers,项目名称:modelbrouwers,代码行数:15,代码来源:test_api.py

示例3: setUp

# 需要导入模块: from brouwers.users.tests.factories import UserFactory [as 别名]
# 或者: from brouwers.users.tests.factories.UserFactory import create [as 别名]
    def setUp(self):
        # user - forumuser linked by id
        self.user = UserFactory.create()
        self.forum_user = ForumUserFactory.create(username=self.user.username)
        self.user.forumuser_id = self.forum_user.pk
        self.user.save()

        # user -forumuser linked by username
        self.user2 = UserFactory.create()
        self.forum_user2 = ForumUserFactory.create(username=self.user2.username)

        # forum user without user
        self.forum_user3 = ForumUserFactory.create()
开发者ID:modelbrouwers,项目名称:modelbrouwers,代码行数:15,代码来源:test_views.py

示例4: test_submit_review_with_topic

# 需要导入模块: from brouwers.users.tests.factories import UserFactory [as 别名]
# 或者: from brouwers.users.tests.factories.UserFactory import create [as 别名]
    def test_submit_review_with_topic(self):
        """
        Assert that only the relevant topics are listed.
        """
        kit = ModelKitFactory.create()
        user = UserFactory.create()
        forum_user = ForumUserFactory.create(username=user.username)
        user.forumuser_id = forum_user.pk
        user.save()

        topic1 = TopicFactory.create()
        topic2 = TopicFactory.create(author=forum_user)


        url = reverse('kitreviews:review-add', kwargs={'slug': kit.slug})
        add_page = self.app.get(url, user=user)

        # non-authored topics may not be shown
        with self.assertRaisesRegexp(ValueError, r'^Option %s not found \(from' % topic1.pk):
            add_page.form['topic'].select(topic1.pk)
        add_page.form['topic'].select(topic2.pk)
        add_page.form['raw_text'] = 'Dummy review'
        response = add_page.form.submit().follow()

        review = KitReview.objects.get()
        self.assertEqual(review.topic, topic2)
开发者ID:modelbrouwers,项目名称:modelbrouwers,代码行数:28,代码来源:test_views.py

示例5: test_dashboard

# 需要导入模块: from brouwers.users.tests.factories import UserFactory [as 别名]
# 或者: from brouwers.users.tests.factories.UserFactory import create [as 别名]
 def test_dashboard(self):
     """
     Test that the admin dashboard works as expected.
     """
     superuser = UserFactory.create(is_superuser=True, is_staff=True)
     admin = self.app.get(reverse('admin:index'), user=superuser)
     self.assertEqual(admin.status_code, 200)
开发者ID:modelbrouwers,项目名称:modelbrouwers,代码行数:9,代码来源:test_dashboard.py

示例6: test_anonymous_add_kit

# 需要导入模块: from brouwers.users.tests.factories import UserFactory [as 别名]
# 或者: from brouwers.users.tests.factories.UserFactory import create [as 别名]
    def test_anonymous_add_kit(self):
        """
        When not logged in, you may not get the popup to add a kit, but you must
        be presented with a login button.
        """
        # search by brand
        search_page = self.app.get(self.url)
        search_page.form['kit_name'] = 'gibberish'
        search_results = search_page.form.submit()
        queryset = search_results.context['kits']
        self.assertFalse(queryset.exists())

        search_url = search_results.request.url

        self.assertEqual(len(search_results.forms), 2)
        login_form = search_results.forms[1]
        self.assertEqual(login_form.action, reverse('users:login'))
        login_page = login_form.submit()

        user = UserFactory.create(password='letmein')
        login_page.form['username'] = user.username
        login_page.form['password'] = 'letmein'
        search_results = login_page.form.submit().follow()
        self.assertEqual(search_results.request.url, search_url)
        self.assertContains(search_results, _('Add kit'))
开发者ID:modelbrouwers,项目名称:modelbrouwers,代码行数:27,代码来源:test_views.py

示例7: test_preferences

# 需要导入模块: from brouwers.users.tests.factories import UserFactory [as 别名]
# 或者: from brouwers.users.tests.factories.UserFactory import create [as 别名]
    def test_preferences(self):
        """
        Ensure we can retrieve the album preferences.
        """
        url = reverse('api:preferences-list')
        url_detail = reverse('api:preferences-detail', kwargs={'pk': 'self'})

        # anonymous
        response = self.client.get(url)
        self.assertEqual(response.data, [])
        response = self.client.get(url_detail)
        self.assertEqual(response.data, PreferencesSerializer(Preferences()).data)

        # authenticated
        self.client.login(username=self.user.username, password='password')
        response = self.client.get(url_detail)
        self.assertEqual(response.data['id'], self.user.preferences.id)
        self.assertEqual(response.data['user'], self.user.pk)

        user2 = UserFactory.create()
        Preferences.objects.get_for(user2)

        self.assertEqual(Preferences.objects.count(), 2)
        response = self.client.get(url)
        self.assertEqual(len(response.data), 1)
        self.assertEqual(response.data[0]['id'], self.user.preferences.id)
开发者ID:Clarity-89,项目名称:modelbrouwers,代码行数:28,代码来源:test_my_preferences.py

示例8: test_update_photo

# 需要导入模块: from brouwers.users.tests.factories import UserFactory [as 别名]
# 或者: from brouwers.users.tests.factories.UserFactory import create [as 别名]
    def test_update_photo(self):
        albums = AlbumFactory.create_batch(2, user=self.user)
        photo = PhotoFactory.create(
            user=self.user, description='Initial description',
            album=albums[0]
        )
        url_update = reverse('albums:photo_update', kwargs={'pk': photo.pk})

        # anonymous user
        album_page = self.app.get(photo.album.get_absolute_url(), status=200)
        self.assertNotContains(album_page, url_update)
        detail_page = self.app.get(photo.get_absolute_url(), status=200)
        self.assertNotContains(detail_page, url_update)
        # try it anyway
        update_page = self.app.get(url_update)
        expected_redirect = u'%s?next=%s' % (settings.LOGIN_URL, url_update)
        self.assertRedirects(update_page, expected_redirect)

        # other user
        other_user = UserFactory.create()
        self.assertNotEqual(photo.user, other_user)
        update_page = self.app.get(url_update, user=other_user, status=404)

        # photo owner
        update_page = self.app.get(url_update, user=self.user, status=200)
        update_page.form['description'] = 'New description'
        update_page.form['album'] = [str(albums[1].pk)]
        update_page.form.submit().follow()

        photo = Photo.objects.get(pk=photo.pk)
        self.assertEqual(photo.description, 'New description')
        self.assertEqual(photo.album, albums[1])
开发者ID:modelbrouwers,项目名称:modelbrouwers,代码行数:34,代码来源:test_views.py

示例9: test_gb_participant_check

# 需要导入模块: from brouwers.users.tests.factories import UserFactory [as 别名]
# 或者: from brouwers.users.tests.factories.UserFactory import create [as 别名]
    def test_gb_participant_check(self):
        """
        Test that the check returns the expected data.
        """
        user = UserFactory.create()
        self.client.login(username=user.username, password='password')
        forums = ForumFactory.create_batch(2)
        gb = GroupBuildFactory.create(status=GroupbuildStatuses.accepted,
                                      forum_id=forums[0].pk)

        five_min_ago = int((timezone.now() - timedelta(minutes=5)).strftime("%s"))
        topic1 = TopicFactory.create(forum=forums[0], create_time=five_min_ago)
        topic2 = TopicFactory.create(forum=forums[0])

        ParticipantFactory.create(
            groupbuild=gb, topic_id=topic1.pk, user=user)

        endpoint = reverse('api:groupbuilds:participant-check')

        invalid_data = {'forum_id': 'abcd', 'topic_id': topic1.pk}
        response = self.client.get(endpoint, invalid_data)
        self.assertEqual(response.status_code, 400)
        self.assertDictEqual(response.data, {'error': 'Bad query parameters'})

        # check with existing topic (created > 3 min ago)
        valid_data = {'forum_id': forums[0].pk, 'topic_id': topic1.pk}
        response = self.client.get(endpoint, valid_data)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.data, {'topic_created': False})

        # check with new topic
        valid_data['topic_id'] = topic2.pk
        response = self.client.get(endpoint, valid_data)
        self.assertEqual(response.status_code, 200)
        self.assertTrue(response.data['topic_created'])
        self.assertEqual(response.data['groupbuild']['id'], gb.pk)

        # test irrelevant forum
        valid_data['forum_id'] = forums[1].pk
        response = self.client.get(endpoint, valid_data)
        self.assertEqual(response.status_code, 200)
        self.assertFalse(response.data['topic_created'])

        topic3 = TopicFactory.create(
            forum=forums[0], topic_title='my wonderful model')
        participant = ParticipantFactory.create(
            groupbuild=gb, model_name='My model', user=user)
        valid_data['topic_id'] = topic3.pk
        valid_data['forum_id'] = forums[0].pk
        response = self.client.get(endpoint, valid_data)
        self.assertEqual(response.status_code, 200)
        self.assertTrue(response.data['topic_created'])
        self.assertEqual(response.data['participant'], {
            'id': participant.id,
            'model_name': 'My model',
            'username': user.username,
            'topic': None,
            'finished': False,
        })
        self.assertEqual(response.data['groupbuild']['id'], gb.pk)
开发者ID:modelbrouwers,项目名称:modelbrouwers,代码行数:62,代码来源:test_api.py

示例10: test_preferences_cache

# 需要导入模块: from brouwers.users.tests.factories import UserFactory [as 别名]
# 或者: from brouwers.users.tests.factories.UserFactory import create [as 别名]
    def test_preferences_cache(self):
        user = UserFactory.create()

        # log the user in
        self.client.login(username=user.username, password='password')
        self.assertEqual(Preferences.objects.filter(user=user).count(), 0)

        cache_key = 'album-preferences:%d' % user.id

        # make sure the cache is empty
        prefs = cache.get(cache_key)
        self.assertIsNone(prefs)

        # ok, get the preferences now
        prefs = Preferences.objects.get_for(user)
        self.assertTrue(isinstance(prefs, dict))

        cached_prefs = cache.get(cache_key)
        self.assertEqual(cached_prefs, prefs)

        # change preferences, make sure the cache is updated
        prefs_obj = Preferences.objects.get(user=user)
        prefs_obj.auto_start_uploading = True
        prefs_obj.save()

        cached_prefs = cache.get(cache_key)
        self.assertEqual(cached_prefs['auto_start_uploading'], prefs_obj.auto_start_uploading)
开发者ID:modelbrouwers,项目名称:modelbrouwers,代码行数:29,代码来源:test_cache.py

示例11: test_restore_album

# 需要导入模块: from brouwers.users.tests.factories import UserFactory [as 别名]
# 或者: from brouwers.users.tests.factories.UserFactory import create [as 别名]
    def test_restore_album(self):
        album = AlbumFactory.create(user=self.user, title='Album to restore')
        self.assertEqual(album.clean_title, 'Album to restore')
        album.trash = True
        album.save()

        url_restore = reverse('albums:restore', kwargs={'pk': album.pk})

        # anonymous user
        self.app.get(album.get_absolute_url(), status=404)
        # try it anyway
        restore_page = self.app.get(url_restore)
        expected_redirect = u'%s?next=%s' % (settings.LOGIN_URL, url_restore)
        self.assertRedirects(restore_page, expected_redirect)

        # other user
        other_user = UserFactory.create()
        self.assertNotEqual(album.user, other_user)
        restore_page = self.app.get(url_restore, user=other_user, status=404)

        # album owner
        restore_page = self.app.get(url_restore, user=self.user, status=200)
        restore_page.form.submit().follow()

        album = Album.objects.get(pk=album.pk)
        self.assertFalse(album.trash)
        self.assertEqual(album.title, 'Album to restore')
开发者ID:modelbrouwers,项目名称:modelbrouwers,代码行数:29,代码来源:test_views.py

示例12: test_restore_photo

# 需要导入模块: from brouwers.users.tests.factories import UserFactory [as 别名]
# 或者: from brouwers.users.tests.factories.UserFactory import create [as 别名]
    def test_restore_photo(self):
        photo = PhotoFactory.create(user=self.user)
        photo.trash = True
        photo.save()

        url_restore = reverse('albums:photo_restore', kwargs={'pk': photo.pk})

        # anonymous user
        self.app.get(photo.get_absolute_url(), status=404)
        # try it anyway
        restore_page = self.app.get(url_restore)
        expected_redirect = u'%s?next=%s' % (settings.LOGIN_URL, url_restore)
        self.assertRedirects(restore_page, expected_redirect)

        # other user
        other_user = UserFactory.create()
        self.assertNotEqual(photo.user, other_user)
        restore_page = self.app.get(url_restore, user=other_user, status=404)

        # photo owner
        restore_page = self.app.get(url_restore, user=self.user, status=200)
        restore_page.form.submit().follow()

        photo = Photo.objects.get(pk=photo.pk)
        self.assertFalse(photo.trash)
开发者ID:modelbrouwers,项目名称:modelbrouwers,代码行数:27,代码来源:test_views.py

示例13: test_update_album

# 需要导入模块: from brouwers.users.tests.factories import UserFactory [as 别名]
# 或者: from brouwers.users.tests.factories.UserFactory import create [as 别名]
    def test_update_album(self):
        album = AlbumFactory.create(user=self.user, title='Initial title')
        url_update = reverse('albums:update', kwargs={'pk': album.pk})

        # anonymous user
        detail_page = self.app.get(album.get_absolute_url())
        self.assertEqual(detail_page.status_code, 200)
        self.assertNotContains(detail_page, url_update)
        # try it anyway
        update_page = self.app.get(url_update)
        expected_redirect = u'%s?next=%s' % (settings.LOGIN_URL, url_update)
        self.assertRedirects(update_page, expected_redirect)

        # other user
        other_user = UserFactory.create()
        self.assertNotEqual(album.user, other_user)
        update_page = self.app.get(url_update, user=other_user, status=404)

        # album owner
        update_page = self.app.get(url_update, user=self.user, status=200)
        update_page.form['title'] = 'New title'
        update_page.form.submit().follow()

        album = Album.objects.get(pk=album.pk)
        self.assertEqual(album.title, 'New title')
开发者ID:modelbrouwers,项目名称:modelbrouwers,代码行数:27,代码来源:test_views.py

示例14: test_update

# 需要导入模块: from brouwers.users.tests.factories import UserFactory [as 别名]
# 或者: from brouwers.users.tests.factories.UserFactory import create [as 别名]
    def test_update(self):
        """
        Tests that updating builds works as expected.

        It should be possible to add/remove kits of a build
        """
        kits = ModelKitFactory.create_batch(2)
        build = BuildFactory.create(user=self.user, kits=kits)
        build_photo = BuildPhotoFactory.create(build=build)

        url = reverse('builds:update', kwargs={'slug': build.slug})

        # test that non-auth can't update
        response = self.app.get(url)
        self.assertRedirects(response, '{}?next={}'.format(settings.LOGIN_URL, url))

        # test that different user can't update
        other_user = UserFactory.create()
        self.app.get(url, user=other_user, status=404)

        # owner
        page = self.app.get(url, user=self.user, status=200)

        kit_fields = page.form.fields.get('kits')
        self.assertEqual(len(kit_fields), build.kits.count())

        # delete a kit
        pk = int(kit_fields[0].value)
        kit_fields[0].checked = False

        # test add photo
        self.assertEqual(page.form['photos-TOTAL_FORMS'].value, '1')
        self.assertEqual(page.form['photos-INITIAL_FORMS'].value, '1')

        photo = PhotoFactory.create(user=self.user)
        page.form['photos-TOTAL_FORMS'] = '2'
        self._add_field(page.form, 'photos-1-id', '')
        self._add_field(page.form, 'photos-1-build', '')
        self._add_field(page.form, 'photos-1-photo', '{}'.format(photo.pk))
        self._add_field(page.form, 'photos-1-photo_url', '')
        self._add_field(page.form, 'photos-1-order', '')

        # test delete photo
        page.form['photos-0-DELETE'].checked = True

        redirect = page.form.submit()
        self.assertRedirects(redirect, build.get_absolute_url())

        build.refresh_from_db()

        kits = build.kits.all()
        self.assertEqual(kits.count(), 1)
        self.assertFalse(kits.filter(pk=pk).exists())

        # check photos
        self.assertEqual(build.photos.count(), 1)
        self.assertNotEqual(build.photos.get(), build_photo)
开发者ID:modelbrouwers,项目名称:modelbrouwers,代码行数:59,代码来源:test_views.py

示例15: test_mark_done

# 需要导入模块: from brouwers.users.tests.factories import UserFactory [as 别名]
# 或者: from brouwers.users.tests.factories.UserFactory import create [as 别名]
    def test_mark_done(self):
        """
        Test that a participant can be marked as ready.
        """
        gb = GroupBuildFactory.create(status=GroupbuildStatuses.accepted)

        user = UserFactory.create()
        other_user = UserFactory.create()
        topic = TopicFactory.create(forum__forum_name=gb.theme,
                                    topic_title='Participant 1')
        participant = ParticipantFactory.create(topic_id=topic.topic_id, user=user)

        endpoint = reverse('api:participant-detail', kwargs={'pk': participant.pk})
        self.client.login(username=user.username, password='password')
        response = self.client.patch(endpoint, {'finished': True}, format='json')
        self.assertEqual(response.status_code, 200)
        participant = Participant.objects.get(pk=participant.pk)
        self.assertTrue(participant.finished)

        self.client.login(username=other_user.username, password='password')
        response = self.client.patch(endpoint, {'finished': False}, format='json')
        self.assertEqual(response.status_code, 403)
开发者ID:modelbrouwers,项目名称:modelbrouwers,代码行数:24,代码来源:test_api.py


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