Exemplo n.º 1
0
    def test_translation_var(self, mock_logging_error: mock.MagicMock) -> None:
        """Check for unused template variables."""

        self._db.translations.insert_one({
            'string': 'original template',
            'en': 'translated template with %known variable',
        })
        maintenance.check_template_variables(self._db)
        self.assertFalse(mock_logging_error.called, msg=mock_logging_error.call_args)
Exemplo n.º 2
0
    def test_unused_var(self, mock_logging_error: mock.MagicMock) -> None:
        """Check for unused template variables."""

        self._db.has_template.insert_one({
            '_id': 'using-no-variable',
            'textTemplate': 'This either',
        })
        maintenance.check_template_variables(self._db)
        mock_logging_error.assert_called_once()
        self.assertIn(
            '%known', mock_logging_error.call_args[0][0] % mock_logging_error.call_args[0][1:])
Exemplo n.º 3
0
    def test_airtable_dedup(self) -> None:
        """Template with the same variable twice should only be recorded once."""

        self._db.has_template.insert_one({
            '_id': 'using-known-variable',
            'textTemplate': 'Using a %known variable: %known',
        })
        maintenance.check_template_variables(self._db)

        records = self._get_airtable_records()

        self.assertEqual(1, len(records), msg=records)
Exemplo n.º 4
0
    def test_missing_var(self, mock_logging_error: mock.MagicMock) -> None:
        """Check for non-implemented template variables."""

        self._db.has_template.insert_one({
            '_id': 'using-missing',
            'textTemplate': 'This is a %missingVariable and a %known variable',
        })
        maintenance.check_template_variables(self._db)
        mock_logging_error.assert_called_once()
        error_message = mock_logging_error.call_args[0][0] % mock_logging_error.call_args[0][1:]
        self.assertIn('%missingVariable', error_message)
        self.assertIn('using-missing', error_message)
Exemplo n.º 5
0
    def test_translation_var_missing(self, mock_logging_error: mock.MagicMock) -> None:
        """Check for unused template variables."""

        self._db.translations.insert_one({
            'string': 'original template with %known variable',
            'en': 'translated template with %unknown variable',
        })
        self._db.has_template.insert_one({
            '_id': 'using-variable',
            'textTemplate': 'original template with %known variable',
        })
        maintenance.check_template_variables(self._db)
        mock_logging_error.assert_called_once()
        self.assertIn(
            '%unknown', mock_logging_error.call_args[0][0] % mock_logging_error.call_args[0][1:])
Exemplo n.º 6
0
    def test_airtable_create(self) -> None:
        """Check that records are created for each found variable."""

        self._db.has_template.insert_one({
            '_id': 'using-known-variable',
            'textTemplate': 'Using a %known variable',
        })
        maintenance.check_template_variables(self._db)

        records = self._get_airtable_records()

        self.assertEqual(1, len(records), msg=records)
        record = typing.cast(dict[str, str], records[0]['fields'])
        self.assertEqual('%known', record.get('variable'))
        self.assertEqual('Using a %known variable', record.get('template'))
        self.assertEqual('has_template:using-known-variable:textTemplate', record.get('origin'))
Exemplo n.º 7
0
    def test_airtable_update(self) -> None:
        """Airtable records are updated if the origin and variable are the same."""

        self._db.has_template.insert_one({
            '_id': 'using-known-variable',
            'textTemplate': 'Using a %known variable',
        })
        maintenance.check_template_variables(self._db)

        self._db.has_template.replace_one({'_id': 'using-known-variable'}, {
            'textTemplate': 'Using a %known variable with another template',
        })
        maintenance.check_template_variables(self._db)

        records = self._get_airtable_records()

        self.assertEqual(1, len(records), msg=records)
        record = typing.cast(dict[str, str], records[0]['fields'])
        self.assertEqual('%known', record.get('variable'))
        self.assertEqual('Using a %known variable with another template', record.get('template'))
        self.assertEqual('has_template:using-known-variable:textTemplate', record.get('origin'))
Exemplo n.º 8
0
    def test_missing_airtable_key(self, mock_warning: mock.MagicMock) -> None:
        """Check that user is warned of a missing airtable API key."""

        maintenance.check_template_variables(self._db)
        mock_warning.assert_called_once()
        self.assertIn('AIRTABLE_API_KEY', mock_warning.call_args[0][0])