Exemplo n.º 1
0
    def test_is_supported(self):
        em = EnvironmentsManager()
        em.environments = {}
        em.support_statuses = {}

        tk = TaskHeaderKeeper(environments_manager=EnvironmentsManager(),
                              node=p2p.Node(),
                              min_price=10.0)

        header = get_task_header()
        header.fixed_header.environment = None
        header.fixed_header.max_price = None
        header.fixed_header.min_version = None
        self.assertFalse(tk.check_support(header))

        header.fixed_header.environment = Environment.get_id()
        header.fixed_header.max_price = 0
        supported = tk.check_support(header)
        self.assertFalse(supported)
        self.assertIn(UnsupportReason.ENVIRONMENT_MISSING, supported.desc)

        e = Environment()
        e.accept_tasks = True
        tk.environments_manager.add_environment(e)
        supported = tk.check_support(header)
        self.assertFalse(supported)
        self.assertIn(UnsupportReason.MAX_PRICE, supported.desc)

        header.fixed_header.max_price = 10.0
        supported = tk.check_support(header)
        self.assertFalse(supported)
        self.assertIn(UnsupportReason.APP_VERSION, supported.desc)

        header.fixed_header.min_version = golem.__version__
        self.assertTrue(tk.check_support(header))

        header.fixed_header.max_price = 10.0
        self.assertTrue(tk.check_support(header))

        config_desc = mock.Mock()
        config_desc.min_price = 13.0
        tk.change_config(config_desc)
        self.assertFalse(tk.check_support(header))

        config_desc.min_price = 10.0
        tk.change_config(config_desc)
        self.assertTrue(tk.check_support(header))

        header.fixed_header.min_version = "120"
        self.assertFalse(tk.check_support(header))

        header.fixed_header.min_version = tk.app_version
        self.assertTrue(tk.check_support(header))

        header.fixed_header.min_version = "abc"
        with self.assertLogs(logger=logger, level='WARNING'):
            self.assertFalse(tk.check_support(header))
Exemplo n.º 2
0
    def test_get_task(self):
        em = EnvironmentsManager()
        em.environments = {}
        em.support_statuses = {}

        tk = TaskHeaderKeeper(environments_manager=em,
                              node=p2p.Node(),
                              min_price=10)

        self.assertIsNone(tk.get_task())
        task_header = get_task_header("uvw")
        self.assertTrue(tk.add_task_header(task_header))
        self.assertIsNone(tk.get_task())
        e = Environment()
        e.accept_tasks = True
        tk.environments_manager.add_environment(e)
        task_header2 = get_task_header("xyz")
        self.assertTrue(tk.add_task_header(task_header2))
        th = tk.get_task()
        assert isinstance(th.task_owner, Node)
        self.assertEqual(task_header2.to_dict(), th.to_dict())