Coverage for tests/django_tests/api/spaces/test_space_view.py: 59%

27 statements  

« prev     ^ index     » next       coverage.py v7.4.3, created at 2024-03-12 13:49 +0000

1import contextlib 

2 

3from django_napse.api.spaces import SpaceView 

4from django_napse.utils.api_test_case import APITestCase, ViewTest 

5from django_napse.utils.dict_comparison import compare_responses 

6 

7""" 

8python tests/test_app/manage.py test tests.django_tests.api.spaces.test_space_view -v2 --keepdb --parallel 

9""" 

10 

11 

12class ListSpaceViewTest(ViewTest): 

13 def check_response(self, response) -> bool: 

14 return compare_responses( 

15 response.data[0], 

16 { 

17 "name": str(), 

18 "description": str(), 

19 "uuid": str(), 

20 "delta": float(), 

21 "value": float(), 

22 "exchange_account": str(), 

23 }, 

24 ) 

25 

26 def run(self): 

27 return [ 

28 { 

29 "name": "response", 

30 "setup": self.setup(data=None), 

31 "status_code": 200, 

32 "checks": [self.check_response], 

33 }, 

34 ] 

35 

36 

37class RetrieveSpaceViewTest(ViewTest): 

38 def check_response(self, response) -> bool: 

39 return compare_responses( 

40 response.data, 

41 { 

42 "name": str(), 

43 "description": str(), 

44 "uuid": str(), 

45 "exchange_account": str(), 

46 "created_at": str(), 

47 "statistics": { 

48 "value": float(), 

49 "order_count_30": float(), 

50 "delta_30": float(), 

51 }, 

52 "wallet": {}, 

53 "history": [], 

54 "fleets": [], 

55 }, 

56 authorize_abstract_comparison=True, 

57 ) 

58 

59 def run(self): 

60 return [ 

61 { 

62 "name": "missing_data", 

63 "setup": self.setup(), 

64 "status_code": 200, 

65 "checks": [self.check_response], 

66 }, 

67 ] 

68 

69 

70class SpaceViewTestCase: 

71 # def test_list(self): 

72 # self.run_tests("list") 

73 

74 # def test_retrieve(self): 

75 # self.run_tests("retrieve") 

76 

77 def setUp(self): 

78 super().setUp() 

79 from django_napse.core.models import SpaceHistory 

80 

81 with contextlib.suppress(Exception): 

82 SpaceHistory.objects.create(owner=self.space) 

83 

84 def setup(self): 

85 list_test = ListSpaceViewTest(self) 

86 retrieve_test = RetrieveSpaceViewTest(self) 

87 

88 return { 

89 "list": { 

90 "url_name": "space-list", 

91 "view": SpaceView, 

92 "method": "GET", 

93 "tests": list_test.run(), 

94 }, 

95 "retrieve": { 

96 "url_name": "space-detail", 

97 "view": SpaceView, 

98 "method": "GET", 

99 "kwargs": {"pk": self.space.uuid}, 

100 "tests": retrieve_test.run(), 

101 }, 

102 } 

103 

104 

105class SpaceViewAPIBinanceTestCase(SpaceViewTestCase, APITestCase): 

106 exchange = "BINANCE"