<commit_before>from common_fixtures import *  # NOQA
import websocket as ws
import pytest
import time


def get_logs(admin_client):
    hosts = admin_client.list_host(kind='docker', removed_null=True)
    assert len(hosts) > 0
    inLog = random_str()
    cmd = "/bin/bash -c \"echo "+inLog+"\""
    c = admin_client.create_container(imageUuid=TEST_IMAGE_UUID,
                                      command=cmd)
    c = admin_client.wait_success(c)
    logs = c.logs()
    return logs,inLog,c


def test_logs_token(admin_client):
    logs, inLog,c = get_logs(admin_client)
    conn = ws.create_connection(logs.url + '?token='+logs.token)
    result = conn.recv()
    assert result is not None
    assert inLog in result

    admin_client.delete(c)


def test_logs_no_token(admin_client):
    logs,_ ,c = get_logs(admin_client)
    with pytest.raises(Exception) as excinfo:
            ws.create_connection(logs.url)
    assert 'Handshake status 401' in str(excinfo.value)
    admin_client.delete(c)


def test_host_api_garbage_token(admin_client):
    logs,_ ,c = get_logs(admin_client)
    with pytest.raises(Exception) as excinfo:
        ws.create_connection(logs.url+'?token=random.garbage.token')
    assert 'Handshake status 401' in str(excinfo.value)
    admin_client.delete(c)<commit_msg>Fixed flake 8 in logs test<commit_after>from common_fixtures import *  # NOQA
import websocket as ws
import pytest


def get_logs(admin_client):
    hosts = admin_client.list_host(kind='docker', removed_null=True)
    assert len(hosts) > 0
    inLog = random_str()
    cmd = "/bin/bash -c \"echo "+inLog+"\""
    c = admin_client.create_container(imageUuid=TEST_IMAGE_UUID,
                                      command=cmd)
    c = admin_client.wait_success(c)
    logs = c.logs()
    return logs, inLog, c


def test_logs_token(admin_client):
    logs, inLog, c = get_logs(admin_client)
    conn = ws.create_connection(logs.url + '?token='+logs.token)
    result = conn.recv()
    assert result is not None
    assert inLog in result

    admin_client.delete(c)


def test_logs_no_token(admin_client):
    logs, _, c = get_logs(admin_client)
    with pytest.raises(Exception) as excinfo:
            ws.create_connection(logs.url)
    assert 'Handshake status 401' in str(excinfo.value)
    admin_client.delete(c)


def test_host_api_garbage_token(admin_client):
    logs, _, c = get_logs(admin_client)
    with pytest.raises(Exception) as excinfo:
        ws.create_connection(logs.url+'?token=<PASSWORD>')
    assert 'Handshake status 401' in str(excinfo.value)
    admin_client.delete(c)
{'fraction_non_alphanumeric': 0.10510046367851623, 'fraction_numerical': 0.005795981452859351, 'mean_word_length': 3.471502590673575, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '255141', 'n_tokens_mistral': 899, 'n_tokens_neox': 862, 'n_words': 185}