Permalink
Cannot retrieve contributors at this time
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?
Group15_all_project/yangc code testing
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
22 lines (18 sloc)
808 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |