Beispiel #1
0
def test_delete_normal(client):
	response = client.post('/api/documents', 
		headers=make_header(test_users[0]["username"], 
			test_users[0]["password"]),
		json=test_input)

	assert response.status_code == 201
	assert "Location" in response.headers
	assert "message" in response.json
	assert "id" in response.json

	location = response.headers["Location"].split("/")
	id = None
	
	for w in location:
		try:
			id = int(w)
		except ValueError:
			pass

	assert id is not None
	response = client.delete('/api/documents/' + str(id),
		headers=make_header(test_users[0]["username"], 
			test_users[0]["password"]))

	assert response.status_code == 200
	assert "message" in response.json

	response = client.delete('/api/documents/' + str(id),
		headers=make_header(test_users[0]["username"], 
			test_users[0]["password"]))

	assert response.status_code == 400
	assert "message" in response.json
Beispiel #2
0
def test_auth_token(client, app):
    response = client.get('/api/auth/token',
                          headers=make_header(test_users[0]["username"],
                                              test_users[0]["password"]))
    assert response.status_code == 200

    try_again = client.get('/api/auth/token',
                           headers=make_header(response.json["token"],
                                               "unused"))

    assert try_again.status_code == 200
def test_get_wrong_user(client):
	response = client.post('/api/documents', 
		headers=make_header(test_users[0]["username"], 
			test_users[0]["password"]),
		json=test_input)

	assert response.status_code == 201
	location = response.headers["Location"]

	response = client.get(location,
		headers=make_header(test_users[1]["username"],
			test_users[1]["password"]))

	assert response.status_code == 403
Beispiel #4
0
def test_post_repeat(client):
	response = client.post('/api/documents', 
		headers=make_header(test_users[0]["username"], 
			test_users[0]["password"]),
		json=test_input)

	assert response.status_code == 201
	assert "message" in response.json


	response = client.post('/api/documents', 
		headers=make_header(test_users[0]["username"], 
			test_users[0]["password"]),
		json=test_input)

	assert response.status_code == 302
	assert "message" in response.json
def test_get_normal(client):
	response = client.post('/api/documents', 
		headers=make_header(test_users[0]["username"], 
			test_users[0]["password"]),
		json=test_input)

	assert response.status_code == 201
	location = response.headers["Location"]

	response = client.get(location,
		headers=make_header(test_users[0]["username"],
			test_users[0]["password"]))

	assert response.status_code == 200
	assert len(response.json) > 0
	assert "test" in response.json.keys() or "this" in response.json.keys()
	assert not "a" in response.json.keys()
def test_get_not_exist(client):

	response = client.get("/api/documents/32/absolute_keywords",
		headers=make_header(test_users[0]["username"],
			test_users[0]["password"]))

	assert response.status_code == 400
	assert "message" in response.json
Beispiel #7
0
def test_post_empty(client):

	response = client.post('/api/documents', 
		headers=make_header(test_users[0]["username"], 
			test_users[0]["password"]),
		json=None)

	assert response.status_code == 400
	assert "message" in response.json
Beispiel #8
0
def test_post_no_name(client):

	response = client.post('/api/documents', 
		headers=make_header(test_users[0]["username"], 
			test_users[0]["password"]),
		json={"content": "This is a test."})

	assert response.status_code == 400
	assert "message" in response.json
Beispiel #9
0
def test_post_normal(client):
	response = client.post('/api/documents', 
		headers=make_header(test_users[0]["username"], 
			test_users[0]["password"]),
		json=test_input)

	assert response.status_code == 201
	assert "Location" in response.headers
	assert "message" in response.json
	assert "id" in response.json
def test_get_groups_normal(client):
    response = client.get('/api/groups',
                          headers=make_header(test_users[0]["username"],
                                              test_users[0]["password"]))

    assert response.status_code == 200
def test_delete_group_normal(client):
    response = client.delete('/api/groups/0',
                             headers=make_header(test_users[0]["username"],
                                                 test_users[0]["password"]))

    assert response.status_code == 200
Beispiel #12
0
def test_unauth_token(client):
    response = client.get('/api/auth/token',
                          headers=make_header(test_users[0]["username"],
                                              "wrong"))
    assert response.status_code == 401
Beispiel #13
0
def test_bad_token(client, app):

    response = client.get('/api/auth/token',
                          headers=make_header("badtoken", "unused"))

    assert response.status_code == 401
def test_get_normal_document(client):
	response = client.get('/api/documents/0/relative_keywords', 
		headers=make_header(test_users[0]["username"], 
			test_users[0]["password"]))

	assert response.status_code == 200