from djangosanetesting.cases import DatabaseTestCase

from djangomarkup.fields import RichTextField
from djangomarkup.models import SourceText

from exampleapp.models import Article

class TestRichTextField(DatabaseTestCase):

    def setUp(self):
        super(TestRichTextField, self).setUp()
        self.field = RichTextField(
            instance = Article(),
            model = Article,
            syntax_processor_name = "markdown",
            field_name = "text",
            required = True,
            label = "Text"
        )


    def test_retrieve_empty_source_for_empty_article(self):
        self.assert_equals(u'', self.field.get_source().content)

    def test_source_available_for_empty_article(self):
        self.assert_equals(u'', self.field.get_source_text())

    def test_render_available_for_empty_article(self):
        self.assert_equals(u'<p></p>', self.field.get_rendered_text().strip())


from djangosanetesting.cases import UnitTestCase

from djangomarkup.fields import RichTextField

from exampleapp.models import Article

class TestRichTextField(UnitTestCase):

    def setUp(self):
        super(TestRichTextField, self).setUp()
        self.field = RichTextField(
            instance = Article(),
            model = Article,
            syntax_processor_name = "markdown",
            field_name = "text",
            required = True,
            label = "Text"
        )


    def test_retrieve_empty_source_for_empty_article(self):
        self.assert_equals(u'', self.field.get_source().content)

    def test_source_available_for_empty_article(self):
        self.assert_equals(u'', self.field.get_source_text())

    def test_render_available_for_empty_article(self):
        self.assert_equals(u'<p></p>', self.field.get_rendered_text().strip())

    def test_value_error_raised_when_accessing_source_without_instance(self):
        field = RichTextField(
            instance = None,
            model = Article,
            syntax_processor_name = "markdown",
            field_name = "text",
            required = True,
            label = "Text"
        )

        self.assert_raises(ValueError, field.get_source)
Check proper error when accessing source without instance
Check proper error when accessing source without instance

- from djangosanetesting.cases import DatabaseTestCase
+ from djangosanetesting.cases import UnitTestCase
  
  from djangomarkup.fields import RichTextField
- from djangomarkup.models import SourceText
  
  from exampleapp.models import Article
  
- class TestRichTextField(DatabaseTestCase):
+ class TestRichTextField(UnitTestCase):
  
      def setUp(self):
          super(TestRichTextField, self).setUp()
          self.field = RichTextField(
              instance = Article(),
              model = Article,
              syntax_processor_name = "markdown",
              field_name = "text",
              required = True,
              label = "Text"
          )
  
  
      def test_retrieve_empty_source_for_empty_article(self):
          self.assert_equals(u'', self.field.get_source().content)
  
      def test_source_available_for_empty_article(self):
          self.assert_equals(u'', self.field.get_source_text())
  
      def test_render_available_for_empty_article(self):
          self.assert_equals(u'<p></p>', self.field.get_rendered_text().strip())
  
+     def test_value_error_raised_when_accessing_source_without_instance(self):
+         field = RichTextField(
+             instance = None,
+             model = Article,
+             syntax_processor_name = "markdown",
+             field_name = "text",
+             required = True,
+             label = "Text"
+         )
  
+         self.assert_raises(ValueError, field.get_source)
Check proper error when accessing source without instance
## Code Before:
from djangosanetesting.cases import DatabaseTestCase

from djangomarkup.fields import RichTextField
from djangomarkup.models import SourceText

from exampleapp.models import Article

class TestRichTextField(DatabaseTestCase):

    def setUp(self):
        super(TestRichTextField, self).setUp()
        self.field = RichTextField(
            instance = Article(),
            model = Article,
            syntax_processor_name = "markdown",
            field_name = "text",
            required = True,
            label = "Text"
        )


    def test_retrieve_empty_source_for_empty_article(self):
        self.assert_equals(u'', self.field.get_source().content)

    def test_source_available_for_empty_article(self):
        self.assert_equals(u'', self.field.get_source_text())

    def test_render_available_for_empty_article(self):
        self.assert_equals(u'<p></p>', self.field.get_rendered_text().strip())


## Instruction:
Check proper error when accessing source without instance
## Code After:
from djangosanetesting.cases import UnitTestCase

from djangomarkup.fields import RichTextField

from exampleapp.models import Article

class TestRichTextField(UnitTestCase):

    def setUp(self):
        super(TestRichTextField, self).setUp()
        self.field = RichTextField(
            instance = Article(),
            model = Article,
            syntax_processor_name = "markdown",
            field_name = "text",
            required = True,
            label = "Text"
        )


    def test_retrieve_empty_source_for_empty_article(self):
        self.assert_equals(u'', self.field.get_source().content)

    def test_source_available_for_empty_article(self):
        self.assert_equals(u'', self.field.get_source_text())

    def test_render_available_for_empty_article(self):
        self.assert_equals(u'<p></p>', self.field.get_rendered_text().strip())

    def test_value_error_raised_when_accessing_source_without_instance(self):
        field = RichTextField(
            instance = None,
            model = Article,
            syntax_processor_name = "markdown",
            field_name = "text",
            required = True,
            label = "Text"
        )

        self.assert_raises(ValueError, field.get_source)