from django.contrib.auth import get_user_model from django.test import TestCase from kfet.models import Account User = get_user_model() class AccountTests(TestCase): def setUp(self): self.account = Account(trigramme='000') self.account.save({'username': 'user'}) def test_get_absolute_url(self): self.assertEqual( self.account.get_absolute_url(), '/k-fet/accounts/000') account_space = Account(trigramme=' ') account_space.save({'username': 'space'}) self.assertEqual( account_space.get_absolute_url(), '/k-fet/accounts/%20%20%20') def test_password(self): self.account.change_pwd('anna') self.account.save() self.assertEqual(Account.objects.get_by_password('anna'), self.account) with self.assertRaises(Account.DoesNotExist): Account.objects.get_by_password(None) with self.assertRaises(Account.DoesNotExist): Account.objects.get_by_password('bernard')