博客系统
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.

79 Zeilen
3.3 KiB

vor 4 Jahren
  1. # -*- coding: utf-8 -*-
  2. """
  3. :author: Grey Li ()
  4. :url: http://greyli.com
  5. :copyright: © 2018 Grey Li <withlihui@gmail.com>
  6. :license: MIT, see LICENSE for more details.
  7. """
  8. from bluelog.models import Admin, Post, Category, Comment
  9. from bluelog.extensions import db
  10. from tests.base import BaseTestCase
  11. class CLITestCase(BaseTestCase):
  12. def setUp(self):
  13. super(CLITestCase, self).setUp()
  14. db.drop_all()
  15. def test_initdb_command(self):
  16. result = self.runner.invoke(args=['initdb'])
  17. self.assertIn('Initialized database.', result.output)
  18. def test_initdb_command_with_drop(self):
  19. result = self.runner.invoke(args=['initdb', '--drop'], input='y\n')
  20. self.assertIn('This operation will delete the database, do you want to continue?', result.output)
  21. self.assertIn('Drop tables.', result.output)
  22. def test_init_command(self):
  23. result = self.runner.invoke(args=['init', '--username', 'grey', '--password', '123'])
  24. self.assertIn('Creating the temporary administrator account...', result.output)
  25. self.assertIn('Creating the default category...', result.output)
  26. self.assertIn('Done.', result.output)
  27. self.assertEqual(Admin.query.count(), 1)
  28. self.assertEqual(Admin.query.first().username, 'grey')
  29. self.assertEqual(Category.query.first().name, 'Default')
  30. def test_init_command_with_update(self):
  31. self.runner.invoke(args=['init', '--username', 'grey', '--password', '123'])
  32. result = self.runner.invoke(args=['init', '--username', 'new grey', '--password', '123'])
  33. self.assertIn('The administrator already exists, updating...', result.output)
  34. self.assertNotIn('Creating the temporary administrator account...', result.output)
  35. self.assertEqual(Admin.query.count(), 1)
  36. self.assertEqual(Admin.query.first().username, 'new grey')
  37. self.assertEqual(Category.query.first().name, 'Default')
  38. def test_forge_command(self):
  39. result = self.runner.invoke(args=['forge'])
  40. self.assertEqual(Admin.query.count(), 1)
  41. self.assertIn('Generating the administrator...', result.output)
  42. self.assertEqual(Post.query.count(), 50)
  43. self.assertIn('Generating 50 posts...', result.output)
  44. self.assertEqual(Category.query.count(), 10 + 1)
  45. self.assertIn('Generating 10 categories...', result.output)
  46. self.assertEqual(Comment.query.count(), 500 + 50 + 50 + 50)
  47. self.assertIn('Generating 500 comments...', result.output)
  48. self.assertIn('Generating links...', result.output)
  49. self.assertIn('Done.', result.output)
  50. def test_forge_command_with_count(self):
  51. result = self.runner.invoke(args=['forge', '--category', '5', '--post', '20', '--comment', '100'])
  52. self.assertEqual(Admin.query.count(), 1)
  53. self.assertIn('Generating the administrator...', result.output)
  54. self.assertEqual(Post.query.count(), 20)
  55. self.assertIn('Generating 20 posts...', result.output)
  56. self.assertEqual(Category.query.count(), 5 + 1)
  57. self.assertIn('Generating 5 categories...', result.output)
  58. self.assertEqual(Comment.query.count(), 100 + 10 + 10 + 10)
  59. self.assertIn('Generating 100 comments...', result.output)
  60. self.assertIn('Generating links...', result.output)
  61. self.assertIn('Done.', result.output)