test_forms.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. # coding: utf-8
  2. from echod.forms import RequestForm, ResponseForm, MockForm
  3. def test_request_form():
  4. data = {
  5. 'body': {
  6. 'name': 'John Doe'
  7. },
  8. 'headers': {
  9. 'content_type': 'application/json',
  10. 'accept': 'application/json'
  11. }
  12. }
  13. form = RequestForm(data=data)
  14. assert form.validate()
  15. def test_response_form():
  16. data = {
  17. 'body': {
  18. 'name': 'John Doe'
  19. },
  20. 'headers': {
  21. 'content_type': 'application/json',
  22. 'accept': 'application/json'
  23. },
  24. 'status_code': 201,
  25. }
  26. form = ResponseForm(data=data)
  27. assert form.validate()
  28. def test_mock_form():
  29. data = {
  30. 'method': 'PUT',
  31. 'path': '/v1/users/',
  32. 'request': {
  33. 'body': {
  34. 'name': 'John Doe'
  35. },
  36. 'headers': {
  37. 'content_type': 'application/json',
  38. 'accept': 'application/json'
  39. }
  40. },
  41. 'response': {
  42. 'body': {
  43. 'name': 'John Doe'
  44. },
  45. 'headers': {
  46. 'content_type': 'application/json',
  47. 'accept': 'application/json'
  48. },
  49. 'status_code': 201,
  50. }
  51. }
  52. form = MockForm(data=data)
  53. assert form.validate()
  54. def test_mock_form_without_request():
  55. data = {
  56. 'method': 'PUT',
  57. 'path': '/v1/users/',
  58. 'response': {
  59. 'body': {
  60. 'name': 'John Doe'
  61. },
  62. 'headers': {
  63. 'content_type': 'application/json',
  64. 'accept': 'application/json'
  65. },
  66. 'status_code': 201,
  67. }
  68. }
  69. form = MockForm(data=data)
  70. assert form.validate()