Example #1
0
    def test_check_expired_when_not_expired(self):
        """Testing IntegrationManager.check_expired when not expired"""
        manager = IntegrationManager(IntegrationConfig)

        # Cache some state.
        integration = manager.register_integration_class(DummyIntegration1)
        integration.create_config(enabled=True, save=True)
        manager.get_integration_configs(DummyIntegration1)

        # Make sure the integration isn't enabled. This would be because we
        # haven't refreshed yet.
        self.assertFalse(integration.enabled)
        self.assertNotEqual(manager._integration_configs, {})

        # Fake having the latest state.
        manager._needs_recalc = False

        # Check expired state, without actually expiring it.
        self.assertFalse(manager.is_expired())
        manager.check_expired()

        # Make sure state has not changed.
        self.assertFalse(manager.is_expired())
        self.assertFalse(integration.enabled)
        self.assertNotEqual(manager._integration_configs, {})
Example #2
0
    def test_check_expired_when_expired(self):
        """Testing IntegrationManager.check_expired when expired"""
        manager = IntegrationManager(IntegrationConfig)

        # Cache some state.
        integration1 = manager.register_integration_class(DummyIntegration1)
        integration1.create_config(enabled=True, save=True)
        manager.get_integration_configs(DummyIntegration1)

        integration2 = manager.register_integration_class(DummyIntegration2)
        manager.get_integration_configs(DummyIntegration1)

        # Make sure the integration isn't enabled. This would be because we
        # haven't refreshed yet.
        self.assertFalse(integration1.enabled)
        self.assertFalse(integration2.enabled)
        self.assertNotEqual(manager._integration_configs, {})

        # Check expired state.
        self.assertTrue(manager.is_expired())
        manager.check_expired()

        # Make sure state has been updated and caches cleared.
        self.assertTrue(integration1.enabled)
        self.assertFalse(integration2.enabled)
        self.assertEqual(manager._integration_configs, {})
Example #3
0
    def test_is_expired_after_config_deleted(self):
        """Testing IntegrationManager.is_expired after config deleted"""
        manager = IntegrationManager(IntegrationConfig)

        self.assertFalse(manager.is_expired())
        post_delete.send(sender=IntegrationConfig)
        self.assertTrue(manager.is_expired())
Example #4
0
    def test_is_expired_after_config_deleted(self):
        """Testing IntegrationManager.is_expired after config deleted"""
        manager = IntegrationManager(IntegrationConfig)

        self.assertFalse(manager.is_expired())
        post_delete.send(sender=IntegrationConfig)
        self.assertTrue(manager.is_expired())
Example #5
0
    def test_register_integration_class_with_construct_error(self):
        """Testing IntegrationManager.register_integration_class with
        construction error
        """
        manager = IntegrationManager(IntegrationConfig)

        with self.assertRaises(IntegrationRegistrationError):
            manager.register_integration_class(BrokenIntegration)
Example #6
0
    def test_unregister_integration_class_with_unregistered(self):
        """Testing IntegrationManager.unregister_integration_class with
        unregistered integration
        """
        manager = IntegrationManager(IntegrationConfig)

        with self.assertRaises(IntegrationNotRegisteredError):
            manager.unregister_integration_class(DummyIntegration1)
Example #7
0
    def test_unregister_integration_class_with_unregistered(self):
        """Testing IntegrationManager.unregister_integration_class with
        unregistered integration
        """
        manager = IntegrationManager(IntegrationConfig)

        with self.assertRaises(IntegrationNotRegisteredError):
            manager.unregister_integration_class(DummyIntegration1)
Example #8
0
    def test_get_integration_classes(self):
        """Testing IntegrationManager.get_integration_classes"""
        manager = IntegrationManager(IntegrationConfig)
        manager.register_integration_class(DummyIntegration1)
        manager.register_integration_class(DummyIntegration2)

        classes = manager.get_integration_classes()
        self.assertEqual(set(classes), {DummyIntegration1, DummyIntegration2})
Example #9
0
    def test_register_integration_class_with_construct_error(self):
        """Testing IntegrationManager.register_integration_class with
        construction error
        """
        manager = IntegrationManager(IntegrationConfig)

        with self.assertRaises(IntegrationRegistrationError):
            manager.register_integration_class(BrokenIntegration)
