Skip to content
This repository has been archived by the owner on Oct 29, 2023. It is now read-only.

added unit tests #8

Merged
merged 3 commits into from
Dec 28, 2018
Merged

added unit tests #8

merged 3 commits into from
Dec 28, 2018

Conversation

gsailer
Copy link
Contributor

@gsailer gsailer commented Dec 18, 2018

Writing unit tests for config and api as in #3
I am submitting a work in progress. For now only the config tests are written.
I would really appreciate some feedback on the tests so far.

@femueller
Copy link
Owner

Hey @sublinus - thanks for the submission!

When testing the PR I was trying to execute the test like I am used to from the root directory.

That caused the problem that the test_creds.yml file is not readable from that path and should be from my perspective become more flexible so that you can either execute it from the root or tests directory.

What's your opinion on this?

That's what happens to me when executing it from the root directory:

pytest tests/.
=========================================================================================== test session starts ============================================================================================
platform darwin -- Python 3.5.0, pytest-4.0.2, py-1.7.0, pluggy-0.8.0
rootdir: /Users/femueller/git/tmp/python-n26, inifile:
collected 2 items

tests/test_config.py .F                                                                                                                                                                              [100%]

================================================================================================= FAILURES =================================================================================================
________________________________________________________________________________________________ test_file _________________________________________________________________________________________________

monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x1047740f0>

    @mock.patch.dict(os.environ, {"N26_USER": "", "N26_PASSWORD": "", "N26_CARD_ID": ""})
    def test_file(monkeypatch):
        # patch path to local test file
        def mockreturn(path):
            return "./test_creds.yml"
        monkeypatch.setattr(os.path, "expanduser", mockreturn)
>       assert config.get_config() == config.Config(username='[email protected]',
                                                    password='$upersecret', card_id="123456789")

tests/test_config.py:17:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

    def get_config():
        # try to get values from ENV
        username, password, card_id = [os.environ.get(e)
                                       for e in ["N26_USER", "N26_PASSWORD", "N26_CARD_ID"]]

        if not username or not password or not card_id:
            # print('Environment variables not set. trying to load cfg')

            config_file = os.path.expanduser('~/.config/n26.yml')
>           with open(config_file, 'r') as ymlfile:
E           FileNotFoundError: [Errno 2] No such file or directory: './test_creds.yml'

../../../.pyenv/versions/3.5.0/lib/python3.5/site-packages/n26/config.py:17: FileNotFoundError
==================================================================================== 1 failed, 1 passed in 0.10 seconds ====================================================================================

@gsailer
Copy link
Contributor Author

gsailer commented Dec 28, 2018

Thanks a lot for the feedback @femueller.
I see the problem with the non-relative file path and changed it to a relative path. Additionally I created a new test for prerequisites, so that it is easier to see why tests failed if the "test_creds.yml" is missing for some reason.

Further I also added a new build target in the Makefile, which uses the "pipenv run" command to make sure the pytest from the project virtual environment is used.
I will continue with the testing of the api soon.

@femueller
Copy link
Owner

Great! Thanks for addressing it so quickly!

I will merge your contribution and for future submissions, I would suggest creating a new PR.

@femueller femueller merged commit 9c2d8e6 into femueller:master Dec 28, 2018
@gsailer gsailer deleted the tests branch December 28, 2018 16:55
@gsailer gsailer mentioned this pull request Dec 29, 2018
@gsailer gsailer changed the title WIP: Adding unit tests added unit tests Apr 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants