Exemplo n.º 1
0
class MarshalTests(unittest.TestCase):
    def setUp(self):
        self._conn = Connection(port=P4PORT, client=P4CLIENT, user=P4USER)

    def test_fstat(self):
        self.assertEqual(1, len(self._conn.ls(FILE)))
        self.assertTrue(isinstance(self._conn.ls(FILE)[0], Revision))
Exemplo n.º 2
0
def test_connection_properties():
    c = Connection(port=P4PORT, client=P4CLIENT, user=P4USER)
    assert c.level == ErrorLevel.FAILED
    c.level = ErrorLevel.INFO
    assert c.level == ErrorLevel.INFO
    assert str(c.client) == 'p4_unit_tests'
    assert c.user == 'p4test'
Exemplo n.º 3
0
class MarshalTests(unittest.TestCase):
    def setUp(self):
        self._conn = Connection(port=P4PORT, client=P4CLIENT, user=P4USER)

    def test_fstat(self):
        self.assertEqual(1, len(self._conn.ls(FILE)))
        self.assertTrue(isinstance(self._conn.ls(FILE)[0], Revision))
Exemplo n.º 4
0
def test_connection_properties():
    c = Connection(port=P4PORT, client=P4CLIENT, user=P4USER)
    assert c.level == ErrorLevel.FAILED
    c.level = ErrorLevel.INFO
    assert c.level == ErrorLevel.INFO
    assert str(c.client) == 'p4_unit_tests'
    assert c.user == 'p4test'
Exemplo n.º 5
0
def test_iadd():
    c = Connection(port=P4PORT, client=P4CLIENT, user=P4USER)
    cl = c.findChangelist('iadd')
    files = c.ls('//p4_test/s...', exclude_deleted=True)
    cl += files
    assert len(cl) == 2
    cl.delete()
Exemplo n.º 6
0
def test_iadd():
    c = Connection(port='127.0.0.1:1666', client='p4_unit_tests', user='******')
    cl = c.findChangelist('iadd')
    files = c.ls('//p4_test/s...', exclude_deleted=True)
    cl += files
    assert len(cl) == 3
    cl.delete()
Exemplo n.º 7
0
def test_iadd():
    c = Connection(port=P4PORT, client=P4CLIENT, user=P4USER)
    cl = c.findChangelist('iadd')
    files = c.ls('//p4_test/s...', exclude_deleted=True)
    cl += files
    assert len(cl) == 2
    cl.delete()
Exemplo n.º 8
0
def test_connection_errors():
    with pytest.raises(errors.CommandError):
        api.info(Connection(port='foo'))

    with pytest.raises(errors.CommandError):
        os.environ['P4PORT'] = 'foo'
        api.info(Connection())
        os.unsetenv('P4PORT')
Exemplo n.º 9
0
def test_moved():
    c = Connection(port=P4PORT, client=P4CLIENT, user=P4USER)
    assert '//p4_test/moved_file.txt' in [
        f.depotFile for f in c.ls('//p4_test/...')
    ]
    assert '//p4_test/moved_file.txt' not in [
        f.depotFile for f in c.ls('//p4_test/...', exclude_deleted=True)
    ]
Exemplo n.º 10
0
def test_not_added():
    c = Connection(port=P4PORT, client=P4CLIENT, user=P4USER)
    rev = c.ls(NOT_ADDED)
    assert len(rev) == 0

    res = c.canAdd(NOT_ADDED)
    assert res == True
    res = c.canAdd('foo.txt')
    assert res == False
Exemplo n.º 11
0
class MarshalTests(unittest.TestCase):
    def setUp(self):
        self._conn = Connection(port='127.0.0.1:1666',
                                client='p4_unit_tests',
                                user='******')

    def test_fstat(self):
        self.assertEqual(1, len(self._conn.ls(FILE)))
        self.assertTrue(isinstance(self._conn.ls(FILE)[0], Revision))
Exemplo n.º 12
0
def test_connection_properties():
    c = Connection(port='127.0.0.1:1666',
                   client='p4_unit_tests',
                   user='******')
    assert c.level == ErrorLevel.FAILED
    c.level = ErrorLevel.INFO
    assert c.level == ErrorLevel.INFO
    assert str(c.client) == 'p4_unit_tests'
    assert c.user == 'p4test'
Exemplo n.º 13
0
def test_not_added():
    c = Connection(port=P4PORT, client=P4CLIENT, user=P4USER)
    rev = c.ls(NOT_ADDED)
    assert len(rev) == 0

    res = c.canAdd(NOT_ADDED)
    assert res == True
    res = c.canAdd('foo.txt')
    assert res == False
Exemplo n.º 14
0
def test_moved():
    c = Connection(port='127.0.0.1:1666',
                   client='p4_unit_tests',
                   user='******')
    assert '//p4_test/moved.txt' in [
        f.depotFile for f in c.ls('//p4_test/...')
    ]
    assert '//p4_test/moved.txt' not in [
        f.depotFile for f in c.ls('//p4_test/...', exclude_deleted=True)
    ]
