Add unit tests for Djblets web API backend auth.

Review Request #8440 — Created Sept. 25, 2016 and submitted

Information

Djblets
master
6542556...

Reviewers

Added unit tests for WebAPITokenAuthBackend and WebAPIBasicAuthBackend.

This patch is based on previous work by Minh Le Hoang at
https://reviews.reviewboard.org/r/7997/.

All tests pass.

Description From Last Updated

Your description is missing a period.

brenniebrennie

Please re-write your summary in the imperitive mood.

brenniebrennie

Please include in your summary: This patch is based on work by Minh Le Hong at (the URL)

brenniebrennie

local variable 'user' is assigned to but never used

reviewbotreviewbot

Col: 41 E126 continuation line over-indented for hanging indent

reviewbotreviewbot

local variable 'get_credentials_mock' is assigned to but never used

reviewbotreviewbot

local variable 'get_credentials_mock' is assigned to but never used

reviewbotreviewbot

Col: 53 E126 continuation line over-indented for hanging indent

reviewbotreviewbot

Col: 9 E265 block comment should start with '# '

reviewbotreviewbot

Col: 41 E126 continuation line over-indented for hanging indent

reviewbotreviewbot

Col: 41 E126 continuation line over-indented for hanging indent

reviewbotreviewbot

Col: 41 E126 continuation line over-indented for hanging indent

reviewbotreviewbot

You don't need the entire module path in here, you can just do: """Unit tests for the WebAPITokenBackend.""" For future …

brenniebrennie

See previous comment about docstring formatting.

brenniebrennie

""" will fit on previous line.

brenniebrennie

See previous comment about docstring formatting

brenniebrennie

This attribution should be in the commit message, I believe. May want to ask Christian. Best to include the URL …

brenniebrennie

Needs module-level docstring.

brenniebrennie

See comment re: formatting docstrings.

brenniebrennie

Col: 53 E126 continuation line over-indented for hanging indent

reviewbotreviewbot

See comment re: formatting docstrings.

brenniebrennie

See comment re: formatting docstrings.

brenniebrennie

See comment re: formatting docstrings.

brenniebrennie

See comment re: formatting docstrings.

brenniebrennie

Col: 41 E126 continuation line over-indented for hanging indent

reviewbotreviewbot

See comment re: formatting docstrings.

brenniebrennie

Col: 41 E126 continuation line over-indented for hanging indent

reviewbotreviewbot

See comment re: formatting docstrings.

brenniebrennie

Col: 41 E126 continuation line over-indented for hanging indent

reviewbotreviewbot

See comment re: formatting docstrings.

brenniebrennie

Col: 41 E126 continuation line over-indented for hanging indent

reviewbotreviewbot

See comment re: formatting docstrings.

brenniebrennie

Col: 13 E128 continuation line under-indented for visual indent

reviewbotreviewbot

See comment re: formatting docstrings.

brenniebrennie

Col: 13 E128 continuation line under-indented for visual indent

reviewbotreviewbot

Blank line between these.

brenniebrennie

Docstring (just needs to indicate that its a dummy model for tests.)

brenniebrennie

Likewise.

brenniebrennie

Blank line between these.

brenniebrennie

Single quotes.

brenniebrennie

Single quotes.

brenniebrennie

Single quotes.

brenniebrennie

Single quotes.

brenniebrennie

Single quotes.

brenniebrennie

Single quotes.

brenniebrennie

Blank line between these.

brenniebrennie

Unused method.

brenniebrennie

Since this is a private method for tests, lets call it _validate_credentials. Also, needs a docstring.

brenniebrennie

You can reflow this to fill more of the first line.

brenniebrennie

Single quotes.

brenniebrennie

This should be comparing against a constant.

brenniebrennie

No leading space. Missing a period.

brenniebrennie

Missing a period.

brenniebrennie

Missing super(...).tearDown()

brenniebrennie

You should just use the constant here.

brenniebrennie

Single quotes.

brenniebrennie

You want to use bytes(random()). We avoid str because in Python 2 str is a binary type and not a …

brenniebrennie

bytes(random())

brenniebrennie

missing super(...).setUp()

brenniebrennie

Single quotes.

brenniebrennie

missing super(...).tearDown()

brenniebrennie

No leading or trailing spaces. Missing a period. Missing args, returns.

brenniebrennie

Use either: clean_credentials = \ self.basic_auth_backend.clean_credentials_for_display( credentials) or: clean_credentials = ( self.basic_auth_backend .clean_credentials_for_display( credentials ) )

brenniebrennie

You should inherit from SpyAgency e.g. class WebAPITokenAuthBackendTests(SpyAgency, TestModelsLoaderMixin, TestCase): # ... That way, you dont need self.agency, nor do …

brenniebrennie

"succeeds"

brenniebrennie

Add a trailing , or move the ) onto this line.

brenniebrennie

Same here.

brenniebrennie

Since you're inheriting from SpyAgency, you don't need to unspy in tearDown -- it will happen automatically.

brenniebrennie

Can you rename this to TestWebAPITokenModel

brenniebrennie

TestTokenAuthBackend.

brenniebrennie

You will want to use assertIsNone(result). When comparing against None, you always want to use is or is not.

brenniebrennie

assertIsNone

brenniebrennie

You aren't using middleware or requestfactory in the testcases so why not: self.request = RequestFactory().get('/') SessionMiddleware().process_request(self.request)

brenniebrennie

Does the User need to exist in the database? If not we can just make User() object.

brenniebrennie

"web API" missing period.

brenniebrennie

Can you move this into test_get_credentials_missing_credentials? It is only used in that test.

brenniebrennie

Unnecessary.

brenniebrennie

Put the trailing space on the previous line, even if it means splitting the string earlier.

brenniebrennie

You can move this to a single line statement -- you won't need the comma in that case.

brenniebrennie

Is there any particular reason we are doing rand() here instead of just using a non-matching token

brenniebrennie

Is there any particular reason we are doing rand() here instead of just using a non-matching token

brenniebrennie

Missing period. web API

brenniebrennie

import foo statements go above from foo import bar statements.

brenniebrennie

Can you move this into test_get_credentials_malformed_credentials? It is only used in that test.

brenniebrennie

Unnecessary method. If this class doesn't implement tearDown, the superclass method will be invoked instead.

brenniebrennie

This sentence contains a comma splice. How about: """Fake version of validate credentials that always succeeds. This is used in …

brenniebrennie

None. Only one space between sentences.

brenniebrennie

"request" Missing period.

brenniebrennie

"non-basic"

brenniebrennie

"with"

brenniebrennie

"with"

brenniebrennie

Missing trailing comma.

brenniebrennie

Missing trailing comma.

brenniebrennie

Missing trailing comma.

brenniebrennie

Missing trailing comma.

brenniebrennie

Missing trailing comma.

brenniebrennie

Missing trailing comma.

brenniebrennie

print() is not used.

brenniebrennie

Alphabetize.

brenniebrennie

Alphabetize imports.

brenniebrennie

Blank line between these.

brenniebrennie

Can you rearrange this so that things are defined just before they're tested? result = self.api_token_auth_backend.get_credentials(self.request) self.assertIsNone(result) warning_message = logging.warning.spy.last_call.args[0] …

daviddavid

Please use single quotes around HTTP_AUTHORIZATION

daviddavid

username and password are only used the once, so we could bring them inline instead of creating variables: self.user = …

daviddavid

Same comments about username/password.

daviddavid

print() is not used.

brenniebrennie

Alphabetize these.

brenniebrennie

Blank line between these.

brenniebrennie

can also include that function returns None in function doc string. I believe like Returns: None

LA larmiej

username and password are only used once, so we can simplify: encoded_credentials = 'testuser:testpassword'.encode('base64')

daviddavid

Same here.

daviddavid

Same here.

daviddavid

It's a little silly to define a credentials dict just to unpack it for kwargs. Let's change this to be: …

daviddavid

Same here re: credentials.

daviddavid

Same here re: credentials

daviddavid

Same here re: credentials

daviddavid

Same here re: credentials

daviddavid

Same here re: credentials

daviddavid

No blank line here (django and kgb are both third-party libraries from the point of view of the djblets package).

daviddavid

Why is this 'invalidtoken123? This is a valid token, no? Kinda makes the test confusing when the invalidtoken is valid.

