<commit_before>import unittest2
import shutil
import msgpack
import os

from nose.tools import *

from elevator.api import Handler
from elevator.db import DatabasesHandler
from elevator.constants import *
from elevator.message import Request

from .fakers import gen_test_env


class ApiTests(unittest2.TestCase):
    def _bootstrap_db(self, db):
        for val in xrange(9):
            db.Put(str(val), str(val))

    def setUp(self):
        self.env = gen_test_env()
        self.databases = DatabasesHandler('/tmp/store.json', '/tmp')
        self.default_db_uid = self.databases['index']['default']
        self._bootstrap_db(self.databases[self.default_db_uid])
        self.handler = Handler(self.databases)

    def tearDown(self):
        shutil.rmtree('/tmp/default')
        os.remove('/tmp/store.json')

    def request_message(self, command, args, db_uid=None):
        db_uid = db_uid or self.default_db_uid
        return Request(msgpack.packb({
            'DB_UID': db_uid,
            'COMMAND': command,
            'ARGS': args,
        }))

    def test_command_with_existing_command(self):<commit_msg>Fix : api tests for compatibility with new Req/Resp<commit_after>import unittest2
import shutil
import msgpack
import os

from nose.tools import *

from elevator.api import Handler
from elevator.db import DatabasesHandler
from elevator.constants import *
from elevator.message import Request

from .fakers import gen_test_env


class ApiTests(unittest2.TestCase):
    def _bootstrap_db(self, db):
        for val in xrange(9):
            db.Put(str(val), str(val))

    def setUp(self):
        self.env = gen_test_env()
        self.databases = DatabasesHandler('/tmp/store.json', '/tmp')
        self.default_db_uid = self.databases['index']['default']
        self._bootstrap_db(self.databases[self.default_db_uid])
        self.handler = Handler(self.databases)

    def tearDown(self):
        shutil.rmtree('/tmp/default')
        os.remove('/tmp/store.json')

    def request_message(self, command, args, db_uid=None):
        db_uid = db_uid or self.default_db_uid
        return Request(msgpack.packb({
            'uid': db_uid,
            'cmd': command,
            'args': args,
        }))

    def test_command_with_existing_command(self):
{'fraction_non_alphanumeric': 0.10784743533537922, 'fraction_numerical': 0.00263042525208242, 'mean_word_length': 3.0318021201413425, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '764385', 'n_tokens_mistral': 701, 'n_tokens_neox': 688, 'n_words': 158}