1
0

test_pagure_lib_git.py 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374
  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. from pagure.lib.repo import PagureRepo
  18. sys.path.insert(0, os.path.join(os.path.dirname(
  19. os.path.abspath(__file__)), '..'))
  20. import pagure.lib.git
  21. import tests
  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,23 @@
  386. +{
  387. + "assignee": null,
  388. + "blocks": [],
  389. + "comments": [],
  390. + "content": "We should work on this",
  391. + "date_created": null,
  392. + "depends": [],
  393. + "id": 1,
  394. + "priority": null,
  395. + "private": false,
  396. + "status": "Open",
  397. + "tags": [],
  398. + "title": "Test issue",
  399. + "user": {
  400. + "default_email": "bar@pingou.com",
  401. + "emails": [
  402. + "bar@pingou.com",
  403. + "foo@pingou.com"
  404. + ],
  405. + "fullname": "PY C",
  406. + "name": "pingou"
  407. + }
  408. +}
  409. \ No newline at end of file
  410. """
  411. npatch = []
  412. for row in patch.split('\n'):
  413. if row.startswith('Date:'):
  414. continue
  415. elif row.startswith('From '):
  416. row = row.split(' ', 2)[2]
  417. elif row.startswith('diff --git '):
  418. row = row.split(' ')
  419. row[2] = 'a/123'
  420. row[3] = 'b/456'
  421. row = ' '.join(row)
  422. elif 'Updated issue' in row:
  423. row = row.split()
  424. row[3] = '<hash>:'
  425. row = ' '.join(row)
  426. elif 'date_created' in row:
  427. t = row.split(': ')[0]
  428. row = '%s: null,' % t
  429. elif row.startswith('index 00'):
  430. row = 'index 0000000..60f7480'
  431. elif row.startswith('+++ b/'):
  432. row = '+++ b/456'
  433. npatch.append(row)
  434. patch = '\n'.join(npatch)
  435. #print patch
  436. self.assertEqual(patch, exp)
  437. # Test again after adding a comment
  438. msg = pagure.lib.add_issue_comment(
  439. session=self.session,
  440. issue=issue,
  441. comment='Hey look a comment!',
  442. user='foo',
  443. ticketfolder=tests.HERE
  444. )
  445. self.session.commit()
  446. self.assertEqual(msg, 'Comment added')
  447. # Use patch to validate the repo
  448. repo = pygit2.Repository(self.gitrepo)
  449. commit = repo.revparse_single('HEAD')
  450. patch = pagure.lib.git.commit_to_patch(repo, commit)
  451. exp = """Mon Sep 17 00:00:00 2001
  452. From: pagure <pagure>
  453. Subject: Updated issue <hash>: Test issue
  454. ---
  455. diff --git a/123 b/456
  456. index 458821a..77674a8
  457. --- a/123
  458. +++ b/456
  459. @@ -1,7 +1,24 @@
  460. {
  461. "assignee": null,
  462. "blocks": [],
  463. - "comments": [],
  464. + "comments": [
  465. + {
  466. + "comment": "Hey look a comment!",
  467. + "date_created": null,
  468. + "edited_on": null,
  469. + "editor": null,
  470. + "id": 1,
  471. + "parent": null,
  472. + "user": {
  473. + "default_email": "foo@bar.com",
  474. + "emails": [
  475. + "foo@bar.com"
  476. + ],
  477. + "fullname": "foo bar",
  478. + "name": "foo"
  479. + }
  480. + }
  481. + ],
  482. "content": "We should work on this",
  483. "date_created": null,
  484. "depends": [],
  485. """
  486. npatch = []
  487. for row in patch.split('\n'):
  488. if row.startswith('Date:'):
  489. continue
  490. elif row.startswith('From '):
  491. row = row.split(' ', 2)[2]
  492. elif row.startswith('diff --git '):
  493. row = row.split(' ')
  494. row[2] = 'a/123'
  495. row[3] = 'b/456'
  496. row = ' '.join(row)
  497. elif 'Updated issue' in row:
  498. row = row.split()
  499. row[3] = '<hash>:'
  500. row = ' '.join(row)
  501. elif 'date_created' in row:
  502. t = row.split(': ')[0]
  503. row = '%s: null,' % t
  504. elif row.startswith('index'):
  505. row = 'index 458821a..77674a8'
  506. elif row.startswith('--- a/'):
  507. row = '--- a/123'
  508. elif row.startswith('+++ b/'):
  509. row = '+++ b/456'
  510. npatch.append(row)
  511. patch = '\n'.join(npatch)
  512. #print patch
  513. self.assertEqual(patch, exp)
  514. def test_clean_git(self):
  515. """ Test the clean_git method of pagure.lib.git. """
  516. pagure.lib.git.clean_git(None, None, None)
  517. self.test_update_git()
  518. gitpath = os.path.join(tests.HERE, 'test_ticket_repo.git')
  519. gitrepo = pygit2.init_repository(gitpath, bare=True)
  520. # Get the uid of the ticket created
  521. commit = gitrepo.revparse_single('HEAD')
  522. patch = pagure.lib.git.commit_to_patch(gitrepo, commit)
  523. hash_file = None
  524. for row in patch.split('\n'):
  525. if row.startswith('+++ b/'):
  526. hash_file = row.split('+++ b/')[-1]
  527. break
  528. # The only file in git is the one of that ticket
  529. files = [entry.name for entry in commit.tree]
  530. self.assertEqual(files, [hash_file])
  531. repo = pagure.lib.get_project(self.session, 'test_ticket_repo')
  532. issue = pagure.lib.search_issues(self.session, repo, issueid=1)
  533. pagure.lib.git.clean_git(issue, repo, tests.HERE)
  534. # No more files in the git repo
  535. commit = gitrepo.revparse_single('HEAD')
  536. files = [entry.name for entry in commit.tree]
  537. self.assertEqual(files, [])
  538. @patch('pagure.lib.notify.send_email')
  539. def test_update_git_requests(self, email_f):
  540. """ Test the update_git of pagure.lib.git for pull-requests. """
  541. email_f.return_value = True
  542. # Create project
  543. item = pagure.lib.model.Project(
  544. user_id=1, # pingou
  545. name='test_ticket_repo',
  546. description='test project for ticket',
  547. hook_token='aaabbbxxx',
  548. )
  549. self.session.add(item)
  550. self.session.commit()
  551. # Create repo
  552. self.gitrepo = os.path.join(tests.HERE, 'test_ticket_repo.git')
  553. os.makedirs(self.gitrepo)
  554. repo_obj = pygit2.init_repository(self.gitrepo, bare=True)
  555. repo = pagure.lib.get_project(self.session, 'test_ticket_repo')
  556. # Create an issue to play with
  557. req = pagure.lib.new_pull_request(
  558. session=self.session,
  559. repo_from=repo,
  560. branch_from='feature',
  561. repo_to=repo,
  562. branch_to='master',
  563. title='test PR',
  564. user='pingou',
  565. requestfolder=tests.HERE,
  566. requestuid='foobar',
  567. requestid=None,
  568. status='Open',
  569. notify=True
  570. )
  571. self.assertEqual(req.id, 1)
  572. self.assertEqual(req.title, 'test PR')
  573. request = repo.requests[0]
  574. self.assertEqual(request.title, 'test PR')
  575. pagure.lib.git.update_git(request, request.project, tests.HERE)
  576. repo = pygit2.Repository(self.gitrepo)
  577. commit = repo.revparse_single('HEAD')
  578. # Use patch to validate the repo
  579. patch = pagure.lib.git.commit_to_patch(repo, commit)
  580. exp = """Mon Sep 17 00:00:00 2001
  581. From: pagure <pagure>
  582. Subject: Updated pull-request <hash>: test PR
  583. ---
  584. diff --git a/123 b/456
  585. new file mode 100644
  586. index 0000000..60f7480
  587. --- /dev/null
  588. +++ b/456
  589. @@ -0,0 +1,83 @@
  590. +{
  591. + "assignee": null,
  592. + "branch": "master",
  593. + "branch_from": "feature",
  594. + "closed_at": null,
  595. + "closed_by": null,
  596. + "comments": [],
  597. + "commit_start": null,
  598. + "commit_stop": null,
  599. + "date_created": null,
  600. + "id": 1,
  601. + "initial_comment": null,
  602. + "project": {
  603. + "date_created": null,
  604. + "description": "test project for ticket",
  605. + "id": 1,
  606. + "name": "test_ticket_repo",
  607. + "parent": null,
  608. + "priorities": {},
  609. + "settings": {
  610. + "Enforce_signed-off_commits_in_pull-request": false,
  611. + "Minimum_score_to_merge_pull-request": -1,
  612. + "Only_assignee_can_merge_pull-request": false,
  613. + "Web-hooks": null,
  614. + "always_merge": false,
  615. + "issue_tracker": true,
  616. + "project_documentation": false,
  617. + "pull_requests": true
  618. + },
  619. + "tags": [],
  620. + "user": {
  621. + "default_email": "bar@pingou.com",
  622. + "emails": [
  623. + "bar@pingou.com",
  624. + "foo@pingou.com"
  625. + ],
  626. + "fullname": "PY C",
  627. + "name": "pingou"
  628. + }
  629. + },
  630. + "remote_git": null,
  631. + "repo_from": {
  632. + "date_created": null,
  633. + "description": "test project for ticket",
  634. + "id": 1,
  635. + "name": "test_ticket_repo",
  636. + "parent": null,
  637. + "priorities": {},
  638. + "settings": {
  639. + "Enforce_signed-off_commits_in_pull-request": false,
  640. + "Minimum_score_to_merge_pull-request": -1,
  641. + "Only_assignee_can_merge_pull-request": false,
  642. + "Web-hooks": null,
  643. + "always_merge": false,
  644. + "issue_tracker": true,
  645. + "project_documentation": false,
  646. + "pull_requests": true
  647. + },
  648. + "tags": [],
  649. + "user": {
  650. + "default_email": "bar@pingou.com",
  651. + "emails": [
  652. + "bar@pingou.com",
  653. + "foo@pingou.com"
  654. + ],
  655. + "fullname": "PY C",
  656. + "name": "pingou"
  657. + }
  658. + },
  659. + "status": "Open",
  660. + "title": "test PR",
  661. + "uid": "foobar",
  662. + "updated_on": null,
  663. + "user": {
  664. + "default_email": "bar@pingou.com",
  665. + "emails": [
  666. + "bar@pingou.com",
  667. + "foo@pingou.com"
  668. + ],
  669. + "fullname": "PY C",
  670. + "name": "pingou"
  671. + }
  672. +}
  673. \ No newline at end of file
  674. """
  675. npatch = []
  676. for row in patch.split('\n'):
  677. if row.startswith('Date:'):
  678. continue
  679. elif row.startswith('From '):
  680. row = row.split(' ', 2)[2]
  681. elif row.startswith('diff --git '):
  682. row = row.split(' ')
  683. row[2] = 'a/123'
  684. row[3] = 'b/456'
  685. row = ' '.join(row)
  686. elif 'Updated pull-request' in row:
  687. row = row.split()
  688. row[3] = '<hash>:'
  689. row = ' '.join(row)
  690. elif 'date_created' in row:
  691. t = row.split(': ')[0]
  692. row = '%s: null,' % t
  693. elif 'updated_on' in row:
  694. t = row.split(': ')[0]
  695. row = '%s: null,' % t
  696. elif row.startswith('index 00'):
  697. row = 'index 0000000..60f7480'
  698. elif row.startswith('+++ b/'):
  699. row = '+++ b/456'
  700. npatch.append(row)
  701. patch = '\n'.join(npatch)
  702. #print patch
  703. self.assertEqual(patch, exp)
  704. def test_update_ticket_from_git(self):
  705. """ Test the update_ticket_from_git method from pagure.lib.git. """
  706. tests.create_projects(self.session)
  707. repo = pagure.lib.get_project(self.session, 'test')
  708. # Before
  709. self.assertEqual(len(repo.issues), 0)
  710. self.assertEqual(repo.issues, [])
  711. data = {
  712. "status": "Open", "title": "foo", "comments": [],
  713. "content": "bar", "date_created": "1426500263",
  714. "user": {
  715. "name": "pingou", "emails": ["pingou@fedoraproject.org"]},
  716. }
  717. self.assertRaises(
  718. pagure.exceptions.PagureException,
  719. pagure.lib.git.update_ticket_from_git,
  720. self.session,
  721. reponame='foobar',
  722. username=None,
  723. issue_uid='foobar',
  724. json_data=data
  725. )
  726. pagure.lib.git.update_ticket_from_git(
  727. self.session, reponame='test', username=None,
  728. issue_uid='foobar', json_data=data
  729. )
  730. self.session.commit()
  731. # After 1 insertion
  732. self.assertEqual(len(repo.issues), 1)
  733. self.assertEqual(repo.issues[0].id, 1)
  734. self.assertEqual(repo.issues[0].uid, 'foobar')
  735. self.assertEqual(repo.issues[0].title, 'foo')
  736. self.assertEqual(repo.issues[0].depends_text, [])
  737. self.assertEqual(repo.issues[0].blocks_text, [])
  738. data["title"] = "fake issue for tests"
  739. pagure.lib.git.update_ticket_from_git(
  740. self.session, reponame='test', username=None,
  741. issue_uid='foobar', json_data=data
  742. )
  743. self.session.commit()
  744. # After edit
  745. self.assertEqual(len(repo.issues), 1)
  746. self.assertEqual(repo.issues[0].id, 1)
  747. self.assertEqual(repo.issues[0].uid, 'foobar')
  748. self.assertEqual(repo.issues[0].title, 'fake issue for tests')
  749. self.assertEqual(repo.issues[0].depends_text, [])
  750. self.assertEqual(repo.issues[0].blocks_text, [])
  751. data = {
  752. "status": "Open", "title": "Rename pagure", "private": False,
  753. "content": "This is too much of a conflict with the book",
  754. "user": {
  755. "fullname": "Pierre-YvesChibon",
  756. "name": "pingou",
  757. "default_email": "pingou@fedoraproject.org",
  758. "emails": ["pingou@fedoraproject.org"]
  759. },
  760. "id": 20,
  761. "blocks": [1],
  762. "depends": [3, 4],
  763. "date_created": "1426595224",
  764. "comments": [
  765. {
  766. "comment": "Nirik:\r\n\r\n- sourceforge++ \r\n- "
  767. "gitmaker\r\n- mastergit \r\n- hostomatic\r\n- "
  768. "gitcorp\r\n- git-keiretsu \r\n- gitbuffet\r\n- "
  769. "cogitator\r\n- cogitate\r\n\r\nrandomuser:\r\n\r\n- "
  770. "COLLABORATRON5000\r\n- git-sm\u00f6rg\u00e5sbord\r\n- "
  771. "thislittlegittywenttomarket\r\n- git-o-rama\r\n- "
  772. "gitsundheit",
  773. "date_created": "1426595224", "id": 250, "parent": None,
  774. "user": {
  775. "fullname": "Pierre-YvesChibon",
  776. "name": "pingou",
  777. "default_email": "pingou@fedoraproject.org",
  778. "emails": ["pingou@fedoraproject.org"]
  779. }
  780. },
  781. {
  782. "comment": "Nirik:\r\n\r\n- sourceforge++ \r\n- "
  783. "gitmaker\r\n- mastergit \r\n- hostomatic\r\n- "
  784. "gitcorp\r\n- git-keiretsu \r\n- gitbuffet\r\n- "
  785. "cogitator\r\n- cogitate\r\n\r\nrandomuser:\r\n\r\n- "
  786. "COLLABORATRON5000\r\n- git-sm\u00f6rg\u00e5sbord\r\n- "
  787. "thislittlegittywenttomarket\r\n- git-o-rama\r\n- "
  788. "gitsundheit",
  789. "date_created": "1426595340", "id": 324, "parent": None,
  790. "user": {
  791. "fullname": "Ralph Bean",
  792. "name": "ralph",
  793. "default_email": "ralph@fedoraproject.org",
  794. "emails": ["ralph@fedoraproject.org"]
  795. }
  796. }
  797. ]
  798. }
  799. pagure.lib.git.update_ticket_from_git(
  800. self.session, reponame='test', username=None,
  801. issue_uid='foobar2', json_data=data
  802. )
  803. # After second insertion
  804. self.assertEqual(len(repo.issues), 2)
  805. self.assertEqual(repo.issues[0].uid, 'foobar')
  806. self.assertEqual(repo.issues[0].title, 'fake issue for tests')
  807. self.assertEqual(repo.issues[0].depends_text, [20])
  808. self.assertEqual(repo.issues[0].blocks_text, [])
  809. # New one
  810. self.assertEqual(repo.issues[1].uid, 'foobar2')
  811. self.assertEqual(repo.issues[1].title, 'Rename pagure')
  812. self.assertEqual(repo.issues[1].depends_text, [])
  813. self.assertEqual(repo.issues[1].blocks_text, [1])
  814. def test_update_request_from_git(self):
  815. """ Test the update_request_from_git method from pagure.lib.git. """
  816. tests.create_projects(self.session)
  817. tests.create_projects_git(os.path.join(tests.HERE, 'repos'))
  818. repo = pagure.lib.get_project(self.session, 'test')
  819. # Before
  820. self.assertEqual(len(repo.requests), 0)
  821. self.assertEqual(repo.requests, [])
  822. data = {
  823. "status": True,
  824. "uid": "d4182a2ac2d541d884742d3037c26e56",
  825. "project": {
  826. "parent": None,
  827. "settings": {
  828. "issue_tracker": True,
  829. "project_documentation": True,
  830. "pull_requests": True,
  831. },
  832. "name": "test",
  833. "date_created": "1426500194",
  834. "tags": [],
  835. "user": {
  836. "fullname": "Pierre-YvesChibon",
  837. "name": "pingou",
  838. "default_email": "pingou@fedoraproject.org",
  839. "emails": [
  840. "pingou@fedoraproject.org"
  841. ]
  842. },
  843. "id": 1,
  844. "description": "test project"
  845. },
  846. "commit_stop": "eface8e13bc2a08a3fb22af9a72a8c90e36b8b89",
  847. "user": {
  848. "fullname": "Pierre-YvesChibon",
  849. "name": "pingou",
  850. "default_email": "pingou@fedoraproject.org",
  851. "emails": ["pingou@fedoraproject.org"]
  852. },
  853. "id": 7,
  854. "comments": [
  855. {
  856. "comment": "really?",
  857. "user": {
  858. "fullname": "Pierre-YvesChibon",
  859. "name": "pingou",
  860. "default_email": "pingou@fedoraproject.org",
  861. "emails": ["pingou@fedoraproject.org"]
  862. },
  863. "parent": None,
  864. "date_created": "1426843778",
  865. "commit": "fa72f315373ec5f98f2b08c8ffae3645c97aaad2",
  866. "line": 5,
  867. "id": 1,
  868. "filename": "test"
  869. },
  870. {
  871. "comment": "Again ?",
  872. "user": {
  873. "fullname": "Pierre-YvesChibon",
  874. "name": "pingou",
  875. "default_email": "pingou@fedoraproject.org",
  876. "emails": [
  877. "pingou@fedoraproject.org"
  878. ]
  879. },
  880. "parent": None,
  881. "date_created": "1426866781",
  882. "commit": "94ebaf900161394059478fd88aec30e59092a1d7",
  883. "line": 5,
  884. "id": 2,
  885. "filename": "test2"
  886. },
  887. {
  888. "comment": "Should be fine in fact",
  889. "user": {
  890. "fullname": "Pierre-YvesChibon",
  891. "name": "pingou",
  892. "default_email": "pingou@fedoraproject.org",
  893. "emails": [
  894. "pingou@fedoraproject.org"
  895. ]
  896. },
  897. "parent": None,
  898. "date_created": "1426866950",
  899. "commit": "94ebaf900161394059478fd88aec30e59092a1d7",
  900. "line": 5,
  901. "id": 3,
  902. "filename": "test2"
  903. }
  904. ],
  905. "branch_from": "master",
  906. "title": "test request",
  907. "commit_start": "788efeaaf86bde8618f594a8181abb402e1dd904",
  908. "repo_from": {
  909. "parent": {
  910. "parent": None,
  911. "name": "test",
  912. "date_created": "1426500194",
  913. "tags": [],
  914. "user": {
  915. "fullname": "Pierre-YvesChibon",
  916. "name": "pingou",
  917. "default_email": "pingou@fedoraproject.org",
  918. "emails": [
  919. "pingou@fedoraproject.org"
  920. ]
  921. },
  922. "settings": {
  923. "issue_tracker": True,
  924. "project_documentation": True,
  925. "pull_requests": True,
  926. },
  927. "id": 1,
  928. "description": "test project"
  929. },
  930. "settings": {
  931. "issue_tracker": True,
  932. "project_documentation": True,
  933. "pull_requests": True,
  934. },
  935. "name": "test",
  936. "date_created": "1426843440",
  937. "tags": [],
  938. "user": {
  939. "fullname": "fake user",
  940. "name": "fake",
  941. "default_email": "fake@fedoraproject.org",
  942. "emails": [
  943. "fake@fedoraproject.org"
  944. ]
  945. },
  946. "id": 6,
  947. "description": "test project"
  948. },
  949. "branch": "master",
  950. "date_created": "1426843732"
  951. }
  952. self.assertRaises(
  953. pagure.exceptions.PagureException,
  954. pagure.lib.git.update_request_from_git,
  955. self.session,
  956. reponame='foobar',
  957. username=None,
  958. request_uid='d4182a2ac2d541d884742d3037c26e56',
  959. json_data=data,
  960. gitfolder=tests.HERE,
  961. docfolder=os.path.join(tests.HERE, 'docs'),
  962. ticketfolder=os.path.join(tests.HERE, 'tickets'),
  963. requestfolder=os.path.join(tests.HERE, 'requests')
  964. )
  965. pagure.lib.git.update_request_from_git(
  966. self.session,
  967. reponame='test',
  968. username=None,
  969. request_uid='d4182a2ac2d541d884742d3037c26e56',
  970. json_data=data,
  971. gitfolder=tests.HERE,
  972. docfolder=os.path.join(tests.HERE, 'docs'),
  973. ticketfolder=os.path.join(tests.HERE, 'tickets'),
  974. requestfolder=os.path.join(tests.HERE, 'requests')
  975. )
  976. self.session.commit()
  977. # After 1 st insertion
  978. self.assertEqual(len(repo.requests), 1)
  979. self.assertEqual(repo.requests[0].id, 7)
  980. self.assertEqual(
  981. repo.requests[0].uid, 'd4182a2ac2d541d884742d3037c26e56')
  982. self.assertEqual(repo.requests[0].title, 'test request')
  983. self.assertEqual(len(repo.requests[0].comments), 3)
  984. data = {
  985. "status": True,
  986. "uid": "d4182a2ac2d541d884742d3037c26e57",
  987. "project": {
  988. "parent": None,
  989. "name": "test",
  990. "date_created": "1426500194",
  991. "tags": [],
  992. "user": {
  993. "fullname": "Pierre-YvesChibon",
  994. "name": "pingou",
  995. "default_email": "pingou@fedoraproject.org",
  996. "emails": [
  997. "pingou@fedoraproject.org"
  998. ]
  999. },
  1000. "settings": {
  1001. "issue_tracker": True,
  1002. "project_documentation": True,
  1003. "pull_requests": True,
  1004. },
  1005. "id": 1,
  1006. "description": "test project"
  1007. },
  1008. "commit_stop": "eface8e13bc2a08a3fb22af9a72a8c90e36b8b89",
  1009. "user": {
  1010. "fullname": "Pierre-YvesChibon",
  1011. "name": "pingou",
  1012. "default_email": "pingou@fedoraproject.org",
  1013. "emails": ["pingou@fedoraproject.org"]
  1014. },
  1015. "id": 4,
  1016. "comments": [],
  1017. "branch_from": "master",
  1018. "title": "test request #2",
  1019. "commit_start": "788efeaaf86bde8618f594a8181abb402e1dd904",
  1020. "repo_from": {
  1021. "parent": {
  1022. "parent": None,
  1023. "name": "test",
  1024. "date_created": "1426500194",
  1025. "tags": [],
  1026. "user": {
  1027. "fullname": "Pierre-YvesChibon",
  1028. "name": "pingou",
  1029. "default_email": "pingou@fedoraproject.org",
  1030. "emails": [
  1031. "pingou@fedoraproject.org"
  1032. ]
  1033. },
  1034. "settings": {
  1035. "issue_tracker": True,
  1036. "project_documentation": True,
  1037. "pull_requests": True,
  1038. },
  1039. "id": 1,
  1040. "description": "test project"
  1041. },
  1042. "settings": {
  1043. "issue_tracker": True,
  1044. "project_documentation": True,
  1045. "pull_requests": True,
  1046. },
  1047. "name": "test",
  1048. "date_created": "1426843440",
  1049. "tags": [],
  1050. "user": {
  1051. "fullname": "fake user",
  1052. "name": "fake",
  1053. "default_email": "fake@fedoraproject.org",
  1054. "emails": [
  1055. "fake@fedoraproject.org"
  1056. ]
  1057. },
  1058. "project_docs": True,
  1059. "id": 6,
  1060. "description": "test project"
  1061. },
  1062. "branch": "master",
  1063. "date_created": "1426843745"
  1064. }
  1065. pagure.lib.git.update_request_from_git(
  1066. self.session,
  1067. reponame='test',
  1068. username=None,
  1069. request_uid='d4182a2ac2d541d884742d3037c26e57',
  1070. json_data=data,
  1071. gitfolder=tests.HERE,
  1072. docfolder=os.path.join(tests.HERE, 'docs'),
  1073. ticketfolder=os.path.join(tests.HERE, 'tickets'),
  1074. requestfolder=os.path.join(tests.HERE, 'requests')
  1075. )
  1076. self.session.commit()
  1077. # After 2 nd insertion
  1078. self.assertEqual(len(repo.requests), 2)
  1079. self.assertEqual(repo.requests[0].id, 7)
  1080. self.assertEqual(
  1081. repo.requests[0].uid, 'd4182a2ac2d541d884742d3037c26e56')
  1082. self.assertEqual(repo.requests[0].title, 'test request')
  1083. self.assertEqual(len(repo.requests[0].comments), 3)
  1084. # 2 entry
  1085. self.assertEqual(repo.requests[1].id, 4)
  1086. self.assertEqual(
  1087. repo.requests[1].uid, 'd4182a2ac2d541d884742d3037c26e57')
  1088. self.assertEqual(repo.requests[1].title, 'test request #2')
  1089. self.assertEqual(len(repo.requests[1].comments), 0)
  1090. def test_read_git_lines(self):
  1091. """ Test the read_git_lines method of pagure.lib.git. """
  1092. self.test_update_git()
  1093. gitrepo = os.path.join(tests.HERE, 'test_ticket_repo.git')
  1094. output = pagure.lib.git.read_git_lines(
  1095. ['log', '-1', "--pretty='%s'"], gitrepo)
  1096. self.assertEqual(len(output), 1)
  1097. self.assertTrue(
  1098. output[0].startswith("'Updated issue ")
  1099. )
  1100. self.assertTrue(
  1101. output[0].endswith(": Test issue'")
  1102. )
  1103. # Keeping the new line symbol
  1104. output = pagure.lib.git.read_git_lines(
  1105. ['log', '-1', "--pretty='%s'"], gitrepo, keepends=True)
  1106. self.assertEqual(len(output), 1)
  1107. self.assertTrue(
  1108. output[0].endswith(": Test issue'\n")
  1109. )
  1110. def test_get_revs_between(self):
  1111. """ Test the get_revs_between method of pagure.lib.git. """
  1112. self.test_update_git()
  1113. gitrepo = os.path.join(tests.HERE, 'test_ticket_repo.git')
  1114. output = pagure.lib.git.read_git_lines(
  1115. ['log', '-3', "--pretty='%H'"], gitrepo)
  1116. self.assertEqual(len(output), 2)
  1117. from_hash = output[1].replace("'", '')
  1118. # Case 1, repo BASE is null and HEAD is equal to from_hash
  1119. to_hash = '0'
  1120. output1 = pagure.lib.git.get_revs_between(
  1121. to_hash, from_hash, gitrepo, 'refs/heads/master')
  1122. self.assertEqual(output1, [from_hash])
  1123. # Case 2, get revs between two commits (to_hash, from_hash)
  1124. to_hash = output[0].replace("'", '')
  1125. output2 = pagure.lib.git.get_revs_between(
  1126. to_hash, from_hash, gitrepo, 'refs/heads/master')
  1127. self.assertEqual(output2, [to_hash])
  1128. # Case 3, get revs between two commits (from_hash, to_hash)
  1129. output3 = pagure.lib.git.get_revs_between(
  1130. from_hash, to_hash, gitrepo, 'refs/heads/master')
  1131. self.assertEqual(output3, [to_hash])
  1132. # Case 4, get revs between two commits on two different branches
  1133. newgitrepo = tempfile.mkdtemp(prefix='pagure-')
  1134. newrepo = pygit2.clone_repository(gitrepo, newgitrepo)
  1135. newrepo.create_branch('feature', newrepo.head.get_object())
  1136. with open(os.path.join(newgitrepo, 'sources'), 'w') as stream:
  1137. stream.write('foo\n bar')
  1138. newrepo.index.add('sources')
  1139. newrepo.index.write()
  1140. # Commits the files added
  1141. tree = newrepo.index.write_tree()
  1142. author = pygit2.Signature(
  1143. 'Alice Author', 'alice@authors.tld')
  1144. committer = pygit2.Signature(
  1145. 'Cecil Committer', 'cecil@committers.tld')
  1146. newrepo.create_commit(
  1147. 'refs/heads/feature', # the name of the reference to update
  1148. author,
  1149. committer,
  1150. 'Add sources file for testing',
  1151. # binary string representing the tree object ID
  1152. tree,
  1153. # list of binary strings representing parents of the new commit
  1154. [to_hash]
  1155. )
  1156. branch_commit = newrepo.revparse_single('refs/heads/feature')
  1157. # Push to origin
  1158. ori_remote = newrepo.remotes[0]
  1159. PagureRepo.push(ori_remote, 'refs/heads/feature')
  1160. # Remove the clone
  1161. shutil.rmtree(newgitrepo)
  1162. output4 = pagure.lib.git.get_revs_between(
  1163. '0', branch_commit.oid.hex, gitrepo, 'refs/heads/feature')
  1164. self.assertEqual(output4, [branch_commit.oid.hex])
  1165. def test_get_author(self):
  1166. """ Test the get_author method of pagure.lib.git. """
  1167. self.test_update_git()
  1168. gitrepo = os.path.join(tests.HERE, 'test_ticket_repo.git')
  1169. output = pagure.lib.git.read_git_lines(
  1170. ['log', '-3', "--pretty='%H'"], gitrepo)
  1171. self.assertEqual(len(output), 2)
  1172. for githash in output:
  1173. githash = githash.replace("'", '')
  1174. output = pagure.lib.git.get_author(githash, gitrepo)
  1175. self.assertEqual(output, 'pagure')
  1176. def get_author_email(self):
  1177. """ Test the get_author_email method of pagure.lib.git. """
  1178. self.test_update_git()
  1179. gitrepo = os.path.join(tests.HERE, 'test_ticket_repo.git')
  1180. output = pagure.lib.git.read_git_lines(
  1181. ['log', '-3', "--pretty='%H'"], gitrepo)
  1182. self.assertEqual(len(output), 2)
  1183. for githash in output:
  1184. githash = githash.replace("'", '')
  1185. output = pagure.lib.git.get_author_email(githash, gitrepo)
  1186. self.assertEqual(output, 'pagure')
  1187. def test_get_repo_name(self):
  1188. """ Test the get_repo_name method of pagure.lib.git. """
  1189. gitrepo = os.path.join(tests.HERE, 'test_ticket_repo.git')
  1190. repo_name = pagure.lib.git.get_repo_name(gitrepo)
  1191. self.assertEqual(repo_name, 'test_ticket_repo')
  1192. repo_name = pagure.lib.git.get_repo_name('foo/bar/baz/test.git')
  1193. self.assertEqual(repo_name, 'test')
  1194. repo_name = pagure.lib.git.get_repo_name('foo.test.git')
  1195. self.assertEqual(repo_name, 'foo.test')
  1196. def test_get_username(self):
  1197. """ Test the get_username method of pagure.lib.git. """
  1198. gitrepo = os.path.join(tests.HERE, 'test_ticket_repo.git')
  1199. repo_name = pagure.lib.git.get_username(gitrepo)
  1200. self.assertEqual(repo_name, None)
  1201. repo_name = pagure.lib.git.get_username('foo/bar/baz/test.git')
  1202. self.assertEqual(repo_name, None)
  1203. repo_name = pagure.lib.git.get_username('foo.test.git')
  1204. self.assertEqual(repo_name, None)
  1205. repo_name = pagure.lib.git.get_username(
  1206. os.path.join(tests.HERE, 'forks', 'pingou', 'foo.test.git'))
  1207. self.assertEqual(repo_name, 'pingou')
  1208. if __name__ == '__main__':
  1209. SUITE = unittest.TestLoader().loadTestsFromTestCase(PagureLibGittests)
  1210. unittest.TextTestRunner(verbosity=2).run(SUITE)