test_pagure_lib_git.py 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383
  1. # -*- coding: utf-8 -*-
  2. """
  3. (c) 2015 - Copyright Red Hat Inc
  4. Authors:
  5. Pierre-Yves Chibon <pingou@pingoured.fr>
  6. """
  7. __requires__ = ['SQLAlchemy >= 0.8']
  8. import pkg_resources
  9. import json
  10. import unittest
  11. import shutil
  12. import sys
  13. import os
  14. import tempfile
  15. import pygit2
  16. from mock import patch
  17. sys.path.insert(0, os.path.join(os.path.dirname(
  18. os.path.abspath(__file__)), '..'))
  19. import pagure.lib.git
  20. import tests
  21. from pagure.lib.repo import PagureRepo
  22. class PagureLibGittests(tests.Modeltests):
  23. """ Tests for pagure.lib.git """
  24. def setUp(self):
  25. """ Set up the environnment, ran before every tests. """
  26. super(PagureLibGittests, self).setUp()
  27. pagure.lib.git.SESSION = self.session
  28. pagure.APP.config['GIT_FOLDER'] = os.path.join(
  29. tests.HERE, 'repos')
  30. pagure.APP.config['FORK_FOLDER'] = os.path.join(
  31. tests.HERE, 'forks')
  32. pagure.APP.config['TICKETS_FOLDER'] = os.path.join(
  33. tests.HERE, 'tickets')
  34. pagure.APP.config['DOCS_FOLDER'] = os.path.join(
  35. tests.HERE, 'docs')
  36. pagure.APP.config['REQUESTS_FOLDER'] = os.path.join(
  37. tests.HERE, 'requests')
  38. def test_write_gitolite_acls(self):
  39. """ Test the write_gitolite_acls function of pagure.lib.git. """
  40. tests.create_projects(self.session)
  41. repo = pagure.lib.get_project(self.session, 'test')
  42. # Add an user to a project
  43. msg = pagure.lib.add_user_to_project(
  44. session=self.session,
  45. project=repo,
  46. new_user='foo',
  47. user='pingou',
  48. )
  49. self.session.commit()
  50. self.assertEqual(msg, 'User added')
  51. # Add a forked project
  52. item = pagure.lib.model.Project(
  53. user_id=1, # pingou
  54. name='test3',
  55. description='test project #2',
  56. parent_id=1,
  57. hook_token='aaabbbvvv',
  58. )
  59. self.session.add(item)
  60. self.session.commit()
  61. outputconf = os.path.join(tests.HERE, 'test_gitolite.conf')
  62. pagure.lib.git.write_gitolite_acls(self.session, outputconf)
  63. self.assertTrue(os.path.exists(outputconf))
  64. with open(outputconf) as stream:
  65. data = stream.read()
  66. exp = """
  67. repo test
  68. R = @all
  69. RW+ = pingou
  70. RW+ = foo
  71. repo docs/test
  72. R = @all
  73. RW+ = pingou
  74. RW+ = foo
  75. repo tickets/test
  76. RW+ = pingou
  77. RW+ = foo
  78. repo requests/test
  79. RW+ = pingou
  80. RW+ = foo
  81. repo test2
  82. R = @all
  83. RW+ = pingou
  84. repo docs/test2
  85. R = @all
  86. RW+ = pingou
  87. repo tickets/test2
  88. RW+ = pingou
  89. repo requests/test2
  90. RW+ = pingou
  91. repo forks/pingou/test3
  92. R = @all
  93. RW+ = pingou
  94. repo docs/forks/pingou/test3
  95. R = @all
  96. RW+ = pingou
  97. repo tickets/forks/pingou/test3
  98. RW+ = pingou
  99. repo requests/forks/pingou/test3
  100. RW+ = pingou
  101. """
  102. #print data
  103. self.assertEqual(data, exp)
  104. os.unlink(outputconf)
  105. self.assertFalse(os.path.exists(outputconf))
  106. def test_write_gitolite_acls_groups(self):
  107. """ Test the write_gitolite_acls function of pagure.lib.git with
  108. groups.
  109. """
  110. tests.create_projects(self.session)
  111. repo = pagure.lib.get_project(self.session, 'test')
  112. # Add a couple of groups
  113. msg = pagure.lib.add_group(
  114. self.session,
  115. group_name='sysadmin',
  116. group_type='user',
  117. user='pingou',
  118. is_admin=False,
  119. blacklist=[],
  120. )
  121. self.session.commit()
  122. self.assertEqual(msg, 'User `pingou` added to the group `sysadmin`.')
  123. msg = pagure.lib.add_group(
  124. self.session,
  125. group_name='devs',
  126. group_type='user',
  127. user='pingou',
  128. is_admin=False,
  129. blacklist=[],
  130. )
  131. self.session.commit()
  132. self.assertEqual(msg, 'User `pingou` added to the group `devs`.')
  133. # Associate these groups to a project
  134. msg = pagure.lib.add_group_to_project(
  135. session=self.session,
  136. project=repo,
  137. new_group='sysadmin',
  138. user='pingou',
  139. )
  140. self.session.commit()
  141. self.assertEqual(msg, 'Group added')
  142. msg = pagure.lib.add_group_to_project(
  143. session=self.session,
  144. project=repo,
  145. new_group='devs',
  146. user='pingou',
  147. )
  148. self.session.commit()
  149. self.assertEqual(msg, 'Group added')
  150. # Add an user to a project
  151. msg = pagure.lib.add_user_to_project(
  152. session=self.session,
  153. project=repo,
  154. new_user='foo',
  155. user='pingou',
  156. )
  157. self.session.commit()
  158. self.assertEqual(msg, 'User added')
  159. # Add a forked project
  160. item = pagure.lib.model.Project(
  161. user_id=1, # pingou
  162. name='test2',
  163. description='test project #2',
  164. parent_id=1,
  165. hook_token='aaabbbvvv',
  166. )
  167. self.session.add(item)
  168. self.session.commit()
  169. outputconf = os.path.join(tests.HERE, 'test_gitolite.conf')
  170. pagure.lib.git.write_gitolite_acls(self.session, outputconf)
  171. self.assertTrue(os.path.exists(outputconf))
  172. with open(outputconf) as stream:
  173. data = stream.read()
  174. exp = """@sysadmin = pingou
  175. @devs = pingou
  176. repo test
  177. R = @all
  178. RW+ = @sysadmin @devs
  179. RW+ = pingou
  180. RW+ = foo
  181. repo docs/test
  182. R = @all
  183. RW+ = @sysadmin @devs
  184. RW+ = pingou
  185. RW+ = foo
  186. repo tickets/test
  187. RW+ = @sysadmin @devs
  188. RW+ = pingou
  189. RW+ = foo
  190. repo requests/test
  191. RW+ = @sysadmin @devs
  192. RW+ = pingou
  193. RW+ = foo
  194. repo test2
  195. R = @all
  196. RW+ = pingou
  197. repo docs/test2
  198. R = @all
  199. RW+ = pingou
  200. repo tickets/test2
  201. RW+ = pingou
  202. repo requests/test2
  203. RW+ = pingou
  204. repo forks/pingou/test2
  205. R = @all
  206. RW+ = pingou
  207. repo docs/forks/pingou/test2
  208. R = @all
  209. RW+ = pingou
  210. repo tickets/forks/pingou/test2
  211. RW+ = pingou
  212. repo requests/forks/pingou/test2
  213. RW+ = pingou
  214. """
  215. #print data
  216. self.assertEqual(data.split('\n'), exp.split('\n'))
  217. os.unlink(outputconf)
  218. self.assertFalse(os.path.exists(outputconf))
  219. def test_commit_to_patch(self):
  220. """ Test the commit_to_patch function of pagure.lib.git. """
  221. # Create a git repo to play with
  222. self.gitrepo = os.path.join(tests.HERE, 'test_repo.git')
  223. os.makedirs(self.gitrepo)
  224. repo = pygit2.init_repository(self.gitrepo)
  225. # Create a file in that git repo
  226. with open(os.path.join(self.gitrepo, 'sources'), 'w') as stream:
  227. stream.write('foo\n bar')
  228. repo.index.add('sources')
  229. repo.index.write()
  230. # Commits the files added
  231. tree = repo.index.write_tree()
  232. author = pygit2.Signature(
  233. 'Alice Author', 'alice@authors.tld')
  234. committer = pygit2.Signature(
  235. 'Cecil Committer', 'cecil@committers.tld')
  236. repo.create_commit(
  237. 'refs/heads/master', # the name of the reference to update
  238. author,
  239. committer,
  240. 'Add sources file for testing',
  241. # binary string representing the tree object ID
  242. tree,
  243. # list of binary strings representing parents of the new commit
  244. []
  245. )
  246. first_commit = repo.revparse_single('HEAD')
  247. # Edit the sources file again
  248. with open(os.path.join(self.gitrepo, 'sources'), 'w') as stream:
  249. stream.write('foo\n bar\nbaz\n boose')
  250. repo.index.add('sources')
  251. repo.index.write()
  252. # Commits the files added
  253. tree = repo.index.write_tree()
  254. author = pygit2.Signature(
  255. 'Alice Author', 'alice@authors.tld')
  256. committer = pygit2.Signature(
  257. 'Cecil Committer', 'cecil@committers.tld')
  258. repo.create_commit(
  259. 'refs/heads/master', # the name of the reference to update
  260. author,
  261. committer,
  262. 'Add baz and boose to the sources\n\n There are more objects to '
  263. 'consider',
  264. # binary string representing the tree object ID
  265. tree,
  266. # list of binary strings representing parents of the new commit
  267. [first_commit.oid.hex]
  268. )
  269. second_commit = repo.revparse_single('HEAD')
  270. # Generate a patch for 2 commits
  271. patch = pagure.lib.git.commit_to_patch(
  272. repo, [first_commit, second_commit])
  273. exp = """Mon Sep 17 00:00:00 2001
  274. From: Alice Author <alice@authors.tld>
  275. Subject: [PATCH 1/2] Add sources file for testing
  276. ---
  277. diff --git a/sources b/sources
  278. new file mode 100644
  279. index 0000000..9f44358
  280. --- /dev/null
  281. +++ b/sources
  282. @@ -0,0 +1,2 @@
  283. +foo
  284. + bar
  285. \ No newline at end of file
  286. Mon Sep 17 00:00:00 2001
  287. From: Alice Author <alice@authors.tld>
  288. Subject: [PATCH 2/2] Add baz and boose to the sources
  289. There are more objects to consider
  290. ---
  291. diff --git a/sources b/sources
  292. index 9f44358..2a552bb 100644
  293. --- a/sources
  294. +++ b/sources
  295. @@ -1,2 +1,4 @@
  296. foo
  297. - bar
  298. \ No newline at end of file
  299. + bar
  300. +baz
  301. + boose
  302. \ No newline at end of file
  303. """
  304. npatch = []
  305. for row in patch.split('\n'):
  306. if row.startswith('Date:'):
  307. continue
  308. if row.startswith('From '):
  309. row = row.split(' ', 2)[2]
  310. npatch.append(row)
  311. patch = '\n'.join(npatch)
  312. self.assertEqual(patch, exp)
  313. # Generate a patch for a single commit
  314. patch = pagure.lib.git.commit_to_patch(repo, second_commit)
  315. exp = """Mon Sep 17 00:00:00 2001
  316. From: Alice Author <alice@authors.tld>
  317. Subject: Add baz and boose to the sources
  318. There are more objects to consider
  319. ---
  320. diff --git a/sources b/sources
  321. index 9f44358..2a552bb 100644
  322. --- a/sources
  323. +++ b/sources
  324. @@ -1,2 +1,4 @@
  325. foo
  326. - bar
  327. \ No newline at end of file
  328. + bar
  329. +baz
  330. + boose
  331. \ No newline at end of file
  332. """
  333. npatch = []
  334. for row in patch.split('\n'):
  335. if row.startswith('Date:'):
  336. continue
  337. if row.startswith('From '):
  338. row = row.split(' ', 2)[2]
  339. npatch.append(row)
  340. patch = '\n'.join(npatch)
  341. self.assertEqual(patch, exp)
  342. @patch('pagure.lib.notify.send_email')
  343. def test_update_git(self, email_f):
  344. """ Test the update_git of pagure.lib.git. """
  345. email_f.return_value = True
  346. # Create project
  347. item = pagure.lib.model.Project(
  348. user_id=1, # pingou
  349. name='test_ticket_repo',
  350. description='test project for ticket',
  351. hook_token='aaabbbwww',
  352. )
  353. self.session.add(item)
  354. self.session.commit()
  355. # Create repo
  356. self.gitrepo = os.path.join(tests.HERE, 'test_ticket_repo.git')
  357. os.makedirs(self.gitrepo)
  358. repo_obj = pygit2.init_repository(self.gitrepo, bare=True)
  359. repo = pagure.lib.get_project(self.session, 'test_ticket_repo')
  360. # Create an issue to play with
  361. msg = pagure.lib.new_issue(
  362. session=self.session,
  363. repo=repo,
  364. title='Test issue',
  365. content='We should work on this',
  366. user='pingou',
  367. ticketfolder=tests.HERE
  368. )
  369. self.assertEqual(msg.title, 'Test issue')
  370. issue = pagure.lib.search_issues(self.session, repo, issueid=1)
  371. pagure.lib.git.update_git(issue, repo, tests.HERE)
  372. repo = pygit2.Repository(self.gitrepo)
  373. commit = repo.revparse_single('HEAD')
  374. # Use patch to validate the repo
  375. patch = pagure.lib.git.commit_to_patch(repo, commit)
  376. exp = """Mon Sep 17 00:00:00 2001
  377. From: pagure <pagure>
  378. Subject: Updated issue <hash>: Test issue
  379. ---
  380. diff --git a/123 b/456
  381. new file mode 100644
  382. index 0000000..60f7480
  383. --- /dev/null
  384. +++ b/456
  385. @@ -0,0 +1,24 @@
  386. +{
  387. + "assignee": null,
  388. + "blocks": [],
  389. + "closed_at": null,
  390. + "comments": [],
  391. + "content": "We should work on this",
  392. + "date_created": null,
  393. + "depends": [],
  394. + "id": 1,
  395. + "priority": null,
  396. + "private": false,
  397. + "status": "Open",
  398. + "tags": [],
  399. + "title": "Test issue",
  400. + "user": {
  401. + "default_email": "bar@pingou.com",
  402. + "emails": [
  403. + "bar@pingou.com",
  404. + "foo@pingou.com"
  405. + ],
  406. + "fullname": "PY C",
  407. + "name": "pingou"
  408. + }
  409. +}
  410. \ No newline at end of file
  411. """
  412. npatch = []
  413. for row in patch.split('\n'):
  414. if row.startswith('Date:'):
  415. continue
  416. elif row.startswith('From '):
  417. row = row.split(' ', 2)[2]
  418. elif row.startswith('diff --git '):
  419. row = row.split(' ')
  420. row[2] = 'a/123'
  421. row[3] = 'b/456'
  422. row = ' '.join(row)
  423. elif 'Updated issue' in row:
  424. row = row.split()
  425. row[3] = '<hash>:'
  426. row = ' '.join(row)
  427. elif 'date_created' in row:
  428. t = row.split(': ')[0]
  429. row = '%s: null,' % t
  430. elif 'closed_at' in row:
  431. t = row.split(': ')[0]
  432. row = '%s: null,' % t
  433. elif row.startswith('index 00'):
  434. row = 'index 0000000..60f7480'
  435. elif row.startswith('+++ b/'):
  436. row = '+++ b/456'
  437. npatch.append(row)
  438. patch = '\n'.join(npatch)
  439. #print patch
  440. self.assertEqual(patch, exp)
  441. # Test again after adding a comment
  442. msg = pagure.lib.add_issue_comment(
  443. session=self.session,
  444. issue=issue,
  445. comment='Hey look a comment!',
  446. user='foo',
  447. ticketfolder=tests.HERE
  448. )
  449. self.session.commit()
  450. self.assertEqual(msg, 'Comment added')
  451. # Use patch to validate the repo
  452. repo = pygit2.Repository(self.gitrepo)
  453. commit = repo.revparse_single('HEAD')
  454. patch = pagure.lib.git.commit_to_patch(repo, commit)
  455. exp = """Mon Sep 17 00:00:00 2001
  456. From: pagure <pagure>
  457. Subject: Updated issue <hash>: Test issue
  458. ---
  459. diff --git a/123 b/456
  460. index 458821a..77674a8
  461. --- a/123
  462. +++ b/456
  463. @@ -2,7 +2,25 @@
  464. "assignee": null,
  465. "blocks": [],
  466. "closed_at": null,
  467. - "comments": [],
  468. + "comments": [
  469. + {
  470. + "comment": "Hey look a comment!",
  471. + "date_created": null,
  472. + "edited_on": null,
  473. + "editor": null,
  474. + "id": 1,
  475. + "notification": false,
  476. + "parent": null,
  477. + "user": {
  478. + "default_email": "foo@bar.com",
  479. + "emails": [
  480. + "foo@bar.com"
  481. + ],
  482. + "fullname": "foo bar",
  483. + "name": "foo"
  484. + }
  485. + }
  486. + ],
  487. "content": "We should work on this",
  488. "date_created": null,
  489. "depends": [],
  490. """
  491. npatch = []
  492. for row in patch.split('\n'):
  493. if row.startswith('Date:'):
  494. continue
  495. elif row.startswith('From '):
  496. row = row.split(' ', 2)[2]
  497. elif row.startswith('diff --git '):
  498. row = row.split(' ')
  499. row[2] = 'a/123'
  500. row[3] = 'b/456'
  501. row = ' '.join(row)
  502. elif 'Updated issue' in row:
  503. row = row.split()
  504. row[3] = '<hash>:'
  505. row = ' '.join(row)
  506. elif 'date_created' in row:
  507. t = row.split(': ')[0]
  508. row = '%s: null,' % t
  509. elif 'closed_at' in row:
  510. t = row.split(': ')[0]
  511. row = '%s: null,' % t
  512. elif row.startswith('index'):
  513. row = 'index 458821a..77674a8'
  514. elif row.startswith('--- a/'):
  515. row = '--- a/123'
  516. elif row.startswith('+++ b/'):
  517. row = '+++ b/456'
  518. npatch.append(row)
  519. patch = '\n'.join(npatch)
  520. #print patch
  521. self.assertEqual(patch, exp)
  522. def test_clean_git(self):
  523. """ Test the clean_git method of pagure.lib.git. """
  524. pagure.lib.git.clean_git(None, None, None)
  525. self.test_update_git()
  526. gitpath = os.path.join(tests.HERE, 'test_ticket_repo.git')
  527. gitrepo = pygit2.init_repository(gitpath, bare=True)
  528. # Get the uid of the ticket created
  529. commit = gitrepo.revparse_single('HEAD')
  530. patch = pagure.lib.git.commit_to_patch(gitrepo, commit)
  531. hash_file = None
  532. for row in patch.split('\n'):
  533. if row.startswith('+++ b/'):
  534. hash_file = row.split('+++ b/')[-1]
  535. break
  536. # The only file in git is the one of that ticket
  537. files = [entry.name for entry in commit.tree]
  538. self.assertEqual(files, [hash_file])
  539. repo = pagure.lib.get_project(self.session, 'test_ticket_repo')
  540. issue = pagure.lib.search_issues(self.session, repo, issueid=1)
  541. pagure.lib.git.clean_git(issue, repo, tests.HERE)
  542. # No more files in the git repo
  543. commit = gitrepo.revparse_single('HEAD')
  544. files = [entry.name for entry in commit.tree]
  545. self.assertEqual(files, [])
  546. @patch('pagure.lib.notify.send_email')
  547. def test_update_git_requests(self, email_f):
  548. """ Test the update_git of pagure.lib.git for pull-requests. """
  549. email_f.return_value = True
  550. # Create project
  551. item = pagure.lib.model.Project(
  552. user_id=1, # pingou
  553. name='test_ticket_repo',
  554. description='test project for ticket',
  555. hook_token='aaabbbxxx',
  556. )
  557. self.session.add(item)
  558. self.session.commit()
  559. # Create repo
  560. self.gitrepo = os.path.join(tests.HERE, 'test_ticket_repo.git')
  561. os.makedirs(self.gitrepo)
  562. repo_obj = pygit2.init_repository(self.gitrepo, bare=True)
  563. repo = pagure.lib.get_project(self.session, 'test_ticket_repo')
  564. # Create an issue to play with
  565. req = pagure.lib.new_pull_request(
  566. session=self.session,
  567. repo_from=repo,
  568. branch_from='feature',
  569. repo_to=repo,
  570. branch_to='master',
  571. title='test PR',
  572. user='pingou',
  573. requestfolder=tests.HERE,
  574. requestuid='foobar',
  575. requestid=None,
  576. status='Open',
  577. notify=True
  578. )
  579. self.assertEqual(req.id, 1)
  580. self.assertEqual(req.title, 'test PR')
  581. request = repo.requests[0]
  582. self.assertEqual(request.title, 'test PR')
  583. pagure.lib.git.update_git(request, request.project, tests.HERE)
  584. repo = pygit2.Repository(self.gitrepo)
  585. commit = repo.revparse_single('HEAD')
  586. # Use patch to validate the repo
  587. patch = pagure.lib.git.commit_to_patch(repo, commit)
  588. exp = """Mon Sep 17 00:00:00 2001
  589. From: pagure <pagure>
  590. Subject: Updated pull-request <hash>: test PR
  591. ---
  592. diff --git a/123 b/456
  593. new file mode 100644
  594. index 0000000..60f7480
  595. --- /dev/null
  596. +++ b/456
  597. @@ -0,0 +1,83 @@
  598. +{
  599. + "assignee": null,
  600. + "branch": "master",
  601. + "branch_from": "feature",
  602. + "closed_at": null,
  603. + "closed_by": null,
  604. + "comments": [],
  605. + "commit_start": null,
  606. + "commit_stop": null,
  607. + "date_created": null,
  608. + "id": 1,
  609. + "initial_comment": null,
  610. + "project": {
  611. + "date_created": null,
  612. + "description": "test project for ticket",
  613. + "id": 1,
  614. + "name": "test_ticket_repo",
  615. + "parent": null,
  616. + "priorities": {},
  617. + "settings": {
  618. + "Enforce_signed-off_commits_in_pull-request": false,
  619. + "Minimum_score_to_merge_pull-request": -1,
  620. + "Only_assignee_can_merge_pull-request": false,
  621. + "Web-hooks": null,
  622. + "always_merge": false,
  623. + "issue_tracker": true,
  624. + "project_documentation": false,
  625. + "pull_requests": true
  626. + },
  627. + "tags": [],
  628. + "user": {
  629. + "default_email": "bar@pingou.com",
  630. + "emails": [
  631. + "bar@pingou.com",
  632. + "foo@pingou.com"
  633. + ],
  634. + "fullname": "PY C",
  635. + "name": "pingou"
  636. + }
  637. + },
  638. + "remote_git": null,
  639. + "repo_from": {
  640. + "date_created": null,
  641. + "description": "test project for ticket",
  642. + "id": 1,
  643. + "name": "test_ticket_repo",
  644. + "parent": null,
  645. + "priorities": {},
  646. + "settings": {
  647. + "Enforce_signed-off_commits_in_pull-request": false,
  648. + "Minimum_score_to_merge_pull-request": -1,
  649. + "Only_assignee_can_merge_pull-request": false,
  650. + "Web-hooks": null,
  651. + "always_merge": false,
  652. + "issue_tracker": true,
  653. + "project_documentation": false,
  654. + "pull_requests": true
  655. + },
  656. + "tags": [],
  657. + "user": {
  658. + "default_email": "bar@pingou.com",
  659. + "emails": [
  660. + "bar@pingou.com",
  661. + "foo@pingou.com"
  662. + ],
  663. + "fullname": "PY C",
  664. + "name": "pingou"
  665. + }
  666. + },
  667. + "status": "Open",
  668. + "title": "test PR",
  669. + "uid": "foobar",
  670. + "updated_on": null,
  671. + "user": {
  672. + "default_email": "bar@pingou.com",
  673. + "emails": [
  674. + "bar@pingou.com",
  675. + "foo@pingou.com"
  676. + ],
  677. + "fullname": "PY C",
  678. + "name": "pingou"
  679. + }
  680. +}
  681. \ No newline at end of file
  682. """
  683. npatch = []
  684. for row in patch.split('\n'):
  685. if row.startswith('Date:'):
  686. continue
  687. elif row.startswith('From '):
  688. row = row.split(' ', 2)[2]
  689. elif row.startswith('diff --git '):
  690. row = row.split(' ')
  691. row[2] = 'a/123'
  692. row[3] = 'b/456'
  693. row = ' '.join(row)
  694. elif 'Updated pull-request' in row:
  695. row = row.split()
  696. row[3] = '<hash>:'
  697. row = ' '.join(row)
  698. elif 'date_created' in row:
  699. t = row.split(': ')[0]
  700. row = '%s: null,' % t
  701. elif 'updated_on' in row:
  702. t = row.split(': ')[0]
  703. row = '%s: null,' % t
  704. elif row.startswith('index 00'):
  705. row = 'index 0000000..60f7480'
  706. elif row.startswith('+++ b/'):
  707. row = '+++ b/456'
  708. npatch.append(row)
  709. patch = '\n'.join(npatch)
  710. #print patch
  711. self.assertEqual(patch, exp)
  712. def test_update_ticket_from_git(self):
  713. """ Test the update_ticket_from_git method from pagure.lib.git. """
  714. tests.create_projects(self.session)
  715. repo = pagure.lib.get_project(self.session, 'test')
  716. # Before
  717. self.assertEqual(len(repo.issues), 0)
  718. self.assertEqual(repo.issues, [])
  719. data = {
  720. "status": "Open", "title": "foo", "comments": [],
  721. "content": "bar", "date_created": "1426500263",
  722. "user": {
  723. "name": "pingou", "emails": ["pingou@fedoraproject.org"]},
  724. }
  725. self.assertRaises(
  726. pagure.exceptions.PagureException,
  727. pagure.lib.git.update_ticket_from_git,
  728. self.session,
  729. reponame='foobar',
  730. username=None,
  731. issue_uid='foobar',
  732. json_data=data
  733. )
  734. pagure.lib.git.update_ticket_from_git(
  735. self.session, reponame='test', username=None,
  736. issue_uid='foobar', json_data=data
  737. )
  738. self.session.commit()
  739. # After 1 insertion
  740. self.assertEqual(len(repo.issues), 1)
  741. self.assertEqual(repo.issues[0].id, 1)
  742. self.assertEqual(repo.issues[0].uid, 'foobar')
  743. self.assertEqual(repo.issues[0].title, 'foo')
  744. self.assertEqual(repo.issues[0].depends_text, [])
  745. self.assertEqual(repo.issues[0].blocks_text, [])
  746. data["title"] = "fake issue for tests"
  747. pagure.lib.git.update_ticket_from_git(
  748. self.session, reponame='test', username=None,
  749. issue_uid='foobar', json_data=data
  750. )
  751. self.session.commit()
  752. # After edit
  753. self.assertEqual(len(repo.issues), 1)
  754. self.assertEqual(repo.issues[0].id, 1)
  755. self.assertEqual(repo.issues[0].uid, 'foobar')
  756. self.assertEqual(repo.issues[0].title, 'fake issue for tests')
  757. self.assertEqual(repo.issues[0].depends_text, [])
  758. self.assertEqual(repo.issues[0].blocks_text, [])
  759. data = {
  760. "status": "Open", "title": "Rename pagure", "private": False,
  761. "content": "This is too much of a conflict with the book",
  762. "user": {
  763. "fullname": "Pierre-YvesChibon",
  764. "name": "pingou",
  765. "default_email": "pingou@fedoraproject.org",
  766. "emails": ["pingou@fedoraproject.org"]
  767. },
  768. "id": 20,
  769. "blocks": [1],
  770. "depends": [3, 4],
  771. "date_created": "1426595224",
  772. "comments": [
  773. {
  774. "comment": "Nirik:\r\n\r\n- sourceforge++ \r\n- "
  775. "gitmaker\r\n- mastergit \r\n- hostomatic\r\n- "
  776. "gitcorp\r\n- git-keiretsu \r\n- gitbuffet\r\n- "
  777. "cogitator\r\n- cogitate\r\n\r\nrandomuser:\r\n\r\n- "
  778. "COLLABORATRON5000\r\n- git-sm\u00f6rg\u00e5sbord\r\n- "
  779. "thislittlegittywenttomarket\r\n- git-o-rama\r\n- "
  780. "gitsundheit",
  781. "date_created": "1426595224", "id": 250, "parent": None,
  782. "user": {
  783. "fullname": "Pierre-YvesChibon",
  784. "name": "pingou",
  785. "default_email": "pingou@fedoraproject.org",
  786. "emails": ["pingou@fedoraproject.org"]
  787. }
  788. },
  789. {
  790. "comment": "Nirik:\r\n\r\n- sourceforge++ \r\n- "
  791. "gitmaker\r\n- mastergit \r\n- hostomatic\r\n- "
  792. "gitcorp\r\n- git-keiretsu \r\n- gitbuffet\r\n- "
  793. "cogitator\r\n- cogitate\r\n\r\nrandomuser:\r\n\r\n- "
  794. "COLLABORATRON5000\r\n- git-sm\u00f6rg\u00e5sbord\r\n- "
  795. "thislittlegittywenttomarket\r\n- git-o-rama\r\n- "
  796. "gitsundheit",
  797. "date_created": "1426595340", "id": 324, "parent": None,
  798. "user": {
  799. "fullname": "Ralph Bean",
  800. "name": "ralph",
  801. "default_email": "ralph@fedoraproject.org",
  802. "emails": ["ralph@fedoraproject.org"]
  803. }
  804. }
  805. ]
  806. }
  807. pagure.lib.git.update_ticket_from_git(
  808. self.session, reponame='test', username=None,
  809. issue_uid='foobar2', json_data=data
  810. )
  811. # After second insertion
  812. self.assertEqual(len(repo.issues), 2)
  813. self.assertEqual(repo.issues[0].uid, 'foobar')
  814. self.assertEqual(repo.issues[0].title, 'fake issue for tests')
  815. self.assertEqual(repo.issues[0].depends_text, [20])
  816. self.assertEqual(repo.issues[0].blocks_text, [])
  817. # New one
  818. self.assertEqual(repo.issues[1].uid, 'foobar2')
  819. self.assertEqual(repo.issues[1].title, 'Rename pagure')
  820. self.assertEqual(repo.issues[1].depends_text, [])
  821. self.assertEqual(repo.issues[1].blocks_text, [1])
  822. def test_update_request_from_git(self):
  823. """ Test the update_request_from_git method from pagure.lib.git. """
  824. tests.create_projects(self.session)
  825. tests.create_projects_git(os.path.join(tests.HERE, 'repos'))
  826. repo = pagure.lib.get_project(self.session, 'test')
  827. # Before
  828. self.assertEqual(len(repo.requests), 0)
  829. self.assertEqual(repo.requests, [])
  830. data = {
  831. "status": True,
  832. "uid": "d4182a2ac2d541d884742d3037c26e56",
  833. "project": {
  834. "parent": None,
  835. "settings": {
  836. "issue_tracker": True,
  837. "project_documentation": True,
  838. "pull_requests": True,
  839. },
  840. "name": "test",
  841. "date_created": "1426500194",
  842. "tags": [],
  843. "user": {
  844. "fullname": "Pierre-YvesChibon",
  845. "name": "pingou",
  846. "default_email": "pingou@fedoraproject.org",
  847. "emails": [
  848. "pingou@fedoraproject.org"
  849. ]
  850. },
  851. "id": 1,
  852. "description": "test project"
  853. },
  854. "commit_stop": "eface8e13bc2a08a3fb22af9a72a8c90e36b8b89",
  855. "user": {
  856. "fullname": "Pierre-YvesChibon",
  857. "name": "pingou",
  858. "default_email": "pingou@fedoraproject.org",
  859. "emails": ["pingou@fedoraproject.org"]
  860. },
  861. "id": 7,
  862. "comments": [
  863. {
  864. "comment": "really?",
  865. "user": {
  866. "fullname": "Pierre-YvesChibon",
  867. "name": "pingou",
  868. "default_email": "pingou@fedoraproject.org",
  869. "emails": ["pingou@fedoraproject.org"]
  870. },
  871. "parent": None,
  872. "date_created": "1426843778",
  873. "commit": "fa72f315373ec5f98f2b08c8ffae3645c97aaad2",
  874. "line": 5,
  875. "id": 1,
  876. "filename": "test"
  877. },
  878. {
  879. "comment": "Again ?",
  880. "user": {
  881. "fullname": "Pierre-YvesChibon",
  882. "name": "pingou",
  883. "default_email": "pingou@fedoraproject.org",
  884. "emails": [
  885. "pingou@fedoraproject.org"
  886. ]
  887. },
  888. "parent": None,
  889. "date_created": "1426866781",
  890. "commit": "94ebaf900161394059478fd88aec30e59092a1d7",
  891. "line": 5,
  892. "id": 2,
  893. "filename": "test2"
  894. },
  895. {
  896. "comment": "Should be fine in fact",
  897. "user": {
  898. "fullname": "Pierre-YvesChibon",
  899. "name": "pingou",
  900. "default_email": "pingou@fedoraproject.org",
  901. "emails": [
  902. "pingou@fedoraproject.org"
  903. ]
  904. },
  905. "parent": None,
  906. "date_created": "1426866950",
  907. "commit": "94ebaf900161394059478fd88aec30e59092a1d7",
  908. "line": 5,
  909. "id": 3,
  910. "filename": "test2"
  911. }
  912. ],
  913. "branch_from": "master",
  914. "title": "test request",
  915. "commit_start": "788efeaaf86bde8618f594a8181abb402e1dd904",
  916. "repo_from": {
  917. "parent": {
  918. "parent": None,
  919. "name": "test",
  920. "date_created": "1426500194",
  921. "tags": [],
  922. "user": {
  923. "fullname": "Pierre-YvesChibon",
  924. "name": "pingou",
  925. "default_email": "pingou@fedoraproject.org",
  926. "emails": [
  927. "pingou@fedoraproject.org"
  928. ]
  929. },
  930. "settings": {
  931. "issue_tracker": True,
  932. "project_documentation": True,
  933. "pull_requests": True,
  934. },
  935. "id": 1,
  936. "description": "test project"
  937. },
  938. "settings": {
  939. "issue_tracker": True,
  940. "project_documentation": True,
  941. "pull_requests": True,
  942. },
  943. "name": "test",
  944. "date_created": "1426843440",
  945. "tags": [],
  946. "user": {
  947. "fullname": "fake user",
  948. "name": "fake",
  949. "default_email": "fake@fedoraproject.org",
  950. "emails": [
  951. "fake@fedoraproject.org"
  952. ]
  953. },
  954. "id": 6,
  955. "description": "test project"
  956. },
  957. "branch": "master",
  958. "date_created": "1426843732"
  959. }
  960. self.assertRaises(
  961. pagure.exceptions.PagureException,
  962. pagure.lib.git.update_request_from_git,
  963. self.session,
  964. reponame='foobar',
  965. username=None,
  966. request_uid='d4182a2ac2d541d884742d3037c26e56',
  967. json_data=data,
  968. gitfolder=tests.HERE,
  969. docfolder=os.path.join(tests.HERE, 'docs'),
  970. ticketfolder=os.path.join(tests.HERE, 'tickets'),
  971. requestfolder=os.path.join(tests.HERE, 'requests')
  972. )
  973. pagure.lib.git.update_request_from_git(
  974. self.session,
  975. reponame='test',
  976. username=None,
  977. request_uid='d4182a2ac2d541d884742d3037c26e56',
  978. json_data=data,
  979. gitfolder=tests.HERE,
  980. docfolder=os.path.join(tests.HERE, 'docs'),
  981. ticketfolder=os.path.join(tests.HERE, 'tickets'),
  982. requestfolder=os.path.join(tests.HERE, 'requests')
  983. )
  984. self.session.commit()
  985. # After 1 st insertion
  986. self.assertEqual(len(repo.requests), 1)
  987. self.assertEqual(repo.requests[0].id, 7)
  988. self.assertEqual(
  989. repo.requests[0].uid, 'd4182a2ac2d541d884742d3037c26e56')
  990. self.assertEqual(repo.requests[0].title, 'test request')
  991. self.assertEqual(len(repo.requests[0].comments), 3)
  992. data = {
  993. "status": True,
  994. "uid": "d4182a2ac2d541d884742d3037c26e57",
  995. "project": {
  996. "parent": None,
  997. "name": "test",
  998. "date_created": "1426500194",
  999. "tags": [],
  1000. "user": {
  1001. "fullname": "Pierre-YvesChibon",
  1002. "name": "pingou",
  1003. "default_email": "pingou@fedoraproject.org",
  1004. "emails": [
  1005. "pingou@fedoraproject.org"
  1006. ]
  1007. },
  1008. "settings": {
  1009. "issue_tracker": True,
  1010. "project_documentation": True,
  1011. "pull_requests": True,
  1012. },
  1013. "id": 1,
  1014. "description": "test project"
  1015. },
  1016. "commit_stop": "eface8e13bc2a08a3fb22af9a72a8c90e36b8b89",
  1017. "user": {
  1018. "fullname": "Pierre-YvesChibon",
  1019. "name": "pingou",
  1020. "default_email": "pingou@fedoraproject.org",
  1021. "emails": ["pingou@fedoraproject.org"]
  1022. },
  1023. "id": 4,
  1024. "comments": [],
  1025. "branch_from": "master",
  1026. "title": "test request #2",
  1027. "commit_start": "788efeaaf86bde8618f594a8181abb402e1dd904",
  1028. "repo_from": {
  1029. "parent": {
  1030. "parent": None,
  1031. "name": "test",
  1032. "date_created": "1426500194",
  1033. "tags": [],
  1034. "user": {
  1035. "fullname": "Pierre-YvesChibon",
  1036. "name": "pingou",
  1037. "default_email": "pingou@fedoraproject.org",
  1038. "emails": [
  1039. "pingou@fedoraproject.org"
  1040. ]
  1041. },
  1042. "settings": {
  1043. "issue_tracker": True,
  1044. "project_documentation": True,
  1045. "pull_requests": True,
  1046. },
  1047. "id": 1,
  1048. "description": "test project"
  1049. },
  1050. "settings": {
  1051. "issue_tracker": True,
  1052. "project_documentation": True,
  1053. "pull_requests": True,
  1054. },
  1055. "name": "test",
  1056. "date_created": "1426843440",
  1057. "tags": [],
  1058. "user": {
  1059. "fullname": "fake user",
  1060. "name": "fake",
  1061. "default_email": "fake@fedoraproject.org",
  1062. "emails": [
  1063. "fake@fedoraproject.org"
  1064. ]
  1065. },
  1066. "project_docs": True,
  1067. "id": 6,
  1068. "description": "test project"
  1069. },
  1070. "branch": "master",
  1071. "date_created": "1426843745"
  1072. }
  1073. pagure.lib.git.update_request_from_git(
  1074. self.session,
  1075. reponame='test',
  1076. username=None,
  1077. request_uid='d4182a2ac2d541d884742d3037c26e57',
  1078. json_data=data,
  1079. gitfolder=tests.HERE,
  1080. docfolder=os.path.join(tests.HERE, 'docs'),
  1081. ticketfolder=os.path.join(tests.HERE, 'tickets'),
  1082. requestfolder=os.path.join(tests.HERE, 'requests')
  1083. )
  1084. self.session.commit()
  1085. # After 2 nd insertion
  1086. self.assertEqual(len(repo.requests), 2)
  1087. self.assertEqual(repo.requests[0].id, 7)
  1088. self.assertEqual(
  1089. repo.requests[0].uid, 'd4182a2ac2d541d884742d3037c26e56')
  1090. self.assertEqual(repo.requests[0].title, 'test request')
  1091. self.assertEqual(len(repo.requests[0].comments), 3)
  1092. # 2 entry
  1093. self.assertEqual(repo.requests[1].id, 4)
  1094. self.assertEqual(
  1095. repo.requests[1].uid, 'd4182a2ac2d541d884742d3037c26e57')
  1096. self.assertEqual(repo.requests[1].title, 'test request #2')
  1097. self.assertEqual(len(repo.requests[1].comments), 0)
  1098. def test_read_git_lines(self):
  1099. """ Test the read_git_lines method of pagure.lib.git. """
  1100. self.test_update_git()
  1101. gitrepo = os.path.join(tests.HERE, 'test_ticket_repo.git')
  1102. output = pagure.lib.git.read_git_lines(
  1103. ['log', '-1', "--pretty='%s'"], gitrepo)
  1104. self.assertEqual(len(output), 1)
  1105. self.assertTrue(
  1106. output[0].startswith("'Updated issue ")
  1107. )
  1108. self.assertTrue(
  1109. output[0].endswith(": Test issue'")
  1110. )
  1111. # Keeping the new line symbol
  1112. output = pagure.lib.git.read_git_lines(
  1113. ['log', '-1', "--pretty='%s'"], gitrepo, keepends=True)
  1114. self.assertEqual(len(output), 1)
  1115. self.assertTrue(
  1116. output[0].endswith(": Test issue'\n")
  1117. )
  1118. def test_get_revs_between(self):
  1119. """ Test the get_revs_between method of pagure.lib.git. """
  1120. self.test_update_git()
  1121. gitrepo = os.path.join(tests.HERE, 'test_ticket_repo.git')
  1122. output = pagure.lib.git.read_git_lines(
  1123. ['log', '-3', "--pretty='%H'"], gitrepo)
  1124. self.assertEqual(len(output), 2)
  1125. from_hash = output[1].replace("'", '')
  1126. # Case 1, repo BASE is null and HEAD is equal to from_hash
  1127. to_hash = '0'
  1128. output1 = pagure.lib.git.get_revs_between(
  1129. to_hash, from_hash, gitrepo, 'refs/heads/master')
  1130. self.assertEqual(output1, [from_hash])
  1131. # Case 2, get revs between two commits (to_hash, from_hash)
  1132. to_hash = output[0].replace("'", '')
  1133. output2 = pagure.lib.git.get_revs_between(
  1134. to_hash, from_hash, gitrepo, 'refs/heads/master')
  1135. self.assertEqual(output2, [to_hash])
  1136. # Case 3, get revs between two commits (from_hash, to_hash)
  1137. output3 = pagure.lib.git.get_revs_between(
  1138. from_hash, to_hash, gitrepo, 'refs/heads/master')
  1139. self.assertEqual(output3, [to_hash])
  1140. # Case 4, get revs between two commits on two different branches
  1141. newgitrepo = tempfile.mkdtemp(prefix='pagure-')
  1142. newrepo = pygit2.clone_repository(gitrepo, newgitrepo)
  1143. newrepo.create_branch('feature', newrepo.head.get_object())
  1144. with open(os.path.join(newgitrepo, 'sources'), 'w') as stream:
  1145. stream.write('foo\n bar')
  1146. newrepo.index.add('sources')
  1147. newrepo.index.write()
  1148. # Commits the files added
  1149. tree = newrepo.index.write_tree()
  1150. author = pygit2.Signature(
  1151. 'Alice Author', 'alice@authors.tld')
  1152. committer = pygit2.Signature(
  1153. 'Cecil Committer', 'cecil@committers.tld')
  1154. newrepo.create_commit(
  1155. 'refs/heads/feature', # the name of the reference to update
  1156. author,
  1157. committer,
  1158. 'Add sources file for testing',
  1159. # binary string representing the tree object ID
  1160. tree,
  1161. # list of binary strings representing parents of the new commit
  1162. [to_hash]
  1163. )
  1164. branch_commit = newrepo.revparse_single('refs/heads/feature')
  1165. # Push to origin
  1166. ori_remote = newrepo.remotes[0]
  1167. PagureRepo.push(ori_remote, 'refs/heads/feature')
  1168. # Remove the clone
  1169. shutil.rmtree(newgitrepo)
  1170. output4 = pagure.lib.git.get_revs_between(
  1171. '0', branch_commit.oid.hex, gitrepo, 'refs/heads/feature')
  1172. self.assertEqual(output4, [branch_commit.oid.hex])
  1173. def test_get_author(self):
  1174. """ Test the get_author method of pagure.lib.git. """
  1175. self.test_update_git()
  1176. gitrepo = os.path.join(tests.HERE, 'test_ticket_repo.git')
  1177. output = pagure.lib.git.read_git_lines(
  1178. ['log', '-3', "--pretty='%H'"], gitrepo)
  1179. self.assertEqual(len(output), 2)
  1180. for githash in output:
  1181. githash = githash.replace("'", '')
  1182. output = pagure.lib.git.get_author(githash, gitrepo)
  1183. self.assertEqual(output, 'pagure')
  1184. def get_author_email(self):
  1185. """ Test the get_author_email method of pagure.lib.git. """
  1186. self.test_update_git()
  1187. gitrepo = os.path.join(tests.HERE, 'test_ticket_repo.git')
  1188. output = pagure.lib.git.read_git_lines(
  1189. ['log', '-3', "--pretty='%H'"], gitrepo)
  1190. self.assertEqual(len(output), 2)
  1191. for githash in output:
  1192. githash = githash.replace("'", '')
  1193. output = pagure.lib.git.get_author_email(githash, gitrepo)
  1194. self.assertEqual(output, 'pagure')
  1195. def test_get_repo_name(self):
  1196. """ Test the get_repo_name method of pagure.lib.git. """
  1197. gitrepo = os.path.join(tests.HERE, 'test_ticket_repo.git')
  1198. repo_name = pagure.lib.git.get_repo_name(gitrepo)
  1199. self.assertEqual(repo_name, 'test_ticket_repo')
  1200. repo_name = pagure.lib.git.get_repo_name('foo/bar/baz/test.git')
  1201. self.assertEqual(repo_name, 'test')
  1202. repo_name = pagure.lib.git.get_repo_name('foo.test.git')
  1203. self.assertEqual(repo_name, 'foo.test')
  1204. def test_get_username(self):
  1205. """ Test the get_username method of pagure.lib.git. """
  1206. gitrepo = os.path.join(tests.HERE, 'test_ticket_repo.git')
  1207. repo_name = pagure.lib.git.get_username(gitrepo)
  1208. self.assertEqual(repo_name, None)
  1209. repo_name = pagure.lib.git.get_username('foo/bar/baz/test.git')
  1210. self.assertEqual(repo_name, None)
  1211. repo_name = pagure.lib.git.get_username('foo.test.git')
  1212. self.assertEqual(repo_name, None)
  1213. repo_name = pagure.lib.git.get_username(
  1214. os.path.join(tests.HERE, 'forks', 'pingou', 'foo.test.git'))
  1215. self.assertEqual(repo_name, 'pingou')
  1216. if __name__ == '__main__':
  1217. SUITE = unittest.TestLoader().loadTestsFromTestCase(PagureLibGittests)
  1218. unittest.TextTestRunner(verbosity=2).run(SUITE)