def update_configuration_colors(sender, instance, **kwargs): # /home/valentin/acgh-site/assets/scss/components/helper-block-v1/component.scss # /home/valentin/acgh-site/static/scss/component.scss if instance.configuration: other_schemes = ColorScheme.objects.all().exclude(pk=instance.pk) for scheme in other_schemes: if scheme.configuration: scheme.configuration = None scheme.save() configuration = instance.configuration configuration.save() # import pdb; pdb.set_trace() if instance.colors != configuration.current_color_set: try: update_sass_variables(instance.pk) delete_all_css_files() request = RequestFactory() factory_response = index(request.get('/')) collectstatic = subprocess.Popen(["/home/valentin/django2/bin/python3", "manage.py", "collectstatic", "--ignore=*.scss", "--noinput"]) collectstatic.wait() except Exception as e: print('COLORSCHEME EXCEPTION', e) # subprocess.Popen(["python3", "manage.py", "collectstatic", "--noinput", "--ignore=*.scss"]) finally: configuration.current_color_set = instance.colors configuration.save()
def update_styles_on_component_save(sender, instance, **kwargs): if instance.configuration and instance.title not in instance.configuration.current_component_set: try: delete_all_css_files() request = RequestFactory() factory_response = index(request.get('/')) collectstatic = subprocess.Popen(["/home/valentin/django2/bin/python3", "manage.py", "collectstatic", "--ignore=*.scss", "--noinput"]) collectstatic.wait() except Exception as e: print("COMPONENT EXCEPTION", e) # subprocess.Popen(["python3", "manage.py", "collectstatic", "--noinput", "--ignore=*.scss"]) finally: instance.configuration.update_current_component_set() try: activated_configuration = SiteConfiguration.objects.filter(activated=True).first() if not instance.configuration and instance.title in activated_configuration.current_component_set: try: configuration = SiteConfiguration.objects.filter(activated=True).first() configuration.update_current_component_set() except Exception as e: print('ERROR UPDATING SITE CONFIGURATION', e) finally: pass except Exception as e: print('ERROR: NO SITE CONFIGURATION') pass
def test_side_panel_posts_available_on_main_page(db, rf): dates = [] for i in range(6): dates.append(timezone.now() - datetime.timedelta(days=i)) for date in dates: mixer.blend(Post, active=True, main_picture=File(open('media/img_1.jpg', 'rb')), published_date=date, full_description=mixer.RANDOM) request = rf.get('/') response = mainapp.index(request) html = response.content.decode('utf8') all_posts = Post.objects.all().order_by('-published_date')[:6] for post in all_posts: assert post.title in html for post in all_posts[5:6]: assert post.main_picture.thumbnail.url in html # test details of news req_details = rf.get('/news_details/{}/'.format(post.pk)) res_details = mainapp.news_details(req_details, post.pk) html_details = res_details.content.decode('utf8') assert res_details.status_code == 200 assert post.title in html_details assert post.subtitle in html_details assert post.full_description in html_details
def test_can_make_banners_and_publish_them(db, rf): banner = mixer.blend(Banner, active=True) request = rf.get('/') response = mainapp.index(request) html = response.content.decode('utf8') assert banner.title in html # check if banner.image has different size, made by StdImage assert isinstance(banner.image, StdImageFieldFile) assert banner.image.large.url in html
def test_can_make_publications_on_main_page(db, rf): post = mixer.blend(Post, active=True, main_picture=File(open('media/img_1.jpg', 'rb'))) additional_photo = mixer.blend(Photo, image=File(open('media/img_2.jpg', 'rb')), post=post) request = rf.get('/') response = mainapp.index(request) html = response.content.decode('utf8') assert post.main_picture.medium.url in html assert additional_photo.image.medium.url in html
def test_can_post_form_from_main_page(self): for f in os.listdir(os.path.join(settings.MEDIA_ROOT, "email_out")): os.remove(os.path.join(settings.MEDIA_ROOT, "email_out", f)) self.assertTrue(CaptchaStore.objects.count() == 0) factory_request = self.factory.get('/') factory_response = mainapp.index(factory_request) self.assertEqual(CaptchaStore.objects.count(), 2) # find captcha hash with re f_hash = re.findall(r'value="([0-9a-f]+)"', factory_response.content.decode('utf-8'))[0] #get captcha response captcha_response = CaptchaStore.objects.get(hashkey=f_hash).response request = self.factory.post( '/accept_order/', dict( # captcha_0=hash_, captcha_0=f_hash, captcha_1=captcha_response, name='tolik_make_tests', phone='79257777777')) post_response = mainapp.accept_order(request) self.assertEqual(post_response.status_code, 200)
def test_request_factory_of_index_view(rf, db): """rf - is an instance of django.test.RequestFactory""" request = rf.get('/') response = mainapp.index(request) assert response.status_code == 200