def validate(cls, meta, module, name): super().validate(meta, module, name) #url if not contains_option(meta, 'url'): raise RuntimeError("Test class %s.%s doesn't set the url " % (module, name)) #contents if contains_option(meta, 'contents'): if not isinstance(meta.contents, collections.Sequence): raise RuntimeError( "Test class %s.%s doesn't set contents as a sequence " "instance." % (module, name)) #context_variables if contains_option(meta, 'context_variables'): if not isinstance(meta.context_variables, collections.Sequence): raise RuntimeError( "Test class %s.%s doesn't set context_variables as a sequence " "instance." % (module, name)) # context_model_variable if contains_option(meta, 'context_model_variable'): if not isinstance(meta.context_model_variable, str): raise RuntimeError( "Test class %s.%s doesn't set context_model_variable as a string " % (module, name))
def test_ordering(self): if not self._concrete: return if not contains_option(self._meta, 'ordering'): return ordering = self._meta.ordering self.assertListEqual(ordering, list(self._meta.model._meta.ordering))
def test_str(self): if not self._concrete: return if not contains_option(self._meta, 'string'): return string = self._meta.string self.assertEqual(string, str(self._meta.obj))
def test_template(self): if not self._concrete: return if not contains_option(self._meta, 'template'): return template = self._meta.template self.assertTemplateUsed(self.response, template)
def validate(cls, meta, module, name): super().validate(cls, meta, module, name) #form if not contains_option(meta, 'form'): raise RuntimeError( "Test class %s.%s doesn't set the form " % (module, name) )
def validate(cls, meta, module, name): super().validate(cls, meta, module, name) #blank_fields if contains_option(meta, 'blank_fields'): if not isinstance(meta.blank_fields, collections.Sequence): raise RuntimeError( "Test class %s.%s doesn't set blank_fields as a sequence " "instance." % (module, name))
def test_model_context(self): if not self._concrete: return if not contains_option(self._meta, 'context_model_variable'): return context_model_variable = self._meta.context_model_variable self.assertIn(context_model_variable, self.response.context) variable = self.response.context[context_model_variable] self.assertIsInstance(variable, self._meta.model)
def setUp(self): if not self._concrete: return self._meta.obj.save() self.status_code = 200 if contains_option(self._meta, 'url_arg_field'): arg = getattr(self._meta.obj, self._meta.url_arg_field, '') self.response = self.client.get(resolve_url(self._meta.url, arg)) else: self.response = self.client.get(resolve_url(self._meta.url))
def test_none(self): if not self._concrete: return if not contains_option(self._meta, 'none_fields'): return none_fields = self._meta.none_fields # Verify if was informed one or more fields if isinstance(none_fields, str): self.field_is_none(none_fields) else: for none_field in none_fields: with self.subTest: self.field_is_none(none_field)
def test_blank(self): if not self._concrete: return if not contains_option(self._meta, 'blank_fields'): return blank_fields = self._meta.blank_fields # Verify if was informed one or more fields if isinstance(blank_fields, str): self.field_is_blank(blank_fields) else: for blank_field in blank_fields: with self.subTest: self.field_is_blank(blank_field)
def test_context(self): if not self._concrete: return if not contains_option(self._meta, 'context_variables'): return variables = self._meta.context_variables # Verify if was informed one or more fields if isinstance(variables, str): self.assertIn(variables, self.response.context) else: for variable in variables: with self.subTest(): self.assertIn(variable, self.response.context)
def test_content(self): if not self._concrete: return if not contains_option(self._meta, 'contents'): return contents = self._meta.contents if len(contents) <= 0: return # Verify if was informed one or more fields if isinstance(contents, str): self.assertContains(self.response, contents) elif isinstance(contents[0], tuple): for content, count in contents: with self.subTest(): self.assertContains(self.response, content, count) else: for content in contents: with self.subTest(): self.assertContains(self.response, content)
def __init__(self, meta): self.obj = meta.obj self.model = self.obj.__class__ #ModelTest if contains_option(meta, 'blank_fields'): self.blank_fields = meta.blank_fields if contains_option(meta, 'none_fields'): self.none_fields = meta.none_fields if contains_option(meta, 'string'): self.string = meta.string if contains_option(meta, 'ordering'): self.ordering = meta.ordering #HtmlTest if contains_option(meta, 'url'): self.url = meta.url if contains_option(meta, 'url_arg_field'): self.url_arg_field = meta.url_arg_field if contains_option(meta, 'template'): self.template = meta.template if contains_option(meta, 'contents'): self.contents = meta.contents if contains_option(meta, 'context_variables'): self.context_variables = meta.context_variables if contains_option(meta, 'context_model_variable'): self.context_model_variable = meta.context_model_variable if contains_option(meta, 'ignore_csrfmiddlewaretoken'): self.ignore_csrfmiddlewaretoken = meta.ignore_csrfmiddlewaretoken else: self.ignore_csrfmiddlewaretoken = False #FormTest if contains_option(meta, 'form'): self.form = meta.form if contains_option(meta, 'ignore_form_errors'): self.ignore_form_errors = meta.ignore_form_errors else: self.ignore_form_errors = False
def test_not_found(self): if not self._concrete: return if contains_option(self._meta, 'url_arg_field'): self.response = self.client.get(resolve_url(self._meta.url, 0)) self.assertEqual(self.response.status_code, 404)