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

import unittest2
import requests
import time
import subprocess
import json
from alignak_backend_client.client import Backend


class TestHookLivetest(unittest2.TestCase):

    @classmethod
    def setUpClass(cls):
        cls.p = subprocess.Popen(['alignak_backend', 'start'])
        time.sleep(3)
        cls.backend = Backend('http://127.0.0.1:5000')
        cls.backend.login("admin", "admin")
        cls.backend.delete("host", {})
        cls.backend.delete("livestate", {})
        cls.backend.delete("livesynthesis", {})

    def test_add_host(self):
        data = json.loads(open('cfg/host_srv001.json').read())
        self.backend.post("host", data)
        # Check if host right in backend
        rh = self.backend.get('host')
        self.assertEqual(rh['_items'][0]['host_name'], "srv001")
        # Check if livestate right created
        r = self.backend.get('livestate')
        self.assertEqual(len(r['_items']), 1)
        self.assertEqual(r['_items'][0]['last_state'], 'UNREACHABLE')
        self.assertEqual(r['_items'][0]['last_state_type'], 'HARD')
        self.assertEqual(r['_items'][0]['last_check'], 0)
        self.assertEqual(r['_items'][0]['state_type'], 'HARD')
        self.assertEqual(r['_items'][0]['state'], 'UNREACHABLE')<commit_msg>Update test<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-

import unittest2
import requests
import time
import subprocess
import json
from alignak_backend_client.client import Backend


class TestHookLivetest(unittest2.TestCase):

    @classmethod
    def setUpClass(cls):
        cls.p = subprocess.Popen(['alignak_backend', 'start'])
        time.sleep(3)
        cls.backend = Backend('http://127.0.0.1:5000')
        cls.backend.login("admin", "admin", "force")
        cls.backend.delete("host", {})
        cls.backend.delete("livestate", {})
        cls.backend.delete("livesynthesis", {})

    def test_add_host(self):
        data = json.loads(open('cfg/host_srv001.json').read())
        self.backend.post("host", data)
        # Check if host right in backend
        rh = self.backend.get('host')
        self.assertEqual(rh['_items'][0]['host_name'], "srv001")
        # Check if livestate right created
        r = self.backend.get('livestate')
        self.assertEqual(len(r['_items']), 1)
        self.assertEqual(r['_items'][0]['last_state'], 'UNREACHABLE')
        self.assertEqual(r['_items'][0]['last_state_type'], 'HARD')
        self.assertEqual(r['_items'][0]['last_check'], 0)
        self.assertEqual(r['_items'][0]['state_type'], 'HARD')
        self.assertEqual(r['_items'][0]['state'], 'UNREACHABLE')
{'fraction_non_alphanumeric': 0.1753271028037383, 'fraction_numerical': 0.020934579439252338, 'mean_word_length': 3.4085667215815487, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '1179563', 'n_tokens_mistral': 881, 'n_tokens_neox': 866, 'n_words': 139}