django-camomilla-cms 6.0.0b18__py2.py3-none-any.whl → 6.0.1__py2.py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
tests/test_media.py CHANGED
@@ -8,11 +8,12 @@ from rest_framework.test import APIClient
8
8
 
9
9
  client = APIClient()
10
10
 
11
+
11
12
  class MediaTestCase(TestCase):
12
13
  def setUp(self):
13
14
  self.client = APIClient()
14
15
  token = login_superuser()
15
- self.client.credentials(HTTP_AUTHORIZATION='Token ' + token)
16
+ self.client.credentials(HTTP_AUTHORIZATION="Token " + token)
16
17
 
17
18
  @pytest.mark.django_db
18
19
  def test_media_api_crud(self):
@@ -22,7 +23,17 @@ class MediaTestCase(TestCase):
22
23
  "/api/camomilla/media/",
23
24
  {
24
25
  "file": asset,
25
- "data": json.dumps({"translations": {"en": {"alt_text": "Test 1", "title": "Test 1", "description": "Test 1"}}}),
26
+ "data": json.dumps(
27
+ {
28
+ "translations": {
29
+ "en": {
30
+ "alt_text": "Test 1",
31
+ "title": "Test 1",
32
+ "description": "Test 1",
33
+ }
34
+ }
35
+ }
36
+ ),
26
37
  },
27
38
  format="multipart",
28
39
  )
@@ -40,13 +51,23 @@ class MediaTestCase(TestCase):
40
51
  "/api/camomilla/media/",
41
52
  {
42
53
  "file": asset,
43
- "data": json.dumps({"translations": {"en": {"alt_text": "Test 2", "title": "Test 2", "description": "Test 2"}}}),
54
+ "data": json.dumps(
55
+ {
56
+ "translations": {
57
+ "en": {
58
+ "alt_text": "Test 2",
59
+ "title": "Test 2",
60
+ "description": "Test 2",
61
+ }
62
+ }
63
+ }
64
+ ),
44
65
  },
45
66
  format="multipart",
46
67
  )
47
68
  assert response.status_code == 201
48
69
  assert Media.objects.count() == 2
49
- media = Media.objects.first() # Ordering in model is descending -pk
70
+ media = Media.objects.first() # Ordering in model is descending -pk
50
71
  assert media.alt_text == "Test 2"
51
72
  assert media.title == "Test 2"
52
73
  assert media.description == "Test 2"
@@ -55,17 +76,17 @@ class MediaTestCase(TestCase):
55
76
  # Read media
56
77
  response = self.client.get("/api/camomilla/media/2/")
57
78
  assert response.status_code == 200
58
- assert response.json()['id'] == 2
59
- assert response.json()['title'] == "Test 2"
60
- assert response.json()['file'] == "http://testserver/media/37059501.png"
79
+ assert response.json()["id"] == 2
80
+ assert response.json()["title"] == "Test 2"
81
+ assert response.json()["file"] == "http://testserver/media/37059501.png"
61
82
 
62
83
  # Read medias
63
84
  response = self.client.get("/api/camomilla/media/")
64
85
  assert response.status_code == 200
65
- assert response.json()[0]['id'] == 2 # Ordering in model is descending -pk
66
- assert response.json()[0]['title'] == "Test 2"
67
- assert response.json()[1]['id'] == 1
68
- assert response.json()[1]['title'] == "Test 1"
86
+ assert response.json()[0]["id"] == 2 # Ordering in model is descending -pk
87
+ assert response.json()[0]["title"] == "Test 2"
88
+ assert response.json()[1]["id"] == 1
89
+ assert response.json()[1]["title"] == "Test 1"
69
90
 
70
91
  # Delete media
71
92
  response = self.client.delete("/api/camomilla/media/2/")
@@ -75,7 +96,6 @@ class MediaTestCase(TestCase):
75
96
  assert media.id == 1
76
97
  assert media.title == "Test 1"
77
98
 
78
-
79
99
  @pytest.mark.django_db
80
100
  def test_media_compression(self):
81
101
  asset = load_asset_and_remove_media("Sample-jpg-image-10mb.jpg")
@@ -84,7 +104,17 @@ class MediaTestCase(TestCase):
84
104
  "/api/camomilla/media/",
85
105
  {
86
106
  "file": asset,
87
- "data": json.dumps({"translations": {"en": {"alt_text": "Test", "title": "Test", "description": "Test"}}}),
107
+ "data": json.dumps(
108
+ {
109
+ "translations": {
110
+ "en": {
111
+ "alt_text": "Test",
112
+ "title": "Test",
113
+ "description": "Test",
114
+ }
115
+ }
116
+ }
117
+ ),
88
118
  },