Exemplo n.º 15
0
def test_not_added():
    c = Connection(port='127.0.0.1:1666',
                   client='p4_unit_tests',
                   user='******')
    rev = c.ls(NOT_ADDED)
    assert len(rev) == 0

    res = c.canAdd(NOT_ADDED)
    assert res == True
    res = c.canAdd('foo.txt')
    assert res == False
Exemplo n.º 16
0
def test_status():
    c = Connection(port=P4PORT, client='bad_client', user=P4USER)
    assert c.status == ConnectionStatus.INVALID_CLIENT

    c = Connection(port='foo', client='bar', user='******')
    assert c.status == ConnectionStatus.OFFLINE

    c = Connection(port=P4PORT, client=P4CLIENT, user=P4USER)
    assert c.status == ConnectionStatus.OK
    api.connect(port=P4PORT, client=P4CLIENT, user=P4USER)
    assert api.connect().status == ConnectionStatus.OK
Exemplo n.º 17
0
def test_too_many_files():
    c = Connection(port=P4PORT, client=P4CLIENT, user=P4USER)
    assert c.ls([
        '0' * 1001,
        '0' * 1001,
        '0' * 1001,
        '0' * 1001,
        '0' * 1001,
        '0' * 1001,
        '0' * 1001,
        '0' * 1001,
    ]) == []
Exemplo n.º 18
0
def test_bad_info():
    c = Connection(port='127.0.0.1:1666', client='bad_client', user='******')
    c.run('info')
    with pytest.raises(errors.CommandError):
        cl = c.findChangelist()

    with pytest.raises(errors.CommandError):
        c = Connection(port='foo', client='bar', user='******')
        c.run('info')
Exemplo n.º 19
0
def test_bad_info():
    c = Connection(port=P4PORT, client='bad_client', user=P4USER)
    c.run(['info'])
    with pytest.raises(errors.CommandError):
        cl = c.findChangelist()

    with pytest.raises(errors.CommandError):
        c = Connection(port='foo', client='bar', user='******')
        c.run(['info'])
Exemplo n.º 20
0
def test_status():
    c = Connection(port='127.0.0.1:1666', client='bad_client', user='******')
    assert c.status == ConnectionStatus.INVALID_CLIENT

    c = Connection(port='foo', client='bar', user='******')
    assert c.status == ConnectionStatus.OFFLINE

    c = Connection(port='127.0.0.1:1666',
                   client='p4_unit_tests',
                   user='******')
    assert c.status == ConnectionStatus.OK
    api.connect(port='127.0.0.1:1666', client='p4_unit_tests', user='******')
    assert api.connect().status == ConnectionStatus.OK
Exemplo n.º 21
0
def test_too_many_files():
    c = Connection(port='127.0.0.1:1666',
                   client='p4_unit_tests',
                   user='******')
    assert c.ls([
        '0' * 1001,
        '0' * 1001,
        '0' * 1001,
        '0' * 1001,
        '0' * 1001,
        '0' * 1001,
        '0' * 1001,
        '0' * 1001,
    ]) == []
Exemplo n.º 22
0
def test_open():
    c = Connection(port='127.0.0.1:1666',
                   client='p4_unit_tests',
                   user='******')
    rev = c.ls(NOT_ADDED)
    assert len(rev) == 0
    api.open(NOT_ADDED)
    rev = c.ls(NOT_ADDED)
    assert rev[0].action == 'add'
    api.open(NOT_ADDED)
    rev = c.ls(NOT_ADDED)
    assert rev[0].action == 'add'
    rev[0].revert()

    api.open(NOT_ADDED_EMPTY)
    rev = c.ls(NOT_ADDED_EMPTY)
    assert rev[0].action == 'add'
    rev[0].revert()

    api.open(CLIENT_FILE)
    rev = c.ls(CLIENT_FILE)
    assert rev[0].action == 'edit'
    api.open(CLIENT_FILE)
    rev = c.ls(CLIENT_FILE)
    assert rev[0].action == 'edit'
    rev[0].revert()
Exemplo n.º 23
0
class ChangelistTests(unittest.TestCase):
    def setUp(self):
        self._conn = Connection(port='127.0.0.1:1666', client='p4_unit_tests', user='******')
        pytest.deprecated_call(self._conn.findChangelist, CL)

    def test_changelist(self):
        cl = self._conn.findChangelist(CL)
        self.assertEqual(cl.description, 'DO NOT COMMIT')
        self.assertEqual(len(cl), 1)
        self.assertEqual(CL, int(cl))
        self.assertEqual('p4_unit_tests', cl.client)
        self.assertEqual('pending', cl.status)
        self.assertEqual('p4test', cl.user)
        self.assertEqual(datetime.datetime(2015, 10, 1, 23, 6, 15), cl.time)
        self.assertEqual(repr(cl), '<Changelist {}>'.format(CL))

        default = self._conn.findChangelist()

        with self.assertRaises(TypeError):
            'foo' in cl

        for r in cl:
            pass

        cl.description = 'xxx'
        self.assertEqual(cl.description, 'xxx')

        with self._conn.findChangelist('testing') as cl:
            self.assertEqual(cl.description, 'testing')
            rev = self._conn.ls('//p4_test/synced.txt')[0]
            cl.append(rev)
            try:
                cl.append(r'C:/tmp/foo.txt')
            except errors.RevisionError:
                pass
            cl.append(TO_ADD)
            self.assertEqual(len(cl), 2)
            self.assertTrue(cl.isDirty)

        cl = self._conn.findChangelist('testing')
        self.assertEqual(len(cl), 2)
        rev = self._conn.ls('//p4_test/synced.txt')[0]
        rev.revert()
        cl.query()
        self.assertEqual(len(cl), 1)
        cl.revert()
        self.assertEqual(len(cl), 0)

        cl.delete()

        cl = self._conn.findChangelist('submitting')
        with cl:
            rev = self._conn.ls('//p4_test/submit.txt')[0]
            cl.append(rev)
            with open(rev.clientFile, 'w+') as fh:
                s = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(64))
                fh.write(s)

        cl.submit()
