def test_retrieve_repository_info_correct(self, mock_requests):
        """
        Tests that the function returns correct data when it is all found in
        the Release file.
        """
        architectures = (
            'amd64 armel armhf i386 ia64 kfreebsd-amd64 '
            'kfreebsd-i386 mips mipsel powerpc s390 s390x sparc'.split()
        )
        components = ['main', 'contrib', 'non-free']
        mock_response_text = (
            'Suite: stable\n'
            'Codename: wheezy\n'
            'Architectures: ' + ' '.join(architectures) + '\n'
            'Components: ' + ' '.join(components) + '\n'
            'Version: 7.1\n'
            'Description: Debian 7.1 Released 15 June 2013\n'
        )
        set_mock_response(mock_requests, mock_response_text)

        repository_info = retrieve_repository_info(
            'deb http://repository.com/ stable')

        expected_info = {
            'uri': 'http://repository.com/',
            'architectures': architectures,
            'components': components,
            'binary': True,
            'source': False,
            'codename': 'wheezy',
            'suite': 'stable',
        }

        self.assertDictEqual(expected_info, repository_info)
    def test_retrieve_repository_info_missing_required(self, mock_requests):
        """
        Tests that the function raises an exception when some required keys are
        missing from the Release file.
        """
        mock_response_text = (
            'Suite: stable\n'
            'Codename: wheezy\n'
            'Architectures: amd64\n'
            'Version: 7.1\n'
            'Description: Debian 7.1 Released 15 June 2013\n'
        )
        set_mock_response(mock_requests, mock_response_text)

        from pts.core.retrieve_data import InvalidRepositoryException
        with self.assertRaises(InvalidRepositoryException):
            retrieve_repository_info('deb http://repository.com/ stable')
 def test_sources_list_entry_validation(self, mock_requests):
     from pts.core.admin import validate_sources_list_entry
     from django.core.exceptions import ValidationError
     # Not enough parts in the entry is an exception
     with self.assertRaises(ValidationError):
         validate_sources_list_entry('texthere')
     # Enough parts, but it does not start with deb|deb-src
     with self.assertRaises(ValidationError):
         validate_sources_list_entry('part1 part2 part3 part4')
     # Starts with deb, but no URL given.
     with self.assertRaises(ValidationError):
         validate_sources_list_entry('deb thisisnotaurl part3 part4')
     ## Make sure requests returns 404
     set_mock_response(mock_requests, status_code=404)
     # There is no Release file at the given URL
     with self.assertRaises(ValidationError):
         validate_sources_list_entry('deb http://does-not-matter.com/ part3 part4')
    def test_retrieve_repository_info_missing_non_required(self, mock_requests):
        """
        Tests the function when some non-required keys are missing from the
        Release file.
        """
        mock_response_text = (
            'Architectures: amd64\n'
            'components: main'
            'Version: 7.1\n'
            'Description: Debian 7.1 Released 15 June 2013\n'
        )
        set_mock_response(mock_requests, mock_response_text)

        repository_info = retrieve_repository_info(
            'deb http://repository.com/ stable')
        # It uses the suite name from the sources.list
        self.assertEqual(repository_info['suite'], 'stable')
        # Codename is not found
        self.assertIsNone(repository_info['codename'])
Ejemplo n.º 5
0
 def set_mock_response(self, mock_requests, headers=None, status_code=200):
     set_mock_response(
         mock_requests,
         text=self.response_content.decode('utf-8'),
         headers=headers,
         status_code=status_code)