Skip to content
This repository has been archived by the owner on Nov 5, 2019. It is now read-only.

Calling two() method in flask util test. #313

Merged

Conversation

dhermes
Copy link
Contributor

@dhermes dhermes commented Sep 22, 2015

In the original code, the line never executes since it is in a method that is decorated with oauth2.required and the method's scopes don't match the credentials used (forcing a redirect). Thus, we call it again with credentials that actually match the scopes.

@dhermes
Copy link
Contributor Author

dhermes commented Sep 22, 2015

@nathanielmanistaatgoogle After this, the only line coverage missing in tests are self.fail() lines.

Towards #212 inch-by-inch!

@dhermes
Copy link
Contributor Author

dhermes commented Sep 22, 2015

@jonparrott FYI I figured this was the easiest fix.

In general I do my best to avoid NO COVER pragmas. If you have a better idea for how to get this line actually executed. LMK.

@theacodes
Copy link
Contributor

You could make another request to /two with all the valid scopes, but it seems like overkill.

@dhermes
Copy link
Contributor Author

dhermes commented Sep 22, 2015

I'll let @nathanielmanistaatgoogle decide.

Now that you point that out, it seems it'd be as easy as:

        credentials2 = self._generate_credentials(scopes=['two'])

        with self.app.test_client() as c:
            with c.session_transaction() as session:
                session['google_oauth2_credentials'] = credentials2.to_json()

            rv = c.get('/two')
            self.assertEqual(rv.status_code, httplib.OK)

@nathanielmanistaatgoogle
Copy link
Contributor

Let's go with the latter approach that is a handful of lines of more code and avoids the coverage suppression pragma.

In the original code, the line never executes since it is in
a method that is decorated with oauth2.required and the
method's scopes don't match the credentials used (forcing a
redirect). Thus, we call it again with credentials that actually
match the scopes.
@dhermes dhermes changed the title Adding no-cover pragma to flask util test. Calling two() method in flask util test. Sep 22, 2015
@dhermes
Copy link
Contributor Author

dhermes commented Sep 22, 2015

@nathanielmanistaatgoogle Updated the commit (and the messaging on the PR).

nathanielmanistaatgoogle added a commit that referenced this pull request Sep 22, 2015
Call two() method in flask util test.
@nathanielmanistaatgoogle nathanielmanistaatgoogle merged commit c412da9 into googleapis:master Sep 22, 2015
@dhermes dhermes deleted the flask-test-add-pragma branch September 22, 2015 23:38
@dhermes dhermes mentioned this pull request Nov 18, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants