Wrote unit tests, added styling, deleted garbage, fixed small stuff
rodzic
70a5b8723c
commit
c15eeb6e64
|
@ -25,5 +25,4 @@
|
|||
{% if store_enabled %}
|
||||
<a href={% url 'cart' %} alt="Koszyk" > Koszyk </a>
|
||||
{% endif %}
|
||||
<a href="/" alt="TEST"> TEST </a>
|
||||
</div>
|
||||
|
|
|
@ -44,5 +44,6 @@ class SkinChangerForm(forms.Form):
|
|||
|
||||
background_color = ColorField(samples=COLOR_PALETTE)
|
||||
font_color = ColorField(samples=COLOR_PALETTE)
|
||||
button_color = ColorField(samples=COLOR_PALETTE)
|
||||
hr_color = ColorField(samples=COLOR_PALETTE)
|
||||
link_color = ColorField(samples=COLOR_PALETTE)
|
||||
hover_on_link_color = ColorField(samples=COLOR_PALETTE)
|
||||
|
|
|
@ -1,22 +1,26 @@
|
|||
{% extends 'base.html' %}
|
||||
|
||||
{% block content %}
|
||||
<div class="container">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-md-8">
|
||||
<div class="border p-4">
|
||||
<form method='POST'>
|
||||
{% csrf_token %}
|
||||
|
||||
<div class="form-group mb-4">
|
||||
<label for="{{ form.background_color.id_for_label }}">Background Color</label>
|
||||
<input type="color" name="background_color" value="{{ form.background_color.value }}">
|
||||
</div>
|
||||
|
||||
|
||||
<div class="form-group mb-4">
|
||||
<label for="{{ form.font_color.id_for_label }}">Font Color</label>
|
||||
<input type="color" name="font_color" value="{{ form.font_color.value }}">
|
||||
</div>
|
||||
|
||||
<div class="form-group mb-4">
|
||||
<label for="{{ form.button_color.id_for_label }}">Button Color</label>
|
||||
<input type="color" name="button_color" value="{{ form.button_color.value }}">
|
||||
<label for="{{ form.hr_color.id_for_label }}">HR Color</label>
|
||||
<input type="color" name="hr_color" value="{{ form.hr_color.value }}">
|
||||
</div>
|
||||
|
||||
<div class="form-group mb-4">
|
||||
|
@ -24,6 +28,15 @@
|
|||
<input type="color" name="link_color" value="{{ form.link_color.value }}">
|
||||
</div>
|
||||
|
||||
<div class="form-group mb-4">
|
||||
<label for="{{ form.hover_on_link_color.id_for_label }}">Hover on link Color</label>
|
||||
<input type="color" name="hover_on_link_color" value="{{ form.hover_on_link_color.value }}">
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-primary">Save</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock content %}
|
||||
|
|
|
@ -2,8 +2,8 @@ from django.test import TestCase
|
|||
from django.urls import reverse
|
||||
import json
|
||||
import os
|
||||
|
||||
from .forms import SiteConfigurationForm
|
||||
from .forms import SiteConfigurationForm, SkinChangerForm
|
||||
from .views import generate_css_content
|
||||
|
||||
|
||||
class SetupPageViewTestCase(TestCase):
|
||||
|
@ -13,12 +13,14 @@ class SetupPageViewTestCase(TestCase):
|
|||
self.assertIsInstance(response.context['form'], SiteConfigurationForm)
|
||||
|
||||
def test_post_valid_form(self):
|
||||
|
||||
logo_path = '/app/artel/static/images/icons/las_ruinas_PL.png'
|
||||
logo_file = open(logo_path, 'rb')
|
||||
form_data = {
|
||||
'logo': logo_file,
|
||||
'shop_enabled': False,
|
||||
'navbar_position': 'left'
|
||||
'navbar_position': 'left',
|
||||
'skin': 'dark',
|
||||
}
|
||||
response = self.client.post(reverse('setup'), data=form_data, follow=True)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
@ -30,6 +32,7 @@ class SetupPageViewTestCase(TestCase):
|
|||
self.assertEqual(json_data['logo'], 'media/images/icons/las_ruinas_PL.png')
|
||||
self.assertFalse(json_data['shop_enabled'])
|
||||
self.assertEqual(json_data['navbar_position'], 'left')
|
||||
self.assertEqual(json_data['skin'], 'dark')
|
||||
os.remove('config.json')
|
||||
|
||||
def test_post_invalid_form(self):
|
||||
|
@ -37,7 +40,6 @@ class SetupPageViewTestCase(TestCase):
|
|||
response = self.client.post(reverse('setup'), data=form_data)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertFalse(os.path.exists('config.json'))
|
||||
self.assertContains(response, 'This field is required')
|
||||
|
||||
|
||||
class CheckSetupMiddlewareTestCase(TestCase):
|
||||
|
@ -62,9 +64,81 @@ class SetupContextProcessorTestCase(TestCase):
|
|||
settings.NAVBAR_POSITION = 'left'
|
||||
settings.LOGO = 'media/images/icons/logo.png'
|
||||
settings.SHOP_ENABLED = True
|
||||
settings.SKIN = 'none'
|
||||
|
||||
response = self.client.get(reverse('setup'))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(response.context['navbar_position'], 'left')
|
||||
self.assertEqual(response.context['logo_url'], 'media/images/icons/logo.png')
|
||||
self.assertTrue(response.context['shop_enabled'])
|
||||
self.assertEqual(response.context['skin'], 'none')
|
||||
|
||||
|
||||
class SkinChangerViewTest(TestCase):
|
||||
def test_get_request(self):
|
||||
if not os.path.exists('config.json'):
|
||||
with open('config.json', 'w') as file:
|
||||
file.write('{}')
|
||||
response = self.client.get(reverse('skin'))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertTemplateUsed(response, 'skin_changer.html')
|
||||
self.assertIsInstance(response.context['form'], SkinChangerForm)
|
||||
os.remove('config.json')
|
||||
|
||||
def test_post_request_with_valid_form(self):
|
||||
if not os.path.exists('config.json'):
|
||||
with open('config.json', 'w') as file:
|
||||
file.write('{}')
|
||||
form_data = {
|
||||
'background_color': '#FFFFFF',
|
||||
'font_color': '#000000',
|
||||
'hr_color': '#FFFFFF',
|
||||
'link_color': '#000000',
|
||||
'hover_on_link_color': '#FFFFFF',
|
||||
}
|
||||
response = self.client.post(reverse('skin'), form_data)
|
||||
self.assertEqual(response.status_code, 302)
|
||||
self.assertRedirects(response, '/')
|
||||
os.remove('config.json')
|
||||
|
||||
def test_post_request_with_invalid_form(self):
|
||||
if not os.path.exists('config.json'):
|
||||
with open('config.json', 'w') as file:
|
||||
file.write('{}')
|
||||
form_data = {}
|
||||
response = self.client.post(reverse('skin'), form_data)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertTemplateUsed(response, 'skin_changer.html')
|
||||
self.assertIsInstance(response.context['form'], SkinChangerForm)
|
||||
os.remove('config.json')
|
||||
|
||||
|
||||
class GenerateCSSContentTest(TestCase):
|
||||
def test_generate_css_content(self):
|
||||
form_data = {
|
||||
'background_color': '#FFFFFF',
|
||||
'font_color': '#000000',
|
||||
'hr_color': '#FFFFFF',
|
||||
'link_color': '#000000',
|
||||
'hover_on_link_color': '#FFFFFF',
|
||||
}
|
||||
expected_css_content = """
|
||||
body {
|
||||
background-color: #FFFFFF;
|
||||
color: #000000;
|
||||
}
|
||||
|
||||
hr {
|
||||
background-color: #FFFFFF;
|
||||
}
|
||||
|
||||
a[href] {
|
||||
color: #000000;
|
||||
}
|
||||
|
||||
a[href]:hover {
|
||||
color: #FFFFFF;
|
||||
}
|
||||
"""
|
||||
css_content = generate_css_content(form_data)
|
||||
self.assertEqual(css_content, expected_css_content)
|
||||
|
|
|
@ -24,11 +24,12 @@ class SetupPageView(View):
|
|||
form_data['logo'] = None
|
||||
|
||||
json_data = json.dumps(form_data, indent=4)
|
||||
|
||||
with open('config.json', 'w') as file:
|
||||
file.write(json_data)
|
||||
|
||||
if form_data['skin'] == 'custom':
|
||||
return redirect('/skins')
|
||||
|
||||
return redirect('/')
|
||||
else:
|
||||
return render(request, self.template_name, {'form': form})
|
||||
|
@ -45,13 +46,13 @@ class SkinChangerView(View):
|
|||
form = SkinChangerForm(request.POST)
|
||||
if form.is_valid():
|
||||
form_data = form.data
|
||||
if form_data:
|
||||
css_content = generate_css_content(form_data)
|
||||
file_name = 'custom.css'
|
||||
css_file_path = os.path.join(settings.MEDIA_ROOT, 'css', file_name)
|
||||
with open(css_file_path, 'w') as css_file:
|
||||
css_file.write(css_content)
|
||||
return redirect('/')
|
||||
else:
|
||||
return render(request, self.template_name, {'form': form})
|
||||
|
||||
|
||||
|
@ -61,11 +62,17 @@ def generate_css_content(form_data):
|
|||
background-color: {form_data['background_color']};
|
||||
color: {form_data['font_color']};
|
||||
}}
|
||||
.btn {{
|
||||
background-color: {form_data['button_color']};
|
||||
|
||||
hr {{
|
||||
background-color: {form_data['hr_color']};
|
||||
}}
|
||||
a {{
|
||||
|
||||
a[href] {{
|
||||
color: {form_data['link_color']};
|
||||
}}
|
||||
|
||||
a[href]:hover {{
|
||||
color: {form_data['hover_on_link_color']};
|
||||
}}
|
||||
"""
|
||||
return css_content
|
||||
|
|
Ładowanie…
Reference in New Issue