j-sokol / filabel

Tool for labeling PRs at GitHub by globs.
MIT License
0 stars 0 forks source link

Testing #3

Closed MarekSuchanek closed 5 years ago

MarekSuchanek commented 5 years ago

There are some important things uncovered by tests:

Also, you should try to avoid DeprecationWarning. You are using parametrized session, where it is not suitable. Long "static data" in code are not nice - it should be in fixtures.

When recording my own cassettes, it will make some tests fail probably because you are using hardcoded j-sokol/mi-pyt-test-repo...

___________________________________________________________ test_post_labels ___________________________________________________________

betamax_parametrized_session = <requests.sessions.Session object at 0x7f52f1f845f8>

    def test_post_labels(betamax_parametrized_session):
        """Test whether filabel posts a label"""
        github = filabel.github.GitHub(token, session=betamax_parametrized_session)

        slug = 'j-sokol/mi-pyt-test-repo'
>       ret = github.post_label(slug, '5', 'ddd')

test/test_internals.py:109: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <filabel.github.GitHub object at 0x7f52f1f84710>, slug = 'j-sokol/mi-pyt-test-repo', pull_request_number = '5', label = 'ddd'

    def post_label(self, slug, pull_request_number, label):
        response = self.session.post("{0}/repos/{1}/issues/{2}/labels".format(github_api_url, slug, pull_request_number, label), json=[label])
        # print( response.status_code, response.text)
        if response.status_code != 200:
>           raise Exception('POSTing label failed.')
E           Exception: POSTing label failed.

filabel/github.py:74: Exception
__________________________________________________________ test_delete_labels __________________________________________________________

betamax_parametrized_session = <requests.sessions.Session object at 0x7f52f1f3e898>

    def test_delete_labels(betamax_parametrized_session):
        """Test whether filabel posts a label"""
        github = filabel.github.GitHub(token, session=betamax_parametrized_session)

        slug = 'j-sokol/mi-pyt-test-repo'
>       ret = github.delete_label(slug, '5', 'ddd')

test/test_internals.py:119: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <filabel.github.GitHub object at 0x7f52f1f3e860>, slug = 'j-sokol/mi-pyt-test-repo', pull_request_number = '5', label = 'ddd'

    def delete_label(self, slug, pull_request_number, label):
        response = self.session.delete("{0}/repos/{1}/issues/{2}/labels/{3}".format(github_api_url, slug, pull_request_number, label))
        if response.status_code != 200:
>           raise Exception('DELETing label failed.')
E           Exception: DELETing label failed.

filabel/github.py:66: Exception
j-sokol commented 5 years ago

Hi, case

if application reacts to webhook of pull request change (you test only ping) and calls some internal methods appropriately

is now covered.

I also removed deprecation warnings.

Static data are now in helper function.

Hardcoded username in slug should be fixed now also.

P.S case if CLI prints something on output while running and calls some internal methods appropriately is now covered also, but when I try to pass betamax session to it, I always fail. Do you have any ideas how to pass betamax session to it?

I did something like this:

def test_cli_post_pr(betamax_session):
    runner = CliRunner()
    config_labels = './test/fixtures/labels.abc.cfg'
    config_auth = './test/fixtures/auth.real.cfg'
    slug = f'{user}/mi-pyt-test-repo'

    filabel.config.session = betamax_session
    result = runner.invoke(filabel.cli, ['--config-labels', config_labels, '--config-auth', config_auth, slug])

in config.py:

session = None

and in cli function:

    if session:
        github = GitHub(config['github']['token'], session)
    else:
        github = GitHub(config['github']['token'])

If you would recommend me better solution, I'd be glad :)

MarekSuchanek commented 5 years ago

For passing something via Click, there is a context: http://click.palletsprojects.com/en/7.x/complex/#calling-convention

Or you could mock your internals and just check that CLI does appropriate calls and outputs...

j-sokol commented 5 years ago

Thank you for recommendation! I changed it that way.

All issues fixed in release v0.4.2.

MarekSuchanek commented 5 years ago

OK, no new version on PyPI but other is great...