import json


def login(client, username, password):
    response = client.post(
        '/login',
        data={
            'username': username,
            'password': password
        }
    )

    return response


def test_good_login(app, session, user):
    client = app.test_client()

    response = login(client, 'admin', 'password')

    assert response.status_code == 200

    data = json.loads(response.data)

    assert data['user_id'] == user.id
    assert 'token' in data


def test_bad_login(app, user):
    client = app.test_client()

    response = login(client, 'admin', 'foo')

    assert response.status_code == 422

    data = json.loads(response.data)

    assert data == {
        'errors': {
            'username': ['Incorrect username or password.']
        }
    }

@@ -6,16 +6,63 @@
 t json%0A%0A
+from radar_api.tests.fixtures import get_user%0A%0A
 %0Adef log
@@ -287,25 +287,40 @@
 (app
-, session, user):
+):%0A    user = get_user('admin')%0A
 %0A   
@@ -544,16 +544,16 @@
  data%0A%0A%0A
+
 def test
@@ -566,22 +566,16 @@
 ogin(app
-, user
 ):%0A    c

Fix login test