Skip to content
Permalink
main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
import pytest
from django.test import Client
from django.contrib.auth.models import User
@pytest.fixture
def client():
return Client()
@pytest.fixture
def test_user():
user = User.objects.create_user(username='test_user', password='test_password')
return user
def test_user_login_success(client, test_user):
response = client.post('/user_login/', {'username': 'test_user', 'password': 'test_password'})
assert response.status_code == 302 # 成功应该重定向
assert response.url == '/home/'
def test_user_login_failed(client):
response = client.post('/user_login/', {'username': 'invalid_user', 'password': 'invalid_password'})
assert response.status_code == 200 # 失败应该返回登录页面
assert 'Invalid username or password' in response.content.decode()