Ejemplo n.º 1
0
class TestComponentManager(unittest.TestCase):
    def setUp(self):
        mocks.mock_conf_settings(self)

        self.default_components_sort = [
            [
                Components.HeadersComponent, Components.DatabaseComponent,
                Components.ExchangeRateManagerComponent,
                Components.PaymentRateComponent,
                Components.RateLimiterComponent, Components.UPnPComponent
            ],
            [
                Components.BlobComponent, Components.DHTComponent,
                Components.WalletComponent
            ],
            [
                Components.FileManagerComponent,
                Components.HashAnnouncerComponent,
                Components.PeerProtocolServerComponent
            ], [Components.ReflectorComponent]
        ]
        self.component_manager = ComponentManager()

    def tearDown(self):
        pass

    def test_sort_components(self):
        stages = self.component_manager.sort_components()
        for stage_list, sorted_stage_list in zip(stages,
                                                 self.default_components_sort):
            self.assertEqual([type(stage) for stage in stage_list],
                             sorted_stage_list)

    def test_sort_components_reverse(self):
        rev_stages = self.component_manager.sort_components(reverse=True)
        reverse_default_components_sort = reversed(
            self.default_components_sort)

        for stage_list, sorted_stage_list in zip(
                rev_stages, reverse_default_components_sort):
            self.assertEqual([type(stage) for stage in stage_list],
                             sorted_stage_list)

    def test_get_component_not_exists(self):

        with self.assertRaises(NameError):
            self.component_manager.get_component("random_component")
Ejemplo n.º 2
0
class TestComponentManager(AsyncioTestCase):
    def setUp(self):
        self.default_components_sort = [
            [
                Components.HeadersComponent, Components.DatabaseComponent,
                Components.ExchangeRateManagerComponent,
                Components.UPnPComponent
            ],
            [
                Components.BlobComponent, Components.DHTComponent,
                Components.WalletComponent
            ],
            [
                Components.HashAnnouncerComponent,
                Components.PeerProtocolServerComponent,
                Components.StreamManagerComponent,
            ]
        ]
        self.component_manager = ComponentManager(Config())

    def test_sort_components(self):
        stages = self.component_manager.sort_components()
        for stage_list, sorted_stage_list in zip(stages,
                                                 self.default_components_sort):
            self.assertEqual([type(stage) for stage in stage_list],
                             sorted_stage_list)

    def test_sort_components_reverse(self):
        rev_stages = self.component_manager.sort_components(reverse=True)
        reverse_default_components_sort = reversed(
            self.default_components_sort)
        for stage_list, sorted_stage_list in zip(
                rev_stages, reverse_default_components_sort):
            self.assertEqual([type(stage) for stage in stage_list],
                             sorted_stage_list)

    def test_get_component_not_exists(self):
        with self.assertRaises(NameError):
            self.component_manager.get_component("random_component")