Example #10
0
    def setUp(self):
        super(IntegrationConfigTests, self).setUp()

        self.manager = IntegrationManager(IntegrationConfig)
        self.integration = \
            self.manager.register_integration_class(DummyIntegration1)
        self.config = self.integration.create_config()
        self.config.manager = self.manager
Example #11
0
    def test_shutdown_integration_managers(self):
        """Testing shutdown_integration_managers"""
        IntegrationManager(IntegrationConfig)
        IntegrationManager(IntegrationConfig)

        shutdown_integration_managers()

        self.assertEqual(get_integration_managers(), [])
Example #12
0
    def test_get_integration_classes(self):
        """Testing IntegrationManager.get_integration_classes"""
        manager = IntegrationManager(IntegrationConfig)
        manager.register_integration_class(DummyIntegration1)
        manager.register_integration_class(DummyIntegration2)

        classes = manager.get_integration_classes()
        self.assertEqual(set(classes), {DummyIntegration1, DummyIntegration2})
Example #13
0
    def test_register_integration_class_with_already_registered(self):
        """Testing IntegrationManager.register_integration_class with
        already registered class
        """
        manager = IntegrationManager(IntegrationConfig)
        manager.register_integration_class(DummyIntegration1)

        with self.assertRaises(IntegrationAlreadyRegisteredError):
            manager.register_integration_class(DummyIntegration1)
Example #14
0
    def test_unregister_integration_class(self):
        """Testing IntegrationManager.unregister_integration_class"""
        manager = IntegrationManager(IntegrationConfig)
        manager.register_integration_class(DummyIntegration1)
        manager.unregister_integration_class(DummyIntegration1)

        integration_id = DummyIntegration1.integration_id

        self.assertNotIn(integration_id, manager._integration_classes)
        self.assertNotIn(integration_id, manager._integration_instances)
Example #15
0
    def test_check_expired_when_not_expired(self):
        """Testing IntegrationManager.check_expired when not expired"""
        manager = IntegrationManager(IntegrationConfig)

        # Cache some state.
        integration = manager.register_integration_class(DummyIntegration1)
        integration.create_config(enabled=True, save=True)
        manager.get_integration_configs(DummyIntegration1)

        # Make sure the integration isn't enabled. This would be because we
        # haven't refreshed yet.
        self.assertFalse(integration.enabled)
        self.assertNotEqual(manager._integration_configs, {})

        # Fake having the latest state.
        manager._needs_recalc = False

        # Check expired state, without actually expiring it.
        self.assertFalse(manager.is_expired())
        manager.check_expired()

        # Make sure state has not changed.
        self.assertFalse(manager.is_expired())
        self.assertFalse(integration.enabled)
        self.assertNotEqual(manager._integration_configs, {})
Example #16
0
    def test_get_integration(self):
        """Testing IntegrationManager.get_integration"""
        manager = IntegrationManager(IntegrationConfig)
        manager.register_integration_class(DummyIntegration1)
        manager.register_integration_class(DummyIntegration2)

        integration = manager.get_integration(DummyIntegration1.integration_id)
        self.assertEqual(integration.__class__, DummyIntegration1)

        integration = manager.get_integration(DummyIntegration2.integration_id)
        self.assertEqual(integration.__class__, DummyIntegration2)
Example #17
0
    def test_is_expired_after_other_process_updates(self):
        """Testing IntegrationManager.is_expired after another process updates
        the configuration state
        """
        manager = IntegrationManager(IntegrationConfig)
        self.assertFalse(manager.is_expired())

        gen_sync = GenerationSynchronizer(manager._gen_sync.cache_key, normalize_cache_key=False)
        gen_sync.mark_updated()

        self.assertTrue(manager.is_expired())
Example #18
0
    def test_is_expired_after_other_process_updates(self):
        """Testing IntegrationManager.is_expired after another process updates
        the configuration state
        """
        manager = IntegrationManager(IntegrationConfig)
        self.assertFalse(manager.is_expired())

        gen_sync = GenerationSynchronizer(manager._gen_sync.cache_key,
                                          normalize_cache_key=False)
        gen_sync.mark_updated()

        self.assertTrue(manager.is_expired())