Exemplo n.º 24
0
def test_descriptions():
    c = Connection(port=P4PORT, client=P4CLIENT, user=P4USER)

    cl = c.findChangelist('testing')
    assert cl.description == 'testing'
    cl.delete()

    cl = c.findChangelist('this\nis\nmultiline')
    assert format(cl).endswith('Client: p4_unit_tests\n\nUser:   p4test\n\nStatus: pending\n\nDescription:\n\tthis\n\tis\n\tmultiline\n\t\n\nFiles:\n\n')
    cl.delete()

    cl = c.findChangelist('this\nis\nmultiline\n\n')
    assert format(cl).endswith('Client: p4_unit_tests\n\nUser:   p4test\n\nStatus: pending\n\nDescription:\n\tthis\n\tis\n\tmultiline\n\t\n\nFiles:\n\n')
    cl.delete()

    cl1 = c.findChangelist('this\nis\n\nmultiline')
    cl2 = c.findChangelist('this\nis\n\nmultiline')
    assert cl1 == cl2
    cl1.delete()
Exemplo n.º 25
0
def test_bad_info():
    c = Connection(port=P4PORT, client='bad_client', user=P4USER)
    c.run(['info'])
    with pytest.raises(errors.CommandError):
        cl = c.findChangelist()

    with pytest.raises(errors.CommandError):
        c = Connection(port='foo', client='bar', user='******')
        c.run(['info'])
Exemplo n.º 26
0
def test_connection_errors():
    with pytest.raises(errors.CommandError):
        api.info(Connection(port='foo'))

    with pytest.raises(errors.CommandError):
        os.environ['P4PORT'] = 'foo'
        api.info(Connection())
        os.unsetenv('P4PORT')

    with pytest.raises(errors.CommandError):
        api.info(Connection(port='127.0.0.1:1666'))

    with pytest.raises(errors.CommandError):
        api.info(Connection(port='127.0.0.1:1666', client='p4_unit_tests'))

    with pytest.raises(errors.CommandError):
        api.info(
            Connection(port='127.0.0.1:1666',
                       client='p4_unit_tests',
                       user='******'))
Exemplo n.º 27
0
def test_changelist_object():
    c = Connection(port='127.0.0.1:1666', client='p4_unit_tests', user='******')
    cl = Changelist(c, 145)
    assert len(cl) == 1
    assert cl[0].isEdit == False

    os.chdir(r'C:\Users\brett\Perforce\p4_unit_tests_alt\p4_test')
    os.environ['P4CONFIG'] = '.p4config'
    cl = Changelist(145)
    assert len(cl) == 1
    assert cl[0].isEdit == False
    os.environ['P4CONFIG'] = ''
Exemplo n.º 28
0
def test_reopen():
    c = Connection(port=P4PORT, client=P4CLIENT, user=P4USER)
    rev = c.ls('//p4_test/synced.txt')[0]

    default = c.findChangelist()
    default.append(rev)
    default.save()
    assert len(default) == 1

    cl = c.findChangelist('testing')
    cl.append(rev)
    cl.save()
    assert len(cl) == 1

    cl2 = c.findChangelist('testing2')
    cl2.append(rev)
    cl2.save()
    assert len(cl2) == 1
    #assert len(cl) == 0
    rev.revert()
    assert len(cl2) == 0
    cl.delete()
    cl2.delete()
Exemplo n.º 29
0
    def get_repository(self, repos_type, repos_dir, params):
        """Return a `PerforceRepository`.

        The repository is wrapped in a `CachedRepository`.
        """

        assert repos_type == 'perforce'

        self.log.debug("get_repository dir : %s" % (repos_dir))
        options = dict(self.config.options('perforce'))
        self.log.debug("get_repository options : %s" % (options))

        # Try to connect to the Perforce server
        from perforce import Connection, ConnectionFailed
        p4 = Connection(port=self.port, api='58')  # Limit to 2005.2 behaviour
        try:
            from trac import __version__ as tracVersion
            p4.connect(prog='Trac', version=tracVersion)
        except ConnectionFailed:
            raise TracError(
                message="Could not connect to Perforce repository.",
                title="Perforce connection error")

        if self.user == '':
            raise TracError(
                message="Missing 'user' value in [perforce] config section.",
                title="Perforce configuration error")
        p4.user = self.user
        p4.password = self.password
        p4.charset = self.charset
        p4.language = self.language
        jobPrefixLength = len(options.get('job_prefix', 'job'))
        p4.client = self.workspace

        params.update(labels=self.labels, branches=self.branches)

        # Calling CachedRepository depending on version
        # (for backward-compatibility with 0.11)
        p4_repos = PerforceRepository(p4, None, self.log, jobPrefixLength,
                                      params)
        repos = CachedRepository(self.env, p4_repos, self.log)
        return repos
