<commit_before>#!/usr/bin/python
# -*- coding: utf-8 -*-

# Copyright (c) 2015:
#   <NAME>, <EMAIL>
#
# This file is part of (WebUI).
#
# (WebUI) is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# (WebUI) is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with (WebUI).  If not, see <http://www.gnu.org/licenses/>.
# import the unit testing module

import os
import time
import shlex
import unittest2
import subprocess

from nose import with_setup # optional
from nose.tools import *

pid = None
backend_address = "http://localhost:5000"

def setup_module(module):
    print ("")
    print ("start alignak backend")

    # Set test mode for applications backend
    os.environ['TEST_ALIGNAK_BACKEND'] = '1'
    os.environ['TEST_ALIGNAK_BACKEND_DB'] = 'alignak-backend'

    # Delete used mongo DBs
    exit_code = subprocess.call(
        shlex.split('mongo %s --eval "db.dropDatabase()"' % os.environ['TEST_ALIGNAK_BACKEND_DB'])
    )
    assert exit_code == 0

    global pid
    global backend_address
    pid = subprocess.Popen(
        shlex.split('alignak_backend')
    )
    time.sleep(2)

    print ("populate backend content - delete all content")
    fh = open("NUL","w")
    pid2 = subprocess.Popen(
        shlex.split('cfg_to_backend --verbose --delete')
    )
    pid2.communicate()
    fh.close()

    # Stop and start backend to make sure that it is restarted after its content deletion...
    pid.kill()
    pid = subprocess.Popen(
        shlex.split('alignak_backend')
    )
    time.sleep(2)

def teardown_module(module):
    print ("")
    print ("stop alignak backend")

    global pid
    pid.kill()

from alignak_backend_client.client import Backend, BackendException
# TODO: what a mess ... those imports do not work !!!
# from alignak_backend_client.client import manifest
from alignak_backend_client.client import BACKEND_PAGINATION_LIMIT, BACKEND_PAGINATION_DEFAULT

class test_0_login_logout(unittest2.TestCase):

    def test_01_creation(self):
        global backend_address

        print ''
        print 'test creation'
<commit_msg>Update tests<commit_after>#!/usr/bin/python
# -*- coding: utf-8 -*-

# Copyright (c) 2015:
#   <NAME>, <EMAIL>
#
# This file is part of (WebUI).
#
# (WebUI) is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# (WebUI) is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with (WebUI).  If not, see <http://www.gnu.org/licenses/>.
# import the unit testing module

import os
import time
import shlex
import unittest2
import subprocess

from nose import with_setup # optional
from nose.tools import *

pid = None
backend_address = "http://localhost:5000"

def setup_module(module):
    print ("")
    print ("start alignak backend")

    # Set test mode for applications backend
    os.environ['TEST_ALIGNAK_BACKEND'] = '1'
    os.environ['TEST_ALIGNAK_BACKEND_DB'] = 'alignak-backend'

    # Delete used mongo DBs
    exit_code = subprocess.call(
        shlex.split('mongo %s --eval "db.dropDatabase()"' % os.environ['TEST_ALIGNAK_BACKEND_DB'])
    )
    assert exit_code == 0

    global pid
    global backend_address
    pid = subprocess.Popen(
        shlex.split('alignak_backend')
    )
    time.sleep(2)

    print ("populate backend content - delete all content")
    pid2 = subprocess.Popen(
        shlex.split('alignak_backend_import --verbose --delete')
    )
    pid2.communicate()

    # Stop and start backend to make sure that it is restarted after its content deletion...
    pid.kill()
    pid = subprocess.Popen(
        shlex.split('alignak_backend')
    )
    time.sleep(2)

def teardown_module(module):
    print ("")
    print ("stop alignak backend")

    global pid
    pid.kill()

from alignak_backend_client.client import Backend, BackendException
# TODO: what a mess ... those imports do not work !!!
# from alignak_backend_client.client import manifest
from alignak_backend_client.client import BACKEND_PAGINATION_LIMIT, BACKEND_PAGINATION_DEFAULT

class test_0_login_logout(unittest2.TestCase):

    def test_01_creation(self):
        global backend_address

        print ''
        print 'test creation'

{'fraction_non_alphanumeric': 0.09460266879107747, 'fraction_numerical': 0.008364867556263693, 'mean_word_length': 3.5040358744394617, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5600105', 'n_tokens_mistral': 1544, 'n_tokens_neox': 1499, 'n_words': 514}