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')
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')
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'])
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
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
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()
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'
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()
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()
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) ]
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
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'
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) ]
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='******'))
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
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, ]) == []
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'] = ''
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, ]) == []
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()
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
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()
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()
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()
def setUp(self): self._conn = Connection(port='127.0.0.1:1666', client='p4_unit_tests', user='******')
def setUp(self): self._conn = Connection(port=P4PORT, client=P4CLIENT, user=P4USER)
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
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)
def setUp(self): self._conn = Connection(port='127.0.0.1:1666', client='p4_unit_tests', user='******') pytest.deprecated_call(self._conn.findChangelist, CL)