mike_conleymike_conley

Same as above.

mike_conleymike_conley

No blank line here.

daviddavid

So I believe you may be testing this wrongly after reading further into it. Firstly you are setting the user …

brenniebrennie

I don't think "always succeeds" is true. Because this is returning None, it means we're falling back to the base …

mike_conleymike_conley
reviewbot
  1. Tool: Pyflakes
    Processed Files:
        djblets/webapi/tests/test_basic_auth_backend.py
    
    
    
    Tool: PEP8 Style Checker
    Processed Files:
        djblets/webapi/tests/test_basic_auth_backend.py
    
    
  2. Show all issues
     local variable 'user' is assigned to but never used
    
  3. Show all issues
    Col: 41
     E126 continuation line over-indented for hanging indent
    
  4. Show all issues
     local variable 'get_credentials_mock' is assigned to but never used
    
  5. Show all issues
     local variable 'get_credentials_mock' is assigned to but never used
    
  6. 
      
ST
reviewbot
  1. Tool: PEP8 Style Checker
    Processed Files:
        djblets/webapi/tests/test_basic_auth_backend.py
    
    
    
    Tool: Pyflakes
    Processed Files:
        djblets/webapi/tests/test_basic_auth_backend.py
    
    
  2. Show all issues
    Col: 53
     E126 continuation line over-indented for hanging indent
    
  3. Show all issues
    Col: 9
     E265 block comment should start with '# '
    
  4. Show all issues
    Col: 41
     E126 continuation line over-indented for hanging indent
    
  5. Show all issues
    Col: 41
     E126 continuation line over-indented for hanging indent
    
  6. Show all issues
    Col: 41
     E126 continuation line over-indented for hanging indent
    
  7. 
      
ST
reviewbot
  1. Tool: PEP8 Style Checker
    Processed Files:
        djblets/webapi/tests/test_basic_auth_backend.py
        djblets/webapi/tests/test_api_auth_backend.py
    
    
    
    Tool: Pyflakes
    Processed Files:
        djblets/webapi/tests/test_basic_auth_backend.py
        djblets/webapi/tests/test_api_auth_backend.py
    
    
  2. Show all issues
    Col: 53
     E126 continuation line over-indented for hanging indent
    
  3. Show all issues
    Col: 41
     E126 continuation line over-indented for hanging indent
    
  4. Show all issues
    Col: 41
     E126 continuation line over-indented for hanging indent
    
  5. Show all issues
    Col: 41
     E126 continuation line over-indented for hanging indent
    
  6. Show all issues
    Col: 41
     E126 continuation line over-indented for hanging indent
    
  7. Show all issues
    Col: 13
     E128 continuation line under-indented for visual indent
    
  8. Show all issues
    Col: 13
     E128 continuation line under-indented for visual indent
    
  9. 
      
ST
reviewbot
  1. Tool: PEP8 Style Checker
    Processed Files:
        djblets/webapi/tests/test_basic_auth_backend.py
        djblets/webapi/tests/test_api_auth_backend.py
    
    
    
    Tool: Pyflakes
    Processed Files:
        djblets/webapi/tests/test_basic_auth_backend.py
        djblets/webapi/tests/test_api_auth_backend.py
    
    
  2. 
      