Example #19
0
    def test_shutdown_integration_managers(self):
        """Testing shutdown_integration_managers"""
        manager1 = IntegrationManager(IntegrationConfig)
        self.assertTrue(manager1.enabled)

        manager2 = IntegrationManager(IntegrationConfig)
        self.assertTrue(manager2.enabled)

        shutdown_integration_managers()

        self.assertEqual(get_integration_managers(), [])
        self.assertFalse(manager1.enabled)
        self.assertFalse(manager2.enabled)
Example #20
0
    def test_get_integration_configs_with_filter(self):
        """Testing IntegrationManager.get_integration_configs with filter"""
        manager = IntegrationManager(IntegrationConfig)
        integration1 = manager.register_integration_class(DummyIntegration1)
        integration2 = manager.register_integration_class(DummyIntegration2)

        config1 = integration1.create_config(enabled=False, save=True)
        integration1.create_config(enabled=True, save=True)
        integration2.create_config(enabled=True, save=True)

        with self.assertNumQueries(1):
            configs = manager.get_integration_configs(integration1, enabled=False)

        self.assertEqual(set(configs), {config1})
Example #21
0
    def test_clear_all_configs_cache(self):
        """Testing IntegrationManager.clear_all_configs_cache"""
        manager = IntegrationManager(IntegrationConfig)

        with self.assertNumQueries(1):
            manager.get_integration_configs(DummyIntegration1)

        with self.assertNumQueries(0):
            manager.get_integration_configs(DummyIntegration1)

        manager.clear_all_configs_cache()

        with self.assertNumQueries(1):
            manager.get_integration_configs(DummyIntegration1)
Example #22
0
    def test_register_integration_class(self):
        """Testing IntegrationManager.register_integration_class"""
        manager = IntegrationManager(IntegrationConfig)

        integration = manager.register_integration_class(DummyIntegration1)
        self.assertEqual(integration.__class__, DummyIntegration1)

        integration_id = DummyIntegration1.integration_id
        self.assertEqual(integration_id, "djblets.integrations.tests.test_manager.DummyIntegration1")

        self.assertIn(integration_id, manager._integration_classes)
        self.assertEqual(manager._integration_classes[integration_id], DummyIntegration1)
        self.assertIn(integration_id, manager._integration_instances)
        self.assertEqual(manager._integration_instances[integration_id], integration)
Example #23
0
    def test_unregister_integration_class_with_enabled_integration(self):
        """Testing IntegrationManager.unregister_integration_class with
        enabled integration
        """
        manager = IntegrationManager(IntegrationConfig)
        integration = manager.register_integration_class(DummyIntegration1)

        integration_id = DummyIntegration1.integration_id
        integration.enabled = True

        manager.unregister_integration_class(DummyIntegration1)

        self.assertFalse(integration.enabled)
        self.assertNotIn(integration_id, manager._integration_classes)
        self.assertNotIn(integration_id, manager._integration_instances)
Example #24
0
    def test_get_integration_configs_caches(self):
        """Testing IntegrationManager.get_integration_configs caches results"""
        manager = IntegrationManager(IntegrationConfig)
        integration1 = manager.register_integration_class(DummyIntegration1)

        config1 = integration1.create_config(enabled=True, save=True)
        config2 = integration1.create_config(enabled=False, save=True)

        with self.assertNumQueries(1):
            manager.get_integration_configs()

        with self.assertNumQueries(0):
            configs = manager.get_integration_configs()

        self.assertEqual(set(configs), {config1, config2})
Example #25
0
    def test_unregister_integration_class_with_enabled_integration(self):
        """Testing IntegrationManager.unregister_integration_class with
        enabled integration
        """
        manager = IntegrationManager(IntegrationConfig)
        integration = manager.register_integration_class(DummyIntegration1)

        integration_id = DummyIntegration1.integration_id
        integration.enabled = True

        manager.unregister_integration_class(DummyIntegration1)

        self.assertFalse(integration.enabled)
        self.assertNotIn(integration_id, manager._integration_classes)
        self.assertNotIn(integration_id, manager._integration_instances)
