• 
      

    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.

    brennie brennie

    Please re-write your summary in the imperitive mood.

    brennie brennie

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

    brennie brennie

    local variable 'user' is assigned to but never used

    reviewbot reviewbot

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

    reviewbot reviewbot

    local variable 'get_credentials_mock' is assigned to but never used

    reviewbot reviewbot

    local variable 'get_credentials_mock' is assigned to but never used

    reviewbot reviewbot

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

    reviewbot reviewbot

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

    reviewbot reviewbot

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

    reviewbot reviewbot

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

    reviewbot reviewbot

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

    reviewbot reviewbot

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

    brennie brennie

    See previous comment about docstring formatting.

    brennie brennie

    """ will fit on previous line.

    brennie brennie

    See previous comment about docstring formatting

    brennie brennie

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

    brennie brennie

    Needs module-level docstring.

    brennie brennie

    See comment re: formatting docstrings.

    brennie brennie

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

    reviewbot reviewbot

    See comment re: formatting docstrings.

    brennie brennie

    See comment re: formatting docstrings.

    brennie brennie

    See comment re: formatting docstrings.

    brennie brennie

    See comment re: formatting docstrings.

    brennie brennie

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

    reviewbot reviewbot

    See comment re: formatting docstrings.

    brennie brennie

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

    reviewbot reviewbot

    See comment re: formatting docstrings.

    brennie brennie

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

    reviewbot reviewbot

    See comment re: formatting docstrings.

    brennie brennie

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

    reviewbot reviewbot

    See comment re: formatting docstrings.

    brennie brennie

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

    reviewbot reviewbot

    See comment re: formatting docstrings.

    brennie brennie

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

    reviewbot reviewbot

    Blank line between these.

    brennie brennie

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

    brennie brennie

    Likewise.

    brennie brennie

    Blank line between these.

    brennie brennie

    Single quotes.

    brennie brennie

    Single quotes.

    brennie brennie

    Single quotes.

    brennie brennie

    Single quotes.

    brennie brennie

    Single quotes.

    brennie brennie

    Single quotes.

    brennie brennie

    Blank line between these.

    brennie brennie

    Unused method.

    brennie brennie

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

    brennie brennie

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

    brennie brennie

    Single quotes.

    brennie brennie

    This should be comparing against a constant.

    brennie brennie

    No leading space. Missing a period.

    brennie brennie

    Missing a period.

    brennie brennie

    Missing super(...).tearDown()

    brennie brennie

    You should just use the constant here.

    brennie brennie

    Single quotes.

    brennie brennie

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

    brennie brennie

    bytes(random())

    brennie brennie

    missing super(...).setUp()

    brennie brennie

    Single quotes.

    brennie brennie

    missing super(...).tearDown()

    brennie brennie

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

    brennie brennie

    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 ) )

    brennie brennie

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

    brennie brennie

    "succeeds"

    brennie brennie

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

    brennie brennie

    Same here.

    brennie brennie

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

    brennie brennie

    Can you rename this to TestWebAPITokenModel

    brennie brennie

    TestTokenAuthBackend.

    brennie brennie

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

    brennie brennie

    assertIsNone

    brennie brennie

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

    brennie brennie

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

    brennie brennie

    "web API" missing period.

    brennie brennie

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

    brennie brennie

    Unnecessary.

    brennie brennie

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

    brennie brennie

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

    brennie brennie

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

    brennie brennie

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

    brennie brennie

    Missing period. web API

    brennie brennie

    import foo statements go above from foo import bar statements.

    brennie brennie

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

    brennie brennie

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

    brennie brennie

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

    brennie brennie

    None. Only one space between sentences.

    brennie brennie

    "request" Missing period.

    brennie brennie

    "non-basic"

    brennie brennie

    "with"

    brennie brennie

    "with"

    brennie brennie

    Missing trailing comma.

    brennie brennie

    Missing trailing comma.

    brennie brennie

    Missing trailing comma.

    brennie brennie

    Missing trailing comma.

    brennie brennie

    Missing trailing comma.

    brennie brennie

    Missing trailing comma.

    brennie brennie

    print() is not used.

    brennie brennie

    Alphabetize.

    brennie brennie

    Alphabetize imports.

    brennie brennie

    Blank line between these.

    brennie brennie

    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] …

    david david

    Please use single quotes around HTTP_AUTHORIZATION

    david david

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

    david david

    Same comments about username/password.

    david david

    print() is not used.

    brennie brennie

    Alphabetize these.

    brennie brennie

    Blank line between these.

    brennie brennie

    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')

    david david

    Same here.

    david david

    Same here.

    david david

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

    david david

    Same here re: credentials.

    david david

    Same here re: credentials

    david david

    Same here re: credentials

    david david

    Same here re: credentials

    david david

    Same here re: credentials

    david david

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

    david david

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

    mike_conley mike_conley

    Same as above.

    mike_conley mike_conley

    No blank line here.

    david david

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

    brennie brennie

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

    mike_conley mike_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)