users_and_groups.py 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. # -*- coding: utf-8 -*-
  2. from tracim_backend import models
  3. from tracim_backend.fixtures import Fixture
  4. from tracim_backend.lib.core.user import UserApi
  5. class Base(Fixture):
  6. require = []
  7. def insert(self):
  8. u = models.User()
  9. u.display_name = 'Global manager'
  10. u.email = 'admin@admin.admin'
  11. u.password = 'admin@admin.admin'
  12. self._session.add(u)
  13. uapi = UserApi(
  14. session=self._session,
  15. config=self._config,
  16. current_user=u)
  17. uapi.execute_created_user_actions(u)
  18. g1 = models.Group()
  19. g1.group_id = 1
  20. g1.group_name = 'users'
  21. g1.display_name = 'Users'
  22. g1.users.append(u)
  23. self._session.add(g1)
  24. g2 = models.Group()
  25. g2.group_id = 2
  26. g2.group_name = 'managers'
  27. g2.display_name = 'Global Managers'
  28. g2.users.append(u)
  29. self._session.add(g2)
  30. g3 = models.Group()
  31. g3.group_id = 3
  32. g3.group_name = 'administrators'
  33. g3.display_name = 'Administrators'
  34. g3.users.append(u)
  35. self._session.add(g3)
  36. class Test(Fixture):
  37. require = [Base, ]
  38. def insert(self):
  39. g2 = self._session.query(models.Group).\
  40. filter(models.Group.group_name == 'managers').one()
  41. lawrence = models.User()
  42. lawrence.display_name = 'Lawrence L.'
  43. lawrence.email = 'lawrence-not-real-email@fsf.local'
  44. lawrence.password = 'foobarbaz'
  45. self._session.add(lawrence)
  46. g2.users.append(lawrence)
  47. bob = models.User()
  48. bob.display_name = 'Bob i.'
  49. bob.email = 'bob@fsf.local'
  50. bob.password = 'foobarbaz'
  51. self._session.add(bob)
  52. g2.users.append(bob)
  53. g1 = self._session.query(models.Group).\
  54. filter(models.Group.group_name == 'users').one()
  55. reader = models.User()
  56. reader.display_name = 'John Reader'
  57. reader.email = 'john-the-reader@reader.local'
  58. reader.password = 'read'
  59. self._session.add(reader)
  60. g1.users.append(reader)