richard-better / pushbullet.py

A python client for http://pushbullet.com
MIT License
575 stars 110 forks source link

test_auth contacts Pushbullet for testing #63

Closed simonporter007 closed 8 years ago

simonporter007 commented 8 years ago

I guess this is a question more than an issue. I'd like to help out writing the tests but I'm still wrapping my head around writing tests in python to be honest.

Had a look at the test_auth.py that's already included. From what I have been reading it would seem better if we mocked the call instead of actually called a login to Pushbullet. I wrote some code which I think does the trick but I guess the question is, is this the proper way to mock it out? I notice there's no test_pushbullet yet, so I can't quite see how you would do it properly.

import pytest
import mock
import pushbullet

@mock.patch('pushbullet.Pushbullet._get_data')
class TestAuth(object):

    def test_auth_fail(self, mock__get_data):
        mock__get_data.side_effect = pushbullet.errors.InvalidKeyError()
        with pytest.raises(pushbullet.InvalidKeyError) as exinfo:
            pb = pushbullet.Pushbullet("faultykey")

    def test_auth_success(self, mock__get_data):
        mock__get_data.return_value = { "name" : "Pushbullet Tester" }
        pb = pushbullet.Pushbullet("validKey")
        assert pb.user_info["name"] == "Pushbullet Tester"

If this IS the way to do it and the above is valid, I'd love to see what else I can knock up. Though as I say, literally just getting started in this area!

Cheers,

r-darwish commented 8 years ago

I just started to look at the tests. I'm not sure that mocking is the right idea. The propose of the tests is to detect whether we broke something, as well as detect when Pushbullet break something. If Pushbullet ever change the API (which is not very likely, but still) we would like to find that out by running the tests.

P.S. I just pushed 6c54610eea1fa14ff2cd6448776f1101e8c6a9eb which allows running the tests with your personal account.

simonporter007 commented 8 years ago

Ok. So if my reading (of testing) is correct, you're wanting those to be integration tests then rather than unit tests? Not a problem then. I was looking to try some TDD, so I can keep these offline in that case. Thanks for replying!

r-darwish commented 8 years ago

That's my personal opinion, but I'm 1 collaborator out of 4. :smiley: Also, thank you for your recent pull requests.

simonporter007 commented 8 years ago

No problem! Just trying to improve my developing. Plus pushbullet is great :)