89
119
  format="multipart",
90
120
  )
@@ -94,7 +124,6 @@ class MediaTestCase(TestCase):
94
124
  assert media.file.size < asset_size
95
125
  assert media.file.size < 1000000 # 1MB
96
126
 
97
-
98
127
  @pytest.mark.django_db
99
128
  def test_inflating_prevent(self):
100
129
  asset = load_asset_and_remove_media("optimized.jpg")
@@ -103,7 +132,17 @@ class MediaTestCase(TestCase):
103
132
  "/api/camomilla/media/",
104
133
  {
105
134
  "file": asset,
106
- "data": json.dumps({"translations": {"en": {"alt_text": "Test", "title": "Test", "description": "Test"}}}),
135
+ "data": json.dumps(
136
+ {
137
+ "translations": {
138
+ "en": {
139
+ "alt_text": "Test",
140
+ "title": "Test",
141
+ "description": "Test",
142
+ }
143
+ }
144
+ }
145
+ ),
107
146
  },
108
147
  format="multipart",
109
148
  )
tests/test_menu.py CHANGED
@@ -11,10 +11,10 @@ class MenuTestCase(TestCase):
11
11
  def setUp(self):
12
12
  self.client = APIClient()
13
13
  token = login_superuser()
14
- self.client.credentials(HTTP_AUTHORIZATION='Token ' + token)
14
+ self.client.credentials(HTTP_AUTHORIZATION="Token " + token)
15
15
 
16
- def renderTemplate(self, template, context = None):
17
- return Template('{% load menus %}' + template).render(Context(context))
16
+ def renderTemplate(self, template, context=None):
17
+ return Template("{% load menus %}" + template).render(Context(context))
18
18
 
19
19
  @pytest.mark.django_db
20
20
  def test_template_render_menu(self):
@@ -35,7 +35,7 @@ class MenuTestCase(TestCase):
35
35
  self.renderTemplate('{% render_menu "key_3" %}')
36
36
  self.renderTemplate('{% render_menu "key_4" %}')
37
37
 
38
- rendered = html.unescape(self.renderTemplate('{% get_menus %}'))
38
+ rendered = html.unescape(self.renderTemplate("{% get_menus %}"))
39
39
  assert rendered == "{'key_3': <Menu: key_3>, 'key_4': <Menu: key_4>}"
40
40
 
41
41
  rendered = html.unescape(self.renderTemplate('{% get_menus "arg" %}'))
@@ -43,9 +43,11 @@ class MenuTestCase(TestCase):
43
43
 
44
44
  rendered = html.unescape(self.renderTemplate('{% get_menus "key_3" %}'))
45
45
  assert rendered == "{'key_3': <Menu: key_3>}"
46
-
46
+
47
47
  menus = 'test "menus" in context'
48
- rendered = html.unescape(self.renderTemplate('{% get_menus %}', {"menus": menus}))
48
+ rendered = html.unescape(
49
+ self.renderTemplate("{% get_menus %}", {"menus": menus})
50
+ )
49
51
  assert rendered == menus
50
52
 
51
53
  @pytest.mark.django_db
@@ -53,7 +55,9 @@ class MenuTestCase(TestCase):
53
55
  self.renderTemplate('{% render_menu "key_5" %}')
54
56
 
55
57
  menu = Menu.objects.first()
56
- menu.nodes = [{"title": "key_5_node_title", "link":{"static": "key_5_url_static"}}]
58
+ menu.nodes = [
59
+ {"title": "key_5_node_title", "link": {"static": "key_5_url_static"}}
60
+ ]
57
61
  menu.save()
58
62
 
59
63
  rendered = html.unescape(self.renderTemplate('{% render_menu "key_5" %}'))
@@ -64,11 +68,17 @@ class MenuTestCase(TestCase):
64
68
  self.renderTemplate('{% render_menu "key_6_custom" %}')
65
69
 
66
70
  menu = Menu.objects.first()
67
- menu.nodes = [{"title": "key_6_node_title", "link":{"static": "key_6_url_static"}}]
71
+ menu.nodes = [
72
+ {"title": "key_6_node_title", "link": {"static": "key_6_url_static"}}
73
+ ]
68
74
  menu.save()
69
75
 
70
- rendered = html.unescape(self.renderTemplate('{% render_menu "key_6_custom" "website/menu_custom.html" %}'))
71
- assert {'This is custom menu: key_6_node_title' in rendered}
76
+ rendered = html.unescape(
77
+ self.renderTemplate(
78
+ '{% render_menu "key_6_custom" "website/menu_custom.html" %}'
79
+ )
80
+ )
81
+ assert {"This is custom menu: key_6_node_title" in rendered}
72
82
 
73
83
  @pytest.mark.django_db
74
84
  def test_menu_in_page_template(self):
@@ -77,20 +87,25 @@ class MenuTestCase(TestCase):
77
87
  response = self.client.post(
78
88
  "/api/camomilla/pages/",
79
89
  {
80
- "translations": {
81
- "en": {
82
- "title": "title_page_menu_1",
83
- "permalink": "permalink_page_menu_en_1",
84
- "autopermalink": False
90
+ "translations": {
91
+ "en": {
92
+ "title": "title_page_menu_1",
93
+ "permalink": "permalink_page_menu_en_1",
94
+ "autopermalink": False,
95
+ }
85
96
  }
86
- }
87
97
  },
88
- format='json'
98
+ format="json",
89
99
  )
90
100
  assert response.status_code == 201
91
101
 
92
102
  menu = Menu.objects.first()
93
- menu.nodes = [{"title": "key_7_node_title", "link":{"page": { "id": 1, "model":"camomilla.page" }}}]
103
+ menu.nodes = [
104
+ {
105
+ "title": "key_7_node_title",
106
+ "link": {"page": {"id": 1, "model": "camomilla.page"}},
107
+ }
108
+ ]
94
109
  menu.save()
95
110
 
96
111
  rendered = html.unescape(self.renderTemplate('{% render_menu "key_7" %}'))
tests/test_model_api.py CHANGED
@@ -12,7 +12,9 @@ client = APIClient()
12
12
  def init_test():
13
13
  token = login_superuser()
14
14
  client.credentials(HTTP_AUTHORIZATION="Token " + token)
15
- SimpleRelationModel.objects.bulk_create([SimpleRelationModel(name=f"test{i}") for i in range(1, 10)])
15
+ SimpleRelationModel.objects.bulk_create(
16
+ [SimpleRelationModel(name=f"test{i}") for i in range(1, 10)]
17
+ )
16
18
 
17
19
 
18
20
  @pytest.mark.django_db
@@ -23,7 +25,9 @@ def test_simple_relation_model_api_endpoint():
23
25
  response = client.get("/api/models/simple-relation-model/1/")
24
26
  assert response.status_code == 200
25
27
  assert response.json()["name"] == "test1"
26
- response = client.patch("/api/models/simple-relation-model/1/", {"name": "updated"}, format="json")
28
+ response = client.patch(
29
+ "/api/models/simple-relation-model/1/", {"name": "updated"}, format="json"
30
+ )
27
31
  assert response.status_code == 200
28
32
  assert response.json()["name"] == "updated"
29
33
  response = client.delete("/api/models/simple-relation-model/1/")
@@ -33,7 +37,10 @@ def test_simple_relation_model_api_endpoint():
33
37
  assert len(response.json()) == 8
34
38
  response = client.get("/api/models/simple-relation-model/1/")
35
39
  assert response.status_code == 404
36
- assert response.json() in [{"detail": "Not found."}, {'detail': 'No SimpleRelationModel matches the given query.'}]
40
+ assert response.json() in [
41
+ {"detail": "Not found."},
42
+ {"detail": "No SimpleRelationModel matches the given query."},
43
+ ]
37
44
 
38
45
 
39
46
  @pytest.mark.django_db
@@ -45,24 +52,62 @@ def test_test_model_api_endpoint():
45
52
  response = client.post("/api/models/test-model/", test_model_data, format="json")
46
53
  assert response.status_code == 201
47
54
  assert response.json()["title"] == test_model_data["title"]
48
- assert response.json()["structured_data"]["name"] == test_model_data["structured_data"]["name"]
49
- assert response.json()["structured_data"]["age"] == test_model_data["structured_data"]["age"]
50
- assert response.json()["structured_data"]["child"]["name"] == test_model_data["structured_data"]["child"]["name"]
51
- assert response.json()["structured_data"]["childs"][0]["name"] == test_model_data["structured_data"]["childs"][0]["name"]
52
- assert response.json()["structured_data"]["fk_field"]["id"] == test_model_data["structured_data"]["fk_field"]["id"]
53
- assert response.json()["structured_data"]["qs_field"][0]["id"] == test_model_data["structured_data"]["qs_field"][0]["id"]
55
+ assert (
56
+ response.json()["structured_data"]["name"]
57
+ == test_model_data["structured_data"]["name"]
58
+ )
59
+ assert (
60
+ response.json()["structured_data"]["age"]
61
+ == test_model_data["structured_data"]["age"]
62
+ )
63
+ assert (
64
+ response.json()["structured_data"]["child"]["name"]
65
+ == test_model_data["structured_data"]["child"]["name"]
66
+ )
67
+ assert (
68
+ response.json()["structured_data"]["childs"][0]["name"]
69
+ == test_model_data["structured_data"]["childs"][0]["name"]
70
+ )
71
+ assert (
72
+ response.json()["structured_data"]["fk_field"]["id"]
73
+ == test_model_data["structured_data"]["fk_field"]["id"]
74
+ )
75
+ assert (
76
+ response.json()["structured_data"]["qs_field"][0]["id"]
77
+ == test_model_data["structured_data"]["qs_field"][0]["id"]
78
+ )
54
79
  response = client.get("/api/models/test-model/")
55
80
  assert response.status_code == 200
56
81
  assert len(response.json()) == 1
57
82
  response = client.get("/api/models/test-model/1/")
58
83
  assert response.status_code == 200
59
84
  assert response.json()["title"] == test_model_data["title"]
60
- assert response.json()["structured_data"]["name"] == test_model_data["structured_data"]["name"]
61
- assert response.json()["structured_data"]["age"] == test_model_data["structured_data"]["age"]
62
- assert response.json()["structured_data"]["child"]["name"] == test_model_data["structured_data"]["child"]["name"]
63
- assert response.json()["structured_data"]["childs"][0]["name"] == test_model_data["structured_data"]["childs"][0]["name"]
64
- assert response.json()["structured_data"]["fk_field"]["id"] == test_model_data["structured_data"]["fk_field"]["id"]
65
- assert response.json()["structured_data"]["qs_field"][0]["id"] == test_model_data["structured_data"]["qs_field"][0]["id"]
66
- response = client.patch("/api/models/test-model/1/", {"title": "updated"}, format="json")
85
+ assert (
86
+ response.json()["structured_data"]["name"]
87
+ == test_model_data["structured_data"]["name"]
88
+ )
89
+ assert (
90
+ response.json()["structured_data"]["age"]
91
+ == test_model_data["structured_data"]["age"]
92
+ )
93
+ assert (
94
+ response.json()["structured_data"]["child"]["name"]
95
+ == test_model_data["structured_data"]["child"]["name"]
96
+ )
97
+ assert (
98
+ response.json()["structured_data"]["childs"][0]["name"]
99
+ == test_model_data["structured_data"]["childs"][0]["name"]
100
+ )
101
+ assert (
102
+ response.json()["structured_data"]["fk_field"]["id"]
103
+ == test_model_data["structured_data"]["fk_field"]["id"]
104
+ )
105
+ assert (
106
+ response.json()["structured_data"]["qs_field"][0]["id"]
107
+ == test_model_data["structured_data"]["qs_field"][0]["id"]
108
+ )
109
+ response = client.patch(
110
+ "/api/models/test-model/1/", {"title": "updated"}, format="json"
111
+ )
67
112
  assert response.status_code == 200
68
113
  assert response.json()["title"] == "updated"
@@ -26,7 +26,9 @@ def test_right_permissions():
26
26
  assert len(response.json()) == 1
27
27
  response = client.get("/api/models/test-model/1/")
28
28
  assert response.status_code == 200
29
- response = client.patch("/api/models/test-model/1/", {"title": "updated"}, format="json")
29
+ response = client.patch(
30
+ "/api/models/test-model/1/", {"title": "updated"}, format="json"
31
+ )
30
32
  assert response.status_code == 200
31
33
  assert response.json()["title"] == "updated"
32
34
  response = client.delete("/api/models/test-model/1/")
@@ -36,4 +38,7 @@ def test_right_permissions():
36
38
  assert len(response.json()) == 0
37
39
  response = client.get("/api/models/test-model/1/")
38
40
  assert response.status_code == 404
39
- assert response.json() in [{"detail": "Not found."}, {'detail': 'No TestModel matches the given query.'}]
41
+ assert response.json() in [
42
+ {"detail": "Not found."},
43
+ {"detail": "No TestModel matches the given query."},
44
+ ]