Example #26
0
    def test_get_integration_configs_with_filter(self):
        """Testing IntegrationManager.get_integration_configs with filter"""
        manager = IntegrationManager(IntegrationConfig)
        integration1 = manager.register_integration_class(DummyIntegration1)
        integration2 = manager.register_integration_class(DummyIntegration2)

        config1 = integration1.create_config(enabled=False, save=True)
        integration1.create_config(enabled=True, save=True)
        integration2.create_config(enabled=True, save=True)

        with self.assertNumQueries(1):
            configs = manager.get_integration_configs(integration1,
                                                      enabled=False)

        self.assertEqual(set(configs), {config1})
Example #27
0
class IntegrationConfigTests(IntegrationsTestCase):
    """Unit tests for djblets.integrations.models.BaseIntegrationConfig."""
    def setUp(self):
        super(IntegrationConfigTests, self).setUp()

        self.manager = IntegrationManager(IntegrationConfig)
        self.integration = \
            self.manager.register_integration_class(DummyIntegration1)
        self.config = self.integration.create_config()
        self.config.manager = self.manager

    def test_integration(self):
        """Testing BaseIntegrationConfig.integration"""
        self.assertEqual(self.config.integration, self.integration)

    def test_get(self):
        """Testing BaseIntegrationConfig.get"""
        self.config.settings['foo'] = 'bar'
        self.assertEqual(self.config.get('foo'), 'bar')

    def test_get_with_integration_defaults(self):
        """Testing BaseIntegrationConfig.get with integration defaults"""
        self.assertEqual(self.config.get('foo'), 'default-foo')

    def test_get_with_default(self):
        """Testing BaseIntegrationConfig.get with default"""
        self.assertEqual(self.config.get('new-key', 'my-default'),
                         'my-default')

    def test_set(self):
        """Testing BaseIntegrationConfig.set"""
        self.config.set('my-key', 'my-value')
        self.assertEqual(self.config.settings.get('my-key'), 'my-value')
Example #28
0
class IntegrationConfigTests(IntegrationsTestCase):
    """Unit tests for djblets.integrations.models.BaseIntegrationConfig."""

    def setUp(self):
        super(IntegrationConfigTests, self).setUp()

        self.manager = IntegrationManager(IntegrationConfig)
        self.integration = \
            self.manager.register_integration_class(DummyIntegration1)
        self.config = self.integration.create_config()
        self.config.manager = self.manager

    def test_integration(self):
        """Testing BaseIntegrationConfig.integration"""
        self.assertEqual(self.config.integration, self.integration)

    def test_get(self):
        """Testing BaseIntegrationConfig.get"""
        self.config.settings['foo'] = 'bar'
        self.assertEqual(self.config.get('foo'), 'bar')

    def test_get_with_integration_defaults(self):
        """Testing BaseIntegrationConfig.get with integration defaults"""
        self.assertEqual(self.config.get('foo'), 'default-foo')

    def test_get_with_default(self):
        """Testing BaseIntegrationConfig.get with default"""
        self.assertEqual(self.config.get('new-key', 'my-default'),
                         'my-default')

    def test_set(self):
        """Testing BaseIntegrationConfig.set"""
        self.config.set('my-key', 'my-value')
        self.assertEqual(self.config.settings.get('my-key'), 'my-value')
Example #29
0
    def test_get_integration_configs(self):
        """Testing IntegrationManager.get_integration_configs with all
        configurations
        """
        manager = IntegrationManager(IntegrationConfig)
        integration1 = manager.register_integration_class(DummyIntegration1)
        integration2 = manager.register_integration_class(DummyIntegration2)

        config1 = integration1.create_config(enabled=True, save=True)
        config2 = integration1.create_config(enabled=False, save=True)
        config3 = integration2.create_config(enabled=True, save=True)

        with self.assertNumQueries(1):
            configs = manager.get_integration_configs()

        self.assertEqual(set(configs), {config1, config2, config3})
Example #30
0
    def test_get_integration_configs(self):
        """Testing IntegrationManager.get_integration_configs with all
        configurations
        """
        manager = IntegrationManager(IntegrationConfig)
        integration1 = manager.register_integration_class(DummyIntegration1)
        integration2 = manager.register_integration_class(DummyIntegration2)

        config1 = integration1.create_config(enabled=True, save=True)
        config2 = integration1.create_config(enabled=False, save=True)
        config3 = integration2.create_config(enabled=True, save=True)

        with self.assertNumQueries(1):
            configs = manager.get_integration_configs()

        self.assertEqual(set(configs), {config1, config2, config3})
