Simple app to add configuration options to a Django project.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: changes on tests

+28 -25
+1
.gitignore
··· 63 63 build/ 64 64 dist/ 65 65 .coverage 66 + cov.xml
+27 -25
tests/test_options.py
··· 1 - from django.test import TestCase 1 + import pytest 2 2 from rest_framework import status 3 3 from rest_framework.test import APITestCase 4 4 ··· 7 7 from tests.factories import OptionFactory, UserFactory, UserOptionFactory 8 8 9 9 10 - class OptionTests(TestCase): 10 + @pytest.mark.django_db 11 + class OptionTests: 11 12 def test_default_options(self): 12 13 value = Option.objects.get_value("default_option", default="other") 13 - self.assertEqual("default", value) 14 + assert value == "default" 14 15 15 16 def test_int_conversion_options(self): 16 17 name = "int_option" 17 18 OptionFactory(name=name, value="42", type=INT) 18 19 value = Option.objects.get_value(name) 19 - self.assertIsInstance(value, int) 20 - self.assertEqual(42, value) 20 + assert isinstance(value, int) 21 + assert value == 42 21 22 22 23 def test_str_conversion_options(self): 23 24 name = "string_option" 24 25 OptionFactory(name=name, value="42") 25 26 value = Option.objects.get_value(name) 26 - self.assertIsInstance(value, str) 27 - self.assertEqual("42", value) 27 + assert isinstance(value, str) 28 + assert value == "42" 28 29 29 30 def test_float_conversion_options(self): 30 31 name = "float_option" 31 32 OptionFactory(name=name, value="42.5", type=FLOAT) 32 33 value = Option.objects.get_value(name) 33 - self.assertIsInstance(value, float) 34 - self.assertAlmostEqual(42.5, value) 34 + assert isinstance(value, float) 35 + assert value == 42.5 35 36 36 37 def test_public(self): 37 38 options = OptionFactory.create_batch(size=5, is_public=True) 38 39 OptionFactory.create_batch(size=3, is_public=False) 39 - self.assertEqual(len(options), Option.objects.public().count()) 40 + assert Option.objects.public().count() == len(options) 40 41 41 42 42 - class UserOptionTests(TestCase): 43 + @pytest.mark.django_db 44 + class UserOptionTests: 43 45 def test_custom_user_options(self): 44 46 user = UserFactory() 45 47 name = "default_option" ··· 48 50 name=name, public_name=name, value=expected_value, type=STR, user=user 49 51 ) 50 52 value = UserOption.objects.get_value(name, user=user, default="other") 51 - self.assertEqual(expected_value, value) 53 + assert value == expected_value 52 54 53 55 54 56 class OptionAPITests(APITestCase): ··· 57 59 admin = UserFactory(is_staff=True) 58 60 self.client.force_authenticate(admin) 59 61 response = self.client.get("/api/options/", format="json") 60 - self.assertEqual(response.status_code, status.HTTP_200_OK) 62 + assert status.HTTP_200_OK == response.status_code 61 63 data = response.json() 62 - self.assertEqual(1 + len(options), len(data)) 64 + assert len(data) == 1 + len(options) 63 65 64 66 def test_list_options_no_staff(self): 65 67 OptionFactory.create_batch(size=10) ··· 67 69 admin = UserFactory() 68 70 self.client.force_authenticate(admin) 69 71 response = self.client.get("/api/options/", format="json") 70 - self.assertEqual(response.status_code, status.HTTP_200_OK) 72 + assert status.HTTP_200_OK == response.status_code 71 73 data = response.json() 72 - self.assertEqual(len(options), len(data)) 74 + assert len(data) == len(options) 73 75 74 76 def test_cant_update_options_no_staff(self): 75 77 OptionFactory.create_batch(size=10) ··· 80 82 response = self.client.patch( 81 83 f"/api/options/{options[0].pk}/", data=data, format="json" 82 84 ) 83 - self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) 85 + assert status.HTTP_403_FORBIDDEN == response.status_code 84 86 85 87 def test_can_update_options_staff(self): 86 88 OptionFactory.create_batch(size=10) ··· 91 93 response = self.client.patch( 92 94 f"/api/options/{options[0].pk}/", data=data, format="json" 93 95 ) 94 - self.assertEqual(response.status_code, status.HTTP_200_OK) 96 + assert status.HTTP_200_OK == response.status_code 95 97 96 98 def test_list_user_options(self): 97 99 user = UserFactory() ··· 100 102 UserOptionFactory(name=name, value=expected_value, user=user, is_public=True) 101 103 self.client.force_authenticate(user) 102 104 response = self.client.get("/api/user-options/", format="json") 103 - self.assertEqual(response.status_code, status.HTTP_200_OK) 105 + assert status.HTTP_200_OK == response.status_code 104 106 data = response.json() 105 - self.assertEqual(1, len(data)) 107 + assert len(data) == 1 106 108 107 109 def test_list_user_options_with_exclude(self): 108 110 user = UserFactory() ··· 114 116 UserOptionFactory(name=name, value=expected_value, user=user, is_public=True) 115 117 self.client.force_authenticate(user) 116 118 response = self.client.get("/api/user-options/", format="json") 117 - self.assertEqual(response.status_code, status.HTTP_200_OK) 119 + assert status.HTTP_200_OK == response.status_code 118 120 data = response.json() 119 - self.assertEqual(1, len(data)) 121 + assert len(data) == 1 120 122 121 123 def test_create_user_options(self): 122 124 user = UserFactory() ··· 125 127 data = {"name": name, "value": expected_value} 126 128 self.client.force_authenticate(user) 127 129 response = self.client.post("/api/user-options/", data=data, format="json") 128 - self.assertEqual(response.status_code, status.HTTP_201_CREATED) 129 - self.assertEqual(1, UserOption.objects.filter(user=user).count()) 130 + assert status.HTTP_201_CREATED == response.status_code 131 + assert UserOption.objects.filter(user=user).count() == 1 130 132 131 133 def test_create_user_options_excluded(self): 132 134 user = UserFactory() ··· 135 137 data = {"name": name, "value": expected_value} 136 138 self.client.force_authenticate(user) 137 139 response = self.client.post("/api/user-options/", data=data, format="json") 138 - self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) 140 + assert status.HTTP_400_BAD_REQUEST == response.status_code