#!/usr/bin/python2.4
#
# Copyright (c) 2005-2006 rPath, Inc.
#
# All Rights Reserved
#
import testsuite
testsuite.setup()

import mint_rephelp

from repostest import testRecipe
from conary import versions

class WebReposTest(mint_rephelp.WebRepositoryHelper):
    def testRepositoryBrowser(self):
        client, userId = self.quickMintUser('testuser', 'testpass')
        projectId = self.newProject(client, 'Foo', 'test')

        self.makeSourceTrove("testcase", testRecipe)
        self.cookFromRepository("testcase",
            versions.Label("test.rpath.local@rpl:devel"),
            ignoreDeps = True)

        # first try anonymous browsing
        page = self.assertContent('/repos/test/browse', ok_codes = [200],
            content = 'troveInfo?t=testcase:runtime')

        # now try logged-in
        page = self.webLogin('testuser', 'testpass')
        page = page.assertContent('/repos/test/browse', ok_codes = [200],
            content = 'troveInfo?t=testcase:runtime')

    def testBrowseHiddenProject(self):
        raise testsuite.SkipTestException
        adminClient, adminUserId = self.quickMintAdmin("adminuser", "testpass")

        client, userId = self.quickMintUser('testuser', 'testpass')
        projectId = self.newProject(client, 'Foo', 'test')

        adminClient.hideProject(projectId)

        self.makeSourceTrove("testcase", testRecipe)
        self.cookFromRepository("testcase",
            versions.Label("test.rpath.local@rpl:devel"),
            ignoreDeps = True)

        # anonymous user should see a 404
        page = self.assertCode('/repos/test/browse', code = 404)

        # logged-in user should see the browser
        page = self.webLogin('testuser', 'testpass')
        page = page.assertContent('/repos/test/browse', ok_codes = [200],
            content = 'troveInfo?t=testcase:runtime')

    def testBrowseExternalProject(self):
        raise testsuite.SkipTestException, "our multirepos support is broken"
        client, userId = self.quickMintUser("testuser", "testpass")
        extProjectId = self.newProject(client, "External Project", "external")

        extProject = client.getProject(extProjectId)
        labelId = extProject.getLabelIdMap()['external.rpath.local@rpl:devel']

        self.openRepository(0)
        self.openRepository(1)
        self.makeSourceTrove("testcase", testRecipe, buildLabel = versions.Label('localhost1@rpl:linux'), serverIdx = 1)

        extProject.editLabel(labelId, "localhost1@rpl:devel",
            'http://localhost1:%d/conary/' % self.servers.getServer(1).port, 'anonymous', 'anonymous')

        page = self.assertCode('/repos/external/browse', code = 200)

        page = page.assertCode('/repos/external/troveInfo?t=testcase:source', code = 200)

    def testTroveInfoPage(self):
        raise testsuite.SkipTestException("This test needs networked repostiory client workaround")
        client, userId = self.quickMintUser('foouser','foopass')
        projectId = self.newProject(client)

        # test that missing troves are a 404 not found error
        page = self.fetch('/repos/foo/troveInfo?t=group-foo', ok_codes = [404])

        self.addQuickTestComponent('foo:source',
                                   '/testproject.rpath.local@rpl:devel/1.0-1')

        # test that trove info page renders without error
        page = self.assertContent('/repos/testproject/troveInfo?t=foo:source',
                                  content = "Trove information for")


if __name__ == "__main__":
    testsuite.main()

@@ -406,35 +406,42 @@
 nt, 'Foo', 'test
+project
 ')%0A
-
 %0A        self.ma
@@ -546,32 +546,39 @@
 ions.Label(%22test
+project
 .rpath.local@rpl
@@ -696,32 +696,39 @@
 ent('/repos/test
+project
 /browse', ok_cod
@@ -867,32 +867,32 @@
 r', 'testpass')%0A
-
         page = p
@@ -913,32 +913,39 @@
 ent('/repos/test
+project
 /browse', ok_cod

fix project name