An ebook/comic library service and web client
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
2.0 KiB

  1. from flask import json
  2. from flask.testing import FlaskClient
  3. from tests.conftest import AuthActions
  4. def test_get_user_happy_path(auth: AuthActions, client: FlaskClient):
  5. auth.login()
  6. auth_header = auth.get_authorization_header_token()
  7. result = client.get(
  8. '/user/{}'.format(client.application.config['test_username']),
  9. headers={
  10. auth_header[0]: auth_header[1]
  11. })
  12. assert 200 == result.status_code
  13. assert result.json is not None
  14. assert result.json['name'] == client.application.config['test_username']
  15. def test_register_user_happy_path(auth: AuthActions, client: FlaskClient):
  16. auth.login()
  17. auth_header = auth.get_authorization_header_token()
  18. result = client.post(
  19. '/user/',
  20. data=json.dumps({
  21. 'name': 'test_registered_user'
  22. }),
  23. headers={
  24. auth_header[0]: auth_header[1],
  25. 'Content-Type': 'application/json'
  26. })
  27. assert 200 == result.status_code
  28. assert result.json is not None
  29. assert result.json['name'] == 'test_registered_user'
  30. def test_register_user_twice_failure(auth: AuthActions, client: FlaskClient):
  31. auth.login()
  32. auth_header = auth.get_authorization_header_token()
  33. result1 = client.post(
  34. '/user/',
  35. data=json.dumps({
  36. 'name': 'test_registered_user'
  37. }),
  38. headers={
  39. auth_header[0]: auth_header[1],
  40. 'Content-Type': 'application/json'
  41. })
  42. result2 = client.post(
  43. '/user/',
  44. data=json.dumps({
  45. 'name': 'test_registered_user'
  46. }),
  47. headers={
  48. auth_header[0]: auth_header[1],
  49. 'Content-Type': 'application/json'
  50. })
  51. assert 200 == result1.status_code
  52. assert result1.json is not None
  53. assert result1.json['name'] == 'test_registered_user'
  54. assert 400 == result2.status_code
  55. assert result2.json is not None
  56. assert result2.json['message'] == 'User name is already taken.'