marksweb / django-bleach

Bleach is a Python module that takes any HTML input, and returns valid, sanitised HTML that contains only an allowed subset of HTML tags, attributes and styles. django-bleach is a Django app that makes using bleach extremely easy.
MIT License
148 stars 23 forks source link

Fix custom widget tests #34

Closed MrkGrgsn closed 3 years ago

MrkGrgsn commented 3 years ago

Description

Previous tests test_custom_widget and test_custom_widget2 failed to override the BLEACH_DEFAULT_WIDGET at the correct time to influence the form being used to test thus the tests were not actually testing with the intended widget class.

The reason the old tests were not correct is that testproject.forms.BleachForm is evaluated at compile time (with settings as per testproject.settings) while the mock only changes the settings when the individual test is run and it is too late.

This PR defines a class within the setUp method of the test class while override_settings is in effect.

Checklist

codecov[bot] commented 3 years ago

Codecov Report

Merging #34 (f89faed) into master (527c1c9) will not change coverage. The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##            master       #34   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            3         3           
  Lines           81        81           
  Branches        16        16           
=========================================
  Hits            81        81           

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 527c1c9...f89faed. Read the comment docs.

marksweb commented 3 years ago

Great catch! Thanks @MrkGrgsn.