~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/code/xmlrpc/tests/test_codehosting.py

  • Committer: Colin Watson
  • Date: 2011-08-19 00:25:11 UTC
  • mfrom: (7675.1045.728 db-devel)
  • mto: This revision was merged to the branch mainline in revision 13909.
  • Revision ID: cjwatson@canonical.com-20110819002511-0x8hrqs1ckiqk53g
merge db-devel

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright 2009 Canonical Ltd.  This software is licensed under the
 
1
# Copyright 2009-2011 Canonical Ltd.  This software is licensed under the
2
2
# GNU Affero General Public License version 3 (see the file LICENSE).
3
3
 
4
4
"""Tests for the internal codehosting API."""
392
392
        # If createBranch is called with the path to a non-existent distro, it
393
393
        # will return a Fault saying so in plain English.
394
394
        owner = self.factory.makePerson()
395
 
        distroseries = self.factory.makeDistroRelease()
 
395
        distroseries = self.factory.makeDistroSeries()
396
396
        sourcepackagename = self.factory.makeSourcePackageName()
397
397
        branch_name = self.factory.getUniqueString()
398
398
        unique_name = '/~%s/ningnangnong/%s/%s/%s' % (
418
418
        message = "No such distribution series: 'ningnangnong'."
419
419
        self.assertEqual(faults.NotFound(message), fault)
420
420
 
 
421
    def test_createBranch_missing_sourcepackagename(self):
 
422
        # If createBranch is called with the path to a missing source
 
423
        # package, it will create the source package.
 
424
        owner = self.factory.makePerson()
 
425
        distroseries = self.factory.makeDistroSeries()
 
426
        branch_name = self.factory.getUniqueString()
 
427
        unique_name = '/~%s/%s/%s/ningnangnong/%s' % (
 
428
            owner.name, distroseries.distribution.name, distroseries.name,
 
429
            branch_name)
 
430
        branch_id = self.codehosting_api.createBranch(
 
431
            owner.id, escape(unique_name))
 
432
        login(ANONYMOUS)
 
433
        branch = self.branch_lookup.get(branch_id)
 
434
        self.assertEqual(owner, branch.owner)
 
435
        self.assertEqual(distroseries, branch.distroseries)
 
436
        self.assertEqual(
 
437
            'ningnangnong', branch.sourcepackagename.name)
 
438
        self.assertEqual(branch_name, branch.name)
 
439
        self.assertEqual(owner, branch.registrant)
 
440
        self.assertEqual(BranchType.HOSTED, branch.branch_type)
 
441
 
421
442
    def test_createBranch_invalid_sourcepackagename(self):
422
 
        # If createBranch is called with the path to an invalid source
423
 
        # package, it will return a Fault saying so.
 
443
        # If createBranch is called with an invalid path, it will fault.
424
444
        owner = self.factory.makePerson()
425
 
        distroseries = self.factory.makeDistroRelease()
 
445
        distroseries = self.factory.makeDistroSeries()
426
446
        branch_name = self.factory.getUniqueString()
427
 
        unique_name = '/~%s/%s/%s/ningnangnong/%s' % (
 
447
        unique_name = '/~%s/%s/%s/ningn%%20angnong/%s' % (
428
448
            owner.name, distroseries.distribution.name, distroseries.name,
429
449
            branch_name)
430
450
        fault = self.codehosting_api.createBranch(
431
451
            owner.id, escape(unique_name))
432
 
        message = "No such source package: 'ningnangnong'."
433
 
        self.assertEqual(faults.NotFound(message), fault)
 
452
        self.assertEqual(
 
453
            faults.InvalidSourcePackageName('ningn%20angnong'), fault)
434
454
 
435
455
    def test_createBranch_using_branch_alias(self):
436
456
        # Branches can be created using the branch alias and the full unique
974
994
        self.assertNotFound(requester, path)
975
995
 
976
996
    def test_translatePath_branch_alias_invalid_product_name(self):
977
 
        # translatePath returns a not found when there is an invalid product name.
 
997
        # translatePath returns a not found when there is an invalid product
 
998
        # name.
978
999
        requester = self.factory.makePerson()
979
1000
        invalid_name = '_' + self.factory.getUniqueString()
980
1001
        path = '/%s/%s' % (BRANCH_ALIAS_PREFIX, invalid_name)
1012
1033
        branch = removeSecurityProxy(self.factory.makeAnyBranch())
1013
1034
        path = escape(u'%s/foo/bar' % branch_id_alias(branch))
1014
1035
        translation = self.codehosting_api.translatePath(requester.id, path)
1015
 
        self.assertEqual(
1016
 
            (BRANCH_TRANSPORT, {'id': branch.id, 'writable': False}, 'foo/bar'),
1017
 
            translation)
 
1036
        expected = (
 
1037
            BRANCH_TRANSPORT,
 
1038
            {'id': branch.id, 'writable': False},
 
1039
            'foo/bar',
 
1040
            )
 
1041
        self.assertEqual(expected, translation)
1018
1042
 
1019
1043
    def test_translatePath_branch_id_alias_owned(self):
1020
1044
        # Even if the the requester is the owner, the branch is read only.