Example #31
0
    def setUp(self):
        super(IntegrationConfigTests, self).setUp()

        self.manager = IntegrationManager(IntegrationConfig)
        self.integration = \
            self.manager.register_integration_class(DummyIntegration1)
        self.config = self.integration.create_config()
        self.config.manager = self.manager
Example #32
0
    def test_clear_all_configs_cache(self):
        """Testing IntegrationManager.clear_all_configs_cache"""
        manager = IntegrationManager(IntegrationConfig)

        with self.assertNumQueries(1):
            manager.get_integration_configs(DummyIntegration1)

        with self.assertNumQueries(0):
            manager.get_integration_configs(DummyIntegration1)

        manager.clear_all_configs_cache()

        with self.assertNumQueries(1):
            manager.get_integration_configs(DummyIntegration1)
Example #33
0
    def test_register_integration_class(self):
        """Testing IntegrationManager.register_integration_class"""
        manager = IntegrationManager(IntegrationConfig)

        integration = manager.register_integration_class(DummyIntegration1)
        self.assertEqual(integration.__class__, DummyIntegration1)

        integration_id = DummyIntegration1.integration_id
        self.assertEqual(
            integration_id,
            'djblets.integrations.tests.test_manager.DummyIntegration1')

        self.assertIn(integration_id, manager._integration_classes)
        self.assertEqual(manager._integration_classes[integration_id],
                         DummyIntegration1)
        self.assertIn(integration_id, manager._integration_instances)
        self.assertEqual(manager._integration_instances[integration_id],
                         integration)
Example #34
0
    def setUp(self):
        super(IntegrationHookTests, self).setUp()

        self.manager = IntegrationManager(IntegrationConfig)

        # This will make this class a hook owner.
        self.hooks = set()

        self.hook = DummyIntegrationHook(self.manager, self, DummyIntegration)
Example #35
0
    def setUp(self):
        super(IntegrationConfigFormTests, self).setUp()

        self.manager = IntegrationManager(IntegrationConfig)
        self.integration = \
            self.manager.register_integration_class(DummyIntegration)
        request_factory = RequestFactory()
        self.request = request_factory.get('/getSomeForm/')

        self.form = IntegrationConfigForm(integration=self.integration,
                                          request=self.request,
                                          instance=None,
                                          data={
                                              'enabled': True,
                                              'name': 'FakeName',
                                          })
        self.form.full_clean()
        self.form.save()
Example #36
0
    def test_init_without_app(self):
        """Testing IntegrationManager initialization without INSTALLED_APPS"""
        msg = ('IntegrationManager requires djblets.integrations to be '
               'listed in settings.INSTALLED_APPS.')

        installed_apps = list(settings.INSTALLED_APPS)
        installed_apps.remove('djblets.integrations')

        with self.settings(INSTALLED_APPS=installed_apps):
            with self.assertRaisesMessage(ImproperlyConfigured, msg):
                IntegrationManager(IntegrationConfig)
Example #37
0
    def test_register_integration_class_with_already_registered(self):
        """Testing IntegrationManager.register_integration_class with
        already registered class
        """
        manager = IntegrationManager(IntegrationConfig)
        manager.register_integration_class(DummyIntegration1)

        with self.assertRaises(IntegrationAlreadyRegisteredError):
            manager.register_integration_class(DummyIntegration1)
Example #38
0
def get_integration_manager():
    """Return the integration manager for Review Board.

    Returns:
        djblets.integrations.manager.IntegrationManager:
        The integration manager used for Review Board.
    """
    global _integration_manager

    if not _integration_manager:
        from reviewboard.integrations.models import IntegrationConfig

        _integration_manager = IntegrationManager(IntegrationConfig)

    return _integration_manager
