<commit_before>from __future__ import unicode_literals

import django
from django.test import TestCase
from mock import patch

from mesos_api.api import SlaveInfo
from node.test import utils as node_test_utils
from scheduler.sync.node_manager import NodeManager


class TestNodeManager(TestCase):

    def setUp(self):
        django.setup()

        self.node_agent_1 = 'agent_1'
        self.node_agent_2 = 'agent_2'
        self.node_1 = node_test_utils.create_node(hostname='host_1', slave_id=self.node_agent_1)

        self.slave_infos = [SlaveInfo(self.node_agent_1, 'host_1'), SlaveInfo(self.node_agent_2, 'host_2')]

    @patch('scheduler.sync.node_manager.api.get_slaves')
    def test_successful_update(self, mock_get_slaves):
        """Tests doing a successful database update"""

        mock_get_slaves.return_value = self.slave_infos

        manager = NodeManager()
        manager.add_agent_ids([self.node_agent_1, self.node_agent_2])
        manager.sync_with_database('master_host', 5050)

        self.assertEqual(len(manager.get_nodes()), 2)<commit_msg>Added ability for NodeManager to track online status of nodes<commit_after>from __future__ import unicode_literals

import django
from django.test import TestCase
from mock import patch

from mesos_api.api import SlaveInfo
from node.test import utils as node_test_utils
from scheduler.sync.node_manager import NodeManager


class TestNodeManager(TestCase):

    def setUp(self):
        django.setup()

        self.node_agent_1 = 'agent_1'
        self.node_agent_2 = 'agent_2'
        self.node_1 = node_test_utils.create_node(hostname='host_1', slave_id=self.node_agent_1)

        self.slave_infos = [SlaveInfo(self.node_agent_1, 'host_1'), SlaveInfo(self.node_agent_2, 'host_2')]

    @patch('scheduler.sync.node_manager.api.get_slaves')
    def test_successful_update(self, mock_get_slaves):
        """Tests doing a successful database update"""

        mock_get_slaves.return_value = self.slave_infos

        manager = NodeManager()
        manager.add_agent_ids([self.node_agent_1, self.node_agent_2])
        manager.lost_node(self.node_agent_2)
        manager.sync_with_database('master_host', 5050)

        nodes = manager.get_nodes()
        self.assertEqual(len(nodes), 2)
        for node in nodes:
            if node.slave_id == self.node_agent_1:
                self.assertTrue(node.is_online)
            else:
                self.assertFalse(node.is_online)
{'fraction_non_alphanumeric': 0.09031733116354759, 'fraction_numerical': 0.015459723352318959, 'mean_word_length': 3.666034155597723, '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': '4034393', 'n_tokens_mistral': 797, 'n_tokens_neox': 773, 'n_words': 151}