def test_refresh(self):
        "User refreshes the current, non-default template"
        w = self.window
        with temp_directory_with_files(TESTDATA / 'test.inselect_template') as tempdir,\
                patch.object(QSettings, 'setValue') as mock_setvalue:
            path = tempdir / 'test.inselect_template'
            retval = str(path), w.view_metadata.popup_button.FILE_FILTER
            # Load the test template in tempdir
            with patch.object(QFileDialog, 'getOpenFileName', return_value=retval) as mock_gofn:
                w.view_metadata.popup_button.choose()
                self.assertEqual(1, mock_gofn.call_count)

            self.assertEqual('Test user template',
                             user_template_choice().current.name)
            self.assertEqual('Test user template',
                             self.window.view_metadata.popup_button.text())

            # Write a new template to the file and refresh
            template = """Name: An updated test template
Fields:
    - Name: catalogNumber
"""
            with path.open('w') as outfile:
                outfile.write(template)

            # Refresh loaded template
            with patch.object(QSettings, 'value', return_value=str(path)) as mock_value:
                w.view_metadata.popup_button.refresh()
                self.assertEqual(1, mock_value.call_count)

            self.assertEqual("An updated test template",
                             user_template_choice().current.name)
            self.assertEqual('An updated test template',
                             self.window.view_metadata.popup_button.text())
Example #2
0
    def test_select_default(self, mock_setvalue):
        "User chooses the default template"

        # Set a non-default template before testing the default user template
        # method
        t = user_template_choice()
        t.load(TESTDATA / 'test.inselect_template')
        self.assertEqual('Test user template', t.current.name)

        self.window.view_metadata.popup_button.default()

        self.assertEqual('Simple Darwin Core terms',
                         user_template_choice().current.name)
        self.assertEqual('Simple Darwin Core terms',
                         self.window.view_metadata.popup_button.text())
        mock_setvalue.assert_called_with(user_template_choice().PATH_KEY, '')
    def test_select_default(self, mock_setvalue):
        "User chooses the default template"

        # Set a non-default template before testing the default user template
        # method
        t = user_template_choice()
        t.load(TESTDATA / 'test.inselect_template')
        self.assertEqual('Test user template', t.current.name)

        self.window.view_metadata.popup_button.default()

        self.assertEqual('Simple Darwin Core terms',
                        user_template_choice().current.name)
        self.assertEqual('Simple Darwin Core terms',
                         self.window.view_metadata.popup_button.text())
        mock_setvalue.assert_called_with(user_template_choice().PATH_KEY, '')
    def test_chooses_template(self, mock_setvalue):
        "User chooses a template"

        w = self.window

        # Select default template before testing the choose method
        w.view_metadata.popup_button.default()

        path = TESTDATA / 'test.inselect_template'
        retval = str(path), w.view_metadata.popup_button.FILE_FILTER
        with patch.object(QFileDialog, 'getOpenFileName', return_value=retval) as mock_gofn:
            w.view_metadata.popup_button.choose()
            self.assertEqual(1, mock_gofn.call_count)

        self.assertEqual('Test user template',
                         user_template_choice().current.name)
        self.assertEqual('Test user template',
                         self.window.view_metadata.popup_button.text())
        mock_setvalue.assert_any_call(user_template_choice().PATH_KEY, str(path))
        mock_setvalue.assert_any_call(user_template_choice().DIRECTORY_KEY, str(path.parent))
Example #5
0
    def test_chooses_template(self, mock_setvalue):
        "User chooses a template"

        w = self.window

        # Select default template before testing the choose method
        w.view_metadata.popup_button.default()

        path = TESTDATA / 'test.inselect_template'
        retval = str(path), w.view_metadata.popup_button.FILE_FILTER
        with patch.object(QFileDialog, 'getOpenFileName',
                          return_value=retval) as mock_gofn:
            w.view_metadata.popup_button.choose()
            self.assertEqual(1, mock_gofn.call_count)

        self.assertEqual('Test user template',
                         user_template_choice().current.name)
        self.assertEqual('Test user template',
                         self.window.view_metadata.popup_button.text())
        mock_setvalue.assert_any_call(user_template_choice().PATH_KEY,
                                      str(path))
        mock_setvalue.assert_any_call(user_template_choice().DIRECTORY_KEY,
                                      str(path.parent))
    def __init__(self, parent=None):
        # This view is never made visible
        super(MetadataView, self).__init__(parent)

        user_template_choice().template_changed.connect(self.refresh_user_template)

        self.popup_button = UserTemplatePopupButton()

        # A container for the controls
        self._form_container = FormContainer()
        self._create_controls()

        # Popup button above controls
        layout = QVBoxLayout()
        layout.addWidget(self.popup_button)
        layout.addWidget(self._form_container)

        # Container for the popup and form
        container = QWidget()
        container.setLayout(layout)

        # Widget containing toggle label and container
        self.widget = PopupPanel('Metadata', container)
