Coverage for tests/django_tests/api/keys/test_create.py: 57%

23 statements  

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

1from django_napse.api.keys import KeyView 

2from django_napse.utils.api_test_case import APITestCase 

3from django_napse.utils.dict_comparison import compare_responses 

4 

5""" 

6python tests/test_app/manage.py test tests.django_tests.api.keys.test_create -v2 --keepdb --parallel 

7""" 

8 

9 

10class KeyCreateAPITestCase: 

11 def test_create(self): 

12 self.run_tests("create") 

13 

14 def setup(self): 

15 def create_all_good(): 

16 def setup__create(): 

17 return self.client.post(path=self.url, data=self.data, headers=self.headers) 

18 

19 def check__create(response): 

20 return compare_responses(response.data, {"key": ""}) 

21 

22 return { 

23 "name": "create_all_good", 

24 "setup": setup__create, 

25 "status_code": 201, 

26 "checks": [check__create], 

27 } 

28 

29 def create_missing_username(): 

30 def setup__create(): 

31 return self.client.post(path=self.url, data={}, headers=self.headers) 

32 

33 def check__create(response): 

34 return compare_responses(response.data, {"error": ""}) 

35 

36 return { 

37 "name": "create_missing_username", 

38 "setup": setup__create, 

39 "status_code": 400, 

40 "data": {}, 

41 "checks": [check__create], 

42 } 

43 

44 return { 

45 "create": { 

46 "url_name": "key-list", 

47 "view": KeyView, 

48 "method": "POST", 

49 "data": {"username": "test_username"}, 

50 "tests": [ 

51 # create_all_good(), 

52 # create_missing_username(), 

53 ], 

54 }, 

55 } 

56 

57 

58class KeyCreateAPIBinanceTestCase(KeyCreateAPITestCase, APITestCase): 

59 exchange = "BINANCE"