unit testing controllers

Thomas De Schampheleire patrickdepinguin at gmail.com
Sat Feb 14 16:29:49 EST 2015


Hi,

I would like to add some tests for the pullrequest controller method
_get_repo_refs(), which returns the list of
revisions/branches/tags/... to populate the select boxes on the pull
request creation page.

Most of the current tests are actually parsing the HTTP response data,
but this is an indirect way of testing. I would prefer testing the
function directly.

I'm a bit stuck on setting up the data correctly. I added the
following in tests/functional/test_pullrequests.py:


    def test_repo_refs(self):
        main = fixture.create_repo('main')
        Session.add(main)
        Session.commit()
        #fork = fixture.create_fork(main, 'fork')

        controller = PullrequestsController()

        print controller._get_repo_refs(main)

        fixture.destroy_repo('main')


but when _get_repo_refs is invoked, an error is thrown:

test_repo_refs (kallithea.tests.functional.test_pullrequests.TestPullrequestsController)
... ERROR

======================================================================
ERROR: test_repo_refs
(kallithea.tests.functional.test_pullrequests.TestPullrequestsController)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/tdescham/repo/contrib/kallithea-typos/kallithea/tests/functional/test_pullrequests.py",
line 25, in test_repo_refs
    print controller._get_repo_refs(main)
  File "/home/tdescham/repo/contrib/kallithea-typos/kallithea/controllers/pullrequests.py",
line 108, in _get_repo_refs
    tiprev = repo.tags.get('tip')
AttributeError: 'Repository' object has no attribute 'tags'


I'm guessing that the repository I created is not yet fully created,
or some other setup action is missing.

Any help or feedback is appreciated.

Thanks,
Thomas


More information about the kallithea-general mailing list