brennie
  1. 
      
  2. djblets/webapi/tests/test_api_auth_backend.py (Diff revision 3)
     
     
     
     
    Show all issues

    You don't need the entire module path in here, you can just do:

    """Unit tests for the WebAPITokenBackend."""
    

    For future reference, docstrings should be of the form:

    """Single line sumnary
    
    Multi-line description.
    """
    

    (except for test_ method docstrings, of course).

    1. Sorry about that! I copied docstrings from Minh's RR.

  3. Show all issues

    See previous comment about docstring formatting.

    1. For all of the test docstrings would you prefer the following format?

      """Testing Token Auth get_credentials with missing token."""
      
    2. Yes, with the exception that we don't include the trailing period because the test suite will add "..." in the output.

  4. Show all issues

    """ will fit on previous line.

  5. djblets/webapi/tests/test_api_auth_backend.py (Diff revision 3)
     
     
     
     
    Show all issues

    See previous comment about docstring formatting

  6. Show all issues

    This attribution should be in the commit message, I believe. May want to ask Christian. Best to include the URL instead of just the ID.

  7. Show all issues

    Needs module-level docstring.

    1. What do you mean by module level docstring?

  8. Show all issues

    See comment re: formatting docstrings.

  9. djblets/webapi/tests/test_basic_auth_backend.py (Diff revision 3)
     
     
     
     
    Show all issues

    See comment re: formatting docstrings.

  10. Show all issues

    See comment re: formatting docstrings.

  11. Show all issues

    See comment re: formatting docstrings.

  12. Show all issues

    See comment re: formatting docstrings.

  13. Show all issues

    See comment re: formatting docstrings.

  14. Show all issues

    See comment re: formatting docstrings.

  15. Show all issues

    See comment re: formatting docstrings.

  16. Show all issues

    See comment re: formatting docstrings.

  17. Show all issues

    See comment re: formatting docstrings.

  18. 
      
ST
reviewbot
  1. Tool: PEP8 Style Checker
    Processed Files:
        djblets/webapi/tests/test_basic_auth_backend.py
        djblets/webapi/tests/test_api_auth_backend.py
    
    
    
    Tool: Pyflakes
    Processed Files:
        djblets/webapi/tests/test_basic_auth_backend.py
        djblets/webapi/tests/test_api_auth_backend.py
    
    
  2. 
      
ST
reviewbot
  1. Tool: Pyflakes
    Processed Files:
        djblets/webapi/tests/test_basic_auth_backend.py
        djblets/webapi/tests/test_api_auth_backend.py
    
    
    
    Tool: PEP8 Style Checker
    Processed Files:
        djblets/webapi/tests/test_basic_auth_backend.py
        djblets/webapi/tests/test_api_auth_backend.py
    
    
  2. 
      
brennie
  1. 
      
  2. Show all issues

    Blank line between these.

  3. Show all issues

    Docstring (just needs to indicate that its a dummy model for tests.)

  4. Show all issues

    Likewise.

  5. Show all issues

    Blank line between these.

  6. Show all issues

    Single quotes.

  7. Show all issues

    Single quotes.

  8. Show all issues

    Single quotes.

  9. Show all issues

    Single quotes.

  10. Show all issues

    Single quotes.

  11. Show all issues

    Single quotes.

  12. Show all issues

    Blank line between these.

  13. Show all issues

    Unused method.

  14. Show all issues

    Since this is a private method for tests, lets call it _validate_credentials.

    Also, needs a docstring.

  15. Show all issues

    You can reflow this to fill more of the first line.

  16. djblets/webapi/tests/test_basic_auth_backend.py (Diff revision 6)
     
     
     
     
     
    Show all issues

    Single quotes.

  17. djblets/webapi/tests/test_basic_auth_backend.py (Diff revision 6)
     
     
     
     
    Show all issues

    This should be comparing against a constant.

    1. Do you mean I should use a single assert statement against the entire dictionary?

  18. 
      
ST
reviewbot
  1. Tool: Pyflakes
    Processed Files:
        djblets/webapi/tests/test_basic_auth_backend.py
        djblets/webapi/tests/test_api_auth_backend.py
    
    
    
    Tool: PEP8 Style Checker
    Processed Files:
        djblets/webapi/tests/test_basic_auth_backend.py
        djblets/webapi/tests/test_api_auth_backend.py
    
    
  2. 
      
brennie
  1. 
      
  2. Show all issues

    Your description is missing a period.

  3. Show all issues

    No leading space. Missing a period.

  4. Show all issues

    Missing a period.

  5. Show all issues

    Missing super(...).tearDown()

  6. Show all issues

    You should just use the constant here.

  7. Show all issues

    Single quotes.

  8. Show all issues

    You want to use bytes(random()).

    We avoid str because in Python 2 str is a binary type and not a text type. It has been renamed to bytes in Python 3 and backported. The text type of Python 2 is unicode (which was renamed to str in Python 3). For actual string types, use six.text_type which converts to unicode in py2 and str in py3. For binary data (such as HTTP headers) use bytes. (There is also six.binary_type, but since we are Python 2.7 only we can use bytes instead.)

  9. Show all issues

    bytes(random())

  10. Show all issues

    missing super(...).setUp()

  11. Show all issues

    Single quotes.

  12. Show all issues

    missing super(...).tearDown()

  13. Show all issues

    No leading or trailing spaces.
    Missing a period.
    Missing args, returns.

  14. Show all issues

    Use either:

            clean_credentials = \
                self.basic_auth_backend.clean_credentials_for_display(
                    credentials)
    

    or:

            clean_credentials = (
                self.basic_auth_backend
                .clean_credentials_for_display(
                    credentials
                )
            )
    
  15. 
      
ST
reviewbot
  1. Tool: Pyflakes
    Processed Files:
        djblets/webapi/tests/test_basic_auth_backend.py
        djblets/webapi/tests/test_api_auth_backend.py
    
    
    
    Tool: PEP8 Style Checker
    Processed Files:
        djblets/webapi/tests/test_basic_auth_backend.py
        djblets/webapi/tests/test_api_auth_backend.py
    
    
  2. 
      
brennie
  1. 
      
  2. Show all issues

    Please re-write your summary in the imperitive mood.

  3. Show all issues

    You should inherit from SpyAgency e.g.

    class WebAPITokenAuthBackendTests(SpyAgency, TestModelsLoaderMixin, TestCase):
        # ...
    

    That way, you dont need self.agency, nor do you need your tearDown method -- SpyAgency.tearDown() (which will be called after each test) will unspy on all spies!

  4. Show all issues

    "succeeds"

  5. Show all issues

    Add a trailing , or move the ) onto this line.

  6. Show all issues

    Same here.

  7. djblets/webapi/tests/test_basic_auth_backend.py (Diff revision 8)
     
     
     
     
    Show all issues

    Since you're inheriting from SpyAgency, you don't need to unspy in tearDown -- it will happen automatically.

  8. 
      
ST
brennie
  1. 
      
  2. Show all issues

    Can you rename this to TestWebAPITokenModel

  3. Show all issues

    TestTokenAuthBackend.

  4. Show all issues

    You will want to use assertIsNone(result). When comparing against None, you always want to use is or is not.

  5. Show all issues

    assertIsNone

  6. djblets/webapi/tests/test_basic_auth_backend.py (Diff revision 9)
     
     
     
     
     
     
    Show all issues

    You aren't using middleware or requestfactory in the testcases so why not:

    self.request = RequestFactory().get('/')
    SessionMiddleware().process_request(self.request)
    
  7. djblets/webapi/tests/test_basic_auth_backend.py (Diff revision 9)
     
     
     
     
     
    Show all issues

    Does the User need to exist in the database? If not we can just make User() object.

    1. Two of the functions being tested end up doing a db query for that user to check credentials. Is it a problem that it creates a user? I was under the impression that a test database is created and then destroyed.

    2. No, its no problem. I was just curious.

  8. 
      
ST
reviewbot
  1. Tool: Pyflakes
    Processed Files:
        djblets/webapi/tests/test_basic_auth_backend.py
        djblets/webapi/tests/test_api_auth_backend.py
    
    
    
    Tool: PEP8 Style Checker
    Processed Files:
        djblets/webapi/tests/test_basic_auth_backend.py
        djblets/webapi/tests/test_api_auth_backend.py
    
    
    
    Tool: Pyflakes
    Processed Files:
        djblets/webapi/tests/test_basic_auth_backend.py
        djblets/webapi/tests/test_api_auth_backend.py
    
    
    
    Tool: PEP8 Style Checker
    Processed Files:
        djblets/webapi/tests/test_basic_auth_backend.py
        djblets/webapi/tests/test_api_auth_backend.py
    
    
  2. 
      
brennie
  1. 
      
  2. Show all issues

    "web API"
    missing period.

  3. Show all issues

    Can you move this into test_get_credentials_missing_credentials? It is only used in that test.

  4. djblets/webapi/tests/test_api_auth_backend.py (Diff revision 10)
     
     
     
    Show all issues

    Unnecessary.

  5. djblets/webapi/tests/test_api_auth_backend.py (Diff revision 10)
     
     
     
    Show all issues

    Put the trailing space on the previous line, even if it means splitting the string earlier.

  6. djblets/webapi/tests/test_api_auth_backend.py (Diff revision 10)
     
     
     
     
    Show all issues

    You can move this to a single line statement -- you won't need the comma in that case.

  7. Show all issues

    Is there any particular reason we are doing rand() here instead of just using a non-matching token

  8. Show all issues

    Is there any particular reason we are doing rand() here instead of just using a non-matching token

  9. Show all issues

    Missing period.

    web API

  10. Show all issues

    import foo statements go above from foo import bar statements.

  11. Show all issues

    Can you move this into test_get_credentials_malformed_credentials? It is only used in that test.

  12. Show all issues

    Unnecessary method. If this class doesn't implement tearDown, the superclass method will be invoked instead.

  13. Show all issues

    This sentence contains a comma splice. How about:

    """Fake version of validate credentials that always succeeds.
    
    This is used in lieu of the actual method for testing purposes.
    
    ...
    """
    

    or similar.

  14. Show all issues

    None.

    Only one space between sentences.

  15. Show all issues

    "request"

    Missing period.

  16. Show all issues

    "non-basic"

  17. Show all issues

    "with"

  18. Show all issues

    "with"

  19. Show all issues

    Missing trailing comma.

  20. Show all issues

    Missing trailing comma.

  21. Show all issues

    Missing trailing comma.

  22. Show all issues

    Missing trailing comma.

  23. Show all issues

    Missing trailing comma.

  24. Show all issues

    Missing trailing comma.

  25. 
      
ST
reviewbot
  1. Tool: Pyflakes
    Processed Files:
        djblets/webapi/tests/test_basic_auth_backend.py
        djblets/webapi/tests/test_api_auth_backend.py
    
    
    
    Tool: PEP8 Style Checker
    Processed Files:
        djblets/webapi/tests/test_basic_auth_backend.py
        djblets/webapi/tests/test_api_auth_backend.py
    
    
  2. 
      
ST
brennie
  1. 
      
  2. Show all issues

    Please include in your summary:

    This patch is based on work by Minh Le Hong at (the URL)
    
  3. Show all issues

    print() is not used.

  4. djblets/webapi/tests/test_api_auth_backend.py (Diff revision 11)
     
     
     
    Show all issues

    Alphabetize.

  5. djblets/webapi/tests/test_api_auth_backend.py (Diff revision 11)
     
     
     
    Show all issues

    Alphabetize imports.

  6. djblets/webapi/tests/test_api_auth_backend.py (Diff revision 11)
     
     
     
    Show all issues

    Blank line between these.

  7. Show all issues

    print() is not used.

  8. Show all issues

    Alphabetize these.

  9. Show all issues

    Blank line between these.

  10. 
      
david
  1. 
      
  2. djblets/webapi/tests/test_api_auth_backend.py (Diff revision 11)
     
     
     
     
     
     
     
     
    Show all issues

    Can you rearrange this so that things are defined just before they're tested?

    result = self.api_token_auth_backend.get_credentials(self.request)
    self.assertIsNone(result)
    
    warning_message = logging.warning.spy.last_call.args[0]
    self.assertTrue(warning_message.startswith(
        ...)
    
  3. Show all issues

    Please use single quotes around HTTP_AUTHORIZATION

  4. djblets/webapi/tests/test_api_auth_backend.py (Diff revision 11)
     
     
     
    Show all issues

    username and password are only used the once, so we could bring them inline instead of creating variables:

    self.user = User.objects.create_user(
        username='testuser', password='testuser_password')
    

    That said, I don't see anywhere that we actually care about the password being set, so we could leave that out entirely.

  5. djblets/webapi/tests/test_api_auth_backend.py (Diff revision 11)
     
     
     
    Show all issues

    Same comments about username/password.

  6. djblets/webapi/tests/test_basic_auth_backend.py (Diff revision 11)
     
     
     
     
    Show all issues

    username and password are only used once, so we can simplify:

    encoded_credentials = 'testuser:testpassword'.encode('base64')
    
  7. djblets/webapi/tests/test_basic_auth_backend.py (Diff revision 11)
     
     
     
     
    Show all issues

    Same here.

  8. djblets/webapi/tests/test_basic_auth_backend.py (Diff revision 11)
     
     
     
     
    Show all issues

    Same here.

  9. Show all issues

    It's a little silly to define a credentials dict just to unpack it for kwargs. Let's change this to be:

    result = self.basic_auth_backend.login_with_credentials(
        request, username=username, password=password)
    

    and kill the credentials definition.

  10. Show all issues

    Same here re: credentials.

  11. Show all issues

    Same here re: credentials

  12. Show all issues

    Same here re: credentials

  13. Show all issues

    Same here re: credentials

  14. Show all issues

    Same here re: credentials

  15. 
      
ST
ST
reviewbot
  1. Tool: Pyflakes
    Processed Files:
        djblets/webapi/tests/test_basic_auth_backend.py
        djblets/webapi/tests/test_api_auth_backend.py
    
    
    
    Tool: PEP8 Style Checker
    Processed Files:
        djblets/webapi/tests/test_basic_auth_backend.py
        djblets/webapi/tests/test_api_auth_backend.py
    
    
  2. 
      
LA
  1. 
      
  2. Show all issues

    can also include that function returns None in function doc string. I believe like
    Returns: None

    1. See: https://reviewboard.slack.com/archives/general/p1477019907002766

  3. 
      
mike_conley
  1. Thanks stensby - just a few questions. See below.

  2. Show all issues

    Why is this 'invalidtoken123? This is a valid token, no? Kinda makes the test confusing when the invalidtoken is valid.

    1. What the token itself is doesn't really matter, it is named that to signify that it is not a token that has been handed to a user (so the token doesn't exist in our TestWebAPITokenModel). Any suggestions on what to rename it to so that is clear?

  3. Show all issues

    Same as above.

  4. Show all issues

    I don't think "always succeeds" is true. Because this is returning None, it means we're falling back to the base authentication mechanism. At least, that's what I understand from reading https://github.com/djblets/djblets/blob/c4fa360ad80e72bab4cca142e17a90ee9dbfb68a/djblets/webapi/auth/backends/base.py#L59

    1. The function is actually replacing a function that is used to 'short-circut' the authentication process if the current user is already logged in. See https://github.com/djblets/djblets/blob/c4fa360ad80e72bab4cca142e17a90ee9dbfb68a/djblets/webapi/auth/backends/base.py#L159

  5. 
      
david
  1. 
      
  2. djblets/webapi/tests/test_api_auth_backend.py (Diff revision 12)
     
     
     
     
    Show all issues

    No blank line here (django and kgb are both third-party libraries from the point of view of the djblets package).

  3. djblets/webapi/tests/test_basic_auth_backend.py (Diff revision 12)
     
     
     
     
    Show all issues

    No blank line here.

  4. 
      
ST
reviewbot
  1. Tool: Pyflakes
    Processed Files:
        djblets/webapi/tests/test_basic_auth_backend.py
        djblets/webapi/tests/test_api_auth_backend.py
    
    
    
    Tool: PEP8 Style Checker
    Processed Files:
        djblets/webapi/tests/test_basic_auth_backend.py
        djblets/webapi/tests/test_api_auth_backend.py
    
    
  2. 
      
brennie
  1. 
      
  2. djblets/webapi/tests/test_basic_auth_backend.py (Diff revision 12)
     
     
     
     
     
     
     
    Show all issues

    So I believe you may be testing this wrongly after reading further into it.

    Firstly you are setting the user on the request AND short circuiting the validate_credentials method. We shouldn't have to do either of these things.

    Instead, you should create the user and store it as self.user and set self.request.user = AnonymousUser(). That way, the real validate_credentials will be called and return None.

  3. 
      
ST
reviewbot
  1. Tool: PEP8 Style Checker
    Processed Files:
        djblets/webapi/tests/test_basic_auth_backend.py
        djblets/webapi/tests/test_api_auth_backend.py
    
    
    
    Tool: Pyflakes
    Processed Files:
        djblets/webapi/tests/test_basic_auth_backend.py
        djblets/webapi/tests/test_api_auth_backend.py
    
    
  2. 
      
brennie
  1. Ship It!
  2. 
      
ST
Review request changed
Status:
Completed
Change Summary:
Pushed to release-0.9.x (9b44865)