class TestCanonical(TestCase):

    def setUp(self):
        self.p = Project(
            name='foo',
            repo='http://github.com/ericholscher/django-kong',
            )
        self.p.save()


    def test_canonical_clean(self):
        # Only a url
        self.p.canonical_url = "djangokong.com"
        self.assertEqual(self.p.clean_canonical_url, "http://djangokong.com/")
        # Extra bits in the URL
        self.p.canonical_url = "http://djangokong.com/en/latest/"
        self.assertEqual(self.p.clean_canonical_url, "http://djangokong.com/")
        self.p.canonical_url = "http://djangokong.com//"
        self.assertEqual(self.p.clean_canonical_url, "http://djangokong.com/")
        # Subdomain
        self.p.canonical_url = "foo.djangokong.com"
        self.assertEqual(self.p.clean_canonical_url, "http://foo.djangokong.com/")
        # Https
        self.p.canonical_url = "https://djangokong.com//"
        self.assertEqual(self.p.clean_canonical_url, "https://djangokong.com/")
        self.p.canonical_url = "https://foo.djangokong.com//"
        self.assertEqual(self.p.clean_canonical_url, "https://foo.djangokong.com/")

    """
Example #2
0
class TestCanonical(TestCase):
    def setUp(self):
        self.p = Project(
            name='foo',
            repo='http://github.com/ericholscher/django-kong',
        )
        self.p.save()

    def test_canonical_clean(self):
        # Only a url
        self.p.canonical_url = "djangokong.com"
        self.assertEqual(self.p.clean_canonical_url, "http://djangokong.com/")
        # Extra bits in the URL
        self.p.canonical_url = "http://djangokong.com/en/latest/"
        self.assertEqual(self.p.clean_canonical_url, "http://djangokong.com/")
        self.p.canonical_url = "http://djangokong.com//"
        self.assertEqual(self.p.clean_canonical_url, "http://djangokong.com/")
        # Subdomain
        self.p.canonical_url = "foo.djangokong.com"
        self.assertEqual(self.p.clean_canonical_url,
                         "http://foo.djangokong.com/")
        # Https
        self.p.canonical_url = "https://djangokong.com//"
        self.assertEqual(self.p.clean_canonical_url, "https://djangokong.com/")
        self.p.canonical_url = "https://foo.djangokong.com//"
        self.assertEqual(self.p.clean_canonical_url,
                         "https://foo.djangokong.com/")

    """
Example #3
0
def make_api_project(project_data):
    from readthedocs.projects.models import Project
    for key in ['users', 'resource_uri', 'absolute_url', 'downloads', 'main_language_project', 'related_projects']:
        if key in project_data:
            del project_data[key]
    project = Project(**project_data)
    project.save = _new_save
    return project
Example #4
0
    def get_project(self, **kwargs):
        """
        Get authenticated user projects, or token authed projects.

        Allow for a user to either be authed to receive a project, or require
        the integration token to be specified as a POST argument.
        """
        # If the user is not an admin of the project, fall back to token auth
        if self.request.user.is_authenticated():
            try:
                return (Project.objects
                        .for_admin_user(self.request.user)
                        .get(**kwargs))
            except Project.DoesNotExist:
                pass
        # Recheck project and integration relationship during token auth check
        token = self.request.data.get('token')
        if token:
            integration = self.get_integration()
            obj = Project.objects.get(**kwargs)
            is_valid = (
                integration.project == obj and
                token == getattr(integration, 'token', None)
            )
            if is_valid:
                return obj
        raise Project.DoesNotExist()
Example #5
0
def make_api_project(project_data):
    from readthedocs.projects.models import Project
    for key in ['users', 'resource_uri', 'absolute_url', 'downloads']:
        if project_data.has_key(key):
            del project_data[key]
    project = Project(**project_data)
    return project
 def setUp(self):
     self.p = Project(
         name='foo',
         repo='http://github.com/ericholscher/django-kong',
         )
     self.p.save()
Example #7
0
 def setUp(self):
     self.p = Project(
         name='foo',
         repo='http://github.com/ericholscher/django-kong',
     )
     self.p.save()