Exemplo n.º 30
0
    def get_repository(self, repos_type, repos_dir, authname):
        """Return a `PerforceRepository`.

        The repository is wrapped in a `CachedRepository`.
        """

        assert repos_type == 'perforce'

        self.log.debug("get_repository dir : %s" % (repos_dir))
        options = dict(self.config.options('perforce'))
        self.log.debug("get_repository options : %s" % (options))

        # Try to connect to the Perforce server
        from perforce import Connection, ConnectionFailed
        p4 = Connection(port=self.port, api='58') # Limit to 2005.2 behaviour
        try:
            from trac import __version__ as tracVersion
            p4.connect(prog='Trac', version=tracVersion)
        except ConnectionFailed:
            raise TracError(
                message="Could not connect to Perforce repository.",
                title="Perforce connection error")

        if self.user == '':
            raise TracError(
                message="Missing 'user' value in [perforce] config section.",
                title="Perforce configuration error")
        p4.user = self.user
        p4.password = self.password
        p4.charset = self.charset
        p4.language = self.language
        jobPrefixLength = len(options.get('job_prefix', 'job'))
        p4.client = self.workspace

        p4_repos = PerforceRepository(p4, None, self.log, jobPrefixLength,
                                      {'labels': self.labels,
                                       'branches': self.branches})
        repos = CachedRepository(self.env.get_db_cnx(), p4_repos, None, self.log)
        if authname:
            pass
        return repos
Exemplo n.º 31
0
def test_open():
    c = Connection(port=P4PORT, client=P4CLIENT, user=P4USER)
    rev = c.ls(NOT_ADDED)
    assert len(rev) == 0
    api.open(NOT_ADDED)
    rev = c.ls(NOT_ADDED)
    assert rev[0].action == 'add'
    api.open(NOT_ADDED)
    rev = c.ls(NOT_ADDED)
    assert rev[0].action == 'add'
    rev[0].revert()

    api.open(NOT_ADDED_EMPTY)
    rev = c.ls(NOT_ADDED_EMPTY)
    assert rev[0].action == 'add'
    rev[0].revert()

    api.open(CLIENT_FILE)
    rev = c.ls(CLIENT_FILE)
    assert rev[0].action == 'edit'
    api.open(CLIENT_FILE)
    rev = c.ls(CLIENT_FILE)
    assert rev[0].action == 'edit'
    rev[0].revert()
Exemplo n.º 32
0
def test_descriptions():
    c = Connection(port='127.0.0.1:1666', client='p4_unit_tests', user='******')

    cl = c.findChangelist('testing')
    assert cl.description == 'testing'
    cl.delete()

    cl = c.findChangelist('this\nis\nmultiline')
    assert format(cl).endswith('Client: p4_unit_tests\n\nUser:   p4test\n\nStatus: pending\n\nDescription:\n\tthis\n\tis\n\tmultiline\n\t\n\nFiles:\n\n')
    cl.delete()

    cl = c.findChangelist('this\nis\nmultiline\n\n')
    assert format(cl).endswith('Client: p4_unit_tests\n\nUser:   p4test\n\nStatus: pending\n\nDescription:\n\tthis\n\tis\n\tmultiline\n\t\n\nFiles:\n\n')
    cl.delete()

    cl1 = c.findChangelist('this\nis\n\nmultiline')
    cl2 = c.findChangelist('this\nis\n\nmultiline')
    assert cl1 == cl2
    cl1.delete()
Exemplo n.º 33
0
def test_open():
    c = Connection(port=P4PORT, client=P4CLIENT, user=P4USER)
    rev = c.ls(NOT_ADDED)
    assert len(rev) == 0
    api.open(NOT_ADDED)
    rev = c.ls(NOT_ADDED)
    assert rev[0].action == 'add'
    api.open(NOT_ADDED)
    rev = c.ls(NOT_ADDED)
    assert rev[0].action == 'add'
    rev[0].revert()

    api.open(NOT_ADDED_EMPTY)
    rev = c.ls(NOT_ADDED_EMPTY)
    assert rev[0].action == 'add'
    rev[0].revert()

    api.open(CLIENT_FILE)
    rev = c.ls(CLIENT_FILE)
    assert rev[0].action == 'edit'
    api.open(CLIENT_FILE)
    rev = c.ls(CLIENT_FILE)
    assert rev[0].action == 'edit'
    rev[0].revert()
Exemplo n.º 34
0
def test_reopen():
    c = Connection(port=P4PORT, client=P4CLIENT, user=P4USER)
    rev = c.ls('//p4_test/synced.txt')[0]

    default = c.findChangelist()
    default.append(rev)
    default.save()
    assert len(default) == 1

    cl = c.findChangelist('testing')
    cl.append(rev)
    cl.save()
    assert len(cl) == 1

    cl2 = c.findChangelist('testing2')
    cl2.append(rev)
    cl2.save()
    assert len(cl2) == 1
    #assert len(cl) == 0
    rev.revert()
    assert len(cl2) == 0
    cl.delete()
    cl2.delete()
Exemplo n.º 35
0
def test_reopen():
    c = Connection(port='127.0.0.1:1666', client='p4_unit_tests', user='******')
    rev = c.ls('//p4_test/synced.txt')[0]

    default = c.findChangelist()
    default.append(rev)
    default.save()
    assert len(default) == 1

    cl = c.findChangelist('testing')
    cl.append(rev)
    cl.save()
    assert len(cl) == 1

    cl2 = c.findChangelist('testing2')
    cl2.append(rev)
    cl2.save()
    assert len(cl2) == 1
    #assert len(cl) == 0
    rev.revert()
    assert len(cl2) == 0
    cl.delete()
    cl2.delete()
Exemplo n.º 36
0
    def get_repository(self, repos_type, repos_dir, authname):

        assert repos_type == 'perforce'

        import urllib
        urltype, url = urllib.splittype(repos_dir)
        assert urltype == 'p4' or url == 'p4'

        options = dict(self.config.options('perforce'))
        if urltype != None:
            machine, path_query = urllib.splithost(url)
            user_passwd, host_port = urllib.splituser(machine)
            user, password = urllib.splitpasswd(user_passwd)
            self._update_option(options, 'port', host_port)
            self._update_option(options, 'password', password)
            self._update_option(options, 'user', user)

            path, query = urllib.splitquery(path_query)
            if path and path != '':
                for attr in self._splitattributes(query):
                    key, val = urllib.splitvalue(attr)
                    self._update_option(options, key, val)
            self._update_option(options, 'path', path)
            self.log.debug("get_repository options : %s" % (options))

        if 'port' not in options:
            raise TracError(
                message="Missing 'port' value in [perforce] config section.",
                title="TracPerforce configuration error",
            )

        # Try to connect to the Perforce server
        from perforce import Connection, ConnectionFailed
        p4 = Connection(
            port=options['port'],
            api='58',  # Limit to 2005.2 behaviour
        )
        try:
            from trac import __version__ as tracVersion
            p4.connect(prog='Trac', version=tracVersion)
        except ConnectionFailed:
            raise TracError(
                message="Could not connect to Perforce repository.",
                title="Perforce connection error",
            )

        if 'user' not in options:
            raise TracError(
                message="Missing 'user' value in [perforce] config section.",
                title="Perforce configuration error",
            )
        p4.user = options['user']

        if 'password' in options:
            p4.password = options['password']
        else:
            p4.password = ''

        if 'unicode' in options:
            if options['unicode'] == '1':
                p4.charset = 'utf8'
            elif options['unicode'] == '0':
                p4.charset = 'none'
            else:
                raise TracError(
                    message="Invalid 'unicode' value in [perforce] config " \
                    "section.",
                    title="Perforce configuration error",
                    )
        else:
            p4.charset = 'none'

        if 'language' in options:
            p4.language = options['language']
        else:
            p4.language = ''

        jobPrefixLength = 3  # default value because by default prefix is 'job'
        if 'job_prefix' in options:
            jobPrefixLength = len(options['job_prefix'])

        p4.client = ''

        repos = PerforceRepository(p4, None, self.log, jobPrefixLength)
        crepos = CachedRepository(self.env.get_db_cnx(), repos, None, self.log)
        return crepos
Exemplo n.º 37
0
 def setUp(self):
     self._conn = Connection(port=P4PORT, client=P4CLIENT, user=P4USER)
