test_populate.py 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import pytest
  2. from flaskbb.utils.populate import *
  3. from flaskbb.fixtures.groups import fixture as group_fixture
  4. from flaskbb.fixtures.settings import fixture as settings_fixture
  5. from flaskbb.user.models import Group
  6. from flaskbb.forum.models import Category, Topic, Post
  7. # 184-199, 218-268, 278-307
  8. def test_delete_settings_from_fixture(default_settings):
  9. groups_count = SettingsGroup.query.count()
  10. assert len(settings_fixture) == groups_count
  11. deleted = delete_settings_from_fixture(settings_fixture)
  12. assert len(settings_fixture) == len(deleted)
  13. assert not SettingsGroup.query.count()
  14. assert not Setting.query.count()
  15. def test_create_settings_from_fixture(database):
  16. assert not SettingsGroup.query.count()
  17. assert not Setting.query.count()
  18. created = create_settings_from_fixture(settings_fixture)
  19. assert len(settings_fixture) == len(created)
  20. assert SettingsGroup.query.count() == len(created)
  21. def test_update_settings_from_fixture(database):
  22. # No force-overwrite - the fixtures will be created because
  23. # do not exist.
  24. assert not SettingsGroup.query.count()
  25. assert not Setting.query.count()
  26. updated = update_settings_from_fixture(settings_fixture)
  27. assert len(updated) == SettingsGroup.query.count()
  28. # force-overwrite - the fixtures exist, but they will be overwritten now.
  29. force_updated = update_settings_from_fixture(settings_fixture,
  30. overwrite_group=True,
  31. overwrite_setting=True)
  32. assert len(force_updated) == SettingsGroup.query.count()
  33. def test_create_user(default_groups):
  34. user = User.query.filter_by(username="admin").first()
  35. assert not user
  36. user = create_user(username="admin", password="test",
  37. email="test@example.org", groupname="admin")
  38. assert user.username == "admin"
  39. assert user.permissions["admin"]
  40. def test_create_welcome_forum(default_groups):
  41. assert not create_welcome_forum()
  42. create_user(username="admin", password="test",
  43. email="test@example.org", groupname="admin")
  44. assert create_welcome_forum()
  45. def test_create_test_data(database):
  46. assert Category.query.count() == 0
  47. data_created = create_test_data()
  48. assert Category.query.count() == data_created['categories']
  49. def test_insert_bulk_data(database):
  50. assert not insert_bulk_data(topic_count=1, post_count=1)
  51. create_test_data(categories=1, forums=1, topics=0)
  52. assert Topic.query.count() == 0
  53. topics, posts = insert_bulk_data(topic_count=1, post_count=1)
  54. assert Topic.query.count() == topics
  55. # -1 bc the topic post also counts as post
  56. assert Post.query.count() - 1 == posts
  57. def test_create_default_groups(database):
  58. """Test that the default groups are created correctly."""
  59. assert Group.query.count() == 0
  60. create_default_groups()
  61. assert Group.query.count() == len(group_fixture)
  62. for key, attributes in group_fixture.items():
  63. group = Group.query.filter_by(name=key).first()
  64. for attribute, value in attributes.items():
  65. assert getattr(group, attribute) == value