def test_integration_setup_success(self): #raise DoesNotExist error if failed a = User.objects.get(name='ece651', password=hash_code('ece651'), email='*****@*****.**') b = Table.objects.get(table_id = 1, cap=4) c = Table.objects.get(table_id = 2, cap=8) d = Waitlist.objects.get(id=0, guests=3, lastname='xu', catagory='a') e = Reservation.objects.get(rsv_number = 1, table_id = b, no_of_guests = 3, user='******', date='2020-5-1')
def add_user(username, password, email, sex): same_name_user = User.objects.filter(name=username) if same_name_user: message = '用户名已存在' return None same_email_user = User.objects.filter(email=email) if same_email_user: message = '该邮箱已经被注册了!' return None new_user = User() new_user.name = username new_user.password = hash_code(password) new_user.email = email new_user.sex = sex new_user.has_confirmed = True #直接跳过邮件确认 new_user.save() new_userprofile = UserProfile() new_userprofile.user = new_user new_userprofile.save() new_userprofile.follow_list.add(new_userprofile) new_userprofile.save() return
def setUp(self): user1 = User.objects.create(name='ece651', password=hash_code('ece651'), email='*****@*****.**') user1.save() table1= Table.objects.create(table_id = 1, cap=4) table2= Table.objects.create(table_id = 2, cap=8) table1.save() table2.save() rsv1 = Reservation.objects.create(rsv_number = 1, table_id = table1, no_of_guests = 3, user='******', date='2020-5-1') rsv1.save() wait1 = Waitlist.objects.create(id=0, guests=3, lastname='xu', catagory='a') wait1.save()
def test_integration_frontend_register_login_chpasswd_logout(self): response = self.client.post(reverse('register'), {'username':'******','firstname':'first','lastname':'last','password1':'12345678','password2':'12345678', 'email':'*****@*****.**'}) self.assertTrue('is_login' not in self.client.session) self.assertRedirects(response,reverse('login')) response = self.client.post(reverse('login'),{'username':'******', 'password':'******'}) self.assertRedirects(response,reverse('index')) response = self.client.post(reverse('chpasswd'), {'password':'******', 'password1':'87654321', 'password2':'87654321'}) self.assertEqual(User.objects.get(name='newuser').password, hash_code('87654321')) self.assertRedirects(response, reverse('chpasswdsuccess'))
def test_view_chpasswd_success(self): session = self.client.session session['user_name'] = 'ece651' session.save() response = self.client.post(reverse('chpasswd'), { 'password': '******', 'password1': '87654321', 'password2': '87654321' }) self.assertEqual( User.objects.get(name='ece651').password, hash_code('87654321')) self.assertRedirects(response, reverse('chpasswdsuccess')) session.flush()
def setUp(self): user1 = User.objects.create(name='ece651', password=hash_code('ece651'), email='*****@*****.**') user1.save() table1 = Table.objects.create(table_id=1, cap=4) table2 = Table.objects.create(table_id=2, cap=8) table1.save() table2.save() wait = Waitlist.objects.create(id=1, guests=3, lastname='xu', catagory='a') wait.save()
def setUp(self): user1 = User.objects.create(name='ece651', password=hash_code('ece651'), email='*****@*****.**') user1.save() table1 = Table.objects.create(table_id=1, cap=4, occupied=True) table2 = Table.objects.create(table_id=2, cap=8) table1.save() table2.save() rsv1 = Reservation.objects.create(rsv_number=1, table_id=table1, no_of_guests=3, user='******', date='2020-5-1') rsv1.save()
def test_view_chpasswd_wrong_password(self): session = self.client.session session['user_name'] = 'ece651' session.save() response = self.client.post(reverse('chpasswd'), { 'password': '******', 'password1': '87654321', 'password2': '87654321' }) self.assertEqual( User.objects.get(name='ece651').password, hash_code('ece651')) self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'login/chpasswd.html') self.assertEqual(response.context['message'], 'Incorrect password!') session.flush()
def test_view_chpasswd_new_password_mismatch(self): session = self.client.session session['user_name'] = 'ece651' session.save() response = self.client.post(reverse('chpasswd'), { 'password': '******', 'password1': '87654321', 'password2': '99954321' }) self.assertEqual( User.objects.get(name='ece651').password, hash_code('ece651')) self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'login/chpasswd.html') self.assertEqual(response.context['message'], 'The passwords you entered do not match') session.flush()
def test_integration_frontend_login_profile_deluser(self): response = self.client.post(reverse('login'),{'username':'******', 'password':'******'}) self.assertEqual(User.objects.get(name='ece651').password, hash_code('ece651')) self.assertRedirects(response,reverse('index')) response = self.client.get(reverse('profile')) self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'login/profile.html') response = self.client.get(reverse('deleteuser')) try: a=User.objects.get(name='ece651') except: pass else: raise NameError("fail to delete") self.assertRedirects(response,reverse('index'))
def test_integration_frontend_login_book_chkrsv(self): response = self.client.post(reverse('login'),{'username':'******', 'password':'******'}) self.assertEqual(User.objects.get(name='ece651').password, hash_code('ece651')) self.assertRedirects(response,reverse('index')) response = self.client.get(reverse('booktable')) self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'booktable.html') response = self.client.post(reverse('booktable'),{'no_of_guests': 2, 'bookdate':'2020-5-2'}) new = Reservation.objects.filter(user = '******').count() self.assertEqual(new, 2) self.assertRedirects(response,reverse('booksuccess')) response = self.client.get(reverse('booksuccess')) self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'booksuccess.html') response = self.client.get(reverse('checkrev')) self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'checkrev.html')
def test_object_created(self): a = User.objects.get(name='ece651') b = Table.objects.get(table_id=1) c = Table.objects.get(table_id=2) d = Reservation.objects.get(rsv_number=1) self.assertEqual(a.password, hash_code('ece651'))
def test_user_created(self): a = User.objects.get(name='ece651') self.assertEqual(a.password, hash_code('ece651'))