Exemplo n.º 38
0
class ChangelistTests(unittest.TestCase):
    def setUp(self):
        self._conn = Connection(port=P4PORT, client=P4CLIENT, user=P4USER)
        # pytest.deprecated_call(self._conn.findChangelist, CL)

    def test_changelist(self):
        cl = self._conn.findChangelist(CL)
        self.assertEqual(cl.description, 'DO NOT COMMIT')
        self.assertEqual(len(cl), 2)
        self.assertEqual(CL, int(cl))
        self.assertEqual(P4CLIENT, cl.client)
        self.assertEqual('pending', cl.status)
        self.assertEqual(P4USER, cl.user)
        self.assertEqual(datetime.datetime(2017, 7, 3, 21, 4, 32), cl.time)
        self.assertEqual(repr(cl), '<Changelist {}>'.format(CL))

        assert cl[0].depotFile == '//p4_test/edit.txt'

        default = self._conn.findChangelist()

        with self.assertRaises(TypeError):
            'foo' in cl

        for r in cl:
            pass

        cl.description = 'xxx'
        self.assertEqual(cl.description, 'xxx')

        with self._conn.findChangelist('testing') as cl:
            self.assertEqual(cl.description, 'testing')
            rev = self._conn.ls('//p4_test/synced.txt')[0]
            cl.append(rev)
            try:
                cl.append(r'C:/tmp/foo.txt')
            except errors.RevisionError:
                pass
            cl.append(TO_ADD)
            self.assertEqual(len(cl), 2)
            self.assertTrue(cl.isDirty)

        cl = self._conn.findChangelist('testing')
        self.assertEqual(len(cl), 2)
        rev = self._conn.ls('//p4_test/synced.txt')[0]
        rev.revert()
        cl.query()
        self.assertEqual(len(cl), 1)
        cl.revert()
        self.assertEqual(len(cl), 0)

        cl.delete()

        cl = self._conn.findChangelist('submitting')
        with cl:
            rev = self._conn.ls('//p4_test/submit.txt')[0]
            cl.append(rev)
            with open(rev.clientFile, 'w+') as fh:
                s = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(64))
                fh.write(s)

        cl.submit()
Exemplo n.º 39
0
    def get_repository(self, repos_type, repos_dir, authname):

        assert repos_type == 'perforce'

        import urllib
        urltype, url = urllib.splittype(repos_dir)
        assert urltype == 'p4' or url == 'p4'

        options = dict(self.config.options('perforce'))
        if urltype != None:
            machine, path_query = urllib.splithost(url)
            user_passwd, host_port = urllib.splituser(machine)
            user, password = urllib.splitpasswd(user_passwd)
            self._update_option(options, 'port', host_port)
            self._update_option(options, 'password', password)
            self._update_option(options, 'user', user)

            path, query = urllib.splitquery(path_query)
            if path and path != '':
                for attr in self._splitattributes(query):
                    key, val = urllib.splitvalue(attr)
                    self._update_option(options, key, val)
            self._update_option(options, 'path', path)
            self.log.debug("get_repository options : %s" % (options))

        if 'port' not in options:
            raise TracError(
                message="Missing 'port' value in [perforce] config section.",
                title="TracPerforce configuration error",
                )

        # Try to connect to the Perforce server
        from perforce import Connection, ConnectionFailed
        p4 = Connection(port=options['port'],
                        api='58', # Limit to 2005.2 behaviour
                        )
        try:
            from trac import __version__ as tracVersion
            p4.connect(prog='Trac',
                       version=tracVersion)
        except ConnectionFailed:
            raise TracError(
                message="Could not connect to Perforce repository.",
                title="Perforce connection error",
                )

        if 'user' not in options:
            raise TracError(
                message="Missing 'user' value in [perforce] config section.",
                title="Perforce configuration error",
                )
        p4.user = options['user']

        if 'password' in options:
            p4.password = options['password']
        else:
            p4.password = ''

        if 'unicode' in options:
            if options['unicode'] == '1':
                p4.charset = 'utf8'
            elif options['unicode'] == '0':
                p4.charset = 'none'
            else:
                raise TracError(
                    message="Invalid 'unicode' value in [perforce] config " \
                    "section.",
                    title="Perforce configuration error",
                    )
        else:
            p4.charset = 'none'

        if 'language' in options:
            p4.language = options['language']
        else:
            p4.language = ''
            
        jobPrefixLength = 3 # default value because by default prefix is 'job'
        if 'job_prefix' in options:
            jobPrefixLength = len(options['job_prefix'])

        p4.client = ''

        repos = PerforceRepository(p4, self.log, jobPrefixLength)

        from trac.versioncontrol.cache import CachedRepository
        return PerforceCachedRepository(self.env.get_db_cnx(),
                                        repos,
                                        None,
                                        self.log)
Exemplo n.º 40
0
def test_too_many_files():
    c = Connection(port=P4PORT, client=P4CLIENT, user=P4USER)
    assert c.ls(['0'*1001, '0'*1001, '0'*1001, '0'*1001, '0'*1001, '0'*1001, '0'*1001, '0'*1001, ]) == []
Exemplo n.º 41
0
    def get_repository(self, repos_type, repos_dir, authname):

        assert repos_type == 'perforce'

        options = dict(self.config.options('perforce'))
        
        if 'port' not in options:
            raise TracError(
                message="Missing 'port' value in [perforce] config section.",
                title="TracPerforce configuration error",
                )

        # Try to connect to the Perforce server
        from perforce import Connection, ConnectionFailed
        p4 = Connection(port=options['port'],
                        api='58', # Limit to 2005.2 behaviour
                        )
        try:
            from trac import __version__ as tracVersion
            p4.connect(prog='Trac',
                       version=tracVersion)
        except ConnectionFailed:
            raise TracError(
                message="Could not connect to Perforce repository.",
                title="Perforce connection error",
                )

        if 'user' not in options:
            raise TracError(
                message="Missing 'user' value in [perforce] config section.",
                title="Perforce configuration error",
                )
        p4.user = options['user']

        if 'password' in options:
            p4.password = options['password']
        else:
            p4.password = ''

        if 'unicode' in options:
            if options['unicode'] == '1':
                p4.charset = 'utf8'
            elif options['unicode'] == '0':
                p4.charset = 'none'
            else:
                raise TracError(
                    message="Invalid 'unicode' value in [perforce] config " \
                    "section.",
                    title="Perforce configuration error",
                    )
        else:
            p4.charset = 'none'

        if 'language' in options:
            p4.language = options['language']
        else:
            p4.language = ''

        p4.client = ''

        repos = PerforceRepository(p4, self.log)

        from trac.versioncontrol.cache import CachedRepository
        return PerforceCachedRepository(self.env.get_db_cnx(),
                                        repos,
                                        None,
                                        self.log)
