def setUp(self): """Setup.""" self.widget = OTPGenWidget() self.env = Environment( loader=PackageLoader("django_otp.widgets", "files")) self.env.globals.update({ "btn": self.widget.btn, "img": self.widget.img })
class OTPGenWidgetTemplateLoadTest(TestCase): """OTPGenerator template load test.""" def setUp(self): """Setup.""" self.widget = OTPGenWidget() self.env = Environment( loader=PackageLoader("django_otp.widgets", "files")) self.env.globals.update({ "btn": self.widget.btn, "img": self.widget.img }) def test_template_load(self): """The template should be compiled properly.""" self.assertEqual( self.widget.template.render(widget=self.widget), self.env.get_template("widget.html").render(widget=self.widget)) def test_render(self): """Render should compile the template and should return the result.""" result = self.widget.render("test", "test_value", {"data-hello": "world"}) self.assertIn("data-hello=\"world\"", result) self.assertIn("value=\"test_value\"", result) self.assertEqual( result, self.widget.template.render(widget=self.widget, attrs={ "data-hello": "world", "value": "test_value", "name": "test" }))
class OTPGenWidgetTemplateLoadWithoutValueTest(TestCase): """OTP Secret Generator widget without value test.""" def setUp(self): """Setup.""" self.widget = OTPGenWidget() self.env = Environment( loader=PackageLoader("django_otp.widgets", "files")) self.env.globals.update({ "btn": self.widget.btn, "img": self.widget.img }) def test_render(self): """Render should compile the template and should return the result.""" result = self.widget.render("test", None, {"data-hello": "world"}) self.assertIn("data-hello=\"world\"", result) self.assertNotIn("value=\"test_value\"", result) self.assertEqual( result, self.widget.template.render(widget=self.widget, attrs={ "data-hello": "world", "name": "test" }))
class Form(Form): """Form.""" gen = OTPGenField(widget=OTPGenWidget( img_attrs={"data-ng-src": "{{ model.qrcode }}"}))
def setUp(self, *args): """Setup.""" self.btn_attrs = {"data-ng-click": "test()", "type": "button"} self.widget = OTPGenWidget(btn_attrs=self.btn_attrs)
def setUp(self, *args): """Setup.""" self.img_attrs = {"data-ng-src": "{{ model.secret }}"} self.widget = OTPGenWidget(img_attrs=self.img_attrs)
def setUp(self, *args): """Setup.""" self.txt_attrs = {"data-ng-model": "model.secret"} self.widget = OTPGenWidget(attrs={"data-ng-model": "model.secret"})
def setUp(self, loader, env): """Setup.""" self.widget = OTPGenWidget() self.loader = loader self.env = env
def setUp(self, *args): """Setup.""" self.widget = OTPGenWidget(embed_script=True)
def setUp(self, *args): """Setup.""" self.widget = OTPGenWidget(enable_btn=False)
def setUp(self, *args): """Setup.""" self.btn_label = "Hello World" self.widget = OTPGenWidget(btn_label=self.btn_label)