Example #39
0
    def test_init_without_middleware(self):
        """Testing IntegrationManager initialization without
        MIDDLEWARE_CLASSES
        """
        msg = ('IntegrationManager requires djblets.integrations.middleware.'
               'IntegrationsMiddleware to be listed in '
               'settings.MIDDLEWARE_CLASSES')

        middleware_classes = list(settings.MIDDLEWARE_CLASSES)
        middleware_classes.remove('djblets.integrations.middleware.'
                                  'IntegrationsMiddleware')

        with self.settings(MIDDLEWARE_CLASSES=middleware_classes):
            with self.assertRaisesMessage(ImproperlyConfigured, msg):
                IntegrationManager(IntegrationConfig)
Example #40
0
    def test_unregister_integration_class(self):
        """Testing IntegrationManager.unregister_integration_class"""
        manager = IntegrationManager(IntegrationConfig)
        manager.register_integration_class(DummyIntegration1)
        manager.unregister_integration_class(DummyIntegration1)

        integration_id = DummyIntegration1.integration_id

        self.assertNotIn(integration_id, manager._integration_classes)
        self.assertNotIn(integration_id, manager._integration_instances)
Example #41
0
    def test_get_integration(self):
        """Testing IntegrationManager.get_integration"""
        manager = IntegrationManager(IntegrationConfig)
        manager.register_integration_class(DummyIntegration1)
        manager.register_integration_class(DummyIntegration2)

        integration = manager.get_integration(DummyIntegration1.integration_id)
        self.assertEqual(integration.__class__, DummyIntegration1)

        integration = manager.get_integration(DummyIntegration2.integration_id)
        self.assertEqual(integration.__class__, DummyIntegration2)
Example #42
0
class IntegrationConfigTests(IntegrationsTestCase):
    """Unit tests for djblets.integrations.models.BaseIntegrationConfig."""
    def setUp(self):
        super(IntegrationConfigTests, self).setUp()

        self.manager = IntegrationManager(IntegrationConfig)
        self.integration = \
            self.manager.register_integration_class(DummyIntegration1)
        self.config = self.integration.create_config(name='Test Config')
        self.config.manager = self.manager

    def test_integration(self):
        """Testing BaseIntegrationConfig.integration"""
        self.assertEqual(self.config.integration, self.integration)

    def test_get(self):
        """Testing BaseIntegrationConfig.get"""
        self.config.settings['foo'] = 'bar'
        self.assertEqual(self.config.get('foo'), 'bar')

    def test_get_with_integration_defaults(self):
        """Testing BaseIntegrationConfig.get with integration defaults"""
        self.assertEqual(self.config.get('foo'), 'default-foo')

    def test_get_with_default(self):
        """Testing BaseIntegrationConfig.get with default"""
        self.assertEqual(self.config.get('new-key', 'my-default'),
                         'my-default')

    def test_set(self):
        """Testing BaseIntegrationConfig.set"""
        self.config.set('my-key', 'my-value')
        self.assertEqual(self.config.settings.get('my-key'), 'my-value')

    def test_str_with_available_integration(self):
        """Testing BaseIntegrationConfig.__str__ with available integration"""
        self.assertEqual(six.text_type(self.config), 'Test Config (Dummy)')

    def test_str_without_available_integration(self):
        """Testing BaseIntegrationConfig.__str__ without available integration
        """
        self.config.integration_id = 'foo.bar.BadIntegration'

        self.assertEqual(six.text_type(self.config),
                         'Test Config (foo.bar.BadIntegration)')
Example #43
0
class IntegrationConfigFormTests(IntegrationsTestCase):
    """Unit tests for djblets.integrations.forms.IntegrationConfigForm."""
    def setUp(self):
        super(IntegrationConfigFormTests, self).setUp()

        self.manager = IntegrationManager(IntegrationConfig)
        self.integration = \
            self.manager.register_integration_class(DummyIntegration)
        request_factory = RequestFactory()
        self.request = request_factory.get('/getSomeForm/')

        self.form = IntegrationConfigForm(integration=self.integration,
                                          request=self.request,
                                          instance=None,
                                          data={
                                              'enabled': True,
                                              'name': 'FakeName',
                                          })
        self.form.full_clean()
        self.form.save()

    def test_config(self):
        """Testing IntegrationConfigForm.config returns the config instance"""
        self.assertIsInstance(self.form.config, IntegrationConfig)

    def test_get_key_value_model_field(self):
        """Testing IntegrationConfigForm.get_key_value() returns values from
        form data"""
        self.assertEqual(self.form.get_key_value('name'), 'FakeName')
        self.assertTrue(self.form.get_key_value('enabled'))

    def test_set_key_value_model_field(self):
        """Testing IntegrationConfigForm.set_key_value() overrides form
        data"""
        name_field = 'name'
        expected_value = 'NewName'
        self.form.set_key_value(name_field, expected_value)
        self.assertEqual(self.form.get_key_value(name_field), expected_value)

    def test_set_key_value_non_model_field(self):
        """Testing IntegrationConfigForm.set_key_value() sets custom non-field
        data"""
        test_field = 'new_non_model_field'
        self.form.set_key_value(test_field, True)
        self.assertTrue(self.form.get_key_value(test_field))
