test_commands.py 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. # -*- coding: utf-8 -*-
  2. import os
  3. import subprocess
  4. import pytest
  5. import transaction
  6. from pkg_resources import load_entry_point
  7. from sqlalchemy.orm.exc import NoResultFound
  8. import tracim
  9. from tracim.command import TracimCLI
  10. from tracim.command.user import UserCommand
  11. from tracim.exceptions import UserNotExist
  12. from tracim.lib.core.user import UserApi
  13. from tracim.tests import CommandFunctionalTest
  14. class TestCommands(CommandFunctionalTest):
  15. """
  16. Test tracimcli command line ui.
  17. """
  18. config_section = 'app:command_test'
  19. def test_func__check_commands_list__ok__nominal_case(self):
  20. """
  21. Test listing of tracimcli command: Tracim commands must be listed
  22. :return:
  23. """
  24. os.chdir(os.path.dirname(tracim.__file__) + '/../')
  25. output = subprocess.check_output(["tracimcli", "-h"])
  26. output = output.decode('utf-8')
  27. assert output.find('user create') > 0
  28. assert output.find('user update') > 0
  29. assert output.find('db init') > 0
  30. assert output.find('db delete') > 0
  31. assert output.find('webdav start') > 0
  32. def test_func__user_create_command__ok__nominal_case(self):
  33. """
  34. Test User creation
  35. """
  36. api = UserApi(
  37. current_user=None,
  38. session=self.session,
  39. config=self.app_config,
  40. )
  41. with pytest.raises(NoResultFound):
  42. api.get_one_by_email('command_test@user')
  43. app = TracimCLI()
  44. result = app.run([
  45. 'user', 'create',
  46. '-c', 'tests_configs.ini#command_test',
  47. '-l', 'command_test@user',
  48. '-p', 'new_password'
  49. ])
  50. new_user = api.get_one_by_email('command_test@user')
  51. assert new_user.email == 'command_test@user'
  52. assert new_user.validate_password('new_password')
  53. def test_func__user_update_command__ok__nominal_case(self):
  54. """
  55. Test user password update
  56. """
  57. api = UserApi(
  58. current_user=None,
  59. session=self.session,
  60. config=self.app_config,
  61. )
  62. user = api.get_one_by_email('admin@admin.admin')
  63. assert user.email == 'admin@admin.admin'
  64. assert user.validate_password('admin@admin.admin')
  65. assert not user.validate_password('new_password')
  66. app = TracimCLI()
  67. result = app.run([
  68. 'user', 'update',
  69. '-c', 'tests_configs.ini#command_test',
  70. '-l', 'admin@admin.admin',
  71. '-p', 'new_password'
  72. ])
  73. new_user = api.get_one_by_email('admin@admin.admin')
  74. assert new_user.email == 'admin@admin.admin'
  75. assert new_user.validate_password('new_password')
  76. assert not new_user.validate_password('admin@admin.admin')