def test_tethys_apps_context_feedback(self, mock_get_active_app):
        mock_args = mock.MagicMock()
        app = TethysApp()
        app.id = 'foo.id'
        app.name = models.CharField(max_length=200, default='')
        app.name.value = 'foo.name'
        app.icon = models.CharField(max_length=200, default='')
        app.icon.value = 'foo.icon'
        app.color = models.CharField(max_length=10, default='')
        app.color.value = '#foobar'
        app.tags = models.CharField(max_length=200, blank=True, default='')
        app.tags.value = 'tags'
        app.description = models.TextField(max_length=1000, blank=True, default='')
        app.description.value = 'foo.description'
        app.enable_feedback = models.BooleanField(default=True)
        app.enable_feedback.value = True
        app.feedback_emails = ListField(default='', blank=True)
        app.feedback_emails.append('foo.feedback')
        mock_get_active_app.return_value = app

        context = tethys_apps_context(mock_args)

        mock_get_active_app.assert_called_once()
        self.assertEqual('foo.id', context['tethys_app']['id'])
        self.assertEqual('foo.name', context['tethys_app']['name'].value)
        self.assertEqual('foo.icon', context['tethys_app']['icon'].value)
        self.assertEqual('#foobar', context['tethys_app']['color'].value)
        self.assertEqual('tags', context['tethys_app']['tags'].value)
        self.assertEqual('foo.description', context['tethys_app']['description'].value)
        self.assertTrue('enable_feedback' in context['tethys_app'])
        self.assertTrue('feedback_emails' in context['tethys_app'])
        self.assertEqual(True, context['tethys_app']['enable_feedback'].value)
        self.assertEqual(['foo.feedback'], context['tethys_app']['feedback_emails'])
    def test_tethys_apps_context(self, mock_get_active_app):
        mock_args = mock.MagicMock()
        app = TethysApp()
        app.id = 'foo.id'
        app.name = 'foo.name'
        app.icon = 'foo.icon'
        app.color = '#foobar'
        app.tags = 'tags'
        app.description = 'foo.description'
        app.enable_feedback = models.BooleanField(default=True)
        app.enable_feedback.value = False

        mock_get_active_app.return_value = app

        context = tethys_apps_context(mock_args)

        mock_get_active_app.assert_called_once()
        self.assertEqual('foo.id', context['tethys_app']['id'])
        self.assertEqual('foo.name', context['tethys_app']['name'])
        self.assertEqual('foo.icon', context['tethys_app']['icon'])
        self.assertEqual('#foobar', context['tethys_app']['color'])
        self.assertEqual('tags', context['tethys_app']['tags'])
        self.assertEqual('foo.description', context['tethys_app']['description'])
        self.assertFalse('enable_feedback' in context['tethys_app'])
        self.assertFalse('feedback_emails' in context['tethys_app'])
    def test_tethys_apps_context_feedback(self, mock_get_active_app):
        mock_args = mock.MagicMock()
        app = TethysApp()
        app.id = 'foo.id'
        app.name = 'foo.name'
        app.icon = 'foo.icon'
        app.color = '#foobar'
        app.tags = 'tags'
        app.description = 'foo.description'
        app.enable_feedback = True
        app.feedback_emails.append('foo.feedback')

        mock_get_active_app.return_value = app

        context = tethys_apps_context(mock_args)

        mock_get_active_app.assert_called_once()
        self.assertEqual('foo.id', context['tethys_app']['id'])
        self.assertEqual('foo.name', context['tethys_app']['name'])
        self.assertEqual('foo.icon', context['tethys_app']['icon'])
        self.assertEqual('#foobar', context['tethys_app']['color'])
        self.assertEqual('tags', context['tethys_app']['tags'])
        self.assertEqual('foo.description', context['tethys_app']['description'])
        self.assertTrue('enable_feedback' in context['tethys_app'])
        self.assertTrue('feedback_emails' in context['tethys_app'])
        self.assertEqual(True, context['tethys_app']['enable_feedback'])
        self.assertEqual(['foo.feedback'], context['tethys_app']['feedback_emails'])
Beispiel #4
0
    def sync_with_tethys_db(self):
        """
        Sync installed apps with database.
        """
        from django.conf import settings
        from tethys_apps.models import TethysApp

        try:
            # Make pass to add apps to db that are newly installed
            # Query to see if installed app is in the database
            db_apps = TethysApp.objects.\
                filter(package__exact=self.package).all()

            # If the app is not in the database, then add it
            if len(db_apps) == 0:
                db_app = TethysApp(
                    name=self.name,
                    package=self.package,
                    description=self.description,
                    enable_feedback=self.enable_feedback,
                    feedback_emails=self.feedback_emails,
                    index=self.index,
                    icon=self.icon,
                    root_url=self.root_url,
                    color=self.color,
                    tags=self.tags
                )
                db_app.save()

                # custom settings
                db_app.add_settings(self.custom_settings())
                # dataset services settings
                db_app.add_settings(self.dataset_service_settings())
                # spatial dataset services settings
                db_app.add_settings(self.spatial_dataset_service_settings())
                # wps settings
                db_app.add_settings(self.web_processing_service_settings())
                # persistent store settings
                db_app.add_settings(self.persistent_store_settings())

                db_app.save()

            # If the app is in the database, update developer-first attributes
            elif len(db_apps) == 1:
                db_app = db_apps[0]
                db_app.index = self.index
                db_app.icon = self.icon
                db_app.root_url = self.root_url
                db_app.color = self.color
                db_app.save()

                if hasattr(settings, 'DEBUG') and settings.DEBUG:
                    db_app.name = self.name
                    db_app.description = self.description
                    db_app.tags = self.tags
                    db_app.enable_feedback = self.enable_feedback
                    db_app.feedback_emails = self.feedback_emails
                    db_app.save()

                    # custom settings
                    db_app.add_settings(self.custom_settings())
                    # dataset services settings
                    db_app.add_settings(self.dataset_service_settings())
                    # spatial dataset services settings
                    db_app.add_settings(self.spatial_dataset_service_settings())
                    # wps settings
                    db_app.add_settings(self.web_processing_service_settings())
                    # persistent store settings
                    db_app.add_settings(self.persistent_store_settings())
                    db_app.save()

            # More than one instance of the app in db... (what to do here?)
            elif len(db_apps) >= 2:
                pass
        except Exception as e:
            tethys_log.error(e)