test_api.py 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. from django.urls import reverse
  2. from django.utils import timezone
  3. from utilities.testing import APITestCase, APIViewTestCases
  4. from ..models import *
  5. class AppTest(APITestCase):
  6. def test_root(self):
  7. url = reverse('core-api:api-root')
  8. response = self.client.get('{}?format=api'.format(url), **self.header)
  9. self.assertEqual(response.status_code, 200)
  10. class DataSourceTest(APIViewTestCases.APIViewTestCase):
  11. model = DataSource
  12. brief_fields = ['description', 'display', 'id', 'name', 'url']
  13. bulk_update_data = {
  14. 'enabled': False,
  15. 'description': 'foo bar baz',
  16. }
  17. @classmethod
  18. def setUpTestData(cls):
  19. data_sources = (
  20. DataSource(name='Data Source 1', type='local', source_url='file:///var/tmp/source1/'),
  21. DataSource(name='Data Source 2', type='local', source_url='file:///var/tmp/source2/'),
  22. DataSource(name='Data Source 3', type='local', source_url='file:///var/tmp/source3/'),
  23. )
  24. DataSource.objects.bulk_create(data_sources)
  25. cls.create_data = [
  26. {
  27. 'name': 'Data Source 4',
  28. 'type': 'git',
  29. 'source_url': 'https://example.com/git/source4'
  30. },
  31. {
  32. 'name': 'Data Source 5',
  33. 'type': 'git',
  34. 'source_url': 'https://example.com/git/source5'
  35. },
  36. {
  37. 'name': 'Data Source 6',
  38. 'type': 'git',
  39. 'source_url': 'https://example.com/git/source6'
  40. },
  41. ]
  42. class DataFileTest(
  43. APIViewTestCases.GetObjectViewTestCase,
  44. APIViewTestCases.ListObjectsViewTestCase,
  45. APIViewTestCases.GraphQLTestCase
  46. ):
  47. model = DataFile
  48. brief_fields = ['display', 'id', 'path', 'url']
  49. @classmethod
  50. def setUpTestData(cls):
  51. datasource = DataSource.objects.create(
  52. name='Data Source 1',
  53. type='local',
  54. source_url='file:///var/tmp/source1/'
  55. )
  56. data_files = (
  57. DataFile(
  58. source=datasource,
  59. path='dir1/file1.txt',
  60. last_updated=timezone.now(),
  61. size=1000,
  62. hash='442da078f0111cbdf42f21903724f6597c692535f55bdfbbea758a1ae99ad9e1'
  63. ),
  64. DataFile(
  65. source=datasource,
  66. path='dir1/file2.txt',
  67. last_updated=timezone.now(),
  68. size=2000,
  69. hash='a78168c7c97115bafd96450ed03ea43acec495094c5caa28f0d02e20e3a76cc2'
  70. ),
  71. DataFile(
  72. source=datasource,
  73. path='dir1/file3.txt',
  74. last_updated=timezone.now(),
  75. size=3000,
  76. hash='12b8827a14c4d5a2f30b6c6e2b7983063988612391c6cbe8ee7493b59054827a'
  77. ),
  78. )
  79. DataFile.objects.bulk_create(data_files)