Cloud computing coursework:Saas 图片社交网站
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

65 Zeilen
2.5 KiB

vor 3 Jahren
  1. # -*- coding: utf-8 -*-
  2. import unittest
  3. from flask import url_for
  4. from phshare import create_app
  5. from phshare.extensions import db
  6. from phshare.models import User, Role, Photo, Comment, Tag
  7. class BaseTestCase(unittest.TestCase):
  8. def setUp(self):
  9. app = create_app('testing')
  10. self.context = app.test_request_context()
  11. self.context.push()
  12. self.client = app.test_client()
  13. self.runner = app.test_cli_runner()
  14. db.create_all()
  15. Role.init_role()
  16. admin_user = User(email='admin@helloflask.com', name='Admin', username='admin', confirmed=True)
  17. admin_user.set_password('123')
  18. normal_user = User(email='normal@helloflask.com', name='Normal User', username='normal', confirmed=True)
  19. normal_user.set_password('123')
  20. unconfirmed_user = User(email='unconfirmed@helloflask.com', name='Unconfirmed', username='unconfirmed',
  21. confirmed=False)
  22. unconfirmed_user.set_password('123')
  23. locked_user = User(email='locked@helloflask.com', name='Locked User', username='locked',
  24. confirmed=True, locked=True)
  25. locked_user.set_password('123')
  26. locked_user.lock()
  27. blocked_user = User(email='blocked@helloflask.com', name='Blocked User', username='blocked',
  28. confirmed=True, active=False)
  29. blocked_user.set_password('123')
  30. photo = Photo(filename='test.jpg', filename_s='test_s.jpg', filename_m='test_m.jpg',
  31. description='Photo 1', author=admin_user)
  32. photo2 = Photo(filename='test2.jpg', filename_s='test_s2.jpg', filename_m='test_m2.jpg',
  33. description='Photo 2', author=normal_user)
  34. comment = Comment(body='test comment body', photo=photo, author=normal_user)
  35. tag = Tag(name='test tag')
  36. photo.tags.append(tag)
  37. db.session.add_all([admin_user, normal_user, unconfirmed_user, locked_user, blocked_user])
  38. db.session.commit()
  39. def tearDown(self):
  40. db.drop_all()
  41. self.context.pop()
  42. def login(self, email=None, password=None):
  43. if email is None and password is None:
  44. email = 'normal@helloflask.com'
  45. password = '123'
  46. return self.client.post(url_for('auth.login'), data=dict(
  47. email=email,
  48. password=password
  49. ), follow_redirects=True)
  50. def logout(self):
  51. return self.client.get(url_for('auth.logout'), follow_redirects=True)