Exemplo n.º 42
0
    def get_repository(self, repos_type, repos_dir, authname):

        assert repos_type == "perforce"

        options = dict(self.config.options("perforce"))

        if "port" not in options:
            raise TracError(
                message="Missing 'port' value in [perforce] config section.", title="TracPerforce configuration error"
            )

        # Try to connect to the Perforce server
        from perforce import Connection, ConnectionFailed

        p4 = Connection(port=options["port"], api="58")  # Limit to 2005.2 behaviour
        try:
            from trac import __version__ as tracVersion

            p4.connect(prog="Trac", version=tracVersion)
        except ConnectionFailed:
            raise TracError(message="Could not connect to Perforce repository.", title="Perforce connection error")

        if "user" not in options:
            raise TracError(
                message="Missing 'user' value in [perforce] config section.", title="Perforce configuration error"
            )
        p4.user = options["user"]

        if "password" in options:
            p4.password = options["password"]
        else:
            p4.password = ""

        if "unicode" in options:
            if options["unicode"] == "1":
                p4.charset = "utf8"
            elif options["unicode"] == "0":
                p4.charset = "none"
            else:
                raise TracError(
                    message="Invalid 'unicode' value in [perforce] config " "section.",
                    title="Perforce configuration error",
                )
        else:
            p4.charset = "none"

        if "language" in options:
            p4.language = options["language"]
        else:
            p4.language = ""

        p4.client = ""

        repos = PerforceRepository(p4, self.log)

        from trac.versioncontrol.cache import CachedRepository

        return PerforceCachedRepository(self.env.get_db_cnx(), repos, None, self.log)
Exemplo n.º 43
0
class RevisionTests(unittest.TestCase):
    def setUp(self):
        self._conn = Connection(port=P4PORT, client=P4CLIENT, user=P4USER)

    def test_properties(self):
        r = self._conn.ls(FILE)[0]
        self.assertEqual('<Revision: //p4_test/synced.txt#1>', repr(r))
        self.assertEqual(FILE, r.depotFile)
        self.assertEqual(CLIENT_FILE.lower(), r.clientFile.lower())
        self.assertEqual(1, r.revision)
        self.assertTrue(r.isMapped)
        self.assertFalse(r.isShelved)
        self.assertEqual(None, r.action)
        self.assertEqual(None, r.type)
        self.assertEqual([], r.openedBy)
        self.assertEqual([], r.lockedBy)
        self.assertEqual(0, r.resolved)
        self.assertTrue(r.isResolved)
        self.assertTrue(r.isSynced)
        self.assertEqual(len(r), 6)

        r = self._conn.ls(TO_EDIT)[0]
        self.assertEqual('edit', r.action)
        self.assertEqual(23, r.changelist.change)
        self.assertEqual(None, r.description)
        self.assertEqual('text', r.type)
        self.assertEqual('BEB6A43ADFB950EC6F82CEED19BEEE21', r.hash)
        self.assertEqual(10, len(r))

    def test_functions(self):
        r = self._conn.ls(TO_EDIT)[0]

        r.lock()
        self.assertTrue(r.isLocked)
        r.lock(lock=False)
        self.assertFalse(r.isLocked)
        r.sync()

        r = self._conn.ls('//p4_test/not_synced.txt')[0]
        r.sync()
        self.assertTrue(r.isSynced)
        r.sync(revision=1)
        self.assertFalse(r.isSynced)

        r = Revision('//p4_test/synced.txt', self._conn)
        r.move('//p4_test/foo.txt')
        self.assertEqual(r.depotFile, '//p4_test/foo.txt')
        r.revert()

        r = Revision('//p4_test/synced.txt', self._conn)
        r.delete()
        self.assertFalse(r.clientFile.exists())
        r.revert()

    def test_head(self):
        r = self._conn.ls(TO_EDIT)[0]

        self.assertEqual('edit', r.head.action)
        self.assertEqual(26, r.head.change)
        self.assertEqual(2, r.head.revision)
        self.assertEqual('text', r.head.type)
        self.assertEqual(datetime.datetime(2017, 7, 3, 23, 15, 31), r.head.time)
        self.assertEqual(datetime.datetime(2017, 7, 3, 20, 58, 47), r.head.modifiedTime)
        self.assertTrue(r.head.time > r.head.modifiedTime)

    def test_invalid(self):
        r = self._conn.ls('foo')
        self.assertEqual([], r)
