<commit_before>import unittest
import urllib2
import shutil
import json

from flask import Flask
from flask.ext.testing import LiveServerTestCase

from lwp.app import app
from lwp.utils import connect_db

class TestWebIf(LiveServerTestCase):

    render_templates = False

    def create_app(self):
        return app

    def test_server_is_up_and_running(self):
        response = urllib2.urlopen(self.get_server_url())
        self.assertEqual(response.code, 200)

    def test_views(self):
        endpoints = ('/home', '/settings/lxc-net', '/about', '/lwp/users',
            '/lwp/tokens', '/action', '/_refresh_info', '/_check_version')

        for link in endpoints:
            response = urllib2.urlopen(self.get_server_url() + link)
            self.assertEqual(response.code, 200)

class TestApi(LiveServerTestCase):

    token = '<PASSWORD>'
    db = None
    type_json = {'Content-Type': 'application/json'}

    def create_app(self):
        shutil.copyfile('lwp.db', '/tmp/db.sql')
        self.db = connect_db('/tmp/db.sql')
        self.db.execute('insert into api_tokens(description, token) values(?, ?)', ['test', self.token])
        self.db.commit()
        app.config['DATABASE'] = '/tmp/db.sql'
        return app

    def test_get_containers(self):
        request = urllib2.Request(self.get_server_url() + '/api/v1/containers/')
        request.add_header('Private-Token', self.token)
        response = urllib2.urlopen(request)
        self.assertEqual(response.code, 200)
        #assert isinstance(response.read(), list)

    def test_put_containers(self):
        data = {'name': 'test_vm_sshd', 'template': 'sshd'}
        request = urllib2.Request(self.get_server_url() + '/api/v1/containers/', json.dumps(data), self.type_json)<commit_msg>remove mock-lxc file before test<commit_after>import unittest
import urllib2
import shutil
import json

from flask import Flask
from flask.ext.testing import LiveServerTestCase

from lwp.app import app
from lwp.utils import connect_db

class TestWebIf(LiveServerTestCase):

    render_templates = False

    def create_app(self):
        return app

    def test_server_is_up_and_running(self):
        response = urllib2.urlopen(self.get_server_url())
        self.assertEqual(response.code, 200)

    def test_views(self):
        endpoints = ('/home', '/settings/lxc-net', '/about', '/lwp/users',
            '/lwp/tokens', '/action', '/_refresh_info', '/_check_version')

        for link in endpoints:
            response = urllib2.urlopen(self.get_server_url() + link)
            self.assertEqual(response.code, 200)

class TestApi(LiveServerTestCase):

    token = '<PASSWORD>'
    db = None
    type_json = {'Content-Type': 'application/json'}

    def create_app(self):
        shutil.rmtree('/tmp/test_vm_sshd', ignore_errors=True)
        shutil.copyfile('lwp.db', '/tmp/db.sql')
        self.db = connect_db('/tmp/db.sql')
        self.db.execute('insert into api_tokens(description, token) values(?, ?)', ['test', self.token])
        self.db.commit()
        app.config['DATABASE'] = '/tmp/db.sql'
        return app

    def test_get_containers(self):
        request = urllib2.Request(self.get_server_url() + '/api/v1/containers/')
        request.add_header('Private-Token', self.token)
        response = urllib2.urlopen(request)
        self.assertEqual(response.code, 200)
        #assert isinstance(response.read(), list)

    def test_put_containers(self):
        data = {'name': 'test_vm_sshd', 'template': 'sshd'}
        request = urllib2.Request(self.get_server_url() + '/api/v1/containers/', json.dumps(data), self.type_json)
{'fraction_non_alphanumeric': 0.13561190738699008, 'fraction_numerical': 0.009371554575523704, 'mean_word_length': 3.1760644418872266, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, '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': '3253736', 'n_tokens_mistral': 1194, 'n_tokens_neox': 1145, 'n_words': 227}