Opened 14 months ago

Closed 3 months ago

#7090 closed defect (fixed)

Oauth2client causing tests to fail

Reported by: atudor Assignee: atudor
Priority: P3 Milestone:
Module: Sitescripts Keywords:
Cc: kvas Blocked By: #7112
Blocking: Platform: Unknown / Cross platform
Ready: yes Confidential: no
Tester: Unknown Verified working: no
Review URL(s):

Description

Environment

  1. Sitescripts from this version: https://hg.adblockplus.org/sitescripts/rev/bd8ac05243d4
  2. Python 2.7
  3. pytest==3.9.3
  4. oauth2client==4.1.3

How to reproduce

  1. Clone sitescripts version from the link mentioned above
  2. Run tox

...

Observed behaviour

There are two tests that fail due to a mismatch beween the expected and actual error messages. See below:

__________________________________________________________________________________________________________ test_keyfile_errors[keyfile_invalid_private_key.json-invalid_client: The OAuth client was not found.-1] ___________________________________________________________________________________________________________

rootdir = local(u'/private/var/folders/jv/35fhq1vx7nd68g5j4bbtymr80000gq/T/pytest-of-tavram/pytest-3/test_keyfile_errors_keyfile_in0/root'), key = 'keyfile_invalid_private_key.json', expected_stderr = 'invalid_client: The OAuth client was not found.', expected_code = 1

    @pytest.mark.parametrize('key, expected_stderr, expected_code', [
        ('keyfile_missing_key.json', 'Invalid key file format!', 1),
        ('keyfile_invalid_private_key.json', 'invalid_client: The OAuth '
                                             'client was not found.', 1),
        ('keyfile_invalid_type.json', "('Unexpected credentials type', u'invalid',"
                                      " 'Expected', 'service_account')", 1),
        ('good_keyfile.json', 'invalid_client: The OAuth client was not found.',
         1),
    ])
    def test_keyfile_errors(rootdir, key, expected_stderr, expected_code):
        """Testing how the script handles key file-related error messages.
    
        Connects to the actual google API, using set of dummy key files.
        """
        keyfile_path = rootdir.join(key)
    
        code, stderr, _ = run_script('www.test.com', '-k', str(keyfile_path), '-s',
                                     'test')
    
        assert code == expected_code
>       assert expected_stderr in stderr
E       AssertionError: assert 'invalid_client: The OAuth client was not found.' in 'invalid_grant: Not a valid email or user ID.\n'

sitescripts/oauth2dl/test/test_oauth2dl.py:156: AssertionError
__________________________________________________________________________________________________________________ test_keyfile_errors[good_keyfile.json-invalid_client: The OAuth client was not found.-1] __________________________________________________________________________________________________________________

rootdir = local(u'/private/var/folders/jv/35fhq1vx7nd68g5j4bbtymr80000gq/T/pytest-of-tavram/pytest-3/test_keyfile_errors_good_keyfi0/root'), key = 'good_keyfile.json', expected_stderr = 'invalid_client: The OAuth client was not found.', expected_code = 1

    @pytest.mark.parametrize('key, expected_stderr, expected_code', [
        ('keyfile_missing_key.json', 'Invalid key file format!', 1),
        ('keyfile_invalid_private_key.json', 'invalid_client: The OAuth '
                                             'client was not found.', 1),
        ('keyfile_invalid_type.json', "('Unexpected credentials type', u'invalid',"
                                      " 'Expected', 'service_account')", 1),
        ('good_keyfile.json', 'invalid_client: The OAuth client was not found.',
         1),
    ])
    def test_keyfile_errors(rootdir, key, expected_stderr, expected_code):
        """Testing how the script handles key file-related error messages.
    
        Connects to the actual google API, using set of dummy key files.
        """
        keyfile_path = rootdir.join(key)
    
        code, stderr, _ = run_script('www.test.com', '-k', str(keyfile_path), '-s',
                                     'test')
    
        assert code == expected_code
>       assert expected_stderr in stderr
E       AssertionError: assert 'invalid_client: The OAuth client was not found.' in 'invalid_grant: Not a valid email or user ID.\n'

sitescripts/oauth2dl/test/test_oauth2dl.py:156: AssertionError

Expected behaviour

All tests should pass.

Research done

The errors above are caused by the latest release of oath2client, which changed the error messages displayed.

According to it's PyPi page(https://pypi.org/project/oauth2client/), oath2client is now deprecated and should be replaced by google-auth and oauthlib

To Do

  1. Replace oauth2client with google-auth and googleapiclient.
  2. Re-write the tests accordingly.
  3. Adapt the Dependencies section from README.md

Change History (3)

comment:1 Changed 14 months ago by kvas

  • Priority changed from P2 to P3
  • Ready set

I reduced the priority because the code in question is not used in production ATM. The test failures are getting in the way but it's not the end of the world.

comment:2 Changed 13 months ago by atudor

  • Blocked By 7112 added

comment:3 Changed 3 months ago by kvas

  • Resolution set to fixed
  • Status changed from new to closed

Now we have CI and the tests pass!

Note: See TracTickets for help on using tickets.