test_pagure_flask_ui_app.py 91 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258
  1. # -*- coding: utf-8 -*-
  2. """
  3. (c) 2015-2018 - Copyright Red Hat Inc
  4. Authors:
  5. Pierre-Yves Chibon <pingou@pingoured.fr>
  6. """
  7. from __future__ import unicode_literals, absolute_import
  8. import datetime
  9. import unittest
  10. import shutil
  11. import sys
  12. import tempfile
  13. import os
  14. import six
  15. import json
  16. import pygit2
  17. from mock import patch, MagicMock
  18. sys.path.insert(0, os.path.join(os.path.dirname(
  19. os.path.abspath(__file__)), '..'))
  20. import pagure.lib.query
  21. import tests
  22. class PagureFlaskApptests(tests.Modeltests):
  23. """ Tests for flask app controller of pagure """
  24. def test_watch_list(self):
  25. ''' Test for watch list of a user '''
  26. user = tests.FakeUser(username='pingou')
  27. with tests.user_set(self.app.application, user):
  28. output = self.app.get('/', follow_redirects=True)
  29. output_text = output.get_data(as_text=True)
  30. self.assertIn(
  31. '<div class="text-center">You have no Projects</div>',
  32. output_text)
  33. tests.create_projects(self.session)
  34. output = self.app.get('/', follow_redirects=True)
  35. output_text = output.get_data(as_text=True)
  36. self.assertIn(
  37. '<h4 class="font-weight-bold mb-0">My Projects</h4>',
  38. output_text)
  39. def test_view_users(self):
  40. """ Test the view_users endpoint. """
  41. output = self.app.get('/users/?page=abc')
  42. self.assertEqual(output.status_code, 200)
  43. output_text = output.get_data(as_text=True)
  44. self.assertIn(
  45. '<h3 class="mb-3 font-weight-bold">\n Users '
  46. '<span class="badge badge-secondary">2</span>', output_text)
  47. self.assertIn(
  48. '<a href="/user/pingou">\n '
  49. '<div class="nowrap"><strong>pingou</strong>',
  50. output_text)
  51. self.assertIn(
  52. '<a href="/user/foo">\n '
  53. '<div class="nowrap"><strong>foo</strong>',
  54. output_text)
  55. @patch.dict('pagure.config.config', {'ITEM_PER_PAGE': 2})
  56. def test_view_user_repo_cnt(self):
  57. """ Test the repo counts on the view_user endpoint. """
  58. tests.create_projects(self.session)
  59. self.gitrepos = tests.create_projects_git(
  60. pagure.config.config['GIT_FOLDER'])
  61. output = self.app.get('/user/pingou')
  62. self.assertEqual(output.status_code, 200)
  63. output_text = output.get_data(as_text=True)
  64. self.assertIn(
  65. """<span>
  66. <i class="fa fa-fw text-muted fa-calendar-o fa-rotate-270"></i>
  67. <span class="d-none d-md-inline">Projects&nbsp;</span>
  68. </span>
  69. <div class="ml-auto">
  70. <span class="badge badge-secondary">
  71. 3
  72. </span>
  73. </div>""", output_text)
  74. self.assertIn(
  75. """<span>
  76. <i class="fa fa-fw text-muted fa-code-fork"></i>
  77. <span class="d-none d-md-inline">Forks&nbsp;</span>
  78. </span>
  79. <div class="ml-auto">
  80. <span class="badge badge-secondary">
  81. 0
  82. </span>
  83. </div>""", output_text)
  84. def test_view_user(self):
  85. """ Test the view_user endpoint. """
  86. output = self.app.get('/user/pingou?repopage=abc&forkpage=def')
  87. self.assertEqual(output.status_code, 200)
  88. output_text = output.get_data(as_text=True)
  89. self.assertIn(
  90. """<span>
  91. <i class="fa fa-fw text-muted fa-calendar-o fa-rotate-270"></i>
  92. <span class="d-none d-md-inline">Projects&nbsp;</span>
  93. </span>
  94. <div class="ml-auto">
  95. <span class="badge badge-secondary">
  96. 0
  97. </span>
  98. </div>""", output_text)
  99. self.assertIn(
  100. """<span>
  101. <i class="fa fa-fw text-muted fa-code-fork"></i>
  102. <span class="d-none d-md-inline">Forks&nbsp;</span>
  103. </span>
  104. <div class="ml-auto">
  105. <span class="badge badge-secondary">
  106. 0
  107. </span>
  108. </div>""", output_text)
  109. tests.create_projects(self.session)
  110. self.gitrepos = tests.create_projects_git(
  111. pagure.config.config['GIT_FOLDER'])
  112. output = self.app.get('/user/pingou?repopage=abc&forkpage=def')
  113. self.assertEqual(output.status_code, 200)
  114. output_text = output.get_data(as_text=True)
  115. self.assertIn(
  116. """<span>
  117. <i class="fa fa-fw text-muted fa-calendar-o fa-rotate-270"></i>
  118. <span class="d-none d-md-inline">Projects&nbsp;</span>
  119. </span>
  120. <div class="ml-auto">
  121. <span class="badge badge-secondary">
  122. 3
  123. </span>
  124. </div>""", output_text)
  125. self.assertIn(
  126. """<span>
  127. <i class="fa fa-fw text-muted fa-code-fork"></i>
  128. <span class="d-none d-md-inline">Forks&nbsp;</span>
  129. </span>
  130. <div class="ml-auto">
  131. <span class="badge badge-secondary">
  132. 0
  133. </span>
  134. </div>""", output_text)
  135. self.assertNotIn(
  136. '<a class="page-link" href="#" tabindex="-1">page 1 of 2</a>',
  137. output_text)
  138. @patch.dict('pagure.config.config', {'ENABLE_UI_NEW_PROJECTS': False})
  139. def test_new_project_when_turned_off_in_the_ui(self):
  140. """ Test the new_project endpoint when new project creation is
  141. not allowed in the UI of this pagure instance. """
  142. user = tests.FakeUser(username='foo')
  143. with tests.user_set(self.app.application, user):
  144. output = self.app.get('/new/')
  145. self.assertEqual(output.status_code, 404)
  146. data = {
  147. 'description': 'Project #1',
  148. 'name': 'project-1',
  149. }
  150. output = self.app.post('/new/', data=data, follow_redirects=True)
  151. self.assertEqual(output.status_code, 404)
  152. @patch.dict('pagure.config.config', {'ENABLE_UI_NEW_PROJECTS': False})
  153. def test_new_project_button_when_turned_off_in_the_ui_no_project(self):
  154. """ Test the index endpoint when new project creation is
  155. not allowed in the UI of this pagure instance. """
  156. user = tests.FakeUser(username='foo')
  157. with tests.user_set(self.app.application, user):
  158. output = self.app.get('/', follow_redirects=True)
  159. self.assertEqual(output.status_code, 200)
  160. output_text = output.get_data(as_text=True)
  161. self.assertIn(
  162. '<h4 class="font-weight-bold mb-0">My Projects</h4>',
  163. output_text)
  164. # master template
  165. self.assertNotIn(
  166. '<span class="oi" data-glyph="plus" title="Create New"',
  167. output_text)
  168. # index_auth template
  169. self.assertNotIn(
  170. 'title="Create New Project" aria-hidden="true">',
  171. output_text)
  172. @patch.dict('pagure.config.config', {'ENABLE_UI_NEW_PROJECTS': False})
  173. def test_new_project_button_when_turned_off_in_the_ui_w_project(self):
  174. """ Test the index endpoint when new project creation is
  175. not allowed in the UI of this pagure instance. """
  176. tests.create_projects(self.session)
  177. user = tests.FakeUser(username='pingou')
  178. with tests.user_set(self.app.application, user):
  179. output = self.app.get('/', follow_redirects=True)
  180. self.assertEqual(output.status_code, 200)
  181. output_text = output.get_data(as_text=True)
  182. self.assertIn(
  183. '<h4 class="font-weight-bold mb-0">My Projects</h4>',
  184. output_text)
  185. # master template
  186. self.assertNotIn(
  187. '<span class="oi" data-glyph="plus" title="Create New"',
  188. output_text)
  189. # index_auth template
  190. self.assertNotIn(
  191. 'title="Create New Project" aria-hidden="true">',
  192. output_text)
  193. def test_new_project_when_turned_off(self):
  194. """ Test the new_project endpoint when new project creation is
  195. not allowed in the pagure instance. """
  196. #turn the project creation off
  197. pagure.config.config['ENABLE_NEW_PROJECTS'] = False
  198. # Before
  199. projects = pagure.lib.query.search_projects(self.session)
  200. self.assertEqual(len(projects), 0)
  201. self.assertFalse(os.path.exists(
  202. os.path.join(self.path, 'repos', 'project-1.git')))
  203. self.assertFalse(os.path.exists(
  204. os.path.join(self.path, 'repos', 'tickets', 'project-1.git')))
  205. self.assertFalse(os.path.exists(
  206. os.path.join(self.path, 'repos', 'docs', 'project-1.git')))
  207. self.assertFalse(os.path.exists(
  208. os.path.join(self.path, 'repos', 'requests', 'project-1.git')))
  209. user = tests.FakeUser()
  210. with tests.user_set(self.app.application, user):
  211. output = self.app.get('/new/')
  212. self.assertEqual(output.status_code, 404)
  213. #just get the csrf token
  214. pagure.config.config['ENABLE_NEW_PROJECTS'] = True
  215. output = self.app.get('/new/')
  216. pagure.config.config['ENABLE_NEW_PROJECTS'] = False
  217. csrf_token = output.get_data(as_text=True).split(
  218. 'name="csrf_token" type="hidden" value="')[1].split('">')[0]
  219. data = {
  220. 'description': 'Project #1',
  221. 'name': 'project-1',
  222. }
  223. user.username = 'foo'
  224. with tests.user_set(self.app.application, user):
  225. data['csrf_token'] = csrf_token
  226. output = self.app.post('/new/', data=data, follow_redirects=True)
  227. self.assertEqual(output.status_code, 404)
  228. #After
  229. projects = pagure.lib.query.search_projects(self.session)
  230. self.assertEqual(len(projects), 0)
  231. self.assertFalse(os.path.exists(
  232. os.path.join(self.path, 'repos', 'project-1.git')))
  233. self.assertFalse(os.path.exists(
  234. os.path.join(self.path, 'repos', 'tickets', 'project-1.git')))
  235. self.assertFalse(os.path.exists(
  236. os.path.join(self.path, 'repos', 'docs', 'project-1.git')))
  237. self.assertFalse(os.path.exists(
  238. os.path.join(self.path, 'repos', 'requests', 'project-1.git')))
  239. pagure.config.config['ENABLE_NEW_PROJECTS'] = True
  240. def test_new_project_mirrored_invalid_url(self):
  241. """ Test the new_project with a mirrored repo but an invalid URL. """
  242. user = tests.FakeUser(username='foo')
  243. with tests.user_set(self.app.application, user):
  244. output = self.app.get('/new/')
  245. self.assertEqual(output.status_code, 200)
  246. csrf_token = self.get_csrf(output=output)
  247. data = {
  248. 'description': 'Project #1',
  249. 'name': 'project-1',
  250. 'mirrored_from': 'abcd',
  251. 'csrf_token': csrf_token,
  252. }
  253. output = self.app.post('/new/', data=data, follow_redirects=True)
  254. self.assertEqual(output.status_code, 200)
  255. output_text = output.get_data(as_text=True)
  256. self.assertIn(
  257. '<title>New project - Pagure</title>', output_text)
  258. self.assertIn(
  259. 'Invalid input.&nbsp;', output_text)
  260. def test_new_project_mirrored_invalid_sshurl(self):
  261. """ Test the new_project with a mirrored repo but an invalid
  262. SSH-like url.
  263. """
  264. user = tests.FakeUser(username='foo')
  265. with tests.user_set(self.app.application, user):
  266. output = self.app.get('/new/')
  267. self.assertEqual(output.status_code, 200)
  268. csrf_token = self.get_csrf(output=output)
  269. data = {
  270. 'description': 'Project #1',
  271. 'name': 'project-1',
  272. 'mirrored_from': 'ssh://git@server.org/foo/bar.git',
  273. 'csrf_token': csrf_token,
  274. }
  275. output = self.app.post('/new/', data=data, follow_redirects=True)
  276. self.assertEqual(output.status_code, 200)
  277. output_text = output.get_data(as_text=True)
  278. self.assertIn(
  279. '<title>New project - Pagure</title>', output_text)
  280. self.assertIn(
  281. 'Invalid input.&nbsp;', output_text)
  282. def test_new_project_mirrored_valid_url(self):
  283. """ Test the new_project with a mirrored repo with a valid url. """
  284. user = tests.FakeUser(username='foo')
  285. with tests.user_set(self.app.application, user):
  286. output = self.app.get('/new/')
  287. self.assertEqual(output.status_code, 200)
  288. output_text = output.get_data(as_text=True)
  289. self.assertIn(
  290. '<strong><label for="mirrored_from">Mirror from URL'
  291. '</label></strong>', output_text)
  292. csrf_token = self.get_csrf(output=output)
  293. data = {
  294. 'description': 'Project #1',
  295. 'name': 'project-1',
  296. 'mirrored_from': 'https://example.com/foo/bar.git',
  297. 'csrf_token': csrf_token,
  298. }
  299. output = self.app.post('/new/', data=data, follow_redirects=True)
  300. self.assertEqual(output.status_code, 200)
  301. output_text = output.get_data(as_text=True)
  302. self.assertIn(
  303. '<title>Overview - project-1 - Pagure</title>',
  304. output_text)
  305. self.assertIn(
  306. '<p>This repo is brand new and meant to be mirrored from '
  307. 'https://example.com/foo/bar.git !</p>', output_text)
  308. @patch.dict('pagure.config.config', {'DISABLE_MIRROR_IN': True})
  309. def test_new_project_mirrored_mirror_disabled(self):
  310. """ Test the new_project with a mirrored repo when that feature is
  311. disabled.
  312. """
  313. user = tests.FakeUser(username='foo')
  314. with tests.user_set(self.app.application, user):
  315. output = self.app.get('/new/')
  316. self.assertEqual(output.status_code, 200)
  317. output_text = output.get_data(as_text=True)
  318. self.assertNotIn(
  319. '<strong><label for="mirrored_from">Mirror from URL'
  320. '</label></strong>', output_text)
  321. csrf_token = self.get_csrf(output=output)
  322. data = {
  323. 'description': 'Project #1',
  324. 'name': 'project-1',
  325. 'mirrored_from': 'https://example.com/foo/bar.git',
  326. 'csrf_token': csrf_token,
  327. }
  328. output = self.app.post('/new/', data=data, follow_redirects=True)
  329. self.assertEqual(output.status_code, 200)
  330. output_text = output.get_data(as_text=True)
  331. self.assertIn(
  332. '<title>New project - Pagure</title>', output_text)
  333. self.assertIn(
  334. '</i> Mirroring in projects has been disabled in '
  335. 'this instance</div>', output_text)
  336. def test_new_project(self):
  337. """ Test the new_project endpoint. """
  338. # Before
  339. projects = pagure.lib.query.search_projects(self.session)
  340. self.assertEqual(len(projects), 0)
  341. self.assertFalse(os.path.exists(
  342. os.path.join(self.path, 'repos', 'project#1.git')))
  343. self.assertFalse(os.path.exists(
  344. os.path.join(self.path, 'repos', 'tickets', 'project#1.git')))
  345. self.assertFalse(os.path.exists(
  346. os.path.join(self.path, 'repos', 'docs', 'project#1.git')))
  347. self.assertFalse(os.path.exists(
  348. os.path.join(self.path, 'repos', 'requests', 'project#1.git')))
  349. user = tests.FakeUser()
  350. with tests.user_set(self.app.application, user):
  351. output = self.app.get('/new/')
  352. self.assertEqual(output.status_code, 200)
  353. output_text = output.get_data(as_text=True)
  354. self.assertIn(
  355. '<strong>Create new Project</strong>', output_text)
  356. csrf_token = output_text.split(
  357. 'name="csrf_token" type="hidden" value="')[1].split('">')[0]
  358. data = {
  359. 'description': 'Project #1',
  360. }
  361. output = self.app.post('/new/', data=data)
  362. self.assertEqual(output.status_code, 200)
  363. output_text = output.get_data(as_text=True)
  364. self.assertIn(
  365. '<strong>Create new Project</strong>', output_text)
  366. self.assertIn(
  367. '<small>\n This field is required.&nbsp;\n'
  368. ' </small>', output_text)
  369. data['name'] = 'project-1'
  370. output = self.app.post('/new/', data=data)
  371. self.assertEqual(output.status_code, 200)
  372. output_text = output.get_data(as_text=True)
  373. self.assertIn('<strong>Create new Project</strong>', output_text)
  374. self.assertNotIn(
  375. '<small>\n This field is required.&nbsp;\n'
  376. ' </small>', output_text)
  377. data['csrf_token'] = csrf_token
  378. output = self.app.post('/new/', data=data)
  379. self.assertEqual(output.status_code, 200)
  380. output_text = output.get_data(as_text=True)
  381. self.assertIn('<strong>Create new Project</strong>', output_text)
  382. self.assertIn(
  383. 'No user '
  384. '&#34;username&#34; found',
  385. output_text)
  386. user.username = 'foo'
  387. with tests.user_set(self.app.application, user):
  388. data['csrf_token'] = csrf_token
  389. output = self.app.post('/new/', data=data, follow_redirects=True)
  390. self.assertEqual(output.status_code, 200)
  391. output_text = output.get_data(as_text=True)
  392. self.assertIn(
  393. '<div class="projectinfo my-3">\nProject #1',
  394. output_text)
  395. self.assertIn('<p>This repo is brand new!</p>',
  396. output_text)
  397. self.assertIn(
  398. '<title>Overview - project-1 - Pagure</title>', output_text)
  399. # After
  400. projects = pagure.lib.query.search_projects(self.session)
  401. self.assertEqual(len(projects), 1)
  402. self.assertTrue(os.path.exists(
  403. os.path.join(self.path, 'repos', 'project-1.git')))
  404. self.assertTrue(os.path.exists(
  405. os.path.join(self.path, 'repos', 'tickets', 'project-1.git')))
  406. self.assertTrue(os.path.exists(
  407. os.path.join(self.path, 'repos', 'docs', 'project-1.git')))
  408. self.assertTrue(os.path.exists(
  409. os.path.join(self.path, 'repos', 'requests', 'project-1.git')))
  410. @patch.dict('pagure.config.config', {'PAGURE_ADMIN_USERS': ['pingou'],
  411. 'ALLOW_ADMIN_IGNORE_EXISTING_REPOS': True})
  412. def test_adopt_repos(self):
  413. """ Test the new_project endpoint with existing git repo. """
  414. # Before
  415. projects = pagure.lib.query.search_projects(self.session)
  416. self.assertEqual(len(projects), 0)
  417. tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
  418. tests.add_content_git_repo(os.path.join(self.path, 'repos', 'test.git'))
  419. user = tests.FakeUser(username='pingou')
  420. with tests.user_set(self.app.application, user):
  421. data = {
  422. 'csrf_token': self.get_csrf(),
  423. 'name': 'test',
  424. 'description': 'Project #1',
  425. }
  426. output = self.app.post('/new/', data=data, follow_redirects=True)
  427. self.assertEqual(output.status_code, 200)
  428. output_text = output.get_data(as_text=True)
  429. self.assertIn('The main repo test.git already exists', output_text)
  430. data['ignore_existing_repos'] = 'y'
  431. output = self.app.post('/new/', data=data, follow_redirects=True)
  432. self.assertEqual(output.status_code, 200)
  433. output_text = output.get_data(as_text=True)
  434. self.assertIn("Alice Author", output_text)
  435. @patch.dict('pagure.config.config', {'PAGURE_ADMIN_USERS': [],
  436. 'USERS_IGNORE_EXISTING_REPOS': ['pingou']})
  437. def test_adopt_repos_non_admin(self):
  438. """ Test the new_project endpoint with existing git repo for non-admins. """
  439. # Before
  440. projects = pagure.lib.query.search_projects(self.session)
  441. self.assertEqual(len(projects), 0)
  442. tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
  443. tests.add_content_git_repo(os.path.join(self.path, 'repos', 'test.git'))
  444. user = tests.FakeUser(username='pingou')
  445. with tests.user_set(self.app.application, user):
  446. data = {
  447. 'csrf_token': self.get_csrf(),
  448. 'name': 'test',
  449. 'description': 'Project #1',
  450. }
  451. output = self.app.post('/new/', data=data, follow_redirects=True)
  452. self.assertEqual(output.status_code, 200)
  453. output_text = output.get_data(as_text=True)
  454. self.assertIn('The main repo test.git already exists', output_text)
  455. data['ignore_existing_repos'] = 'y'
  456. output = self.app.post('/new/', data=data, follow_redirects=True)
  457. self.assertEqual(output.status_code, 200)
  458. output_text = output.get_data(as_text=True)
  459. self.assertIn("Alice Author", output_text)
  460. @patch.dict('pagure.config.config', {'PAGURE_ADMIN_USERS': [],
  461. 'USERS_IGNORE_EXISTING_REPOS': []})
  462. def test_adopt_repos_not_allowed(self):
  463. """ Test the new_project endpoint with existing git repo for no access. """
  464. # Before
  465. projects = pagure.lib.query.search_projects(self.session)
  466. self.assertEqual(len(projects), 0)
  467. tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
  468. tests.add_content_git_repo(os.path.join(self.path, 'repos', 'test.git'))
  469. user = tests.FakeUser(username='pingou')
  470. with tests.user_set(self.app.application, user):
  471. data = {
  472. 'csrf_token': self.get_csrf(),
  473. 'name': 'test',
  474. 'description': 'Project #1',
  475. }
  476. output = self.app.post('/new/', data=data, follow_redirects=True)
  477. self.assertEqual(output.status_code, 200)
  478. output_text = output.get_data(as_text=True)
  479. self.assertIn('The main repo test.git already exists', output_text)
  480. data['ignore_existing_repos'] = 'y'
  481. output = self.app.post('/new/', data=data, follow_redirects=True)
  482. self.assertEqual(output.status_code, 200)
  483. output_text = output.get_data(as_text=True)
  484. self.assertIn('The main repo test.git already exists', output_text)
  485. @patch.dict('pagure.config.config', {'PROJECT_NAME_REGEX': '^1[a-z]*$'})
  486. def test_new_project_diff_regex(self):
  487. """ Test the new_project endpoint with a different regex. """
  488. # Before
  489. projects = pagure.lib.query.search_projects(self.session)
  490. self.assertEqual(len(projects), 0)
  491. user = tests.FakeUser(username='foo')
  492. with tests.user_set(self.app.application, user):
  493. output = self.app.get('/new/')
  494. self.assertEqual(output.status_code, 200)
  495. output_text = output.get_data(as_text=True)
  496. self.assertIn(
  497. '<strong>Create new Project</strong>', output_text)
  498. csrf_token = self.get_csrf(output=output)
  499. data = {
  500. 'description': 'Project #1',
  501. 'name': 'project-1',
  502. 'csrf_token': csrf_token,
  503. }
  504. output = self.app.post('/new/', data=data, follow_redirects=True)
  505. self.assertEqual(output.status_code, 200)
  506. output_text = output.get_data(as_text=True)
  507. self.assertIn(
  508. '<title>New project - Pagure</title>', output_text)
  509. self.assertIn(
  510. '<strong>Create new Project</strong>', output_text)
  511. self.assertIn(
  512. '<small>\n Invalid input.&nbsp;\n'
  513. ' </small>', output_text)
  514. @patch.dict('pagure.config.config', {'PRIVATE_PROJECTS': True})
  515. def test_new_project_private(self):
  516. """ Test the new_project endpoint for a private project. """
  517. # Before
  518. projects = pagure.lib.query.search_projects(self.session)
  519. self.assertEqual(len(projects), 0)
  520. self.assertFalse(os.path.exists(
  521. os.path.join(self.path, 'repos', 'foo', 'project#1.git')))
  522. self.assertFalse(os.path.exists(
  523. os.path.join(self.path, 'repos', 'tickets', 'foo', 'project#1.git')))
  524. self.assertFalse(os.path.exists(
  525. os.path.join(self.path, 'repos', 'docs', 'foo', 'project#1.git')))
  526. self.assertFalse(os.path.exists(
  527. os.path.join(self.path, 'repos', 'requests', 'foo', 'project#1.git')))
  528. user = tests.FakeUser()
  529. with tests.user_set(self.app.application, user):
  530. output = self.app.get('/new/')
  531. self.assertEqual(output.status_code, 200)
  532. self.assertIn(
  533. '<strong>Create new Project</strong>', output.get_data(as_text=True))
  534. csrf_token = self.get_csrf(output=output)
  535. data = {
  536. 'description': 'Project #1',
  537. 'private': True,
  538. }
  539. output = self.app.post('/new/', data=data)
  540. self.assertEqual(output.status_code, 200)
  541. output_text = output.get_data(as_text=True)
  542. self.assertIn(
  543. '<strong>Create new Project</strong>', output_text)
  544. self.assertIn(
  545. '<small>\n This field is required.&nbsp;\n'
  546. ' </small>', output_text)
  547. data['name'] = 'project-1'
  548. output = self.app.post('/new/', data=data)
  549. self.assertEqual(output.status_code, 200)
  550. output_text = output.get_data(as_text=True)
  551. self.assertIn('<strong>Create new Project</strong>', output_text)
  552. self.assertNotIn(
  553. '<small>\n This field is required.&nbsp;\n'
  554. ' </small>', output_text)
  555. data['csrf_token'] = csrf_token
  556. output = self.app.post('/new/', data=data)
  557. self.assertEqual(output.status_code, 200)
  558. output_text = output.get_data(as_text=True)
  559. self.assertIn('<strong>Create new Project</strong>', output_text)
  560. self.assertIn(
  561. 'No user '
  562. '&#34;username&#34; found',
  563. output_text)
  564. user.username = 'foo'
  565. with tests.user_set(self.app.application, user):
  566. data['csrf_token'] = csrf_token
  567. output = self.app.post('/new/', data=data, follow_redirects=True)
  568. self.assertEqual(output.status_code, 200)
  569. output_text = output.get_data(as_text=True)
  570. self.assertIn(
  571. '<div class="projectinfo my-3">\nProject #1',
  572. output_text)
  573. self.assertIn('<p>This repo is brand new!</p>',
  574. output_text)
  575. self.assertIn(
  576. '<title>Overview - foo/project-1 - Pagure</title>', output_text)
  577. # After
  578. projects = pagure.lib.query.search_projects(self.session)
  579. self.assertEqual(len(projects), 0)
  580. projects = pagure.lib.query.search_projects(self.session, private=True)
  581. self.assertEqual(len(projects), 1)
  582. self.assertTrue(os.path.exists(
  583. os.path.join(self.path, 'repos', 'foo', 'project-1.git')))
  584. self.assertTrue(os.path.exists(
  585. os.path.join(self.path, 'repos', 'tickets', 'foo', 'project-1.git')))
  586. self.assertTrue(os.path.exists(
  587. os.path.join(self.path, 'repos', 'docs', 'foo', 'project-1.git')))
  588. self.assertTrue(os.path.exists(
  589. os.path.join(self.path, 'repos', 'requests', 'foo', 'project-1.git')))
  590. def test_non_ascii_new_project(self):
  591. """ Test the new_project endpoint with a non-ascii project. """
  592. # Before
  593. projects = pagure.lib.query.search_projects(self.session)
  594. self.assertEqual(len(projects), 0)
  595. self.assertFalse(os.path.exists(
  596. os.path.join(self.path, 'repos', 'project-1.git')))
  597. self.assertFalse(os.path.exists(
  598. os.path.join(self.path, 'repos', 'tickets', 'project-1.git')))
  599. self.assertFalse(os.path.exists(
  600. os.path.join(self.path, 'repos', 'docs', 'project-1.git')))
  601. self.assertFalse(os.path.exists(
  602. os.path.join(self.path, 'repos', 'requests', 'project-1.git')))
  603. user = tests.FakeUser()
  604. user.username = 'foo'
  605. with tests.user_set(self.app.application, user):
  606. output = self.app.get('/new/')
  607. self.assertEqual(output.status_code, 200)
  608. output_text = output.get_data(as_text=True)
  609. self.assertIn(
  610. '<strong>Create new Project</strong>', output_text)
  611. csrf_token = output_text.split(
  612. 'name="csrf_token" type="hidden" value="')[1].split('">')[0]
  613. data = {
  614. 'description': 'Prõjéctö #1',
  615. 'name': 'project-1',
  616. 'csrf_token': csrf_token,
  617. 'create_readme': True,
  618. }
  619. output = self.app.post('/new/', data=data, follow_redirects=True)
  620. self.assertEqual(output.status_code, 200)
  621. output_text = output.get_data(as_text=True)
  622. self.assertIn(
  623. '<div class="projectinfo my-3">\nPrõjéctö #1',
  624. output_text)
  625. self.assertIn(
  626. '''<section class="readme">
  627. <h1>project-1</h1>
  628. <p>Prõjéctö #1</p>
  629. </section>''',
  630. output_text)
  631. data = {
  632. 'description': 'Мой первый суперский репозиторий',
  633. 'name': 'project-2',
  634. 'csrf_token': csrf_token,
  635. 'create_readme': True,
  636. }
  637. output = self.app.post('/new/', data=data, follow_redirects=True)
  638. self.assertEqual(output.status_code, 200)
  639. output_text = output.get_data(as_text=True)
  640. self.assertIn(
  641. '<div class="projectinfo my-3">\nМой первый суперский репозиторий',
  642. output_text)
  643. self.assertIn(
  644. '''<section class="readme">
  645. <h1>project-2</h1>
  646. <p>Мой первый суперский репозиторий</p>
  647. </section>''',
  648. output_text)
  649. # After
  650. projects = pagure.lib.query.search_projects(self.session)
  651. self.assertEqual(len(projects), 2)
  652. for project in ['project-1', 'project-2']:
  653. self.assertTrue(os.path.exists(
  654. os.path.join(self.path, 'repos', '%s.git' % project)))
  655. self.assertTrue(os.path.exists(
  656. os.path.join(self.path, 'repos', 'tickets', '%s.git' % project)))
  657. self.assertTrue(os.path.exists(
  658. os.path.join(self.path, 'repos', 'docs', '%s.git' % project)))
  659. self.assertTrue(os.path.exists(
  660. os.path.join(self.path, 'repos', 'requests', '%s.git' % project)))
  661. @patch('pygit2.init_repository', wraps=pygit2.init_repository)
  662. def test_new_project_with_template(self, pygit2init):
  663. """ Test the new_project endpoint for a new project with a template set.
  664. """
  665. # Before
  666. projects = pagure.lib.query.search_projects(self.session)
  667. self.assertEqual(len(projects), 0)
  668. self.assertFalse(os.path.exists(
  669. os.path.join(self.path, 'repos', 'project-1.git')))
  670. self.assertFalse(os.path.exists(
  671. os.path.join(self.path, 'repos', 'tickets', 'project-1.git')))
  672. self.assertFalse(os.path.exists(
  673. os.path.join(self.path, 'repos', 'docs', 'project-1.git')))
  674. self.assertFalse(os.path.exists(
  675. os.path.join(self.path, 'repos', 'requests', 'project-1.git')))
  676. user = tests.FakeUser()
  677. user.username = 'foo'
  678. with tests.user_set(self.app.application, user):
  679. output = self.app.get('/new/')
  680. self.assertEqual(output.status_code, 200)
  681. self.assertIn(
  682. '<strong>Create new Project</strong>', output.get_data(as_text=True))
  683. csrf_token = self.get_csrf(output=output)
  684. data = {
  685. 'description': 'test',
  686. 'name': 'project-1',
  687. 'csrf_token': csrf_token,
  688. 'create_readme': True,
  689. }
  690. output = self.app.post('/new/', data=data, follow_redirects=True)
  691. self.assertEqual(output.status_code, 200)
  692. self.assertIn(
  693. '<div class="projectinfo my-3">\ntest',
  694. output.get_data(as_text=True))
  695. self.assertEqual(pygit2init.call_count, 4)
  696. pygit2init.assert_any_call(
  697. '%s/repos/project-1.git' % self.path,
  698. bare=True, template_path=None)
  699. path = os.path.join(self.path, 'repos', 'project-1.git')
  700. with patch.dict(
  701. 'pagure.config.config',
  702. {'PROJECT_TEMPLATE_PATH': path}):
  703. data = {
  704. 'description': 'test2',
  705. 'name': 'project-2',
  706. 'csrf_token': csrf_token,
  707. 'create_readme': True,
  708. }
  709. output = self.app.post('/new/', data=data, follow_redirects=True)
  710. self.assertEqual(output.status_code, 200)
  711. self.assertIn(
  712. '<div class="projectinfo my-3">\ntest2',
  713. output.get_data(as_text=True))
  714. self.assertEqual(pygit2init.call_count, 8)
  715. pygit2init.assert_any_call(
  716. '%s/repos/project-2.git' % self.path,
  717. bare=True,
  718. template_path='%s/repos/project-1.git' % self.path)
  719. # After
  720. projects = pagure.lib.query.search_projects(self.session)
  721. self.assertEqual(len(projects), 2)
  722. for project in ['project-1', 'project-2']:
  723. self.assertTrue(os.path.exists(
  724. os.path.join(self.path, 'repos', '%s.git' % project)))
  725. self.assertTrue(os.path.exists(
  726. os.path.join(self.path, 'repos', 'tickets', '%s.git' % project)))
  727. self.assertTrue(os.path.exists(
  728. os.path.join(self.path, 'repos', 'docs', '%s.git' % project)))
  729. self.assertTrue(os.path.exists(
  730. os.path.join(self.path, 'repos', 'requests', '%s.git' % project)))
  731. @patch.dict('pagure.config.config', {'CASE_SENSITIVE': True})
  732. def test_new_project_case_sensitive(self):
  733. tests.create_projects(self.session)
  734. tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
  735. output = self.app.get('/test')
  736. self.assertEqual(output.status_code, 200)
  737. output = self.app.get('/TEST')
  738. self.assertEqual(output.status_code, 404)
  739. user = tests.FakeUser()
  740. user.username = 'foo'
  741. with tests.user_set(self.app.application, user):
  742. output = self.app.get('/new/')
  743. self.assertEqual(output.status_code, 200)
  744. csrf_token = self.get_csrf(output=output)
  745. data = {
  746. 'description': 'TEST',
  747. 'name': 'TEST',
  748. 'csrf_token': csrf_token,
  749. 'create_readme': True,
  750. }
  751. self.app.post('/new/', data=data, follow_redirects=True)
  752. output = self.app.get('/TEST')
  753. self.assertEqual(output.status_code, 200)
  754. @patch('pagure.ui.app.admin_session_timedout')
  755. def test_user_settings(self, ast):
  756. """ Test the user_settings endpoint. """
  757. ast.return_value = False
  758. self.test_new_project()
  759. user = tests.FakeUser()
  760. with tests.user_set(self.app.application, user):
  761. output = self.app.get('/settings/')
  762. self.assertEqual(output.status_code, 404)
  763. self.assertIn('<h2>Page not found (404)</h2>', output.get_data(as_text=True))
  764. user.username = 'foo'
  765. with tests.user_set(self.app.application, user):
  766. output = self.app.get('/settings/')
  767. self.assertEqual(output.status_code, 200)
  768. output_text = output.get_data(as_text=True)
  769. self.assertIn(
  770. '<title>foo\'s settings - Pagure</title>', output_text)
  771. ast.return_value = True
  772. output = self.app.get('/settings/')
  773. self.assertEqual(output.status_code, 302)
  774. @patch('pagure.decorators.admin_session_timedout')
  775. def test_add_user_sshkey(self, ast):
  776. """ Test the add_user_sshkey endpoint. """
  777. ast.return_value = False
  778. # User not logged in
  779. output = self.app.get('/settings/')
  780. self.assertEqual(output.status_code, 302)
  781. ast.return_value = False
  782. user = tests.FakeUser(username='pingou')
  783. with tests.user_set(self.app.application, user):
  784. output = self.app.get('/settings', follow_redirects=True)
  785. self.assertEqual(output.status_code, 200)
  786. output_text = output.get_data(as_text=True)
  787. self.assertIn('<strong>Add SSH key', output_text)
  788. csrf_token = self.get_csrf(output=output)
  789. data = {
  790. 'ssh_key': 'asdf',
  791. }
  792. # No CSRF token
  793. output = self.app.post(
  794. '/settings/usersettings/addkey', data=data , follow_redirects=True)
  795. self.assertEqual(output.status_code, 200)
  796. output_text = output.get_data(as_text=True)
  797. self.assertIn('<strong>Add SSH key', output_text)
  798. data['csrf_token'] = csrf_token
  799. # First, invalid SSH key
  800. output = self.app.post(
  801. '/settings/usersettings/addkey', data=data, follow_redirects=True)
  802. self.assertEqual(output.status_code, 200)
  803. output_text = output.get_data(as_text=True)
  804. self.assertIn('<strong>Add SSH key', output_text)
  805. self.assertIn('SSH key invalid', output_text)
  806. # Next up, multiple SSH keys
  807. data['ssh_key'] = 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDAzBMSIlvPRaEiLOTVInErkRIw9CzQQcnslDekAn1jFnGf+SNa1acvbTiATbCX71AA03giKrPxPH79dxcC7aDXerc6zRcKjJs6MAL9PrCjnbyxCKXRNNZU5U9X/DLaaL1b3caB+WD6OoorhS3LTEtKPX8xyjOzhf3OQSzNjhJp5Q==\nssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDAzBMSIlvPRaEiLOTVInErkRIw9CzQQcnslDekAn1jFnGf+SNa1acvbTiATbCX71AA03giKrPxPH79dxcC7aDXerc6zRcKjJs6MAL9PrCjnbyxCKXRNNZU5U9X/DLaaL1b3caB+WD6OoorhS3LTEtKPX8xyjOzhf3OQSzNjhJp5Q=='
  808. output = self.app.post(
  809. '/settings/usersettings/addkey', data=data, follow_redirects=True)
  810. self.assertEqual(output.status_code, 200)
  811. output_text = output.get_data(as_text=True)
  812. self.assertIn('Please add single SSH keys.', output_text)
  813. # Now, a valid SSH key
  814. data['ssh_key'] = 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDAzBMSIlvPRaEiLOTVInErkRIw9CzQQcnslDekAn1jFnGf+SNa1acvbTiATbCX71AA03giKrPxPH79dxcC7aDXerc6zRcKjJs6MAL9PrCjnbyxCKXRNNZU5U9X/DLaaL1b3caB+WD6OoorhS3LTEtKPX8xyjOzhf3OQSzNjhJp5Q=='
  815. output = self.app.post(
  816. '/settings/usersettings/addkey', data=data, follow_redirects=True)
  817. self.assertEqual(output.status_code, 200)
  818. output_text = output.get_data(as_text=True)
  819. self.assertIn(
  820. "<title>pingou's settings - Pagure</title>", output_text)
  821. self.assertIn('SSH key added', output_text)
  822. self.assertNotIn('Push Access', output_text)
  823. # And now, adding the same key
  824. output = self.app.post(
  825. '/settings/usersettings/addkey', data=data, follow_redirects=True)
  826. self.assertEqual(output.status_code, 200)
  827. output_text = output.get_data(as_text=True)
  828. self.assertIn('SSH key already exists', output_text)
  829. # And next, a key with push access
  830. data['ssh_key'] = 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQC9Xwc2RDzPBhlEDARfHldGjudIVoa04tqT1JVKGQmyllTFz7Rb8CngQL3e7zyNzotnhwYKHdoiLlPkVEiDee4dWMUe48ilqId+FJZQGhyv8fu4BoFdE1AJUVylzmltbLg14VqG5gjTpXgtlrEva9arKwBMHJjRYc8ScaSn3OgyQw=='
  831. output = self.app.post(
  832. '/settings/usersettings/addkey', data=data, follow_redirects=True)
  833. self.assertEqual(output.status_code, 200)
  834. output_text = output.get_data(as_text=True)
  835. self.assertIn(
  836. "<title>pingou's settings - Pagure</title>", output_text)
  837. self.assertIn('SSH key added', output_text)
  838. @patch('pagure.decorators.admin_session_timedout')
  839. def test_remove_user_sshkey(self, ast):
  840. """ Test the remove_sshkey endpoint. """
  841. ast.return_value = False
  842. user = tests.FakeUser()
  843. # User not logged in
  844. output = self.app.post('/settings/usersettings/removekey/1')
  845. self.assertEqual(output.status_code, 302)
  846. user.username = 'pingou'
  847. with tests.user_set(self.app.application, user):
  848. data = {'csrf_token': self.get_csrf()}
  849. output = self.app.post(
  850. '/settings/usersettings/removekey/1', data=data, follow_redirects=True)
  851. self.assertEqual(output.status_code, 200)
  852. output_text = output.get_data(as_text=True)
  853. self.assertIn(
  854. "<title>pingou's settings - Pagure</title>", output_text)
  855. self.assertIn('SSH key does not exist', output_text)
  856. # Add a deploy key to a project
  857. pingou = pagure.lib.query.get_user(self.session, 'pingou')
  858. msg = pagure.lib.query.add_sshkey_to_project_or_user(
  859. session=self.session,
  860. ssh_key='ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDAzBMSIlvPRaEiLOTVInErkRIw9CzQQcnslDekAn1jFnGf+SNa1acvbTiATbCX71AA03giKrPxPH79dxcC7aDXerc6zRcKjJs6MAL9PrCjnbyxCKXRNNZU5U9X/DLaaL1b3caB+WD6OoorhS3LTEtKPX8xyjOzhf3OQSzNjhJp5Q==',
  861. user=pingou,
  862. pushaccess=True,
  863. creator=pingou,
  864. )
  865. self.session.commit()
  866. self.assertEqual(msg, 'SSH key added')
  867. with tests.user_set(self.app.application, user):
  868. output = self.app.post('/settings/usersettings/removekey/1', follow_redirects=True)
  869. self.assertEqual(output.status_code, 200)
  870. output_text = output.get_data(as_text=True)
  871. self.assertIn(
  872. "<title>pingou's settings - Pagure</title>", output_text)
  873. self.assertNotIn('SSH key removed', output_text)
  874. data = {'csrf_token': self.get_csrf()}
  875. output = self.app.post(
  876. '/settings/usersettings/removekey/1', data=data, follow_redirects=True)
  877. self.assertEqual(output.status_code, 200)
  878. output_text = output.get_data(as_text=True)
  879. self.assertIn(
  880. "<title>pingou's settings - Pagure</title>", output_text)
  881. self.assertIn('SSH key removed', output_text)
  882. def patched_commit_exists(user, namespace, repo, githash):
  883. ''' Patched version of pagure.pfmarkdown._commit_exists to enforce
  884. returning true on some given hash without having us actually check
  885. the git repos.
  886. '''
  887. if githash in ['9364354', '9364354a', '9364354a4555ba17aa60f0dc844d70b74eb1aecd']:
  888. return True
  889. else:
  890. return False
  891. @patch(
  892. 'pagure.pfmarkdown._commit_exists',
  893. MagicMock(side_effect=patched_commit_exists))
  894. def test_patched_markdown_preview(self):
  895. """ Test the markdown_preview endpoint. """
  896. data = {
  897. 'content': 'test\n----\n\n * 1\n * item 2'
  898. }
  899. # CSRF missing
  900. output = self.app.post('/markdown/', data=data)
  901. self.assertEqual(output.status_code, 400)
  902. user = tests.FakeUser()
  903. user.username = 'foo'
  904. with tests.user_set(self.app.application, user):
  905. output = self.app.get('/settings/')
  906. self.assertEqual(output.status_code, 200)
  907. output_text = output.get_data(as_text=True)
  908. self.assertIn(
  909. '<title>foo\'s settings - Pagure</title>', output_text)
  910. csrf_token = self.get_csrf(output=output)
  911. # With CSRF
  912. data['csrf_token'] = csrf_token
  913. output = self.app.post('/markdown/', data=data)
  914. self.assertEqual(output.status_code, 200)
  915. exp = """<h2>test</h2>
  916. <ul>
  917. <li>1</li>
  918. <li>item 2</li>
  919. </ul>"""
  920. self.assertEqual(output.get_data(as_text=True), exp)
  921. tests.create_projects(self.session)
  922. texts = [
  923. 'pingou committed on test#9364354a4555ba17aa60f0dc844d70b74eb1aecd',
  924. 'Cf commit 936435', # 6 chars - not long enough
  925. 'Cf commit 9364354', # 7 chars - long enough
  926. 'Cf commit 9364354a', # 8 chars - still long enough
  927. 'Cf commit 9364354a4555ba17aa60f0dc844d70b74eb1aecd', # 40 chars
  928. ]
  929. expected = [
  930. # 'pingou committed on test#9364354a4555ba17aa60f0dc844d70b74eb1aecd',
  931. '<p>pingou committed on <a href="/test/c/9364354a4555ba17aa60f0dc844d70b74eb1aecd" '
  932. 'title="Commit 9364354a4555ba17aa60f0dc844d70b74eb1aecd"'
  933. '>test#9364354a4555ba17aa60f0dc844d70b74eb1aecd</a></p>',
  934. # 'Cf commit 936435',
  935. '<p>Cf commit 936435</p>',
  936. # 'Cf commit 9364354',
  937. #'<p>Cf commit 9364354</p>',
  938. '<p>Cf commit <a href="/test/c/9364354" '
  939. 'title="Commit 9364354">9364354</a></p>',
  940. # 'Cf commit 9364354a',
  941. '<p>Cf commit <a href="/test/c/9364354a" '
  942. 'title="Commit 9364354a">9364354</a></p>',
  943. # 'Cf commit 9364354a4555ba17aa60f0dc844d70b74eb1aecd',
  944. '<p>Cf commit <a href="/test/c/9364354a4555ba17aa60f0dc844d70b74eb1aecd" '
  945. 'title="Commit 9364354a4555ba17aa60f0dc844d70b74eb1aecd"'
  946. '>9364354</a></p>',
  947. ]
  948. with self.app.application.app_context():
  949. for idx, text in enumerate(texts):
  950. data = {
  951. 'content': text,
  952. 'csrf_token': csrf_token,
  953. }
  954. output = self.app.post('/markdown/?repo=test', data=data)
  955. self.assertEqual(output.status_code, 200)
  956. self.assertEqual(expected[idx], output.get_data(as_text=True))
  957. def test_markdown_preview(self):
  958. """ Test the markdown_preview endpoint with a non-existing commit.
  959. """
  960. user = tests.FakeUser()
  961. user.username = 'foo'
  962. with tests.user_set(self.app.application, user):
  963. output = self.app.get('/settings/')
  964. self.assertEqual(output.status_code, 200)
  965. output_text = output.get_data(as_text=True)
  966. self.assertIn(
  967. '<title>foo\'s settings - Pagure</title>', output_text)
  968. csrf_token = self.get_csrf(output=output)
  969. tests.create_projects(self.session)
  970. tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
  971. text = 'Cf commit 9364354a4555ba17aa60f0d'
  972. exp = '<p>Cf commit 9364354a4555ba17aa60f0d</p>'
  973. with self.app.application.app_context():
  974. data = {
  975. 'content': text,
  976. 'csrf_token': csrf_token,
  977. }
  978. output = self.app.post('/markdown/?repo=test', data=data)
  979. self.assertEqual(output.status_code, 200)
  980. self.assertEqual(exp, output.get_data(as_text=True))
  981. def test_markdown_preview_valid_commit(self):
  982. """ Test the markdown_preview endpoint with an existing commit. """
  983. user = tests.FakeUser()
  984. user.username = 'foo'
  985. with tests.user_set(self.app.application, user):
  986. output = self.app.get('/settings/')
  987. self.assertEqual(output.status_code, 200)
  988. output_text = output.get_data(as_text=True)
  989. self.assertIn(
  990. '<title>foo\'s settings - Pagure</title>', output_text)
  991. csrf_token = self.get_csrf(output=output)
  992. tests.create_projects(self.session)
  993. tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
  994. repopath = os.path.join(self.path, 'repos', 'test.git')
  995. tests.add_content_git_repo(repopath)
  996. repo = pygit2.Repository(repopath)
  997. first_commit = repo.revparse_single('HEAD')
  998. text = 'Cf commit %s' % first_commit.oid.hex
  999. exp = '<p>Cf commit <a href="/test/c/{0}" title="Commit {0}">{1}'\
  1000. '</a></p>'.format(first_commit.oid.hex, first_commit.oid.hex[:7])
  1001. with self.app.application.app_context():
  1002. data = {
  1003. 'content': text,
  1004. 'csrf_token': csrf_token,
  1005. }
  1006. output = self.app.post('/markdown/?repo=test', data=data)
  1007. self.assertEqual(output.status_code, 200)
  1008. self.assertEqual(exp, output.get_data(as_text=True))
  1009. @patch('pagure.ui.app.admin_session_timedout')
  1010. def test_remove_user_email(self, ast):
  1011. """ Test the remove_user_email endpoint. """
  1012. ast.return_value = False
  1013. self.test_new_project()
  1014. user = tests.FakeUser()
  1015. with tests.user_set(self.app.application, user):
  1016. output = self.app.post('/settings/email/drop')
  1017. self.assertEqual(output.status_code, 404)
  1018. self.assertIn('<h2>Page not found (404)</h2>', output.get_data(as_text=True))
  1019. user.username = 'foo'
  1020. with tests.user_set(self.app.application, user):
  1021. output = self.app.get('/settings/')
  1022. self.assertEqual(output.status_code, 200)
  1023. output_text = output.get_data(as_text=True)
  1024. self.assertIn(
  1025. '<title>foo\'s settings - Pagure</title>', output_text)
  1026. csrf_token = self.get_csrf(output=output)
  1027. data = {
  1028. 'email': 'foo@pingou.com',
  1029. }
  1030. output = self.app.post(
  1031. '/settings/email/drop', data=data, follow_redirects=True)
  1032. self.assertEqual(output.status_code, 200)
  1033. output_text = output.get_data(as_text=True)
  1034. self.assertIn(
  1035. '<title>foo\'s settings - Pagure</title>', output_text)
  1036. self.assertIn(
  1037. 'You must always have at '
  1038. 'least one email', output_text)
  1039. user.username = 'pingou'
  1040. with tests.user_set(self.app.application, user):
  1041. output = self.app.get('/settings/')
  1042. self.assertEqual(output.status_code, 200)
  1043. output_text = output.get_data(as_text=True)
  1044. self.assertIn(
  1045. '<title>pingou\'s settings - Pagure</title>', output_text)
  1046. csrf_token = self.get_csrf(output=output)
  1047. data = {
  1048. 'email': 'foo@pingou.com',
  1049. }
  1050. output = self.app.post(
  1051. '/settings/email/drop', data=data, follow_redirects=True)
  1052. self.assertEqual(output.status_code, 200)
  1053. output_text = output.get_data(as_text=True)
  1054. self.assertIn(
  1055. '<title>pingou\'s settings - Pagure</title>', output_text)
  1056. self.assertEqual(output_text.count('foo@pingou.com'), 4)
  1057. data = {
  1058. 'csrf_token': csrf_token,
  1059. 'email': 'foobar@pingou.com',
  1060. }
  1061. output = self.app.post(
  1062. '/settings/email/drop', data=data, follow_redirects=True)
  1063. self.assertEqual(output.status_code, 200)
  1064. output_text = output.get_data(as_text=True)
  1065. self.assertIn(
  1066. '<title>pingou\'s settings - Pagure</title>', output_text)
  1067. self.assertIn(
  1068. 'You do not have the '
  1069. 'email: foobar@pingou.com, nothing to remove', output_text)
  1070. data = {
  1071. 'csrf_token': csrf_token,
  1072. 'email': 'foo@pingou.com',
  1073. }
  1074. output = self.app.post(
  1075. '/settings/email/drop', data=data, follow_redirects=True)
  1076. self.assertEqual(output.status_code, 200)
  1077. output_text = output.get_data(as_text=True)
  1078. self.assertEqual(output_text.count('foo@pingou.com'), 0)
  1079. self.assertEqual(output_text.count('bar@pingou.com'), 3)
  1080. output = self.app.post(
  1081. '/settings/email/drop', data=data, follow_redirects=True)
  1082. self.assertEqual(output.status_code, 200)
  1083. output_text = output.get_data(as_text=True)
  1084. self.assertEqual(output_text.count('foo@pingou.com'), 0)
  1085. self.assertEqual(output_text.count('bar@pingou.com'), 3)
  1086. ast.return_value = True
  1087. output = self.app.post('/settings/email/drop', data=data)
  1088. self.assertEqual(output.status_code, 302)
  1089. @patch('pagure.lib.notify.send_email')
  1090. @patch('pagure.ui.app.admin_session_timedout')
  1091. def test_add_api_user_email(self, ast, send_email):
  1092. """ Test the add_api_user_email endpoint. """
  1093. send_email.return_value = True
  1094. ast.return_value = False
  1095. self.test_new_project()
  1096. user = tests.FakeUser()
  1097. with tests.user_set(self.app.application, user):
  1098. output = self.app.post('/settings/email/add')
  1099. self.assertEqual(output.status_code, 404)
  1100. self.assertIn('<h2>Page not found (404)</h2>', output.get_data(as_text=True))
  1101. user.username = 'foo'
  1102. with tests.user_set(self.app.application, user):
  1103. output = self.app.post('/settings/email/add')
  1104. self.assertEqual(output.status_code, 200)
  1105. output_text = output.get_data(as_text=True)
  1106. self.assertIn("<strong>Add new email</strong>", output_text)
  1107. if self.get_wtforms_version() >= (2, 2):
  1108. self.assertIn(
  1109. '<input class="form-control form-control-error" id="email" '
  1110. 'name="email" required type="text" value="">', output_text)
  1111. else:
  1112. self.assertIn(
  1113. '<input class="form-control form-control-error" id="email" '
  1114. 'name="email" type="text" value="">', output_text)
  1115. user.username = 'pingou'
  1116. with tests.user_set(self.app.application, user):
  1117. output = self.app.post('/settings/email/add')
  1118. self.assertEqual(output.status_code, 200)
  1119. output_text = output.get_data(as_text=True)
  1120. self.assertIn("<strong>Add new email</strong>", output_text)
  1121. if self.get_wtforms_version() >= (2, 2):
  1122. self.assertIn(
  1123. '<input class="form-control form-control-error" id="email" '
  1124. 'name="email" required type="text" value="">', output_text)
  1125. else:
  1126. self.assertIn(
  1127. '<input class="form-control form-control-error" id="email" '
  1128. 'name="email" type="text" value="">', output_text)
  1129. csrf_token = output_text.split(
  1130. 'name="csrf_token" type="hidden" value="')[1].split('">')[0]
  1131. data = {
  1132. 'email': 'foo2@pingou.com',
  1133. }
  1134. output = self.app.post(
  1135. '/settings/email/add', data=data, follow_redirects=True)
  1136. self.assertEqual(output.status_code, 200)
  1137. output_text = output.get_data(as_text=True)
  1138. self.assertIn("<strong>Add new email</strong>", output_text)
  1139. self.assertEqual(output_text.count('foo2@pingou.com'), 1)
  1140. # New email
  1141. data = {
  1142. 'csrf_token': csrf_token,
  1143. 'email': 'foðbar@pingou.com',
  1144. }
  1145. output = self.app.post(
  1146. '/settings/email/add', data=data, follow_redirects=True)
  1147. self.assertEqual(output.status_code, 200)
  1148. output_text = output.get_data(as_text=True)
  1149. self.assertIn(
  1150. '<title>pingou\'s settings - Pagure</title>', output_text)
  1151. self.assertIn(
  1152. 'Email pending validation',
  1153. output_text)
  1154. self.assertEqual(output_text.count('foo@pingou.com'), 4)
  1155. self.assertEqual(output_text.count('bar@pingou.com'), 5)
  1156. self.assertEqual(output_text.count('foðbar@pingou.com'), 2)
  1157. # Email already pending
  1158. output = self.app.post(
  1159. '/settings/email/add', data=data, follow_redirects=True)
  1160. self.assertEqual(output.status_code, 200)
  1161. output_text = output.get_data(as_text=True)
  1162. self.assertIn(
  1163. '<div class="card-header">\n '
  1164. '<strong>Add new email</strong>', output_text)
  1165. self.assertIn(
  1166. 'This email is already '
  1167. 'pending confirmation', output_text)
  1168. # User already has this email
  1169. data = {
  1170. 'csrf_token': csrf_token,
  1171. 'email': 'foo@pingou.com',
  1172. }
  1173. output = self.app.post(
  1174. '/settings/email/add', data=data, follow_redirects=True)
  1175. self.assertEqual(output.status_code, 200)
  1176. output_text = output.get_data(as_text=True)
  1177. self.assertTrue("<strong>Add new email</strong>" in output_text)
  1178. self.assertTrue(
  1179. 'Invalid value, can&#39;t be any of: bar@pingou.com, '
  1180. 'foo@pingou.com.&nbsp;' in output_text
  1181. or
  1182. 'Invalid value, can&#39;t be any of: foo@pingou.com, '
  1183. 'bar@pingou.com.&nbsp;' in output_text
  1184. )
  1185. self.assertEqual(
  1186. output_text.count('foo@pingou.com'), 6)
  1187. self.assertEqual(
  1188. output_text.count('bar@pingou.com'), 5)
  1189. self.assertEqual(
  1190. output_text.count('foðbar@pingou.com'), 0)
  1191. # Email registered by someone else
  1192. data = {
  1193. 'csrf_token': csrf_token,
  1194. 'email': 'foo@bar.com',
  1195. }
  1196. output = self.app.post(
  1197. '/settings/email/add', data=data, follow_redirects=True)
  1198. self.assertEqual(output.status_code, 200)
  1199. output_text = output.get_data(as_text=True)
  1200. self.assertTrue("<strong>Add new email</strong>" in output_text)
  1201. self.assertIn(
  1202. 'Invalid value, can&#39;t be any of: foo@bar.com.&nbsp;',
  1203. output_text)
  1204. ast.return_value = True
  1205. output = self.app.post('/settings/email/add', data=data)
  1206. self.assertEqual(output.status_code, 302)
  1207. @patch('pagure.lib.notify.send_email')
  1208. @patch('pagure.ui.app.admin_session_timedout')
  1209. def test_set_default_email(self, ast, send_email):
  1210. """ Test the set_default_email endpoint. """
  1211. send_email.return_value = True
  1212. ast.return_value = False
  1213. self.test_new_project()
  1214. user = tests.FakeUser()
  1215. with tests.user_set(self.app.application, user):
  1216. output = self.app.post('/settings/email/default')
  1217. self.assertEqual(output.status_code, 404)
  1218. self.assertTrue('<h2>Page not found (404)</h2>' in output.get_data(as_text=True))
  1219. user.username = 'pingou'
  1220. with tests.user_set(self.app.application, user):
  1221. output = self.app.get('/settings/')
  1222. self.assertEqual(output.status_code, 200)
  1223. output_text = output.get_data(as_text=True)
  1224. self.assertIn(
  1225. '<title>pingou\'s settings - Pagure</title>', output_text)
  1226. csrf_token = self.get_csrf(output=output)
  1227. data = {
  1228. 'email': 'foo@pingou.com',
  1229. }
  1230. output = self.app.post(
  1231. '/settings/email/default', data=data, follow_redirects=True)
  1232. self.assertEqual(output.status_code, 200)
  1233. output_text = output.get_data(as_text=True)
  1234. self.assertIn(
  1235. '<title>pingou\'s settings - Pagure</title>', output_text)
  1236. self.assertEqual(output_text.count('foo@pingou.com'), 4)
  1237. # Set invalid default email
  1238. data = {
  1239. 'csrf_token': csrf_token,
  1240. 'email': 'foobar@pingou.com',
  1241. }
  1242. output = self.app.post(
  1243. '/settings/email/default', data=data, follow_redirects=True)
  1244. self.assertEqual(output.status_code, 200)
  1245. output_text = output.get_data(as_text=True)
  1246. self.assertIn(
  1247. '<title>pingou\'s settings - Pagure</title>', output_text)
  1248. self.assertEqual(output_text.count('foo@pingou.com'), 4)
  1249. self.assertIn(
  1250. 'You do not have the '
  1251. 'email: foobar@pingou.com, nothing to set',
  1252. output_text)
  1253. # Set default email
  1254. data = {
  1255. 'csrf_token': csrf_token,
  1256. 'email': 'foo@pingou.com',
  1257. }
  1258. output = self.app.post(
  1259. '/settings/email/default', data=data, follow_redirects=True)
  1260. self.assertEqual(output.status_code, 200)
  1261. output_text = output.get_data(as_text=True)
  1262. self.assertIn(
  1263. '<title>pingou\'s settings - Pagure</title>', output_text)
  1264. self.assertEqual(output_text.count('foo@pingou.com'), 4)
  1265. self.assertIn(
  1266. 'Default email set to: '
  1267. 'foo@pingou.com', output_text)
  1268. ast.return_value = True
  1269. output = self.app.post('/settings/email/default', data=data)
  1270. self.assertEqual(output.status_code, 302)
  1271. @patch('pagure.lib.notify.send_email')
  1272. @patch('pagure.ui.app.admin_session_timedout')
  1273. def test_reconfirm_email(self, ast, send_email):
  1274. """ Test the reconfirm_email endpoint. """
  1275. send_email.return_value = True
  1276. ast.return_value = False
  1277. self.test_new_project()
  1278. # Add a pending email to pingou
  1279. userobj = pagure.lib.query.search_user(self.session, username='pingou')
  1280. self.assertEqual(len(userobj.emails), 2)
  1281. email_pend = pagure.lib.model.UserEmailPending(
  1282. user_id=userobj.id,
  1283. email='foo@fp.o',
  1284. token='abcdef',
  1285. )
  1286. self.session.add(email_pend)
  1287. self.session.commit()
  1288. user = tests.FakeUser()
  1289. with tests.user_set(self.app.application, user):
  1290. output = self.app.post('/settings/email/resend')
  1291. self.assertEqual(output.status_code, 404)
  1292. self.assertTrue('<h2>Page not found (404)</h2>' in output.get_data(as_text=True))
  1293. user.username = 'pingou'
  1294. with tests.user_set(self.app.application, user):
  1295. output = self.app.get('/settings/')
  1296. self.assertEqual(output.status_code, 200)
  1297. output_text = output.get_data(as_text=True)
  1298. self.assertIn(
  1299. '<title>pingou\'s settings - Pagure</title>', output_text)
  1300. csrf_token = self.get_csrf(output=output)
  1301. data = {
  1302. 'email': 'foo@pingou.com',
  1303. }
  1304. output = self.app.post(
  1305. '/settings/email/resend', data=data, follow_redirects=True)
  1306. self.assertEqual(output.status_code, 200)
  1307. output_text = output.get_data(as_text=True)
  1308. self.assertIn(
  1309. '<title>pingou\'s settings - Pagure</title>', output_text)
  1310. self.assertEqual(output_text.count('foo@pingou.com'), 4)
  1311. # Set invalid default email
  1312. data = {
  1313. 'csrf_token': csrf_token,
  1314. 'email': 'foobar@pingou.com',
  1315. }
  1316. output = self.app.post(
  1317. '/settings/email/resend', data=data, follow_redirects=True)
  1318. self.assertEqual(output.status_code, 200)
  1319. output_text = output.get_data(as_text=True)
  1320. self.assertIn(
  1321. '<title>pingou\'s settings - Pagure</title>', output_text)
  1322. self.assertEqual(output_text.count('foo@pingou.com'), 4)
  1323. self.assertIn(
  1324. 'This email address has '
  1325. 'already been confirmed', output_text)
  1326. # Validate a non-validated email
  1327. data = {
  1328. 'csrf_token': csrf_token,
  1329. 'email': 'foo@fp.o',
  1330. }
  1331. output = self.app.post(
  1332. '/settings/email/resend', data=data, follow_redirects=True)
  1333. self.assertEqual(output.status_code, 200)
  1334. output_text = output.get_data(as_text=True)
  1335. self.assertIn(
  1336. '<title>pingou\'s settings - Pagure</title>', output_text)
  1337. self.assertEqual(output_text.count('foo@pingou.com'), 4)
  1338. self.assertIn(
  1339. 'Confirmation email re-sent',
  1340. output_text)
  1341. ast.return_value = True
  1342. output = self.app.post('/settings/email/resend', data=data)
  1343. self.assertEqual(output.status_code, 302)
  1344. @patch('pagure.ui.app.admin_session_timedout')
  1345. def test_confirm_email(self, ast):
  1346. """ Test the confirm_email endpoint. """
  1347. output = self.app.get('/settings/email/confirm/foobar')
  1348. self.assertEqual(output.status_code, 302)
  1349. ast.return_value = False
  1350. # Add a pending email to pingou
  1351. userobj = pagure.lib.query.search_user(self.session, username='pingou')
  1352. self.assertEqual(len(userobj.emails), 2)
  1353. email_pend = pagure.lib.model.UserEmailPending(
  1354. user_id=userobj.id,
  1355. email='foo@fp.o',
  1356. token='abcdef',
  1357. )
  1358. self.session.add(email_pend)
  1359. self.session.commit()
  1360. user = tests.FakeUser()
  1361. user.username = 'pingou'
  1362. with tests.user_set(self.app.application, user):
  1363. # Wrong token
  1364. output = self.app.get(
  1365. '/settings/email/confirm/foobar', follow_redirects=True)
  1366. self.assertEqual(output.status_code, 200)
  1367. output_text = output.get_data(as_text=True)
  1368. self.assertIn(
  1369. '<title>pingou\'s settings - Pagure</title>', output_text)
  1370. self.assertIn(
  1371. 'No email associated with this token.',
  1372. output_text)
  1373. # Confirm email
  1374. output = self.app.get(
  1375. '/settings/email/confirm/abcdef', follow_redirects=True)
  1376. self.assertEqual(output.status_code, 200)
  1377. output_text = output.get_data(as_text=True)
  1378. self.assertIn(
  1379. '<title>pingou\'s settings - Pagure</title>', output_text)
  1380. self.assertIn(
  1381. 'Email validated',
  1382. output_text)
  1383. userobj = pagure.lib.query.search_user(self.session, username='pingou')
  1384. self.assertEqual(len(userobj.emails), 3)
  1385. ast.return_value = True
  1386. output = self.app.get('/settings/email/confirm/foobar')
  1387. self.assertEqual(output.status_code, 302)
  1388. def test_view_my_requests_no_user(self):
  1389. """Test the view_user_requests endpoint."""
  1390. output = self.app.get('/user/somenonexistentuser/requests')
  1391. self.assertEqual(output.status_code, 404)
  1392. @patch(
  1393. 'pagure.lib.git.update_git', MagicMock(return_value=True))
  1394. @patch(
  1395. 'pagure.lib.notify.send_email', MagicMock(return_value=True))
  1396. def test_view_my_requests(self):
  1397. """Test the view_user_requests endpoint. """
  1398. # Create the PR
  1399. tests.create_projects(self.session)
  1400. repo = pagure.lib.query._get_project(self.session, 'test')
  1401. req = pagure.lib.query.new_pull_request(
  1402. session=self.session,
  1403. repo_from=repo,
  1404. branch_from='dev',
  1405. repo_to=repo,
  1406. branch_to='master',
  1407. title='test pull-request #1',
  1408. user='pingou',
  1409. )
  1410. self.session.commit()
  1411. self.assertEqual(req.id, 1)
  1412. self.assertEqual(req.title, 'test pull-request #1')
  1413. output = self.app.get('/user/pingou/requests')
  1414. self.assertEqual(output.status_code, 200)
  1415. output_text = output.get_data(as_text=True)
  1416. self.assertIn('test pull-request #1', output_text)
  1417. self.assertEqual(
  1418. output_text.count('pr-status pr-status-open"'),
  1419. 1)
  1420. # Add a PR in a fork
  1421. item = pagure.lib.model.Project(
  1422. user_id=1, # pingou
  1423. name='test_fork',
  1424. description='test project #1',
  1425. is_fork=True,
  1426. parent_id=1,
  1427. hook_token='aaabbbttt',
  1428. )
  1429. self.session.add(item)
  1430. repo = pagure.lib.query._get_project(
  1431. self.session, 'test_fork', user='pingou')
  1432. req = pagure.lib.query.new_pull_request(
  1433. session=self.session,
  1434. repo_from=repo,
  1435. branch_from='dev',
  1436. repo_to=repo,
  1437. branch_to='master',
  1438. title='tést pull-request #2',
  1439. user='pingou',
  1440. )
  1441. self.session.commit()
  1442. self.assertEqual(req.id, 1)
  1443. self.assertEqual(req.title, 'tést pull-request #2')
  1444. output = self.app.get('/user/pingou/requests')
  1445. self.assertEqual(output.status_code, 200)
  1446. output_text = output.get_data(as_text=True)
  1447. self.assertIn('test pull-request #1', output_text)
  1448. self.assertIn('tést pull-request #2', output_text)
  1449. self.assertEqual(
  1450. output_text.count('pr-status pr-status-open"'),
  1451. 2)
  1452. @patch(
  1453. 'pagure.lib.git.update_git', MagicMock(return_value=True))
  1454. @patch(
  1455. 'pagure.lib.notify.send_email', MagicMock(return_value=True))
  1456. def test_view_my_requests_pr_in_another_project(self):
  1457. """Test the view_user_requests endpoint when the user opened a PR
  1458. in another project. """
  1459. # Pingou creates the PR on test
  1460. tests.create_projects(self.session)
  1461. repo = pagure.lib.query._get_project(self.session, 'test')
  1462. req = pagure.lib.query.new_pull_request(
  1463. session=self.session,
  1464. repo_from=repo,
  1465. branch_from='dev',
  1466. repo_to=repo,
  1467. branch_to='master',
  1468. title='test pull-request #1',
  1469. user='pingou',
  1470. )
  1471. self.session.commit()
  1472. self.assertEqual(req.id, 1)
  1473. self.assertEqual(req.title, 'test pull-request #1')
  1474. # foo creates the PR on test
  1475. repo = pagure.lib.query._get_project(self.session, 'test')
  1476. req = pagure.lib.query.new_pull_request(
  1477. session=self.session,
  1478. repo_from=repo,
  1479. branch_from='dev',
  1480. repo_to=repo,
  1481. branch_to='master',
  1482. title='test pull-request #2',
  1483. user='foo',
  1484. )
  1485. self.session.commit()
  1486. self.assertEqual(req.id, 2)
  1487. self.assertEqual(req.title, 'test pull-request #2')
  1488. # Check pingou's PR list
  1489. output = self.app.get('/user/pingou/requests')
  1490. self.assertEqual(output.status_code, 200)
  1491. output_text = output.get_data(as_text=True)
  1492. self.assertIn('test pull-request #1', output_text)
  1493. self.assertIn('test pull-request #2', output_text)
  1494. self.assertEqual(
  1495. output_text.count('pr-status pr-status-open"'),
  1496. 2)
  1497. # Check foo's PR list
  1498. output = self.app.get('/user/foo/requests')
  1499. self.assertEqual(output.status_code, 200)
  1500. output_text = output.get_data(as_text=True)
  1501. self.assertNotIn('test pull-request #1', output_text)
  1502. self.assertIn('test pull-request #2', output_text)
  1503. self.assertEqual(
  1504. output_text.count('pr-status pr-status-open"'),
  1505. 1)
  1506. @patch(
  1507. 'pagure.lib.git.update_git', MagicMock(return_value=True))
  1508. @patch(
  1509. 'pagure.lib.notify.send_email', MagicMock(return_value=True))
  1510. def test_view_my_requests_against_another_project(self):
  1511. """Test the view_user_requests endpoint when there is a PR opened
  1512. by me against a project I do not have rights on. """
  1513. # Create the PR
  1514. tests.create_projects(self.session)
  1515. repo = pagure.lib.query._get_project(self.session, 'test')
  1516. req = pagure.lib.query.new_pull_request(
  1517. session=self.session,
  1518. repo_from=repo,
  1519. branch_from='dev',
  1520. repo_to=repo,
  1521. branch_to='master',
  1522. title='test pull-request #1',
  1523. user='foo',
  1524. )
  1525. self.session.commit()
  1526. self.assertEqual(req.id, 1)
  1527. self.assertEqual(req.title, 'test pull-request #1')
  1528. output = self.app.get('/user/foo/requests')
  1529. self.assertEqual(output.status_code, 200)
  1530. output_text = output.get_data(as_text=True)
  1531. self.assertIn('test pull-request #1', output_text)
  1532. self.assertEqual(
  1533. output_text.count('pr-status pr-status-open"'),
  1534. 1)
  1535. def test_view_my_issues_no_user(self):
  1536. """Test the view_user_issues endpoint with a missing user."""
  1537. output = self.app.get('/user/somenonexistentuser/issues')
  1538. self.assertEqual(output.status_code, 404)
  1539. @patch(
  1540. 'pagure.lib.git.update_git', MagicMock(return_value=True))
  1541. @patch(
  1542. 'pagure.lib.notify.send_email', MagicMock(return_value=True))
  1543. def test_view_my_issues(self):
  1544. """Test the view_user_issues endpoint when the user exists."""
  1545. # Create the issue
  1546. tests.create_projects(self.session)
  1547. repo = pagure.lib.query._get_project(self.session, 'test')
  1548. msg = pagure.lib.query.new_issue(
  1549. session=self.session,
  1550. repo=repo,
  1551. title='Test issue #1',
  1552. content='We should work on this for the second time',
  1553. user='pingou',
  1554. status='Open',
  1555. )
  1556. self.session.commit()
  1557. self.assertEqual(msg.title, 'Test issue #1')
  1558. output = self.app.get('/user/pingou/issues')
  1559. self.assertEqual(output.status_code, 200)
  1560. output_text = output.get_data(as_text=True)
  1561. self.assertIn('Test issue #1', output_text)
  1562. self.assertEqual(
  1563. output_text.count(
  1564. 'issue-status issue-status-open'),
  1565. 1)
  1566. # Add an issue in a fork
  1567. item = pagure.lib.model.Project(
  1568. user_id=2, # foo
  1569. name='test_fork',
  1570. description='test project #1',
  1571. is_fork=True,
  1572. parent_id=1,
  1573. hook_token='aaabbbttt',
  1574. )
  1575. self.session.add(item)
  1576. repo = pagure.lib.query._get_project(self.session, 'test_fork', user='foo')
  1577. msg = pagure.lib.query.new_issue(
  1578. session=self.session,
  1579. repo=repo,
  1580. title='Test issue #2',
  1581. content='We should work on this for the second time',
  1582. user='pingou',
  1583. status='Open',
  1584. )
  1585. self.session.commit()
  1586. self.assertEqual(msg.title, 'Test issue #2')
  1587. # Test the assigned issue table. Create issue then set the assignee
  1588. msg = pagure.lib.query.new_issue(
  1589. session=self.session,
  1590. repo=repo,
  1591. title='Test issue #3',
  1592. content='This issue created by foo, but assigned to pingou',
  1593. user='foo',
  1594. status='Open',
  1595. )
  1596. self.session.commit()
  1597. self.assertEqual(msg.title, 'Test issue #3')
  1598. msg = pagure.lib.query.add_issue_assignee(
  1599. session=self.session,
  1600. issue=msg,
  1601. assignee='pingou',
  1602. user='foo',
  1603. )
  1604. self.session.commit()
  1605. self.assertEqual(msg, 'Issue assigned to pingou')
  1606. output = self.app.get('/user/pingou/issues')
  1607. self.assertEqual(output.status_code, 200)
  1608. output_text = output.get_data(as_text=True)
  1609. self.assertIn('Test issue #1', output_text)
  1610. self.assertIn('Test issue #2', output_text)
  1611. self.assertIn('Test issue #3', output_text)
  1612. self.assertEqual(
  1613. output_text.count(
  1614. 'issue-status issue-status-open'),
  1615. 3)
  1616. @patch(
  1617. 'pagure.lib.git.update_git', MagicMock(return_value=True))
  1618. @patch(
  1619. 'pagure.lib.notify.send_email', MagicMock(return_value=True))
  1620. def test_view_my_issues_disabled(self):
  1621. """Test the view_user_issues endpoint when the project disabled issue
  1622. tracking."""
  1623. # Create the issue
  1624. tests.create_projects(self.session)
  1625. repo = pagure.lib.query._get_project(self.session, 'test')
  1626. msg = pagure.lib.query.new_issue(
  1627. session=self.session,
  1628. repo=repo,
  1629. title='Test issue #1',
  1630. content='We should work on this for the second time',
  1631. user='pingou',
  1632. status='Open',
  1633. )
  1634. self.session.commit()
  1635. self.assertEqual(msg.title, 'Test issue #1')
  1636. # Before
  1637. output = self.app.get('/user/pingou/issues')
  1638. self.assertEqual(output.status_code, 200)
  1639. output_text = output.get_data(as_text=True)
  1640. self.assertIn('Test issue #1', output_text)
  1641. self.assertEqual(
  1642. output_text.count('issue-status issue-status-open'),
  1643. 1)
  1644. # Disable issue tracking
  1645. repo = pagure.lib.query._get_project(self.session, 'test')
  1646. settings = repo.settings
  1647. settings['issue_tracker'] = False
  1648. repo.settings = settings
  1649. self.session.add(repo)
  1650. self.session.commit()
  1651. # After
  1652. output = self.app.get('/user/pingou/issues')
  1653. self.assertEqual(output.status_code, 200)
  1654. output_text = output.get_data(as_text=True)
  1655. self.assertNotIn('Test issue #1', output_text)
  1656. self.assertEqual(
  1657. output_text.count('issue-status issue-status-open'),
  1658. 0)
  1659. def test_view_my_issues_tickets_turned_off(self):
  1660. """Test the view_user_issues endpoint when the user exists and
  1661. and ENABLE_TICKETS is False """
  1662. # Turn off the tickets instance wide
  1663. pagure.config.config['ENABLE_TICKETS'] = False
  1664. output = self.app.get('/user/pingou/issues')
  1665. self.assertEqual(output.status_code, 404)
  1666. pagure.config.config['ENABLE_TICKETS'] = True
  1667. @patch('pagure.ui.app.admin_session_timedout')
  1668. def test_add_user_token(self, ast):
  1669. """ Test the add_user_token endpoint. """
  1670. ast.return_value = False
  1671. self.test_new_project()
  1672. user = tests.FakeUser()
  1673. with tests.user_set(self.app.application, user):
  1674. output = self.app.get('/settings/token/new/')
  1675. self.assertEqual(output.status_code, 404)
  1676. self.assertIn('<h2>Page not found (404)</h2>',
  1677. output.get_data(as_text=True))
  1678. user.username = 'foo'
  1679. with tests.user_set(self.app.application, user):
  1680. output = self.app.get('/settings/token/new')
  1681. self.assertEqual(output.status_code, 200)
  1682. output_text = output.get_data(as_text=True)
  1683. self.assertIn(
  1684. '<div class="card-header">\n <strong>'
  1685. 'Create a new token</strong>\n', output_text)
  1686. self.assertIn(
  1687. '<input type="checkbox" name="acls" value="create_project">',
  1688. output_text)
  1689. csrf_token = output_text.split(
  1690. 'name="csrf_token" type="hidden" value="')[1].split('">')[0]
  1691. data = {
  1692. 'acls': ['create_project', 'fork_project']
  1693. }
  1694. # missing CSRF
  1695. output = self.app.post('/settings/token/new', data=data)
  1696. self.assertEqual(output.status_code, 200)
  1697. output_text = output.get_data(as_text=True)
  1698. self.assertIn(
  1699. '<title>Create token - Pagure</title>', output_text)
  1700. self.assertIn(
  1701. '<div class="card-header">\n <strong>'
  1702. 'Create a new token</strong>\n', output_text)
  1703. self.assertIn(
  1704. '<input type="checkbox" name="acls" value="create_project">',
  1705. output_text)
  1706. data = {
  1707. 'acls': ['new_project'],
  1708. 'csrf_token': csrf_token
  1709. }
  1710. # Invalid ACLs
  1711. output = self.app.post('/settings/token/new', data=data)
  1712. self.assertEqual(output.status_code, 200)
  1713. output_text = output.get_data(as_text=True)
  1714. self.assertIn(
  1715. '<title>Create token - Pagure</title>', output_text)
  1716. self.assertIn(
  1717. '<div class="card-header">\n <strong>'
  1718. 'Create a new token</strong>\n', output_text)
  1719. self.assertIn(
  1720. '<input type="checkbox" name="acls" value="create_project">',
  1721. output_text)
  1722. data = {
  1723. 'acls': ['create_project', 'fork_project'],
  1724. 'csrf_token': csrf_token
  1725. }
  1726. # All good
  1727. output = self.app.post(
  1728. '/settings/token/new', data=data, follow_redirects=True)
  1729. self.assertEqual(output.status_code, 200)
  1730. output_text = output.get_data(as_text=True)
  1731. self.assertIn(
  1732. '<title>foo\'s settings - Pagure</title>', output_text)
  1733. self.assertIn(
  1734. 'Token created',
  1735. output_text)
  1736. self.assertEqual(
  1737. output_text.count(
  1738. '<small class="font-weight-bold text-success input-group-text">Active until'), 1)
  1739. ast.return_value = True
  1740. output = self.app.get('/settings/token/new')
  1741. self.assertEqual(output.status_code, 302)
  1742. @patch('pagure.ui.app.admin_session_timedout')
  1743. def test_revoke_api_user_token(self, ast):
  1744. """ Test the revoke_api_user_token endpoint. """
  1745. ast.return_value = False
  1746. self.test_new_project()
  1747. user = tests.FakeUser()
  1748. with tests.user_set(self.app.application, user):
  1749. # Token doesn't exist
  1750. output = self.app.post('/settings/token/revoke/foobar')
  1751. self.assertEqual(output.status_code, 404)
  1752. self.assertTrue('<h2>Page not found (404)</h2>' in output.get_data(as_text=True))
  1753. # Create the foobar API token but associated w/ the user 'foo'
  1754. item = pagure.lib.model.Token(
  1755. id='foobar',
  1756. user_id=2, # foo
  1757. expiration=datetime.datetime.utcnow() \
  1758. + datetime.timedelta(days=30)
  1759. )
  1760. self.session.add(item)
  1761. self.session.commit()
  1762. # Token not associated w/ this user
  1763. output = self.app.post('/settings/token/revoke/foobar')
  1764. self.assertEqual(output.status_code, 404)
  1765. self.assertTrue('<h2>Page not found (404)</h2>' in output.get_data(as_text=True))
  1766. user.username = 'foo'
  1767. with tests.user_set(self.app.application, user):
  1768. # Missing CSRF token
  1769. output = self.app.post(
  1770. '/settings/token/revoke/foobar', follow_redirects=True)
  1771. self.assertEqual(output.status_code, 200)
  1772. output_text = output.get_data(as_text=True)
  1773. self.assertIn(
  1774. "<title>foo's settings - Pagure</title>", output_text)
  1775. self.assertEqual(
  1776. output_text.count(
  1777. '<small class="font-weight-bold text-success input-group-text">Active until'), 1)
  1778. csrf_token = output_text.split(
  1779. 'name="csrf_token" type="hidden" value="')[1].split('">')[0]
  1780. data = {
  1781. 'csrf_token': csrf_token
  1782. }
  1783. # All good - token is deleted
  1784. output = self.app.post(
  1785. '/settings/token/revoke/foobar', data=data,
  1786. follow_redirects=True)
  1787. self.assertEqual(output.status_code, 200)
  1788. output_text = output.get_data(as_text=True)
  1789. self.assertIn(
  1790. "<title>foo's settings - Pagure</title>", output_text)
  1791. self.assertEqual(
  1792. output_text.count(
  1793. '<small class="font-weight-bold text-success input-group-text">Active until'), 0)
  1794. user = pagure.lib.query.get_user(self.session, key='foo')
  1795. self.assertEqual(len(user.tokens), 1)
  1796. expiration_dt = user.tokens[0].expiration
  1797. # Token was already deleted - no changes
  1798. output = self.app.post(
  1799. '/settings/token/revoke/foobar', data=data,
  1800. follow_redirects=True)
  1801. self.assertEqual(output.status_code, 200)
  1802. output_text = output.get_data(as_text=True)
  1803. self.assertIn(
  1804. "<title>foo's settings - Pagure</title>", output_text)
  1805. self.assertEqual(
  1806. output_text.count(
  1807. '<small class="font-weight-bold text-success input-group-text">Active until'), 0)
  1808. # Ensure the expiration date did not change
  1809. user = pagure.lib.query.get_user(self.session, key='foo')
  1810. self.assertEqual(len(user.tokens), 1)
  1811. self.assertEqual(
  1812. expiration_dt, user.tokens[0].expiration
  1813. )
  1814. ast.return_value = True
  1815. output = self.app.get('/settings/token/new')
  1816. self.assertEqual(output.status_code, 302)
  1817. @patch.dict('pagure.config.config', {'PAGURE_AUTH': 'fas'})
  1818. @patch.dict('pagure.utils.pagure_config', {'PAGURE_AUTH': 'fas'})
  1819. def test_create_project_auth_FAS_no_FPCA(self):
  1820. """ Test creating a project when auth is FAS and the user did not
  1821. sign the FPCA. """
  1822. user = tests.FakeUser(username='foo', cla_done=False)
  1823. with tests.user_set(self.app.application, user):
  1824. output = self.app.get('/new/', follow_redirects=True)
  1825. self.assertEqual(output.status_code, 200)
  1826. output_text = output.get_data(as_text=True)
  1827. self.assertIn('<title>Home - Pagure</title>', output_text)
  1828. self.assertIn(
  1829. '</i> You must <a href="https://admin.fedoraproject.org/accounts/'
  1830. '">sign the FPCA</a> (Fedora Project Contributor Agreement) '
  1831. 'to use pagure</div>', output_text)
  1832. class PagureFlaskAppAboutPagetests(tests.Modeltests):
  1833. """ Unit-tests for the about page. """
  1834. def test_about_page(self):
  1835. """ Test the about page when an admin_email is set. """
  1836. output = self.app.get('/about/')
  1837. self.assertEqual(output.status_code, 200)
  1838. output_text = output.get_data(as_text=True)
  1839. self.assertIn('<title>About - Pagure</title>', output_text)
  1840. self.assertIn(
  1841. 'by emailing:\n '
  1842. '<a href="mailto:root@localhost.localdomain">', output_text)
  1843. self.assertIn(
  1844. 'href="https://pagure.io/pagure/issues">open a ticket</a>',
  1845. output_text)
  1846. @patch.dict('pagure.config.config', {'ADMIN_EMAIL': 'admin@fp.o'})
  1847. def test_about_page_admin_email(self):
  1848. """ Test the about page when an admin_email is set. """
  1849. output = self.app.get('/about/')
  1850. self.assertEqual(output.status_code, 200)
  1851. output_text = output.get_data(as_text=True)
  1852. self.assertIn('<title>About - Pagure</title>', output_text)
  1853. self.assertIn(
  1854. 'by emailing:\n <a href="mailto:admin@fp.o">',
  1855. output_text)
  1856. self.assertIn(
  1857. 'href="https://pagure.io/pagure/issues">open a ticket</a>',
  1858. output_text)
  1859. class PagureFlaskAppNoDocstests(tests.Modeltests):
  1860. """ Tests for flask app controller of pagure """
  1861. config_values = {
  1862. "enable_docs": False,
  1863. "docs_folder": None,
  1864. }
  1865. def test_new_project_no_docs_folder(self):
  1866. """ Test the new_project endpoint with DOCS_FOLDER is None. """
  1867. # Before
  1868. projects = pagure.lib.query.search_projects(self.session)
  1869. self.assertEqual(len(projects), 0)
  1870. self.assertFalse(os.path.exists(
  1871. os.path.join(self.path, 'repos', 'project#1.git')))
  1872. self.assertFalse(os.path.exists(
  1873. os.path.join(self.path, 'repos', 'tickets', 'project#1.git')))
  1874. self.assertFalse(os.path.exists(
  1875. os.path.join(self.path, 'repos', 'docs', 'project#1.git')))
  1876. self.assertFalse(os.path.exists(
  1877. os.path.join(self.path, 'repos', 'requests', 'project#1.git')))
  1878. user = tests.FakeUser(username='foo')
  1879. with tests.user_set(self.app.application, user):
  1880. csrf_token = self.get_csrf()
  1881. data = {
  1882. 'description': 'Project #1',
  1883. 'name': 'project-1',
  1884. 'csrf_token': csrf_token,
  1885. }
  1886. output = self.app.post('/new/', data=data, follow_redirects=True)
  1887. self.assertEqual(output.status_code, 200)
  1888. output_text = output.get_data(as_text=True)
  1889. self.assertIn(
  1890. '<div class="projectinfo my-3">\nProject #1',
  1891. output_text)
  1892. self.assertIn('<p>This repo is brand new!</p>',
  1893. output_text)
  1894. self.assertIn(
  1895. '<title>Overview - project-1 - Pagure</title>', output_text)
  1896. # After
  1897. projects = pagure.lib.query.search_projects(self.session)
  1898. self.assertEqual(len(projects), 1)
  1899. self.assertTrue(os.path.exists(
  1900. os.path.join(self.path, 'repos', 'project-1.git')))
  1901. self.assertTrue(os.path.exists(
  1902. os.path.join(self.path, 'repos', 'tickets', 'project-1.git')))
  1903. self.assertFalse(os.path.exists(
  1904. os.path.join(self.path, 'repos', 'docs', 'project-1.git')))
  1905. self.assertTrue(os.path.exists(
  1906. os.path.join(self.path, 'repos', 'requests', 'project-1.git')))
  1907. class PagureFlaskAppNoTicketstests(tests.Modeltests):
  1908. """ Tests for flask app controller of pagure """
  1909. config_values = {
  1910. "enable_tickets": False,
  1911. "tickets_folder": None,
  1912. }
  1913. def test_new_project_no_tickets_folder(self):
  1914. """ Test the new_project endpoint with TICKETS_FOLDER is None. """
  1915. # Before
  1916. projects = pagure.lib.query.search_projects(self.session)
  1917. self.assertEqual(len(projects), 0)
  1918. self.assertFalse(os.path.exists(
  1919. os.path.join(self.path, 'repos', 'project#1.git')))
  1920. self.assertFalse(os.path.exists(
  1921. os.path.join(self.path, 'repos', 'tickets', 'project#1.git')))
  1922. self.assertFalse(os.path.exists(
  1923. os.path.join(self.path, 'repos', 'docs', 'project#1.git')))
  1924. self.assertFalse(os.path.exists(
  1925. os.path.join(self.path, 'repos', 'requests', 'project#1.git')))
  1926. user = tests.FakeUser(username='foo')
  1927. with tests.user_set(self.app.application, user):
  1928. csrf_token = self.get_csrf()
  1929. data = {
  1930. 'description': 'Project #1',
  1931. 'name': 'project-1',
  1932. 'csrf_token': csrf_token,
  1933. }
  1934. output = self.app.post('/new/', data=data, follow_redirects=True)
  1935. self.assertEqual(output.status_code, 200)
  1936. output_text = output.get_data(as_text=True)
  1937. self.assertIn(
  1938. '<div class="projectinfo my-3">\nProject #1',
  1939. output_text)
  1940. self.assertIn('<p>This repo is brand new!</p>',
  1941. output_text)
  1942. self.assertIn(
  1943. '<title>Overview - project-1 - Pagure</title>', output_text)
  1944. # After
  1945. projects = pagure.lib.query.search_projects(self.session)
  1946. self.assertEqual(len(projects), 1)
  1947. self.assertTrue(os.path.exists(
  1948. os.path.join(self.path, 'repos', 'project-1.git')))
  1949. self.assertFalse(os.path.exists(
  1950. os.path.join(self.path, 'repos', 'tickets', 'project-1.git')))
  1951. self.assertTrue(os.path.exists(
  1952. os.path.join(self.path, 'repos', 'docs', 'project-1.git')))
  1953. self.assertTrue(os.path.exists(
  1954. os.path.join(self.path, 'repos', 'requests', 'project-1.git')))
  1955. if __name__ == '__main__':
  1956. unittest.main(verbosity=2)