Example #44
0
    def test_shutdown(self):
        """Testing IntegrationManager.shutdown"""
        manager = IntegrationManager(IntegrationConfig)
        instance = manager.register_integration_class(DummyIntegration1)
        instance.enable_integration()

        self.assertTrue(instance.enabled)
        self.assertNotEqual(manager._integration_classes, {})
        self.assertNotEqual(manager._integration_instances, {})
        self.assertTrue(manager.is_expired())

        manager.shutdown()

        self.assertFalse(instance.enabled)
        self.assertEqual(manager._integration_classes, {})
        self.assertEqual(manager._integration_instances, {})
        self.assertFalse(manager.is_expired())
Example #45
0
    def test_get_integration_configs_caches(self):
        """Testing IntegrationManager.get_integration_configs caches results"""
        manager = IntegrationManager(IntegrationConfig)
        integration1 = manager.register_integration_class(DummyIntegration1)

        config1 = integration1.create_config(enabled=True, save=True)
        config2 = integration1.create_config(enabled=False, save=True)

        with self.assertNumQueries(1):
            manager.get_integration_configs()

        with self.assertNumQueries(0):
            configs = manager.get_integration_configs()

        self.assertEqual(set(configs), {config1, config2})
Example #46
0
    def test_shutdown(self):
        """Testing IntegrationManager.shutdown"""
        manager = IntegrationManager(IntegrationConfig)
        instance = manager.register_integration_class(DummyIntegration1)
        instance.enable_integration()

        self.assertTrue(instance.enabled)
        self.assertNotEqual(manager._integration_classes, {})
        self.assertNotEqual(manager._integration_instances, {})
        self.assertTrue(manager.is_expired())

        manager.shutdown()

        self.assertFalse(instance.enabled)
        self.assertEqual(manager._integration_classes, {})
        self.assertEqual(manager._integration_instances, {})
        self.assertFalse(manager.is_expired())
Example #47
0
    def test_get_integration_with_invalid_id(self):
        """Testing IntegrationManager.get_integration with invalid ID"""
        manager = IntegrationManager(IntegrationConfig)

        with self.assertRaises(IntegrationNotRegisteredError):
            manager.get_integration("foobar")
Example #48
0
    def test_is_expired_new_instance(self):
        """Testing IntegrationManager.is_expired on a new instance"""
        manager = IntegrationManager(IntegrationConfig)

        self.assertFalse(manager.is_expired())
Example #49
0
    def test_is_expired_after_registration(self):
        """Testing IntegrationManager.is_expired after new registration"""
        manager = IntegrationManager(IntegrationConfig)
        manager.register_integration_class(DummyIntegration1)

        self.assertTrue(manager.is_expired())
Example #50
0
    def test_get_integration_managers(self):
        """Testing get_integration_managers"""
        manager1 = IntegrationManager(IntegrationConfig)
        manager2 = IntegrationManager(IntegrationConfig)

        self.assertEqual(set(get_integration_managers()), {manager1, manager2})