Example #7
0
    def test_refresh(self):
        "User refreshes the current, non-default template"
        w = self.window
        with temp_directory_with_files(TESTDATA / 'test.inselect_template') as tempdir,\
                patch.object(QSettings, 'setValue') as mock_setvalue:
            path = tempdir / 'test.inselect_template'
            retval = str(path), w.view_metadata.popup_button.FILE_FILTER
            # Load the test template in tempdir
            with patch.object(QFileDialog,
                              'getOpenFileName',
                              return_value=retval) as mock_gofn:
                w.view_metadata.popup_button.choose()
                self.assertEqual(1, mock_gofn.call_count)

            self.assertEqual('Test user template',
                             user_template_choice().current.name)
            self.assertEqual('Test user template',
                             self.window.view_metadata.popup_button.text())

            # Write a new template to the file and refresh
            template = """Name: An updated test template
Fields:
    - Name: catalogNumber
"""
            with path.open('w') as outfile:
                outfile.write(template)

            # Refresh loaded template
            with patch.object(QSettings, 'value',
                              return_value=str(path)) as mock_value:
                w.view_metadata.popup_button.refresh()
                self.assertEqual(1, mock_value.call_count)

            self.assertEqual("An updated test template",
                             user_template_choice().current.name)
            self.assertEqual('An updated test template',
                             self.window.view_metadata.popup_button.text())
Example #8
0
    def __init__(self, parent=None):
        # This view is never made visible
        super(MetadataView, self).__init__(parent)

        user_template_choice().template_changed.connect(
            self.refresh_user_template)

        self.popup_button = UserTemplatePopupButton()

        # A container for the controls
        self._form_container = FormContainer()
        self._create_controls()

        # Popup button above controls
        layout = QVBoxLayout()
        layout.addWidget(self.popup_button)
        layout.addWidget(self._form_container)

        # Container for the popup and form
        container = QWidget()
        container.setLayout(layout)

        # Widget containing toggle label and container
        self.widget = PopupPanel('Metadata', container)
Example #9
0
    def test_cancels_choose_template(self, mock_gofn):
        "User cancels the 'choose template' box"

        w = self.window

        # Select default template before testing the choose method
        w.view_metadata.popup_button.default()

        w.view_metadata.popup_button.choose()

        self.assertEqual('Simple Darwin Core terms',
                         user_template_choice().current.name)
        self.assertEqual('Simple Darwin Core terms',
                         self.window.view_metadata.popup_button.text())
        self.assertEqual(1, mock_gofn.call_count)
    def test_cancels_choose_template(self, mock_gofn):
        "User cancels the 'choose template' box"

        w = self.window

        # Select default template before testing the choose method
        w.view_metadata.popup_button.default()

        w.view_metadata.popup_button.choose()

        self.assertEqual('Simple Darwin Core terms',
                         user_template_choice().current.name)
        self.assertEqual('Simple Darwin Core terms',
                         self.window.view_metadata.popup_button.text())
        self.assertEqual(1, mock_gofn.call_count)
Example #11
0
 def _create_controls(self):
     "Creates controls for editing fields in the selected template"
     self._form_container.controls_from_template(
         user_template_choice().current)
Example #12
0
 def _create_controls(self):
     "Creates controls for editing fields in the selected template"
     self._form_container.controls_from_template(user_template_choice().current)
Example #13
0
 def setUp(self):
     super(TestMetadataViewControls, self).setUp()
     t = user_template_choice()
     t.load(TESTDATA / 'test.inselect_template')