<commit_before>import os
import sys
import shutil
import httplib2
import Cookie

from tiddlyweb.model.bag import Bag
from tiddlyweb.model.recipe import Recipe



def get_auth(username, password):
    http = httplib2.Http()
    response, content = http.request(
            'http://0.0.0.0:8080/challenge/cookie_form',
            body='user=%s&password=%s' % (username, password),
            method='POST',
            headers={'Content-Type': 'application/x-www-form-urlencoded'})
    assert response.previous['status'] == '303'

    user_cookie = response.previous['set-cookie']
    cookie = Cookie.SimpleCookie()
    cookie.load(user_cookie)
    return cookie['tiddlyweb_user'].value


def make_test_env():
    try:
        shutil.rmtree('test_instance')
    except OSError:
        pass
    exit = os.system('twinstance_dev tiddlywebplugins.tiddlyspace test_instance')
    if exit == 0:
        os.chdir('test_instance')
        sys.path.insert(0, os.getcwd())
    else:
        assert False is True, 'unable to create test env'


def make_fake_space(store, name):
    public_recipe = Recipe('%s_public' % name)
    private_recipe = Recipe('%s_private' % name)
    public_bag = Bag('%s_public' % name)
    private_bag = Bag('%s_private' % name)
    private_bag.policy.manage = [name]
    public_bag.policy.manage = [name]
    private_recipe.policy.manage = [name]
    public_recipe.policy.manage = [name]
    public_recipe.set_recipe([('system', ''), ('tiddlyspace', ''), ('%s_public' % name, '')])<commit_msg>Make sure the test instance is created via tiddlyweb 1.1.x code.<commit_after>import os
import sys
import shutil
import httplib2
import Cookie

from tiddlyweb.model.bag import Bag
from tiddlyweb.model.recipe import Recipe



def get_auth(username, password):
    http = httplib2.Http()
    response, content = http.request(
            'http://0.0.0.0:8080/challenge/cookie_form',
            body='user=%s&password=%s' % (username, password),
            method='POST',
            headers={'Content-Type': 'application/x-www-form-urlencoded'})
    assert response.previous['status'] == '303'

    user_cookie = response.previous['set-cookie']
    cookie = Cookie.SimpleCookie()
    cookie.load(user_cookie)
    return cookie['tiddlyweb_user'].value


def make_test_env():
    try:
        shutil.rmtree('test_instance')
    except OSError:
        pass
    exit = os.system('PYTHONPATH="." twinstance_dev tiddlywebplugins.tiddlyspace test_instance')
    if exit == 0:
        os.chdir('test_instance')
        sys.path.insert(0, os.getcwd())
    else:
        assert False is True, 'unable to create test env'


def make_fake_space(store, name):
    public_recipe = Recipe('%s_public' % name)
    private_recipe = Recipe('%s_private' % name)
    public_bag = Bag('%s_public' % name)
    private_bag = Bag('%s_private' % name)
    private_bag.policy.manage = [name]
    public_bag.policy.manage = [name]
    private_recipe.policy.manage = [name]
    public_recipe.policy.manage = [name]
    public_recipe.set_recipe([('system', ''), ('tiddlyspace', ''), ('%s_public' % name, '')])
{'fraction_non_alphanumeric': 0.13727390180878554, 'fraction_numerical': 0.0103359173126615, 'mean_word_length': 3.4369627507163325, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '460318', 'n_tokens_mistral': 1056, 'n_tokens_neox': 1016, 'n_words': 205}