예제 #1
0
def test_get_with_users(client):
    add_user("Max Mustermann", "*****@*****.**")
    add_user("Foo Bar", "*****@*****.**")

    response = client.get("/")

    assert response.status_code == 200
    assert b"Alle User:"******"<li>Max Mustermann</li>" in response.data
    assert b"<li>Foo Bar</li>" in response.data
예제 #2
0
def test_all_users(client):
    helpers.add_user("Test", "*****@*****.**")
    helpers.add_user("Test2", "*****@*****.**")

    response = client.get("/users")
    data = json.loads(response.data.decode())

    helpers.assert_json_response(response, 200)
    assert "success" in data["status"]
    assert len(data["data"]["users"]) == 2
예제 #3
0
def test_registered_user_logs_in(client):
    helpers.add_user(username="******",
                     email="*****@*****.**",
                     password="******")
    response, data = post(client, {
        "email": "*****@*****.**",
        "password": "******"
    })

    helpers.assert_json_response(response, 200)
    helpers.assert_data(data, "success", "Successfully logged in")
예제 #4
0
def test_registered_user_logs_in_wrong_password(client):
    helpers.add_user(username="******",
                     email="*****@*****.**",
                     password="******")
    response, data = post(client, {
        "email": "*****@*****.**",
        "password": "******"
    })

    helpers.assert_json_response(response, 400)
    helpers.assert_data(data, "fail", "Check password")
예제 #5
0
def test_email_already_exists(client):
    helpers.add_user(
        username="******", email="*****@*****.**", password="******"
    )
    response, data = post(
        client,
        {
            "username": "******",
            "email": "*****@*****.**",
            "password": "******",
        },
    )

    assert response.status_code == 400
    helpers.assert_data(data, "fail", "User already exists")
예제 #6
0
def test_username_already_exists(client):
    helpers.add_user(
        username="******", email="*****@*****.**", password="******"
    )
    response, data = post(
        client,
        {
            "username": "******",
            "email": "*****@*****.**",
            "password": "******",
        },
    )

    assert response.status_code == 400
    helpers.assert_data(data, "fail", "User already exists")
예제 #7
0
def test_single_id(client):
    user = helpers.add_user("Test", "*****@*****.**")

    response = client.get(f"/users/{user.id}")
    data = json.loads(response.data.decode())

    helpers.assert_json_response(response, 200)
    assert "success" in data["status"]
    assert "Test" in data["data"]["username"]
    assert "*****@*****.**" in data["data"]["email"]
예제 #8
0
    def test_create_bike_creates_bike(self):
        user, password = add_user(db=db, username='******')
        token = user.generate_auth_token().decode('utf-8')
        hs = Headers()
        hs.add('Authorization', 'Bearer {}'.format(token))
        hs.add('Content-Type', 'application/json')
        req_data = json.dumps(dict(name='Felt',
                                   purchased_at='2016-01-21-00-00'))
        resp = self.client.post('/api/bike',
                                headers=hs,
                                data=req_data)

        created_bike = Bike.query.get(resp.json['id'])

        self.assertEqual(201, resp.status_code)
        self.assertEqual('Felt', created_bike.name)