Example #51
0
class IntegrationTests(IntegrationsTestCase):
    """Unit tests for djblets.integrations.integration.Integration."""

    def setUp(self):
        super(IntegrationTests, self).setUp()

        self.manager = IntegrationManager(IntegrationConfig)
        self.integration = \
            self.manager.register_integration_class(DummyIntegration1)

    def test_init(self):
        """Testing Integration initialization"""
        self.assertEqual(self.integration.hooks, set())
        self.assertFalse(self.integration.enabled)
        self.assertFalse(hasattr(self.integration, 'dummy_initted'))

    def test_id(self):
        """Testing Integration.id"""
        self.assertEqual(self.integration.id, self.integration.integration_id)

    def test_enable_integration(self):
        """Testing Integration.enable_integration"""
        self.integration.enable_integration()

        self.assertTrue(self.integration.enabled)
        self.assertTrue(hasattr(self.integration, 'dummy_initted'))
        self.assertTrue(self.integration.dummy_initted)
        self.assertEqual(self.integration.hooks, {self.integration.hook})

    def test_disable_integration(self):
        """Testing Integration.disable_integration"""
        self.integration.enable_integration()
        self.integration.disable_integration()

        self.assertFalse(self.integration.enabled)
        self.assertTrue(hasattr(self.integration, 'dummy_initted'))
        self.assertFalse(self.integration.dummy_initted)
        self.assertEqual(self.integration.hooks, set())

    def test_get_configs(self):
        """Testing Integration.get_configs"""
        config1 = self.integration.create_config(name='Config 1',
                                                 enabled=True,
                                                 save=True)
        config2 = self.integration.create_config(name='Config 2',
                                                 enabled=True,
                                                 save=True)

        # Add some configs that shouldn't be returned.
        integration2 = \
            self.manager.register_integration_class(DummyIntegration2)
        self.integration.create_config(name='Config 3', save=True)
        integration2.create_config(name='Config 4', save=True)

        self.assertEqual(self.integration.get_configs(), [config1, config2])

    def test_get_configs_with_filter(self):
        """Testing Integration.get_configs with filter"""
        config1 = self.integration.create_config(name='Config 1',
                                                 enabled=True,
                                                 save=True)
        self.integration.create_config(name='Config 2',
                                       enabled=True,
                                       save=True)

        # Add some configs that shouldn't be returned.
        integration2 = \
            self.manager.register_integration_class(DummyIntegration2)
        self.integration.create_config(name='Config 3', save=True)
        integration2.create_config(name='Config 4', save=True)

        self.assertEqual(self.integration.get_configs(name='Config 1'),
                         [config1])

    def test_create_config(self):
        """Testing Integration.create_config"""
        config = self.integration.create_config(name='Config 1')
        self.assertFalse(config.enabled)
        self.assertIsNone(config.pk)

    def test_create_config_with_save(self):
        """Testing Integration.create_config with save=True"""
        config = self.integration.create_config(name='Config 1', save=True)
        self.assertFalse(config.enabled)
        self.assertIsNotNone(config.pk)
Example #52
0
    def setUp(self):
        super(IntegrationTests, self).setUp()

        self.manager = IntegrationManager(IntegrationConfig)
        self.integration = \
            self.manager.register_integration_class(DummyIntegration1)
Example #53
0
    def test_is_expired_after_registration(self):
        """Testing IntegrationManager.is_expired after new registration"""
        manager = IntegrationManager(IntegrationConfig)
        manager.register_integration_class(DummyIntegration1)

        self.assertTrue(manager.is_expired())
Example #54
0
    def test_check_expired_when_expired(self):
        """Testing IntegrationManager.check_expired when expired"""
        manager = IntegrationManager(IntegrationConfig)

        # Cache some state.
        integration1 = manager.register_integration_class(DummyIntegration1)
        integration1.create_config(enabled=True, save=True)
        manager.get_integration_configs(DummyIntegration1)

        integration2 = manager.register_integration_class(DummyIntegration2)
        manager.get_integration_configs(DummyIntegration1)

        # Make sure the integration isn't enabled. This would be because we
        # haven't refreshed yet.
        self.assertFalse(integration1.enabled)
        self.assertFalse(integration2.enabled)
        self.assertNotEqual(manager._integration_configs, {})

        # Check expired state.
        self.assertTrue(manager.is_expired())
        manager.check_expired()

        # Make sure state has been updated and caches cleared.
        self.assertFalse(manager.is_expired())
        self.assertTrue(integration1.enabled)
        self.assertFalse(integration2.enabled)
        self.assertEqual(manager._integration_configs, {})