當前位置: 首頁>>代碼示例>>Python>>正文


Python factories.UserFactory方法代碼示例

本文整理匯總了Python中tests.factories.UserFactory方法的典型用法代碼示例。如果您正苦於以下問題:Python factories.UserFactory方法的具體用法?Python factories.UserFactory怎麽用?Python factories.UserFactory使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在tests.factories的用法示例。


在下文中一共展示了factories.UserFactory方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_list

# 需要導入模塊: from tests import factories [as 別名]
# 或者: from tests.factories import UserFactory [as 別名]
def test_list(self, monkeypatch, sm_test_data):

        site = sm_test_data['site']
        org = sm_test_data['organization']
        if organizations_support_sites():
            caller = UserFactory()
            UserOrganizationMappingFactory(user=caller,
                                           organization=org,
                                           is_amc_admin=True)
        else:
            caller = UserFactory(is_staff=True)
        request = APIRequestFactory().get(self.request_path)
        request.META['HTTP_HOST'] = site.domain
        monkeypatch.setattr(django.contrib.sites.shortcuts,
                            'get_current_site',
                            lambda req: site)
        force_authenticate(request, user=caller)
        view = self.view_class.as_view({'get': 'list'})
        response = view(request)

        assert response.status_code == status.HTTP_200_OK 
開發者ID:appsembler,項目名稱:figures,代碼行數:23,代碼來源:test_mau_views.py

示例2: test_site_metrics_list

# 需要導入模塊: from tests import factories [as 別名]
# 或者: from tests.factories import UserFactory [as 別名]
def test_site_metrics_list(self, monkeypatch, sm_test_data):

        site = sm_test_data['site']
        org = sm_test_data['organization']
        if organizations_support_sites():
            caller = UserFactory()
            UserOrganizationMappingFactory(user=caller,
                                           organization=org,
                                           is_amc_admin=True)
        else:
            caller = UserFactory(is_staff=True)
        request = APIRequestFactory().get(self.request_path)
        request.META['HTTP_HOST'] = site.domain
        monkeypatch.setattr(django.contrib.sites.shortcuts,
                            'get_current_site',
                            lambda req: site)
        force_authenticate(request, user=caller)
        view = self.view_class.as_view({'get': 'list'})
        response = view(request)

        assert response.status_code == status.HTTP_200_OK 
開發者ID:appsembler,項目名稱:figures,代碼行數:23,代碼來源:test_mau_views.py

示例3: test_current_user_session_working

# 需要導入模塊: from tests import factories [as 別名]
# 或者: from tests.factories import UserFactory [as 別名]
def test_current_user_session_working(session, token, app):
    """
    Test the current_user endpoint, using a valid session.

    This should work
    """
    # Create a user
    user = factories.UserFactory()
    session.add(user)
    session.commit()

    # Login with that user (we have to use a custom client here)
    with app.test_client(user=user) as client:
        rv = client.get("/rest_api/v1/users/current")

    # Check the request was successful
    assert rv.status_code == 200, rv.json

    # Validate the response
    schemas.UserSchema().validate(rv.json) 
開發者ID:ewels,項目名稱:MegaQC,代碼行數:22,代碼來源:test_current_user.py

示例4: test_sees_error_message_if_user_already_registered

# 需要導入模塊: from tests import factories [as 別名]
# 或者: from tests.factories import UserFactory [as 別名]
def test_sees_error_message_if_user_already_registered(self, user, testapp):
        """Show error if user already registered."""
        user = UserFactory(active=True)  # A registered user
        user.save()
        # Goes to registration page
        res = testapp.get(url_for("account.signup"))
        # Fills out form, but username is already registered
        form = res.forms["registerForm"]
        form["username"] = user.username
        form["email"] = "foo@bar.com"
        form["password"] = "secret"
        form["confirm"] = "secret"
        # Submits
        res = form.submit()
        # sees error
        assert "Username already registered" in res 
開發者ID:hjlarry,項目名稱:flask-shop,代碼行數:18,代碼來源:test_functional.py

示例5: test_retrieve

# 需要導入模塊: from tests import factories [as 別名]
# 或者: from tests.factories import UserFactory [as 別名]
def test_retrieve(self, monkeypatch, sm_test_data):
        monkeypatch.setattr(django.contrib.sites.shortcuts,
                            'get_current_site',
                            lambda req: site)
        site = sm_test_data['site']
        org = sm_test_data['organization']
        co = sm_test_data['course_overviews'][0]

        if organizations_support_sites():
            caller = UserFactory()
            UserOrganizationMappingFactory(user=caller,
                                           organization=org,
                                           is_amc_admin=True)
        else:
            caller = UserFactory(is_staff=True)

        request_path = self.request_path + '?pk=' + str(co.id)
        request = APIRequestFactory().get(request_path)
        request.META['HTTP_HOST'] = site.domain

        force_authenticate(request, user=caller)
        view = self.view_class.as_view({'get': 'retrieve'})
        response = view(request, pk=str(co.id))

        assert response.status_code == status.HTTP_200_OK
        # TODO: Assert data are correct 
開發者ID:appsembler,項目名稱:figures,代碼行數:28,代碼來源:test_mau_views.py

示例6: token

# 需要導入模塊: from tests import factories [as 別名]
# 或者: from tests.factories import UserFactory [as 別名]
def token(db):
    user = factories.UserFactory(is_admin=False)
    db.session.add(user)
    db.session.commit()
    return user.api_token 
開發者ID:ewels,項目名稱:MegaQC,代碼行數:7,代碼來源:conftest.py

示例7: admin_token

# 需要導入模塊: from tests import factories [as 別名]
# 或者: from tests.factories import UserFactory [as 別名]
def admin_token(db):
    user = factories.UserFactory(is_admin=True)
    db.session.add(user)
    db.session.commit()
    return user.api_token 
開發者ID:ewels,項目名稱:MegaQC,代碼行數:7,代碼來源:conftest.py

示例8: test_current_user_session_invalid

# 需要導入模塊: from tests import factories [as 別名]
# 或者: from tests.factories import UserFactory [as 別名]
def test_current_user_session_invalid(session, client, token):
    """
    Test the current_user endpoint, using a valid session.

    This should work
    """
    # Create a user
    user = factories.UserFactory()
    session.add(user)
    session.commit()

    rv = client.get("/rest_api/v1/users/current")

    # Check the request was unauthorized
    assert rv.status_code == 401 
開發者ID:ewels,項目名稱:MegaQC,代碼行數:17,代碼來源:test_current_user.py

示例9: setUp

# 需要導入模塊: from tests import factories [as 別名]
# 或者: from tests.factories import UserFactory [as 別名]
def setUp(self):
        self.user = factories.UserFactory()
        self.client = Client()
        self.response = self.client.query(self.query)
        self.data = self.response.json() 
開發者ID:eamigo86,項目名稱:graphene-django-extras,代碼行數:7,代碼來源:test_fields.py

示例10: test_factory

# 需要導入模塊: from tests import factories [as 別名]
# 或者: from tests.factories import UserFactory [as 別名]
def test_factory(self, db):
        """Test user factory."""
        user = UserFactory(password="myprecious")
        db.session.commit()
        assert bool(user.username)
        assert bool(user.email)
        assert bool(user.created_at)
        assert user.active is True
        assert user.check_password("myprecious") 
開發者ID:hjlarry,項目名稱:flask-shop,代碼行數:11,代碼來源:test_models.py


注:本文中的tests.factories.UserFactory方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。