test_uploads.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import os
  2. import pytest
  3. import pynecone as pc
  4. @pytest.fixture
  5. def upload_component():
  6. """A test upload component function.
  7. Returns:
  8. A test upload component function.
  9. """
  10. def upload_component():
  11. return pc.upload(
  12. pc.button("select file"),
  13. pc.text("Drag and drop files here or click to select files"),
  14. border="1px dotted black",
  15. )
  16. return upload_component()
  17. @pytest.fixture
  18. def upload_component_with_props():
  19. """A test upload component with props function.
  20. Returns:
  21. A test upload component with props function.
  22. """
  23. def upload_component_with_props():
  24. return pc.upload(
  25. pc.button("select file"),
  26. pc.text("Drag and drop files here or click to select files"),
  27. border="1px dotted black",
  28. no_drag=True,
  29. max_files=2,
  30. )
  31. return upload_component_with_props()
  32. def test_upload_component_render(upload_component):
  33. """Test that the render function is set correctly.
  34. Args:
  35. upload_component: component fixture
  36. """
  37. assert (
  38. str(upload_component) == f"<ReactDropzone multiple={{true}}{os.linesep}"
  39. "onDrop={e => File(e)}>{({getRootProps, getInputProps}) => (<Box "
  40. 'sx={{"border": "1px dotted black"}}{...getRootProps()}><Input '
  41. f'type="file"{{...getInputProps()}}/>{os.linesep}'
  42. f"<Button>{{`select file`}}</Button>{os.linesep}"
  43. "<Text>{`Drag and drop files here or click to select "
  44. "files`}</Text></Box>)}</ReactDropzone>"
  45. )
  46. def test_upload_component_with_props_render(upload_component_with_props):
  47. """Test that the render function is set correctly.
  48. Args:
  49. upload_component_with_props: component fixture
  50. """
  51. assert (
  52. str(upload_component_with_props) == f"<ReactDropzone maxFiles={{2}}{os.linesep}"
  53. f"multiple={{true}}{os.linesep}"
  54. f"noDrag={{true}}{os.linesep}"
  55. "onDrop={e => File(e)}>{({getRootProps, getInputProps}) => (<Box "
  56. 'sx={{"border": "1px dotted black"}}{...getRootProps()}><Input '
  57. f'type="file"{{...getInputProps()}}/>{os.linesep}'
  58. f"<Button>{{`select file`}}</Button>{os.linesep}"
  59. "<Text>{`Drag and drop files here or click to select "
  60. "files`}</Text></Box>)}</ReactDropzone>"
  61. )