def test_empty_slug(self):
     initial = {
         'name': "''",
         'repo_type': 'git',
         'repo': 'https://github.com/user/repository',
     }
     form = ProjectBasicsForm(initial)
     self.assertFalse(form.is_valid())
     self.assertIn('name', form.errors)
 def test_empty_slug(self):
     initial = {
         'name': "''",
         'repo_type': 'git',
         'repo': 'https://github.com/user/repository',
     }
     form = ProjectBasicsForm(initial)
     self.assertFalse(form.is_valid())
     self.assertIn('name', form.errors)
Ejemplo n.º 3
0
 def test_strip_repo_url(self):
     form = ProjectBasicsForm({
         'name': 'foo',
         'repo_type': 'git',
         'repo': 'https://github.com/rtfd/readthedocs.org/'
     })
     self.assertTrue(form.is_valid())
     self.assertEqual(
         form.cleaned_data['repo'],
         'https://github.com/rtfd/readthedocs.org'
     )
 def test_strip_repo_url(self):
     form = ProjectBasicsForm({
         'name': 'foo',
         'repo_type': 'git',
         'repo': 'https://github.com/rtfd/readthedocs.org/'
     })
     self.assertTrue(form.is_valid())
     self.assertEqual(
         form.cleaned_data['repo'],
         'https://github.com/rtfd/readthedocs.org'
     )
    def test_changing_vcs_should_change_latest(self):
        """When changing the project's VCS, latest should be changed too."""
        project = get(Project, repo_type=REPO_TYPE_HG, default_branch=None)
        latest = project.versions.get(slug=LATEST)
        self.assertEqual(latest.identifier, 'default')

        form = ProjectBasicsForm(
            {
                'repo': 'http://github.com/test/test',
                'name': 'name',
                'repo_type': REPO_TYPE_GIT,
            },
            instance=project,
        )
        self.assertTrue(form.is_valid())
        form.save()
        latest.refresh_from_db()
        self.assertEqual(latest.identifier, 'master')
    def test_changing_vcs_should_change_latest(self):
        """When changing the project's VCS, latest should be changed too."""
        project = get(Project, repo_type=REPO_TYPE_HG, default_branch=None)
        latest = project.versions.get(slug=LATEST)
        self.assertEqual(latest.identifier, 'default')

        form = ProjectBasicsForm(
            {
                'repo': 'http://github.com/test/test',
                'name': 'name',
                'repo_type': REPO_TYPE_GIT,
            },
            instance=project,
        )
        self.assertTrue(form.is_valid())
        form.save()
        latest.refresh_from_db()
        self.assertEqual(latest.identifier, 'master')
Ejemplo n.º 7
0
    def test_import_repo_url(self):
        """Validate different type of repository URLs on importing a Project."""

        common_urls = [
            # Invalid
            ('./path/to/relative/folder', False),
            ('../../path/to/relative/folder', False),
            ('../../path/to/@/folder', False),
            ('/path/to/local/folder', False),
            ('/path/to/@/folder', False),
            ('file:///path/to/local/folder', False),
            ('file:///path/to/@/folder', False),
            ('github.com/humitos/foo', False),
            ('https://github.com/|/foo', False),
            ('git://github.com/&&/foo', False),
            # Valid
            ('git://github.com/humitos/foo', True),
            ('http://github.com/humitos/foo', True),
            ('https://github.com/humitos/foo', True),
            ('http://gitlab.com/humitos/foo', True),
            ('http://bitbucket.com/humitos/foo', True),
            ('ftp://ftpserver.com/humitos/foo', True),
            ('ftps://ftpserver.com/humitos/foo', True),
            ('lp:zaraza', True),
        ]

        public_urls = [
            ('[email protected]:humitos/foo', False),
            ('ssh://[email protected]/humitos/foo', False),
            ('ssh+git://github.com/humitos/foo', False),
            ('[email protected]:strangeuser/readthedocs.git', False),
            ('[email protected]:22/_ssh/docs', False),
        ] + common_urls

        private_urls = [
            ('[email protected]:humitos/foo', True),
            ('ssh://[email protected]/humitos/foo', True),
            ('ssh+git://github.com/humitos/foo', True),
            ('[email protected]:strangeuser/readthedocs.git', True),
            ('[email protected]:22/_ssh/docs', True),
         ] + common_urls

        for url, valid in public_urls:
            initial = {
                'name': 'foo',
                'repo_type': 'git',
                'repo': url,
            }
            form = ProjectBasicsForm(initial)
            self.assertEqual(form.is_valid(), valid, msg=url)

        with override_settings(ALLOW_PRIVATE_REPOS=True):
            for url, valid in private_urls:
                initial = {
                    'name': 'foo',
                    'repo_type': 'git',
                    'repo': url,
                }
                form = ProjectBasicsForm(initial)
                self.assertEqual(form.is_valid(), valid, msg=url)
    def test_import_repo_url(self):
        """Validate different type of repository URLs on importing a Project."""

        common_urls = [
            # Invalid
            ('./path/to/relative/folder', False),
            ('../../path/to/relative/folder', False),
            ('../../path/to/@/folder', False),
            ('/path/to/local/folder', False),
            ('/path/to/@/folder', False),
            ('file:///path/to/local/folder', False),
            ('file:///path/to/@/folder', False),
            ('github.com/humitos/foo', False),
            ('https://github.com/|/foo', False),
            ('git://github.com/&&/foo', False),
            # Valid
            ('git://github.com/humitos/foo', True),
            ('http://github.com/humitos/foo', True),
            ('https://github.com/humitos/foo', True),
            ('http://gitlab.com/humitos/foo', True),
            ('http://bitbucket.com/humitos/foo', True),
            ('ftp://ftpserver.com/humitos/foo', True),
            ('ftps://ftpserver.com/humitos/foo', True),
            ('lp:zaraza', True),
        ]

        public_urls = [
            ('[email protected]:humitos/foo', False),
            ('ssh://[email protected]/humitos/foo', False),
            ('ssh+git://github.com/humitos/foo', False),
            ('[email protected]:strangeuser/readthedocs.git', False),
            ('[email protected]:22/_ssh/docs', False),
        ] + common_urls

        private_urls = [
            ('[email protected]:humitos/foo', True),
            ('ssh://[email protected]/humitos/foo', True),
            ('ssh+git://github.com/humitos/foo', True),
            ('[email protected]:strangeuser/readthedocs.git', True),
            ('[email protected]:22/_ssh/docs', True),
        ] + common_urls

        with override_settings(ALLOW_PRIVATE_REPOS=False):
            for url, valid in public_urls:
                initial = {
                    'name': 'foo',
                    'repo_type': 'git',
                    'repo': url,
                }
                form = ProjectBasicsForm(initial)
                self.assertEqual(form.is_valid(), valid, msg=url)

        with override_settings(ALLOW_PRIVATE_REPOS=True):
            for url, valid in private_urls:
                initial = {
                    'name': 'foo',
                    'repo_type': 'git',
                    'repo': url,
                }
                form = ProjectBasicsForm(initial)
                self.assertEqual(form.is_valid(), valid, msg=url)