Exemplo n.º 44
0
def test_moved():
    c = Connection(port=P4PORT, client=P4CLIENT, user=P4USER)
    assert '//p4_test/moved_file.txt' in [f.depotFile for f in c.ls('//p4_test/...')]
    assert '//p4_test/moved_file.txt' not in [f.depotFile for f in c.ls('//p4_test/...', exclude_deleted=True)]
Exemplo n.º 45
0
    def get_repository(self, repos_type, repos_dir, authname):

        assert repos_type == 'perforce'

        options = dict(self.config.options('perforce'))
        
        if 'port' not in options:
            raise TracError(
                message="Missing 'port' value in [perforce] config section.",
                title="TracPerforce configuration error",
                )

        # Try to connect to the Perforce server
        from perforce import Connection, ConnectionFailed
        p4 = Connection(port=options['port'],
                        api='58', # Limit to 2005.2 behaviour
                        )
        try:
            from trac import __version__ as tracVersion
            p4.connect(prog='Trac',
                       version=tracVersion)
        except ConnectionFailed:
            raise TracError(
                message="Could not connect to Perforce repository.",
                title="Perforce connection error",
                )

        if 'user' not in options:
            raise TracError(
                message="Missing 'user' value in [perforce] config section.",
                title="Perforce configuration error",
                )
        p4.user = options['user']

        if 'password' in options:
            p4.password = options['password']
        else:
            p4.password = ''

        if 'unicode' in options:
            if options['unicode'] == '1':
                p4.charset = 'utf8'
            elif options['unicode'] == '0':
                p4.charset = 'none'
            else:
                raise TracError(
                    message="Invalid 'unicode' value in [perforce] config " \
                    "section.",
                    title="Perforce configuration error",
                    )
        else:
            p4.charset = 'none'

        if 'language' in options:
            p4.language = options['language']
        else:
            p4.language = ''

        p4.client = ''

        repos = PerforceRepository(p4, self.log)

        from trac.versioncontrol.cache import CachedRepository
        return PerforceCachedRepository(self.env.get_db_cnx(),
                                        repos,
                                        None,
                                        self.log)
Exemplo n.º 46
0
 def setUp(self):
     self._conn = Connection(port='127.0.0.1:1666',
                             client='p4_unit_tests',
                             user='******')
Exemplo n.º 47
0
class RevisionTests(unittest.TestCase):
    def setUp(self):
        self._conn = Connection(port='127.0.0.1:1666',
                                client='p4_unit_tests',
                                user='******')

    def test_properties(self):
        r = self._conn.ls(FILE)[0]
        self.assertEqual('<Revision: //p4_test/synced.txt#2>', repr(r))
        self.assertEqual(FILE, r.depotFile)
        self.assertEqual(CLIENT_FILE.lower(), r.clientFile.lower())
        self.assertEqual(2, r.revision)
        self.assertTrue(r.isMapped)
        self.assertFalse(r.isShelved)
        self.assertEqual(None, r.action)
        self.assertEqual(None, r.type)
        self.assertEqual([], r.openedBy)
        self.assertEqual([], r.lockedBy)
        self.assertEqual(0, r.resolved)
        self.assertTrue(r.isResolved)
        self.assertTrue(r.isSynced)
        self.assertEqual(len(r), 11)

        r = self._conn.ls(TO_EDIT)[0]
        self.assertEqual('edit', r.action)
        self.assertEqual(CL, r.changelist.change)
        self.assertEqual(None, r.description)
        self.assertEqual('text', r.type)
        self.assertEqual('BEB6A43ADFB950EC6F82CEED19BEEE21', r.hash)
        self.assertEqual(10, len(r))

    def test_functions(self):
        r = self._conn.ls(TO_EDIT)[0]

        r.lock()
        self.assertTrue(r.isLocked)
        r.lock(lock=False)
        self.assertFalse(r.isLocked)
        r.sync()

        r = self._conn.ls('//p4_test/not_synced.txt')[0]
        r.sync()
        self.assertTrue(r.isSynced)
        r.sync(revision=1)
        self.assertFalse(r.isSynced)

        r = Revision('//p4_test/synced.txt', self._conn)
        r.move('//p4_test/foo.txt')
        self.assertEqual(r.depotFile, '//p4_test/foo.txt')
        r.revert()

        r = Revision('//p4_test/synced.txt', self._conn)
        r.delete()
        self.assertFalse(r.clientFile.exists())
        r.revert()

    def test_head(self):
        r = self._conn.ls(TO_EDIT)[0]

        self.assertEqual('edit', r.head.action)
        self.assertEqual(230, r.head.change)
        self.assertEqual(3, r.head.revision)
        self.assertEqual('text', r.head.type)
        self.assertEqual(datetime.datetime(2015, 9, 17, 22, 58, 4),
                         r.head.time)
        self.assertEqual(datetime.datetime(2015, 9, 11, 8, 20, 44),
                         r.head.modifiedTime)
        self.assertTrue(r.head.time > r.head.modifiedTime)

    def test_invalid(self):
        r = self._conn.ls('foo')
        self.assertEqual([], r)