import pytest

from zeus import factories
from zeus.auth import AuthenticationFailed
from zeus.api.authentication import ApiTokenAuthentication


def test_no_header(app):
    with app.test_request_context('/'):
        assert not ApiTokenAuthentication().authenticate()


def test_invalid_authentication_type(app):
    with app.test_request_context('/', headers={'Authentication': 'foobar'}):
        assert not ApiTokenAuthentication().authenticate()


def test_invalid_token(app):
    with app.test_request_context('/', headers={'Authentication': 'Bearer: foobar'}):
        with pytest.raises(AuthenticationFailed):
            ApiTokenAuthentication().authenticate()


def test_expired_token(app):
    api_token = factories.ApiTokenFactory(expired=True)
    with app.test_request_context(
        '/', headers={'Authentication': 'Bearer: {}'.format(api_token.access_token)}
    ):
        with pytest.raises(AuthenticationFailed):
            ApiTokenAuthentication().authenticate()


def test_valid_token(app, default_api_token):
    with app.test_request_context(
        '/', headers={'Authentication': 'Bearer: {}'.format(default_api_token.access_token)}
    ):
        tenant = ApiTokenAuthentication().authenticate()
        assert tenant.token_id == default_api_token.id

import pytest

from zeus import factories
from zeus.auth import AuthenticationFailed
from zeus.api.authentication import ApiTokenAuthentication


def test_no_header(app):
    with app.test_request_context('/'):
        assert not ApiTokenAuthentication().authenticate()


def test_invalid_authentication_type(app):
    with app.test_request_context('/', headers={'Authorization': 'foobar'}):
        assert not ApiTokenAuthentication().authenticate()


def test_invalid_token(app):
    with app.test_request_context('/', headers={'Authorization': 'Bearer: foobar'}):
        with pytest.raises(AuthenticationFailed):
            ApiTokenAuthentication().authenticate()


def test_expired_token(app):
    api_token = factories.ApiTokenFactory(expired=True)
    with app.test_request_context(
        '/', headers={'Authorization': 'Bearer: {}'.format(api_token.access_token)}
    ):
        with pytest.raises(AuthenticationFailed):
            ApiTokenAuthentication().authenticate()


def test_valid_token(app, default_api_token):
    with app.test_request_context(
        '/', headers={'Authorization': 'Bearer: {}'.format(default_api_token.access_token)}
    ):
        tenant = ApiTokenAuthentication().authenticate()
        assert tenant.token_id == default_api_token.id

Fix tests for new header
test(auth): Fix tests for new header

  import pytest
  
  from zeus import factories
  from zeus.auth import AuthenticationFailed
  from zeus.api.authentication import ApiTokenAuthentication
  
  
  def test_no_header(app):
      with app.test_request_context('/'):
          assert not ApiTokenAuthentication().authenticate()
  
  
  def test_invalid_authentication_type(app):
-     with app.test_request_context('/', headers={'Authentication': 'foobar'}):
+     with app.test_request_context('/', headers={'Authorization': 'foobar'}):
          assert not ApiTokenAuthentication().authenticate()
  
  
  def test_invalid_token(app):
-     with app.test_request_context('/', headers={'Authentication': 'Bearer: foobar'}):
+     with app.test_request_context('/', headers={'Authorization': 'Bearer: foobar'}):
          with pytest.raises(AuthenticationFailed):
              ApiTokenAuthentication().authenticate()
  
  
  def test_expired_token(app):
      api_token = factories.ApiTokenFactory(expired=True)
      with app.test_request_context(
-         '/', headers={'Authentication': 'Bearer: {}'.format(api_token.access_token)}
+         '/', headers={'Authorization': 'Bearer: {}'.format(api_token.access_token)}
      ):
          with pytest.raises(AuthenticationFailed):
              ApiTokenAuthentication().authenticate()
  
  
  def test_valid_token(app, default_api_token):
      with app.test_request_context(
-         '/', headers={'Authentication': 'Bearer: {}'.format(default_api_token.access_token)}
+         '/', headers={'Authorization': 'Bearer: {}'.format(default_api_token.access_token)}
      ):
          tenant = ApiTokenAuthentication().authenticate()
          assert tenant.token_id == default_api_token.id
  
Fix tests for new header
## Code Before:
import pytest

from zeus import factories
from zeus.auth import AuthenticationFailed
from zeus.api.authentication import ApiTokenAuthentication


def test_no_header(app):
    with app.test_request_context('/'):
        assert not ApiTokenAuthentication().authenticate()


def test_invalid_authentication_type(app):
    with app.test_request_context('/', headers={'Authentication': 'foobar'}):
        assert not ApiTokenAuthentication().authenticate()


def test_invalid_token(app):
    with app.test_request_context('/', headers={'Authentication': 'Bearer: foobar'}):
        with pytest.raises(AuthenticationFailed):
            ApiTokenAuthentication().authenticate()


def test_expired_token(app):
    api_token = factories.ApiTokenFactory(expired=True)
    with app.test_request_context(
        '/', headers={'Authentication': 'Bearer: {}'.format(api_token.access_token)}
    ):
        with pytest.raises(AuthenticationFailed):
            ApiTokenAuthentication().authenticate()


def test_valid_token(app, default_api_token):
    with app.test_request_context(
        '/', headers={'Authentication': 'Bearer: {}'.format(default_api_token.access_token)}
    ):
        tenant = ApiTokenAuthentication().authenticate()
        assert tenant.token_id == default_api_token.id

## Instruction:
Fix tests for new header
## Code After:
import pytest

from zeus import factories
from zeus.auth import AuthenticationFailed
from zeus.api.authentication import ApiTokenAuthentication


def test_no_header(app):
    with app.test_request_context('/'):
        assert not ApiTokenAuthentication().authenticate()


def test_invalid_authentication_type(app):
    with app.test_request_context('/', headers={'Authorization': 'foobar'}):
        assert not ApiTokenAuthentication().authenticate()


def test_invalid_token(app):
    with app.test_request_context('/', headers={'Authorization': 'Bearer: foobar'}):
        with pytest.raises(AuthenticationFailed):
            ApiTokenAuthentication().authenticate()


def test_expired_token(app):
    api_token = factories.ApiTokenFactory(expired=True)
    with app.test_request_context(
        '/', headers={'Authorization': 'Bearer: {}'.format(api_token.access_token)}
    ):
        with pytest.raises(AuthenticationFailed):
            ApiTokenAuthentication().authenticate()


def test_valid_token(app, default_api_token):
    with app.test_request_context(
        '/', headers={'Authorization': 'Bearer: {}'.format(default_api_token.access_token)}
    ):
        tenant = ApiTokenAuthentication().authenticate()
        assert tenant.token_id == default_api_token.id
