I would agree with that - test any custom functionality -

 * Custom methods (including __str__ and __repr__)
 * custom managers
 * Triggers (that maybe save custom fields on update)
 * validations - testing to ensure that the right validation is
   performed on that field - i.e. you linked the right field with the
   right validation.

I would do a cursory test that you can save and retrieve an object - just to make sure that you have executed your migrations correctly


On 13/05/18 19:08, Jani Tiainen wrote:
Hi,

In general you don't need to test your models if you don't use anything special there. If you do have properties or methods on models that do something that is good to test that they return correct values or do correct things.



On Sun, May 13, 2018 at 7:11 PM, Mark Phillips <m...@phillipsmarketing.biz <mailto:m...@phillipsmarketing.biz>> wrote:

    What should be unit tested in models.py? I assume the storing of
    data and retrieving of data from the database does not need to be
    tested, as I further assume django has a full set of tests for
    those operations.

    I can see testing these parts of models.py

    * All custom methods

    * Labels for all fields
    something like
    def test_first_name_label(self):
            author=Author.objects.get(id=1)
            field_label =
    author._meta.get_field('first_name').verbose_name
            self.assertEquals(field_label,'first name')

    * Field attributes (eg length of CharField)? Is this really
    necessary, as I would again assume django covers this in their
    unit tests?

    Anything else that I am missing?

    Thanks!

    Mark
-- You received this message because you are subscribed to the Google
    Groups "Django users" group.
    To unsubscribe from this group and stop receiving emails from it,
    send an email to django-users+unsubscr...@googlegroups.com
    <mailto:django-users+unsubscr...@googlegroups.com>.
    To post to this group, send email to django-users@googlegroups.com
    <mailto:django-users@googlegroups.com>.
    Visit this group at https://groups.google.com/group/django-users
    <https://groups.google.com/group/django-users>.
    To view this discussion on the web visit
    
https://groups.google.com/d/msgid/django-users/CAEqej2P0_sZt2j06nf0OnOL%2BE%3DuVa1Cs0BOFmTx8vjQm6-io2Q%40mail.gmail.com
    
<https://groups.google.com/d/msgid/django-users/CAEqej2P0_sZt2j06nf0OnOL%2BE%3DuVa1Cs0BOFmTx8vjQm6-io2Q%40mail.gmail.com?utm_medium=email&utm_source=footer>.
    For more options, visit https://groups.google.com/d/optout
    <https://groups.google.com/d/optout>.




--
Jani Tiainen

- Well planned is half done, and a half done has been sufficient before...
--
You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com <mailto:django-users+unsubscr...@googlegroups.com>. To post to this group, send email to django-users@googlegroups.com <mailto:django-users@googlegroups.com>.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAHn91oeJYPGbLaJAZbJqd3jxbDcY6m3d8e2fSE06_E_ZwXXosQ%40mail.gmail.com <https://groups.google.com/d/msgid/django-users/CAHn91oeJYPGbLaJAZbJqd3jxbDcY6m3d8e2fSE06_E_ZwXXosQ%40mail.gmail.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.


--
--
Anthony Flury
email : *anthony.fl...@btinternet.com*
Twitter : *@TonyFlury <https://twitter.com/TonyFlury/>*

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/9822baae-9064-2a48-ede3-c4f2c2b4d031%40btinternet.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to