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


Python Mock.POST方法代码示例

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


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

示例1: test_receive_when_target_not_in_post_data

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import POST [as 别名]
    def test_receive_when_target_not_in_post_data(self):
        request = Mock()
        request.method = 'POST'
        request.POST = {'source': self.source}

        response = receive(request)

        self.assertTrue(isinstance(response, HttpResponseBadRequest))
开发者ID:easy-as-python,项目名称:django-webmention,代码行数:10,代码来源:test_views.py

示例2: test_receive_when_target_does_not_resolve

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import POST [as 别名]
    def test_receive_when_target_does_not_resolve(self, mock_url_resolves):
        request = Mock()
        request.method = 'POST'
        request.POST = {'source': self.source, 'target': self.target}

        mock_url_resolves.return_value = False
        response = receive(request)

        mock_url_resolves.assert_called_once_with(self.target)
        self.assertTrue(isinstance(response, HttpResponseBadRequest))
开发者ID:easy-as-python,项目名称:django-webmention,代码行数:12,代码来源:test_views.py

示例3: _get_request

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import POST [as 别名]
 def _get_request(self):
     """Gets mocked request."""
     request = Mock()
     request.POST = {
         'code': 'code',
         'state': 'state',
     }
     request.session = MagicMock()
     request.session.__setitem__.return_value = None
     request.session.save.return_value = None
     return request
开发者ID:UKTradeInvestment,项目名称:export-wins-data,代码行数:13,代码来源:tests.py

示例4: test_receive_when_general_exception_occurs

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import POST [as 别名]
    def test_receive_when_general_exception_occurs(self, mock_url_resolves, mock_fetch_and_validate_source):
        request = Mock()
        request.method = 'POST'
        request.POST = {'source': self.source, 'target': self.target}

        mock_url_resolves.return_value = True
        mock_fetch_and_validate_source.side_effect = Exception
        response = receive(request)

        mock_fetch_and_validate_source.assert_called_once_with(self.source, self.target)
        mock_url_resolves.assert_called_once_with(self.target)
        self.assertTrue(isinstance(response, HttpResponseServerError))
开发者ID:easy-as-python,项目名称:django-webmention,代码行数:14,代码来源:test_views.py

示例5: test_has_permission_not_member_of_company

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import POST [as 别名]
 def test_has_permission_not_member_of_company(self):
     permission = permissions.IsMemberOfBrewingCompany()
     user = User.objects.create(username="user")
     group = Group.objects.create(name="group")
     brewing_company = models.BrewingCompany.objects.create(group=group)
     request = Mock()
     request.user = user
     request.method = "POST"
     request.POST = {
         "company": brewing_company.pk,
     }
     view = None
     self.assertFalse(permission.has_permission(request, view))
开发者ID:willjschmitt,项目名称:joulia-webserver,代码行数:15,代码来源:permissions_test.py

示例6: test_receive_when_source_does_not_contain_target

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import POST [as 别名]
    def test_receive_when_source_does_not_contain_target(self, mock_url_resolves, mock_fetch_and_validate_source, mock_invalidate):
        request = Mock()
        request.method = 'POST'
        request.POST = {'source': self.source, 'target': self.target}

        mock_url_resolves.return_value = True
        mock_fetch_and_validate_source.side_effect = TargetNotFoundError
        response = receive(request)

        mock_fetch_and_validate_source.assert_called_once_with(self.source, self.target)
        mock_url_resolves.assert_called_once_with(self.target)
        self.assertEqual(1, mock_invalidate.call_count)
        self.assertTrue(isinstance(response, HttpResponseBadRequest))
开发者ID:easy-as-python,项目名称:django-webmention,代码行数:15,代码来源:test_views.py

示例7: test_receive_happy_path

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import POST [as 别名]
    def test_receive_happy_path(self, mock_url_resolves, mock_fetch_and_validate_source, mock_update):
        request = Mock()
        request.method = 'POST'
        request.POST = {'source': self.source, 'target': self.target}

        mock_url_resolves.return_value = True
        mock_fetch_and_validate_source.return_value = 'foo'
        response = receive(request)

        mock_fetch_and_validate_source.assert_called_once_with(self.source, self.target)
        mock_update.assert_called_once_with(self.source, self.target, mock_fetch_and_validate_source.return_value)
        mock_url_resolves.assert_called_once_with(self.target)
        self.assertTrue(isinstance(response, HttpResponse))
开发者ID:easy-as-python,项目名称:django-webmention,代码行数:15,代码来源:test_views.py

示例8: _create_request

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import POST [as 别名]
 def _create_request(self):
     """Gets mocked request."""
     request = Mock()
     request.POST = {
         'code': 'code',
         'state': 'state',
     }
     request.user = User(email='[email protected]')
     request.user.save()
     request.session = MagicMock()
     request.session.__setitem__.return_value = None
     request.session.__getitem__.side_effect = _fake_session
     request.session.get.side_effect = _fake_session
     request.session.save.return_value = None
     return request
开发者ID:UKTradeInvestment,项目名称:export-wins-data,代码行数:17,代码来源:tests.py

示例9: test_has_permission_member_of_company

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import POST [as 别名]
 def test_has_permission_member_of_company(self):
     permission = permissions.OwnsRecipe()
     user = User.objects.create(username="user")
     group = Group.objects.create(name="group")
     group.user_set.add(user)
     brewing_company = models.BrewingCompany.objects.create(group=group)
     recipe = models.Recipe.objects.create(company=brewing_company)
     request = Mock()
     request.user = user
     request.method = "POST"
     request.POST = {
         "recipe": recipe.pk,
     }
     view = None
     self.assertTrue(permission.has_permission(request, view))
开发者ID:willjschmitt,项目名称:joulia-webserver,代码行数:17,代码来源:permissions_test.py


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