"""Tests for the Response util.""" from auth.utils import response def test_response_creation(): """Test the default response creation.""" resp = response.Response() assert not resp.message assert not resp.errors assert resp.success assert resp.status == 200 def test_response_creation_with_message(): """Test the creation of a response with a message.""" message = 'something' resp = response.Response(message=message) assert resp.message assert resp.success assert resp.status == 200 data, status = resp assert data == message assert status == 200 def test_response_creation_with_errors(): """Test the response creation with errors.""" error = 'something' resp = response.Response(errors=error) assert not resp.message assert not resp.success assert resp.errors == error assert resp.status == 400 # default data, status = resp assert isinstance(data, dict) assert data.get('errors') == error assert status == 400 def test_create_response(): """Test the creation of a fatal response.""" error = 'something' calls = [ (response.create_fatal_response, 500), (response.create_error_response, 400), (response.create_not_found_response, 404)] for call, status in calls: resp = call() assert not resp.success assert resp.status == status resp = call(error) assert resp.errors == error