python - How to get 100% in my coverage tests for a model? -
python - How to get 100% in my coverage tests for a model? -
i have installed coverage on django project. output is:
name stmts miss cover ---------------------------------------------------------------- test.apps.testapp.models.company 15 5 67% 2, 19-25 ------------------------------------------------------------
i have tested can think of model, 5 missed referring to?
here model:
class company(models.model): """ describes company within system. """ name = models.charfield(max_length=60) address_line1 = models.charfield(max_length=120) address_line2 = models.charfield(max_length=120, null=true, blank=true) address_city = models.charfield(max_length=120) address_county = models.charfield(max_length=120, null=true, blank=true) address_country = models.charfield(max_length=4, choices=country_choices, default="us") address_postcode = models.charfield(max_length=12) class meta: app_label = "testapp" def company_user_count(self): """ homecoming count of numbers of users belong company. :return: int """ homecoming self.users.count()
my tests:
class companymodel(testcase): def setup(self): self.company = companyfactory.create() def teardown(self): pass def test_create_new_company_creation(self): """ ensure new company can created. """ company = companyfactory(name="test co") noz.assert_equal(company.name, "test co") def test_user_is_company(self): """ test relationship on user company method is_company_user(). """ company = companyfactory.create() company_user = userfactory.create(company=company) noz.assert_equal(company_user.is_company_user(), true) def test_company_user_relationship(self): """ test right relationship on company made user. """ company = companyfactory.create() user = userfactory.create(company=company) noz.assert_equal(user.company.name, "valhalla ltd") def test_one_to_many_company_relationship(self): """ test company relationship of one-to-many users. """ company = companyfactory.create() user1 = userfactory.create(company=company) user2 = userfactory.create(company=company) company.company_user_count() noz.assert_equal(company.company_user_count(), 2)
run coverage utility html output , tell lines or branches you've failed test.
if you're using django-nose run tests, add --cover-html
, --cover-html-dir=<dir>
alternative nose_args
settings.
see example output coverage documentation.
python django
Comments
Post a Comment