Unable to pip install 3rd party packages.
(venv) ? pip install django
Collecting django
Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x000001BEF10AD0F0>, 'Connection to pypi.org timed out. (connect timeout=15)')': /simple/django/
Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x000001BEF10ADE48>, 'Connection to pypi.org timed out. (connect timeout=15)')': /simple/django/
Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x000001BEF10BB518>, 'Connection to pypi.org timed out. (connect timeout=15)')': /simple/django/ …Run Code Online (Sandbox Code Playgroud) 我正在测试 中引发的多个验证错误(UserRegistrationSerializer)。但 DRF 仅返回引发的第一个错误:
{'username': [ErrorDetail(string='Choose a different username', code='invalid')]}
我期待:{'username': [ErrorDetail(string='选择不同的用户名', code='invalid')], 'password2': [ErrorDetail(string='密码确认失败', code='invalid' )]
一旦序列化器被验证(如文档示例中所示),如何解释多个错误?
https://www.django-rest-framework.org/api-guide/serializers/#validation
class TestRegisterationSerializer__002(TestCase):
'''Verify that the registeration process fails with respect
to selecting an unavailable username and password confirmation'''
@classmethod
def setUpTestData(cls):
User.objects.create_user(username="Python")
cls.data = {
'username': "Python",
'password': "#secret#",
'password2': "Secret"
}
cls.error_messages = [
"Choose a different username", "Password confirmation failed"
]
cls.serializer = UserRegisterationSerializer(data=cls.data)
def test_user_registeration_invalid_confirmation(self):
self.serializer.is_valid()
print(self.serializer.errors)
Run Code Online (Sandbox Code Playgroud)
import re
from django.contrib.auth.models import User
from rest_framework …Run Code Online (Sandbox Code Playgroud) 熟悉 C# 后,在进行断言的行上进行单元测试时,我收到以下错误Assert.IsInstanceTypeOf。
Error CS0119 'Product' is a type, which is not valid in the given context
创建类型的事情已经执行了。是什么导致了这个错误?
单元测试1.cs
using Microsoft.VisualStudio.TestTools.UnitTesting;
using ProductNamespace;
namespace TestProject2
{
[TestClass]
public class TestProduct
{
[TestMethod]
public void TestNewProduct()
{
Product mock_product = new Product(4.95);
Assert.IsInstanceOfType(mock_product, Product);
}
}
}
Run Code Online (Sandbox Code Playgroud)
产品.cs
namespace ProductNamespace
{
public class Product
{
private double price;
public Product(double price)
{
this.price = price;
}
}
}
Run Code Online (Sandbox Code Playgroud)