test_pagure_lib_git.py 124 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093
  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 os
  10. import shutil
  11. import sys
  12. import tempfile
  13. import time
  14. import unittest
  15. import pygit2
  16. import six
  17. from mock import patch, MagicMock
  18. sys.path.insert(
  19. 0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
  20. )
  21. import pagure.lib.git
  22. import tests
  23. from pagure.lib.repo import PagureRepo
  24. class PagureLibGittests(tests.Modeltests):
  25. """Tests for pagure.lib.git"""
  26. maxDiff = None
  27. def test_write_gitolite_acls(self):
  28. """Test the write_gitolite_acls function of pagure.lib.git.
  29. when the new uesr is an made an admin"""
  30. tests.create_projects(self.session)
  31. repo = pagure.lib.query.get_authorized_project(self.session, "test")
  32. # Add an user to a project
  33. # The user will be an admin of the project
  34. msg = pagure.lib.query.add_user_to_project(
  35. session=self.session, project=repo, new_user="foo", user="pingou"
  36. )
  37. self.session.commit()
  38. self.assertEqual(msg, "User added")
  39. # Add a forked project
  40. item = pagure.lib.model.Project(
  41. user_id=1, # pingou
  42. name="test3",
  43. description="test project #2",
  44. is_fork=True,
  45. parent_id=1,
  46. hook_token="aaabbbvvv",
  47. )
  48. self.session.add(item)
  49. self.session.commit()
  50. outputconf = os.path.join(self.path, "test_gitolite.conf")
  51. helper = pagure.lib.git_auth.get_git_auth_helper("gitolite3")
  52. helper.write_gitolite_acls(
  53. self.session, configfile=outputconf, project=-1
  54. )
  55. self.assertTrue(os.path.exists(outputconf))
  56. with open(outputconf) as stream:
  57. data = stream.read()
  58. exp = """repo test
  59. R = @all
  60. RW+ = pingou
  61. RW+ = foo
  62. repo docs/test
  63. R = @all
  64. RW+ = pingou
  65. RW+ = foo
  66. repo tickets/test
  67. RW+ = pingou
  68. RW+ = foo
  69. repo requests/test
  70. RW+ = pingou
  71. RW+ = foo
  72. repo test2
  73. R = @all
  74. RW+ = pingou
  75. repo docs/test2
  76. R = @all
  77. RW+ = pingou
  78. repo tickets/test2
  79. RW+ = pingou
  80. repo requests/test2
  81. RW+ = pingou
  82. repo somenamespace/test3
  83. R = @all
  84. RW+ = pingou
  85. repo docs/somenamespace/test3
  86. R = @all
  87. RW+ = pingou
  88. repo tickets/somenamespace/test3
  89. RW+ = pingou
  90. repo requests/somenamespace/test3
  91. RW+ = pingou
  92. repo forks/pingou/test3
  93. R = @all
  94. RW+ = pingou
  95. repo docs/forks/pingou/test3
  96. R = @all
  97. RW+ = pingou
  98. repo tickets/forks/pingou/test3
  99. RW+ = pingou
  100. repo requests/forks/pingou/test3
  101. RW+ = pingou
  102. # end of body
  103. """
  104. # print data
  105. self.assertEqual(data, exp)
  106. os.unlink(outputconf)
  107. self.assertFalse(os.path.exists(outputconf))
  108. def test_write_gitolite_acls_preconf(self):
  109. """Test the write_gitolite_acls function of pagure.lib.git with
  110. a preconf set"""
  111. tests.create_projects(self.session)
  112. outputconf = os.path.join(self.path, "test_gitolite.conf")
  113. preconf = os.path.join(self.path, "header_gitolite")
  114. with open(preconf, "w") as stream:
  115. stream.write("# this is a header that is manually added")
  116. helper = pagure.lib.git_auth.get_git_auth_helper("gitolite3")
  117. helper.write_gitolite_acls(
  118. self.session, outputconf, project=-1, preconf=preconf
  119. )
  120. self.assertTrue(os.path.exists(outputconf))
  121. with open(outputconf) as stream:
  122. data = stream.read()
  123. exp = """# this is a header that is manually added
  124. # end of header
  125. repo test
  126. R = @all
  127. RW+ = pingou
  128. repo docs/test
  129. R = @all
  130. RW+ = pingou
  131. repo tickets/test
  132. RW+ = pingou
  133. repo requests/test
  134. RW+ = pingou
  135. repo test2
  136. R = @all
  137. RW+ = pingou
  138. repo docs/test2
  139. R = @all
  140. RW+ = pingou
  141. repo tickets/test2
  142. RW+ = pingou
  143. repo requests/test2
  144. RW+ = pingou
  145. repo somenamespace/test3
  146. R = @all
  147. RW+ = pingou
  148. repo docs/somenamespace/test3
  149. R = @all
  150. RW+ = pingou
  151. repo tickets/somenamespace/test3
  152. RW+ = pingou
  153. repo requests/somenamespace/test3
  154. RW+ = pingou
  155. # end of body
  156. """
  157. # print data
  158. self.assertEqual(data.split("\n"), exp.split("\n"))
  159. os.unlink(outputconf)
  160. self.assertFalse(os.path.exists(outputconf))
  161. def test_write_gitolite_acls_preconf_postconf(self):
  162. """Test the write_gitolite_acls function of pagure.lib.git with
  163. a postconf set"""
  164. tests.create_projects(self.session)
  165. outputconf = os.path.join(self.path, "test_gitolite.conf")
  166. preconf = os.path.join(self.path, "header_gitolite")
  167. with open(preconf, "w") as stream:
  168. stream.write("# this is a header that is manually added")
  169. postconf = os.path.join(self.path, "footer_gitolite")
  170. with open(postconf, "w") as stream:
  171. stream.write("# end of generated configuration")
  172. helper = pagure.lib.git_auth.get_git_auth_helper("gitolite3")
  173. helper.write_gitolite_acls(
  174. self.session,
  175. outputconf,
  176. project=-1,
  177. preconf=preconf,
  178. postconf=postconf,
  179. )
  180. self.assertTrue(os.path.exists(outputconf))
  181. with open(outputconf) as stream:
  182. data = stream.read()
  183. exp = """# this is a header that is manually added
  184. # end of header
  185. repo test
  186. R = @all
  187. RW+ = pingou
  188. repo docs/test
  189. R = @all
  190. RW+ = pingou
  191. repo tickets/test
  192. RW+ = pingou
  193. repo requests/test
  194. RW+ = pingou
  195. repo test2
  196. R = @all
  197. RW+ = pingou
  198. repo docs/test2
  199. R = @all
  200. RW+ = pingou
  201. repo tickets/test2
  202. RW+ = pingou
  203. repo requests/test2
  204. RW+ = pingou
  205. repo somenamespace/test3
  206. R = @all
  207. RW+ = pingou
  208. repo docs/somenamespace/test3
  209. R = @all
  210. RW+ = pingou
  211. repo tickets/somenamespace/test3
  212. RW+ = pingou
  213. repo requests/somenamespace/test3
  214. RW+ = pingou
  215. # end of body
  216. # end of generated configuration
  217. """
  218. # print data
  219. self.assertEqual(data, exp)
  220. os.unlink(outputconf)
  221. self.assertFalse(os.path.exists(outputconf))
  222. def test_write_gitolite_acls_postconf(self):
  223. """Test the write_gitolite_acls function of pagure.lib.git with
  224. a preconf and a postconf set"""
  225. tests.create_projects(self.session)
  226. outputconf = os.path.join(self.path, "test_gitolite.conf")
  227. postconf = os.path.join(self.path, "footer_gitolite")
  228. with open(postconf, "w") as stream:
  229. stream.write("# end of generated configuration")
  230. helper = pagure.lib.git_auth.get_git_auth_helper("gitolite3")
  231. helper.write_gitolite_acls(
  232. self.session, outputconf, project=-1, postconf=postconf
  233. )
  234. self.assertTrue(os.path.exists(outputconf))
  235. with open(outputconf) as stream:
  236. data = stream.read()
  237. exp = """repo test
  238. R = @all
  239. RW+ = pingou
  240. repo docs/test
  241. R = @all
  242. RW+ = pingou
  243. repo tickets/test
  244. RW+ = pingou
  245. repo requests/test
  246. RW+ = pingou
  247. repo test2
  248. R = @all
  249. RW+ = pingou
  250. repo docs/test2
  251. R = @all
  252. RW+ = pingou
  253. repo tickets/test2
  254. RW+ = pingou
  255. repo requests/test2
  256. RW+ = pingou
  257. repo somenamespace/test3
  258. R = @all
  259. RW+ = pingou
  260. repo docs/somenamespace/test3
  261. R = @all
  262. RW+ = pingou
  263. repo tickets/somenamespace/test3
  264. RW+ = pingou
  265. repo requests/somenamespace/test3
  266. RW+ = pingou
  267. # end of body
  268. # end of generated configuration
  269. """
  270. # print data
  271. self.assertEqual(data, exp)
  272. os.unlink(outputconf)
  273. self.assertFalse(os.path.exists(outputconf))
  274. def test_write_gitolite_acls_deploykeys(self):
  275. """Test write_gitolite_acls function to add deploy keys."""
  276. tests.create_projects(self.session)
  277. repo = pagure.lib.query.get_authorized_project(self.session, "test")
  278. # Add two deploy keys (one readonly one push)
  279. pingou = pagure.lib.query.get_user(self.session, "pingou")
  280. msg1 = pagure.lib.query.add_sshkey_to_project_or_user(
  281. session=self.session,
  282. project=repo,
  283. ssh_key="ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDAzBMSIlvPRaEiLOTVInErkRIw9CzQQcnslDekAn1jFnGf+SNa1acvbTiATbCX71AA03giKrPxPH79dxcC7aDXerc6zRcKjJs6MAL9PrCjnbyxCKXRNNZU5U9X/DLaaL1b3caB+WD6OoorhS3LTEtKPX8xyjOzhf3OQSzNjhJp5Q==",
  284. pushaccess=False,
  285. creator=pingou,
  286. )
  287. msg2 = pagure.lib.query.add_sshkey_to_project_or_user(
  288. session=self.session,
  289. project=repo,
  290. ssh_key="ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQC9Xwc2RDzPBhlEDARfHldGjudIVoa04tqT1JVKGQmyllTFz7Rb8CngQL3e7zyNzotnhwYKHdoiLlPkVEiDee4dWMUe48ilqId+FJZQGhyv8fu4BoFdE1AJUVylzmltbLg14VqG5gjTpXgtlrEva9arKwBMHJjRYc8ScaSn3OgyQw==",
  291. pushaccess=True,
  292. creator=pingou,
  293. )
  294. self.session.commit()
  295. self.assertEqual(msg1, "SSH key added")
  296. self.assertEqual(msg2, "SSH key added")
  297. # Add a forked project
  298. item = pagure.lib.model.Project(
  299. user_id=1, # pingou
  300. name="test3",
  301. description="test project #2",
  302. is_fork=True,
  303. parent_id=1,
  304. hook_token="aaabbbvvv",
  305. )
  306. self.session.add(item)
  307. self.session.commit()
  308. outputconf = os.path.join(self.path, "test_gitolite.conf")
  309. helper = pagure.lib.git_auth.get_git_auth_helper("gitolite3")
  310. helper.write_gitolite_acls(self.session, outputconf, project=-1)
  311. self.assertTrue(os.path.exists(outputconf))
  312. with open(outputconf) as stream:
  313. data = stream.read()
  314. exp = """repo test
  315. R = @all
  316. RW+ = pingou
  317. R = deploykey_test_1
  318. RW+ = deploykey_test_2
  319. repo docs/test
  320. R = @all
  321. RW+ = pingou
  322. R = deploykey_test_1
  323. RW+ = deploykey_test_2
  324. repo tickets/test
  325. RW+ = pingou
  326. R = deploykey_test_1
  327. RW+ = deploykey_test_2
  328. repo requests/test
  329. RW+ = pingou
  330. R = deploykey_test_1
  331. RW+ = deploykey_test_2
  332. repo test2
  333. R = @all
  334. RW+ = pingou
  335. repo docs/test2
  336. R = @all
  337. RW+ = pingou
  338. repo tickets/test2
  339. RW+ = pingou
  340. repo requests/test2
  341. RW+ = pingou
  342. repo somenamespace/test3
  343. R = @all
  344. RW+ = pingou
  345. repo docs/somenamespace/test3
  346. R = @all
  347. RW+ = pingou
  348. repo tickets/somenamespace/test3
  349. RW+ = pingou
  350. repo requests/somenamespace/test3
  351. RW+ = pingou
  352. repo forks/pingou/test3
  353. R = @all
  354. RW+ = pingou
  355. repo docs/forks/pingou/test3
  356. R = @all
  357. RW+ = pingou
  358. repo tickets/forks/pingou/test3
  359. RW+ = pingou
  360. repo requests/forks/pingou/test3
  361. RW+ = pingou
  362. # end of body
  363. """
  364. # print data
  365. self.assertEqual(data, exp)
  366. os.unlink(outputconf)
  367. self.assertFalse(os.path.exists(outputconf))
  368. def test_write_gitolite_acls_ticket(self):
  369. """Test the write_gitolite_acls function of pagure.lib.git.
  370. when the new uesr is just a ticketer"""
  371. tests.create_projects(self.session)
  372. repo = pagure.lib.query.get_authorized_project(self.session, "test")
  373. # Add an user to a project
  374. # The user will be an admin of the project
  375. msg = pagure.lib.query.add_user_to_project(
  376. session=self.session,
  377. project=repo,
  378. new_user="foo",
  379. user="pingou",
  380. access="ticket",
  381. )
  382. self.session.commit()
  383. self.assertEqual(msg, "User added")
  384. # Add a forked project
  385. item = pagure.lib.model.Project(
  386. user_id=1, # pingou
  387. name="test3",
  388. description="test project #2",
  389. is_fork=True,
  390. parent_id=1,
  391. hook_token="aaabbbvvv",
  392. )
  393. self.session.add(item)
  394. self.session.commit()
  395. outputconf = os.path.join(self.path, "test_gitolite.conf")
  396. helper = pagure.lib.git_auth.get_git_auth_helper("gitolite3")
  397. helper.write_gitolite_acls(self.session, outputconf, project=-1)
  398. self.assertTrue(os.path.exists(outputconf))
  399. with open(outputconf) as stream:
  400. data = stream.read()
  401. exp = """repo test
  402. R = @all
  403. RW+ = pingou
  404. repo docs/test
  405. R = @all
  406. RW+ = pingou
  407. repo tickets/test
  408. RW+ = pingou
  409. repo requests/test
  410. RW+ = pingou
  411. repo test2
  412. R = @all
  413. RW+ = pingou
  414. repo docs/test2
  415. R = @all
  416. RW+ = pingou
  417. repo tickets/test2
  418. RW+ = pingou
  419. repo requests/test2
  420. RW+ = pingou
  421. repo somenamespace/test3
  422. R = @all
  423. RW+ = pingou
  424. repo docs/somenamespace/test3
  425. R = @all
  426. RW+ = pingou
  427. repo tickets/somenamespace/test3
  428. RW+ = pingou
  429. repo requests/somenamespace/test3
  430. RW+ = pingou
  431. repo forks/pingou/test3
  432. R = @all
  433. RW+ = pingou
  434. repo docs/forks/pingou/test3
  435. R = @all
  436. RW+ = pingou
  437. repo tickets/forks/pingou/test3
  438. RW+ = pingou
  439. repo requests/forks/pingou/test3
  440. RW+ = pingou
  441. # end of body
  442. """
  443. # print data
  444. self.assertEqual(data, exp)
  445. os.unlink(outputconf)
  446. self.assertFalse(os.path.exists(outputconf))
  447. def test_write_gitolite_acls_commit(self):
  448. """Test the write_gitolite_acls function of pagure.lib.git.
  449. when the new uesr is just a committer"""
  450. tests.create_projects(self.session)
  451. repo = pagure.lib.query.get_authorized_project(self.session, "test")
  452. # Add an user to a project
  453. # The user will be an admin of the project
  454. msg = pagure.lib.query.add_user_to_project(
  455. session=self.session,
  456. project=repo,
  457. new_user="foo",
  458. user="pingou",
  459. access="commit",
  460. )
  461. self.session.commit()
  462. self.assertEqual(msg, "User added")
  463. # Add a forked project
  464. item = pagure.lib.model.Project(
  465. user_id=1, # pingou
  466. name="test3",
  467. description="test project #2",
  468. is_fork=True,
  469. parent_id=1,
  470. hook_token="aaabbbvvv",
  471. )
  472. self.session.add(item)
  473. self.session.commit()
  474. outputconf = os.path.join(self.path, "test_gitolite.conf")
  475. helper = pagure.lib.git_auth.get_git_auth_helper("gitolite3")
  476. helper.write_gitolite_acls(self.session, outputconf, project=-1)
  477. self.assertTrue(os.path.exists(outputconf))
  478. with open(outputconf) as stream:
  479. data = stream.read()
  480. exp = """repo test
  481. R = @all
  482. RW+ = pingou
  483. RW+ = foo
  484. repo docs/test
  485. R = @all
  486. RW+ = pingou
  487. RW+ = foo
  488. repo tickets/test
  489. RW+ = pingou
  490. RW+ = foo
  491. repo requests/test
  492. RW+ = pingou
  493. RW+ = foo
  494. repo test2
  495. R = @all
  496. RW+ = pingou
  497. repo docs/test2
  498. R = @all
  499. RW+ = pingou
  500. repo tickets/test2
  501. RW+ = pingou
  502. repo requests/test2
  503. RW+ = pingou
  504. repo somenamespace/test3
  505. R = @all
  506. RW+ = pingou
  507. repo docs/somenamespace/test3
  508. R = @all
  509. RW+ = pingou
  510. repo tickets/somenamespace/test3
  511. RW+ = pingou
  512. repo requests/somenamespace/test3
  513. RW+ = pingou
  514. repo forks/pingou/test3
  515. R = @all
  516. RW+ = pingou
  517. repo docs/forks/pingou/test3
  518. R = @all
  519. RW+ = pingou
  520. repo tickets/forks/pingou/test3
  521. RW+ = pingou
  522. repo requests/forks/pingou/test3
  523. RW+ = pingou
  524. # end of body
  525. """
  526. # print data
  527. self.assertEqual(data, exp)
  528. os.unlink(outputconf)
  529. self.assertFalse(os.path.exists(outputconf))
  530. def test_write_gitolite_acls_groups(self):
  531. """Test the write_gitolite_acls function of pagure.lib.git with
  532. groups as admin
  533. """
  534. tests.create_projects(self.session)
  535. repo = pagure.lib.query.get_authorized_project(self.session, "test")
  536. # Add a couple of groups
  537. # They would be admins
  538. msg = pagure.lib.query.add_group(
  539. self.session,
  540. group_name="sysadmin",
  541. display_name="sysadmin group",
  542. description=None,
  543. group_type="user",
  544. user="pingou",
  545. is_admin=False,
  546. blacklist=[],
  547. )
  548. self.session.commit()
  549. self.assertEqual(msg, "User `pingou` added to the group `sysadmin`.")
  550. msg = pagure.lib.query.add_group(
  551. self.session,
  552. group_name="devs",
  553. display_name="devs group",
  554. description=None,
  555. group_type="user",
  556. user="pingou",
  557. is_admin=False,
  558. blacklist=[],
  559. )
  560. self.session.commit()
  561. self.assertEqual(msg, "User `pingou` added to the group `devs`.")
  562. # Associate these groups to a project
  563. msg = pagure.lib.query.add_group_to_project(
  564. session=self.session,
  565. project=repo,
  566. new_group="sysadmin",
  567. user="pingou",
  568. )
  569. self.session.commit()
  570. self.assertEqual(msg, "Group added")
  571. msg = pagure.lib.query.add_group_to_project(
  572. session=self.session, project=repo, new_group="devs", user="pingou"
  573. )
  574. self.session.commit()
  575. self.assertEqual(msg, "Group added")
  576. # Add an user to a project
  577. msg = pagure.lib.query.add_user_to_project(
  578. session=self.session, project=repo, new_user="foo", user="pingou"
  579. )
  580. self.session.commit()
  581. self.assertEqual(msg, "User added")
  582. # Add a forked project
  583. item = pagure.lib.model.Project(
  584. user_id=1, # pingou
  585. name="test2",
  586. description="test project #2",
  587. is_fork=True,
  588. parent_id=1,
  589. hook_token="aaabbbvvv",
  590. )
  591. self.session.add(item)
  592. self.session.commit()
  593. outputconf = os.path.join(self.path, "test_gitolite.conf")
  594. helper = pagure.lib.git_auth.get_git_auth_helper("gitolite3")
  595. helper.write_gitolite_acls(self.session, outputconf, project=-1)
  596. self.assertTrue(os.path.exists(outputconf))
  597. with open(outputconf) as stream:
  598. data = stream.read()
  599. exp = """@devs = pingou
  600. @sysadmin = pingou
  601. # end of groups
  602. repo test
  603. R = @all
  604. RW+ = @devs @sysadmin
  605. RW+ = pingou
  606. RW+ = foo
  607. repo docs/test
  608. R = @all
  609. RW+ = @devs @sysadmin
  610. RW+ = pingou
  611. RW+ = foo
  612. repo tickets/test
  613. RW+ = @devs @sysadmin
  614. RW+ = pingou
  615. RW+ = foo
  616. repo requests/test
  617. RW+ = @devs @sysadmin
  618. RW+ = pingou
  619. RW+ = foo
  620. repo test2
  621. R = @all
  622. RW+ = pingou
  623. repo docs/test2
  624. R = @all
  625. RW+ = pingou
  626. repo tickets/test2
  627. RW+ = pingou
  628. repo requests/test2
  629. RW+ = pingou
  630. repo somenamespace/test3
  631. R = @all
  632. RW+ = pingou
  633. repo docs/somenamespace/test3
  634. R = @all
  635. RW+ = pingou
  636. repo tickets/somenamespace/test3
  637. RW+ = pingou
  638. repo requests/somenamespace/test3
  639. RW+ = pingou
  640. repo forks/pingou/test2
  641. R = @all
  642. RW+ = pingou
  643. repo docs/forks/pingou/test2
  644. R = @all
  645. RW+ = pingou
  646. repo tickets/forks/pingou/test2
  647. RW+ = pingou
  648. repo requests/forks/pingou/test2
  649. RW+ = pingou
  650. # end of body
  651. """
  652. # print data
  653. self.assertEqual(data.split("\n"), exp.split("\n"))
  654. os.unlink(outputconf)
  655. self.assertFalse(os.path.exists(outputconf))
  656. def test_write_gitolite_acls_groups_ticket(self):
  657. """Test the write_gitolite_acls function of pagure.lib.git with
  658. groups as ticketers
  659. """
  660. tests.create_projects(self.session)
  661. repo = pagure.lib.query.get_authorized_project(self.session, "test")
  662. # Add a couple of groups
  663. # They would be ticketers
  664. msg = pagure.lib.query.add_group(
  665. self.session,
  666. group_name="sysadmin",
  667. display_name="sysadmin group",
  668. description=None,
  669. group_type="user",
  670. user="pingou",
  671. is_admin=False,
  672. blacklist=[],
  673. )
  674. self.session.commit()
  675. self.assertEqual(msg, "User `pingou` added to the group `sysadmin`.")
  676. msg = pagure.lib.query.add_group(
  677. self.session,
  678. group_name="devs",
  679. display_name="devs group",
  680. description=None,
  681. group_type="user",
  682. user="pingou",
  683. is_admin=False,
  684. blacklist=[],
  685. )
  686. self.session.commit()
  687. self.assertEqual(msg, "User `pingou` added to the group `devs`.")
  688. # Associate these groups to a project
  689. msg = pagure.lib.query.add_group_to_project(
  690. session=self.session,
  691. project=repo,
  692. new_group="sysadmin",
  693. user="pingou",
  694. access="ticket",
  695. )
  696. self.session.commit()
  697. self.assertEqual(msg, "Group added")
  698. msg = pagure.lib.query.add_group_to_project(
  699. session=self.session,
  700. project=repo,
  701. new_group="devs",
  702. user="pingou",
  703. access="ticket",
  704. )
  705. self.session.commit()
  706. self.assertEqual(msg, "Group added")
  707. # Add an user to a project
  708. msg = pagure.lib.query.add_user_to_project(
  709. session=self.session, project=repo, new_user="foo", user="pingou"
  710. )
  711. self.session.commit()
  712. self.assertEqual(msg, "User added")
  713. # Add a forked project
  714. item = pagure.lib.model.Project(
  715. user_id=1, # pingou
  716. name="test2",
  717. description="test project #2",
  718. is_fork=True,
  719. parent_id=1,
  720. hook_token="aaabbbvvv",
  721. )
  722. self.session.add(item)
  723. self.session.commit()
  724. outputconf = os.path.join(self.path, "test_gitolite.conf")
  725. helper = pagure.lib.git_auth.get_git_auth_helper("gitolite3")
  726. helper.write_gitolite_acls(self.session, outputconf, project=-1)
  727. self.assertTrue(os.path.exists(outputconf))
  728. with open(outputconf) as stream:
  729. data = stream.read()
  730. exp = """@devs = pingou
  731. @sysadmin = pingou
  732. # end of groups
  733. repo test
  734. R = @all
  735. RW+ = pingou
  736. RW+ = foo
  737. repo docs/test
  738. R = @all
  739. RW+ = pingou
  740. RW+ = foo
  741. repo tickets/test
  742. RW+ = pingou
  743. RW+ = foo
  744. repo requests/test
  745. RW+ = pingou
  746. RW+ = foo
  747. repo test2
  748. R = @all
  749. RW+ = pingou
  750. repo docs/test2
  751. R = @all
  752. RW+ = pingou
  753. repo tickets/test2
  754. RW+ = pingou
  755. repo requests/test2
  756. RW+ = pingou
  757. repo somenamespace/test3
  758. R = @all
  759. RW+ = pingou
  760. repo docs/somenamespace/test3
  761. R = @all
  762. RW+ = pingou
  763. repo tickets/somenamespace/test3
  764. RW+ = pingou
  765. repo requests/somenamespace/test3
  766. RW+ = pingou
  767. repo forks/pingou/test2
  768. R = @all
  769. RW+ = pingou
  770. repo docs/forks/pingou/test2
  771. R = @all
  772. RW+ = pingou
  773. repo tickets/forks/pingou/test2
  774. RW+ = pingou
  775. repo requests/forks/pingou/test2
  776. RW+ = pingou
  777. # end of body
  778. """
  779. # print data
  780. self.assertEqual(data.split("\n"), exp.split("\n"))
  781. os.unlink(outputconf)
  782. self.assertFalse(os.path.exists(outputconf))
  783. def test_write_gitolite_acls_groups_commit(self):
  784. """Test the write_gitolite_acls function of pagure.lib.git with
  785. groups as committers
  786. """
  787. tests.create_projects(self.session)
  788. repo = pagure.lib.query.get_authorized_project(self.session, "test")
  789. # Add a couple of groups
  790. # They would be committers
  791. msg = pagure.lib.query.add_group(
  792. self.session,
  793. group_name="sysadmin",
  794. display_name="sysadmin group",
  795. description=None,
  796. group_type="user",
  797. user="pingou",
  798. is_admin=False,
  799. blacklist=[],
  800. )
  801. self.session.commit()
  802. self.assertEqual(msg, "User `pingou` added to the group `sysadmin`.")
  803. msg = pagure.lib.query.add_group(
  804. self.session,
  805. group_name="devs",
  806. display_name="devs group",
  807. description=None,
  808. group_type="user",
  809. user="pingou",
  810. is_admin=False,
  811. blacklist=[],
  812. )
  813. self.session.commit()
  814. self.assertEqual(msg, "User `pingou` added to the group `devs`.")
  815. # Associate these groups to a project
  816. msg = pagure.lib.query.add_group_to_project(
  817. session=self.session,
  818. project=repo,
  819. new_group="sysadmin",
  820. user="pingou",
  821. access="commit",
  822. )
  823. self.session.commit()
  824. self.assertEqual(msg, "Group added")
  825. msg = pagure.lib.query.add_group_to_project(
  826. session=self.session,
  827. project=repo,
  828. new_group="devs",
  829. user="pingou",
  830. access="commit",
  831. )
  832. self.session.commit()
  833. self.assertEqual(msg, "Group added")
  834. # Add an user to a project
  835. msg = pagure.lib.query.add_user_to_project(
  836. session=self.session, project=repo, new_user="foo", user="pingou"
  837. )
  838. self.session.commit()
  839. self.assertEqual(msg, "User added")
  840. # Add a forked project
  841. item = pagure.lib.model.Project(
  842. user_id=1, # pingou
  843. name="test2",
  844. description="test project #2",
  845. is_fork=True,
  846. parent_id=1,
  847. hook_token="aaabbbvvv",
  848. )
  849. self.session.add(item)
  850. self.session.commit()
  851. outputconf = os.path.join(self.path, "test_gitolite.conf")
  852. helper = pagure.lib.git_auth.get_git_auth_helper("gitolite3")
  853. helper.write_gitolite_acls(self.session, outputconf, project=-1)
  854. self.assertTrue(os.path.exists(outputconf))
  855. with open(outputconf) as stream:
  856. data = stream.read()
  857. exp = """@devs = pingou
  858. @sysadmin = pingou
  859. # end of groups
  860. repo test
  861. R = @all
  862. RW+ = @devs @sysadmin
  863. RW+ = pingou
  864. RW+ = foo
  865. repo docs/test
  866. R = @all
  867. RW+ = @devs @sysadmin
  868. RW+ = pingou
  869. RW+ = foo
  870. repo tickets/test
  871. RW+ = @devs @sysadmin
  872. RW+ = pingou
  873. RW+ = foo
  874. repo requests/test
  875. RW+ = @devs @sysadmin
  876. RW+ = pingou
  877. RW+ = foo
  878. repo test2
  879. R = @all
  880. RW+ = pingou
  881. repo docs/test2
  882. R = @all
  883. RW+ = pingou
  884. repo tickets/test2
  885. RW+ = pingou
  886. repo requests/test2
  887. RW+ = pingou
  888. repo somenamespace/test3
  889. R = @all
  890. RW+ = pingou
  891. repo docs/somenamespace/test3
  892. R = @all
  893. RW+ = pingou
  894. repo tickets/somenamespace/test3
  895. RW+ = pingou
  896. repo requests/somenamespace/test3
  897. RW+ = pingou
  898. repo forks/pingou/test2
  899. R = @all
  900. RW+ = pingou
  901. repo docs/forks/pingou/test2
  902. R = @all
  903. RW+ = pingou
  904. repo tickets/forks/pingou/test2
  905. RW+ = pingou
  906. repo requests/forks/pingou/test2
  907. RW+ = pingou
  908. # end of body
  909. """
  910. # print data
  911. self.assertEqual(data.split("\n"), exp.split("\n"))
  912. os.unlink(outputconf)
  913. self.assertFalse(os.path.exists(outputconf))
  914. def test_write_gitolite_project_pr_only(self):
  915. """Test the write_gitolite_acls function of pagure.lib.git.
  916. when the project enforces the PR approach.
  917. """
  918. tests.create_projects(self.session)
  919. repo = pagure.lib.query._get_project(self.session, "test")
  920. # Make the project enforce the PR workflow
  921. settings = repo.settings
  922. settings["pull_request_access_only"] = True
  923. repo.settings = settings
  924. self.session.add(repo)
  925. self.session.commit()
  926. # Add an user to a project
  927. # The user will be an admin of the project
  928. msg = pagure.lib.query.add_user_to_project(
  929. session=self.session, project=repo, new_user="foo", user="pingou"
  930. )
  931. self.session.commit()
  932. self.assertEqual(msg, "User added")
  933. # Add a forked project
  934. item = pagure.lib.model.Project(
  935. user_id=1, # pingou
  936. name="test3",
  937. description="test project #2",
  938. is_fork=True,
  939. parent_id=1,
  940. hook_token="aaabbbvvv",
  941. )
  942. self.session.add(item)
  943. self.session.commit()
  944. outputconf = os.path.join(self.path, "test_gitolite.conf")
  945. helper = pagure.lib.git_auth.get_git_auth_helper("gitolite3")
  946. helper.write_gitolite_acls(self.session, outputconf, project=-1)
  947. self.assertTrue(os.path.exists(outputconf))
  948. with open(outputconf) as stream:
  949. data = stream.read()
  950. exp = """repo docs/test
  951. R = @all
  952. RW+ = pingou
  953. RW+ = foo
  954. repo tickets/test
  955. RW+ = pingou
  956. RW+ = foo
  957. repo requests/test
  958. RW+ = pingou
  959. RW+ = foo
  960. repo test2
  961. R = @all
  962. RW+ = pingou
  963. repo docs/test2
  964. R = @all
  965. RW+ = pingou
  966. repo tickets/test2
  967. RW+ = pingou
  968. repo requests/test2
  969. RW+ = pingou
  970. repo somenamespace/test3
  971. R = @all
  972. RW+ = pingou
  973. repo docs/somenamespace/test3
  974. R = @all
  975. RW+ = pingou
  976. repo tickets/somenamespace/test3
  977. RW+ = pingou
  978. repo requests/somenamespace/test3
  979. RW+ = pingou
  980. repo forks/pingou/test3
  981. R = @all
  982. RW+ = pingou
  983. repo docs/forks/pingou/test3
  984. R = @all
  985. RW+ = pingou
  986. repo tickets/forks/pingou/test3
  987. RW+ = pingou
  988. repo requests/forks/pingou/test3
  989. RW+ = pingou
  990. # end of body
  991. """
  992. # print data
  993. self.assertEqual(data, exp)
  994. os.unlink(outputconf)
  995. self.assertFalse(os.path.exists(outputconf))
  996. @patch.dict("pagure.config.config", {"PR_ONLY": True})
  997. def test_write_gitolite_global_pr_only(self):
  998. """Test the write_gitolite_acls function of pagure.lib.git.
  999. when the pagure instance enforces the PR approach.
  1000. """
  1001. tests.create_projects(self.session)
  1002. repo = pagure.lib.query._get_project(self.session, "test")
  1003. self.assertFalse(repo.settings["pull_request_access_only"])
  1004. # Add an user to a project
  1005. # The user will be an admin of the project
  1006. msg = pagure.lib.query.add_user_to_project(
  1007. session=self.session, project=repo, new_user="foo", user="pingou"
  1008. )
  1009. self.session.commit()
  1010. self.assertEqual(msg, "User added")
  1011. # Add a forked project
  1012. item = pagure.lib.model.Project(
  1013. user_id=1, # pingou
  1014. name="test3",
  1015. description="test project #2",
  1016. is_fork=True,
  1017. parent_id=1,
  1018. hook_token="aaabbbvvv",
  1019. )
  1020. self.session.add(item)
  1021. self.session.commit()
  1022. outputconf = os.path.join(self.path, "test_gitolite.conf")
  1023. helper = pagure.lib.git_auth.get_git_auth_helper("gitolite3")
  1024. helper.write_gitolite_acls(self.session, outputconf, project=-1)
  1025. self.assertTrue(os.path.exists(outputconf))
  1026. with open(outputconf) as stream:
  1027. data = stream.read()
  1028. exp = """repo docs/test
  1029. R = @all
  1030. RW+ = pingou
  1031. RW+ = foo
  1032. repo tickets/test
  1033. RW+ = pingou
  1034. RW+ = foo
  1035. repo requests/test
  1036. RW+ = pingou
  1037. RW+ = foo
  1038. repo docs/test2
  1039. R = @all
  1040. RW+ = pingou
  1041. repo tickets/test2
  1042. RW+ = pingou
  1043. repo requests/test2
  1044. RW+ = pingou
  1045. repo docs/somenamespace/test3
  1046. R = @all
  1047. RW+ = pingou
  1048. repo tickets/somenamespace/test3
  1049. RW+ = pingou
  1050. repo requests/somenamespace/test3
  1051. RW+ = pingou
  1052. repo forks/pingou/test3
  1053. R = @all
  1054. RW+ = pingou
  1055. repo docs/forks/pingou/test3
  1056. R = @all
  1057. RW+ = pingou
  1058. repo tickets/forks/pingou/test3
  1059. RW+ = pingou
  1060. repo requests/forks/pingou/test3
  1061. RW+ = pingou
  1062. # end of body
  1063. """
  1064. # print data
  1065. self.assertEqual(data, exp)
  1066. os.unlink(outputconf)
  1067. self.assertFalse(os.path.exists(outputconf))
  1068. @patch("pagure.lib.notify.send_email")
  1069. def test_update_git(self, email_f):
  1070. """Test the update_git of pagure.lib.git."""
  1071. email_f.return_value = True
  1072. # Create project
  1073. item = pagure.lib.model.Project(
  1074. user_id=1, # pingou
  1075. name="test_ticket_repo",
  1076. description="test project for ticket",
  1077. hook_token="aaabbbwww",
  1078. )
  1079. self.session.add(item)
  1080. self.session.commit()
  1081. # Create repo
  1082. self.gitrepo = os.path.join(
  1083. self.path, "repos", "tickets", "test_ticket_repo.git"
  1084. )
  1085. pygit2.init_repository(self.gitrepo, bare=True)
  1086. repo = pagure.lib.query.get_authorized_project(
  1087. self.session, "test_ticket_repo"
  1088. )
  1089. # Create an issue to play with
  1090. msg = pagure.lib.query.new_issue(
  1091. session=self.session,
  1092. repo=repo,
  1093. title="Test issue",
  1094. content="We should work on this",
  1095. user="pingou",
  1096. )
  1097. self.assertEqual(msg.title, "Test issue")
  1098. issue = pagure.lib.query.search_issues(self.session, repo, issueid=1)
  1099. pagure.lib.git.update_git(issue, repo).get()
  1100. repo = pygit2.Repository(self.gitrepo)
  1101. commit = repo.revparse_single("HEAD")
  1102. # Use patch to validate the repo
  1103. commit_patch = pagure.lib.git.commit_to_patch(repo, commit)
  1104. exp = r"""Mon Sep 17 00:00:00 2001
  1105. From: pagure <pagure>
  1106. Subject: Updated issue <hash>: Test issue
  1107. ---
  1108. diff --git a/123 b/456
  1109. new file mode 100644
  1110. index 0000000..60f7480
  1111. --- /dev/null
  1112. +++ b/456
  1113. @@ -0,0 +1,33 @@
  1114. +{
  1115. + "assignee": null,
  1116. + "blocks": [],
  1117. + "close_status": null,
  1118. + "closed_at": null,
  1119. + "comments": [],
  1120. + "content": "We should work on this",
  1121. + "custom_fields": [],
  1122. + "date_created": null,
  1123. + "depends": [],
  1124. + "full_url": "http://localhost.localdomain/test_ticket_repo/issue/1",
  1125. + "id": 1,
  1126. + "last_updated": null,
  1127. + "milestone": null,
  1128. + "priority": null,
  1129. + "private": false,
  1130. + "related_prs": [],
  1131. + "status": "Open",
  1132. + "tags": [],
  1133. + "title": "Test issue",
  1134. + "user": {
  1135. + "default_email": "bar@pingou.com",
  1136. + "emails": [
  1137. + "bar@pingou.com",
  1138. + "foo@pingou.com"
  1139. + ],
  1140. + "full_url": "http://localhost.localdomain/user/pingou",
  1141. + "fullname": "PY C",
  1142. + "name": "pingou",
  1143. + "url_path": "user/pingou"
  1144. + }
  1145. +}
  1146. \ No newline at end of file
  1147. """
  1148. npatch = []
  1149. for row in commit_patch.split("\n"):
  1150. if row.startswith("Date:"):
  1151. continue
  1152. elif row.startswith("From "):
  1153. row = row.split(" ", 2)[2]
  1154. elif row.startswith("diff --git "):
  1155. row = row.split(" ")
  1156. row[2] = "a/123"
  1157. row[3] = "b/456"
  1158. row = " ".join(row)
  1159. elif "Updated issue" in row:
  1160. row = row.split()
  1161. row[3] = "<hash>:"
  1162. row = " ".join(row)
  1163. elif "date_created" in row:
  1164. t = row.split(": ")[0]
  1165. row = "%s: null," % t
  1166. elif "last_updated" in row:
  1167. t = row.split(": ")[0]
  1168. row = "%s: null," % t
  1169. elif "closed_at" in row:
  1170. t = row.split(": ")[0]
  1171. row = "%s: null," % t
  1172. elif "closed_by" in row:
  1173. continue
  1174. elif row.startswith("index 00"):
  1175. row = "index 0000000..60f7480"
  1176. elif row.startswith("+++ b/"):
  1177. row = "+++ b/456"
  1178. npatch.append(row)
  1179. commit_patch = "\n".join(npatch)
  1180. # print commit_patch
  1181. self.assertEqual(commit_patch, exp)
  1182. # Enforce having a different last_updated field
  1183. # This is required as the test run fine and fast with sqlite but is
  1184. # much slower with postgresql so we end-up with an updated
  1185. # last_updated in postgresql but not with sqlite
  1186. time.sleep(1)
  1187. # Test again after adding a comment
  1188. # We need to make sure we wait for worker to commit the comment
  1189. with patch("pagure.lib.git._maybe_wait", tests.definitely_wait):
  1190. msg = pagure.lib.query.add_issue_comment(
  1191. session=self.session,
  1192. issue=issue,
  1193. comment="Hey look a comment!",
  1194. user="foo",
  1195. )
  1196. self.session.commit()
  1197. self.assertEqual(msg, "Comment added")
  1198. # Use patch to validate the repo
  1199. repo = pygit2.Repository(self.gitrepo)
  1200. commit = repo.revparse_single("HEAD")
  1201. commit_patch = pagure.lib.git.commit_to_patch(repo, commit)
  1202. exp = r"""Mon Sep 17 00:00:00 2001
  1203. From: pagure <pagure>
  1204. Subject: Updated issue <hash>: Test issue
  1205. ---
  1206. diff --git a/123 b/456
  1207. index 458821a..77674a8
  1208. --- a/123
  1209. +++ b/456
  1210. @@ -4,14 +4,35 @@
  1211. "close_status": null,
  1212. "closed_at": null,
  1213. - "comments": [],
  1214. + "comments": [
  1215. + {
  1216. + "comment": "Hey look a comment!",
  1217. + "date_created": null,
  1218. + "edited_on": null,
  1219. + "editor": null,
  1220. + "id": 1,
  1221. + "notification": false,
  1222. + "parent": null,
  1223. + "reactions": {},
  1224. + "user": {
  1225. + "default_email": "foo@bar.com",
  1226. + "emails": [
  1227. + "foo@bar.com"
  1228. + ],
  1229. + "full_url": "http://localhost.localdomain/user/foo",
  1230. + "fullname": "foo bar",
  1231. + "name": "foo",
  1232. + "url_path": "user/foo"
  1233. + }
  1234. + }
  1235. + ],
  1236. "content": "We should work on this",
  1237. "custom_fields": [],
  1238. "date_created": null,
  1239. "depends": [],
  1240. "full_url": "http://localhost.localdomain/test_ticket_repo/issue/1",
  1241. "id": 1,
  1242. - "last_updated": "<date>",
  1243. + "last_updated": "<date>",
  1244. "milestone": null,
  1245. "priority": null,
  1246. "private": false,
  1247. """
  1248. npatch = []
  1249. for row in commit_patch.split("\n"):
  1250. if row.startswith("Date:"):
  1251. continue
  1252. elif row.startswith("From "):
  1253. row = row.split(" ", 2)[2]
  1254. elif row.startswith("diff --git "):
  1255. row = row.split(" ")
  1256. row[2] = "a/123"
  1257. row[3] = "b/456"
  1258. row = " ".join(row)
  1259. elif "Updated issue" in row:
  1260. row = row.split()
  1261. row[3] = "<hash>:"
  1262. row = " ".join(row)
  1263. elif "date_created" in row:
  1264. t = row.split(": ")[0]
  1265. row = "%s: null," % t
  1266. elif "closed_at" in row:
  1267. t = row.split(": ")[0]
  1268. row = "%s: null," % t
  1269. elif "closed_by" in row:
  1270. continue
  1271. elif row.startswith("index"):
  1272. row = "index 458821a..77674a8"
  1273. elif row.startswith("--- a/"):
  1274. row = "--- a/123"
  1275. elif row.startswith("+++ b/"):
  1276. row = "+++ b/456"
  1277. elif "last_updated" in row:
  1278. t = row.split(": ")[0]
  1279. row = '%s: "<date>",' % t
  1280. npatch.append(row)
  1281. commit_patch = "\n".join(npatch)
  1282. # print commit_patch
  1283. self.assertEqual(commit_patch, exp)
  1284. def test_clean_git(self):
  1285. """Test the clean_git method of pagure.lib.git."""
  1286. self.test_update_git()
  1287. gitpath = os.path.join(
  1288. self.path, "repos", "tickets", "test_ticket_repo.git"
  1289. )
  1290. gitrepo = pygit2.init_repository(gitpath, bare=True)
  1291. # Get the uid of the ticket created
  1292. commit = gitrepo.revparse_single("HEAD")
  1293. patch = pagure.lib.git.commit_to_patch(gitrepo, commit)
  1294. hash_file = None
  1295. for row in patch.split("\n"):
  1296. if row.startswith("+++ b/"):
  1297. hash_file = row.split("+++ b/")[-1]
  1298. break
  1299. # The only file in git is the one of that ticket
  1300. files = [entry.name for entry in commit.tree]
  1301. self.assertEqual(files, [hash_file])
  1302. repo = pagure.lib.query.get_authorized_project(
  1303. self.session, "test_ticket_repo"
  1304. )
  1305. issue = pagure.lib.query.search_issues(self.session, repo, issueid=1)
  1306. pagure.lib.git.clean_git(repo, issue.repotype, issue.uid).get()
  1307. # No more files in the git repo
  1308. commit = gitrepo.revparse_single("HEAD")
  1309. files = [entry.name for entry in commit.tree]
  1310. self.assertEqual(files, [])
  1311. @patch("pagure.lib.notify.send_email")
  1312. def test_update_git_requests(self, email_f):
  1313. """Test the update_git of pagure.lib.git for pull-requests."""
  1314. email_f.return_value = True
  1315. # Create project
  1316. item = pagure.lib.model.Project(
  1317. user_id=1, # pingou
  1318. name="test_ticket_repo",
  1319. description="test project for ticket",
  1320. hook_token="aaabbbxxx",
  1321. )
  1322. self.session.add(item)
  1323. self.session.commit()
  1324. # Create repo
  1325. self.gitrepo = os.path.join(
  1326. self.path, "repos", "requests", "test_ticket_repo.git"
  1327. )
  1328. pygit2.init_repository(self.gitrepo, bare=True)
  1329. # Create a PR to play with
  1330. repo = pagure.lib.query.get_authorized_project(
  1331. self.session, "test_ticket_repo"
  1332. )
  1333. # Create an issue to play with
  1334. req = pagure.lib.query.new_pull_request(
  1335. session=self.session,
  1336. repo_from=repo,
  1337. branch_from="feature",
  1338. repo_to=repo,
  1339. branch_to="master",
  1340. title="test PR",
  1341. user="pingou",
  1342. requestuid="foobar",
  1343. requestid=None,
  1344. status="Open",
  1345. notify=True,
  1346. )
  1347. self.assertEqual(req.id, 1)
  1348. self.assertEqual(req.title, "test PR")
  1349. request = repo.requests[0]
  1350. self.assertEqual(request.title, "test PR")
  1351. pagure.lib.git.update_git(request, request.project).get()
  1352. repo = pygit2.Repository(self.gitrepo)
  1353. commit = repo.revparse_single("HEAD")
  1354. # Use patch to validate the repo
  1355. patch = pagure.lib.git.commit_to_patch(repo, commit)
  1356. exp = r"""Mon Sep 17 00:00:00 2001
  1357. From: pagure <pagure>
  1358. Subject: Updated pull-request <hash>: test PR
  1359. ---
  1360. diff --git a/123 b/456
  1361. new file mode 100644
  1362. index 0000000..60f7480
  1363. --- /dev/null
  1364. +++ b/456
  1365. @@ -0,0 +1,162 @@
  1366. +{
  1367. + "assignee": null,
  1368. + "branch": "master",
  1369. + "branch_from": "feature",
  1370. + "cached_merge_status": "unknown",
  1371. + "closed_at": null,
  1372. + "closed_by": null,
  1373. + "comments": [],
  1374. + "commit_start": null,
  1375. + "commit_stop": null,
  1376. + "date_created": null,
  1377. + "full_url": "http://localhost.localdomain/test_ticket_repo/pull-request/1",
  1378. + "id": 1,
  1379. + "initial_comment": null,
  1380. + "last_updated": null,
  1381. + "project": {
  1382. + "access_groups": {
  1383. + "admin": [],
  1384. + "collaborator": [],
  1385. + "commit": [],
  1386. + "ticket": []
  1387. + },
  1388. + "access_users": {
  1389. + "admin": [],
  1390. + "collaborator": [],
  1391. + "commit": [],
  1392. + "owner": [
  1393. + "pingou"
  1394. + ],
  1395. + "ticket": []
  1396. + },
  1397. + "boards": [],
  1398. + "close_status": [],
  1399. + "custom_keys": [],
  1400. + "date_created": null,
  1401. + "date_modified": null,
  1402. + "description": "test project for ticket",
  1403. + "full_url": "http://localhost.localdomain/test_ticket_repo",
  1404. + "fullname": "test_ticket_repo",
  1405. + "id": 1,
  1406. + "milestones": {},
  1407. + "name": "test_ticket_repo",
  1408. + "namespace": null,
  1409. + "parent": null,
  1410. + "priorities": {},
  1411. + "settings": {
  1412. + "Enforce_signed-off_commits_in_pull-request": false,
  1413. + "Minimum_score_to_merge_pull-request": -1,
  1414. + "Only_assignee_can_merge_pull-request": false,
  1415. + "Web-hooks": null,
  1416. + "always_merge": false,
  1417. + "disable_non_fast-forward_merges": false,
  1418. + "fedmsg_notifications": true,
  1419. + "issue_tracker": true,
  1420. + "issue_tracker_read_only": false,
  1421. + "issues_default_to_private": false,
  1422. + "mqtt_notifications": true,
  1423. + "notify_on_commit_flag": false,
  1424. + "notify_on_pull-request_flag": false,
  1425. + "open_metadata_access_to_all": false,
  1426. + "project_documentation": false,
  1427. + "pull_request_access_only": false,
  1428. + "pull_requests": true,
  1429. + "stomp_notifications": true
  1430. + },
  1431. + "tags": [],
  1432. + "url_path": "test_ticket_repo",
  1433. + "user": {
  1434. + "default_email": "bar@pingou.com",
  1435. + "emails": [
  1436. + "bar@pingou.com",
  1437. + "foo@pingou.com"
  1438. + ],
  1439. + "full_url": "http://localhost.localdomain/user/pingou",
  1440. + "fullname": "PY C",
  1441. + "name": "pingou",
  1442. + "url_path": "user/pingou"
  1443. + }
  1444. + },
  1445. + "remote_git": null,
  1446. + "repo_from": {
  1447. + "access_groups": {
  1448. + "admin": [],
  1449. + "collaborator": [],
  1450. + "commit": [],
  1451. + "ticket": []
  1452. + },
  1453. + "access_users": {
  1454. + "admin": [],
  1455. + "collaborator": [],
  1456. + "commit": [],
  1457. + "owner": [
  1458. + "pingou"
  1459. + ],
  1460. + "ticket": []
  1461. + },
  1462. + "boards": [],
  1463. + "close_status": [],
  1464. + "custom_keys": [],
  1465. + "date_created": null,
  1466. + "date_modified": null,
  1467. + "description": "test project for ticket",
  1468. + "full_url": "http://localhost.localdomain/test_ticket_repo",
  1469. + "fullname": "test_ticket_repo",
  1470. + "id": 1,
  1471. + "milestones": {},
  1472. + "name": "test_ticket_repo",
  1473. + "namespace": null,
  1474. + "parent": null,
  1475. + "priorities": {},
  1476. + "settings": {
  1477. + "Enforce_signed-off_commits_in_pull-request": false,
  1478. + "Minimum_score_to_merge_pull-request": -1,
  1479. + "Only_assignee_can_merge_pull-request": false,
  1480. + "Web-hooks": null,
  1481. + "always_merge": false,
  1482. + "disable_non_fast-forward_merges": false,
  1483. + "fedmsg_notifications": true,
  1484. + "issue_tracker": true,
  1485. + "issue_tracker_read_only": false,
  1486. + "issues_default_to_private": false,
  1487. + "mqtt_notifications": true,
  1488. + "notify_on_commit_flag": false,
  1489. + "notify_on_pull-request_flag": false,
  1490. + "open_metadata_access_to_all": false,
  1491. + "project_documentation": false,
  1492. + "pull_request_access_only": false,
  1493. + "pull_requests": true,
  1494. + "stomp_notifications": true
  1495. + },
  1496. + "tags": [],
  1497. + "url_path": "test_ticket_repo",
  1498. + "user": {
  1499. + "default_email": "bar@pingou.com",
  1500. + "emails": [
  1501. + "bar@pingou.com",
  1502. + "foo@pingou.com"
  1503. + ],
  1504. + "full_url": "http://localhost.localdomain/user/pingou",
  1505. + "fullname": "PY C",
  1506. + "name": "pingou",
  1507. + "url_path": "user/pingou"
  1508. + }
  1509. + },
  1510. + "status": "Open",
  1511. + "tags": [],
  1512. + "threshold_reached": null,
  1513. + "title": "test PR",
  1514. + "uid": "foobar",
  1515. + "updated_on": null,
  1516. + "user": {
  1517. + "default_email": "bar@pingou.com",
  1518. + "emails": [
  1519. + "bar@pingou.com",
  1520. + "foo@pingou.com"
  1521. + ],
  1522. + "full_url": "http://localhost.localdomain/user/pingou",
  1523. + "fullname": "PY C",
  1524. + "name": "pingou",
  1525. + "url_path": "user/pingou"
  1526. + }
  1527. +}
  1528. \ No newline at end of file
  1529. """
  1530. npatch = []
  1531. for row in patch.split("\n"):
  1532. if row.startswith("Date:"):
  1533. continue
  1534. elif row.startswith("From "):
  1535. row = row.split(" ", 2)[2]
  1536. elif row.startswith("diff --git "):
  1537. row = row.split(" ")
  1538. row[2] = "a/123"
  1539. row[3] = "b/456"
  1540. row = " ".join(row)
  1541. elif "Updated pull-request" in row:
  1542. row = row.split()
  1543. row[3] = "<hash>:"
  1544. row = " ".join(row)
  1545. elif "date_created" in row:
  1546. t = row.split(": ")[0]
  1547. row = "%s: null," % t
  1548. elif "date_modified" in row:
  1549. t = row.split(": ")[0]
  1550. row = "%s: null," % t
  1551. elif "last_updated" in row:
  1552. t = row.split(": ")[0]
  1553. row = "%s: null," % t
  1554. elif "updated_on" in row:
  1555. t = row.split(": ")[0]
  1556. row = "%s: null," % t
  1557. elif row.startswith("index 00"):
  1558. row = "index 0000000..60f7480"
  1559. elif row.startswith("+++ b/"):
  1560. row = "+++ b/456"
  1561. npatch.append(row)
  1562. patch = "\n".join(npatch)
  1563. print(patch)
  1564. self.assertEqual(patch, exp)
  1565. def test_update_ticket_from_git_no_priority(self):
  1566. """Test the update_ticket_from_git method from pagure.lib.git."""
  1567. tests.create_projects(self.session)
  1568. repo = pagure.lib.query.get_authorized_project(self.session, "test")
  1569. # Before
  1570. self.assertEqual(len(repo.issues), 0)
  1571. self.assertEqual(repo.issues, [])
  1572. data = {
  1573. "status": "Open",
  1574. "title": "foo",
  1575. "comments": [],
  1576. "content": "bar",
  1577. "date_created": "1426500263",
  1578. "user": {
  1579. "name": "pingou",
  1580. "emails": ["pingou@fedoraproject.org"],
  1581. "full_url": "http://localhost.localdomain/user/pingou",
  1582. },
  1583. "milestone": "Next Release",
  1584. "priority": 1,
  1585. }
  1586. # Invalid project
  1587. self.assertRaises(
  1588. pagure.exceptions.PagureException,
  1589. pagure.lib.git.update_ticket_from_git,
  1590. self.session,
  1591. reponame="foobar",
  1592. namespace=None,
  1593. username=None,
  1594. issue_uid="foobar",
  1595. json_data=data,
  1596. agent="pingou",
  1597. )
  1598. # Create the issue
  1599. data = {
  1600. "status": "Open",
  1601. "title": "foo",
  1602. "comments": [],
  1603. "content": "bar",
  1604. "date_created": "1426500263",
  1605. "user": {
  1606. "name": "pingou",
  1607. "emails": ["pingou@fedoraproject.org"],
  1608. "full_url": "http://localhost.localdomain/user/pingou",
  1609. },
  1610. "milestone": "Next Release",
  1611. }
  1612. pagure.lib.git.update_ticket_from_git(
  1613. self.session,
  1614. reponame="test",
  1615. namespace=None,
  1616. username=None,
  1617. issue_uid="foobar",
  1618. json_data=data,
  1619. agent="pingou",
  1620. )
  1621. self.session.commit()
  1622. # Edit the issue
  1623. data = {
  1624. "status": "Open",
  1625. "title": "foo",
  1626. "comments": [],
  1627. "content": "bar",
  1628. "date_created": "1426500263",
  1629. "user": {
  1630. "name": "pingou",
  1631. "emails": ["pingou@fedoraproject.org"],
  1632. "full_url": "http://localhost.localdomain/user/pingou",
  1633. },
  1634. "milestone": "Next Release",
  1635. "priority": 1,
  1636. }
  1637. pagure.lib.git.update_ticket_from_git(
  1638. self.session,
  1639. reponame="test",
  1640. namespace=None,
  1641. username=None,
  1642. issue_uid="foobar",
  1643. json_data=data,
  1644. agent="pingou",
  1645. )
  1646. self.session.commit()
  1647. # Data contained a priority but not the project, so bailing
  1648. self.assertEqual(len(repo.issues), 1)
  1649. self.assertEqual(repo.issues[0].id, 1)
  1650. self.assertEqual(repo.issues[0].uid, "foobar")
  1651. self.assertEqual(repo.issues[0].title, "foo")
  1652. self.assertEqual(repo.issues[0].depending_text, [])
  1653. self.assertEqual(repo.issues[0].blocking_text, [])
  1654. self.assertEqual(repo.issues[0].milestone, "Next Release")
  1655. self.assertEqual(repo.issues[0].priority, None)
  1656. self.assertEqual(
  1657. repo.milestones, {"Next Release": {"active": True, "date": None}}
  1658. )
  1659. @patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
  1660. def test_update_ticket_from_git_close_ticket(self):
  1661. """Test the update_ticket_from_git method from pagure.lib.git."""
  1662. tests.create_projects(self.session)
  1663. repo = pagure.lib.query.get_authorized_project(self.session, "test")
  1664. # Before
  1665. self.assertEqual(len(repo.issues), 0)
  1666. self.assertEqual(repo.issues, [])
  1667. # Create the issue
  1668. data = {
  1669. "status": "Open",
  1670. "title": "foo",
  1671. "comments": [],
  1672. "content": "bar",
  1673. "date_created": "1426500263",
  1674. "user": {
  1675. "name": "foo",
  1676. "emails": ["foo@fedoraproject.org"],
  1677. "full_url": "http://localhost.localdomain/user/pingou",
  1678. },
  1679. "milestone": "Next Release",
  1680. }
  1681. pagure.lib.git.update_ticket_from_git(
  1682. self.session,
  1683. reponame="test",
  1684. namespace=None,
  1685. username=None,
  1686. issue_uid="foobar",
  1687. json_data=data,
  1688. agent="pingou",
  1689. )
  1690. self.session.commit()
  1691. # Edit the issue
  1692. data = {
  1693. "status": "Closed",
  1694. "close_status": "Fixed",
  1695. "title": "foo",
  1696. "comments": [],
  1697. "content": "bar",
  1698. "date_created": "1426500263",
  1699. "user": {
  1700. "name": "foo",
  1701. "emails": ["foo@fedoraproject.org"],
  1702. "full_url": "http://localhost.localdomain/user/pingou",
  1703. },
  1704. "milestone": "Next Release",
  1705. }
  1706. pagure.lib.git.update_ticket_from_git(
  1707. self.session,
  1708. reponame="test",
  1709. namespace=None,
  1710. username=None,
  1711. issue_uid="foobar",
  1712. json_data=data,
  1713. agent="pingou",
  1714. )
  1715. self.session.commit()
  1716. self.assertEqual(len(repo.issues), 1)
  1717. self.assertEqual(repo.issues[0].id, 1)
  1718. self.assertEqual(repo.issues[0].uid, "foobar")
  1719. self.assertEqual(repo.issues[0].title, "foo")
  1720. self.assertEqual(repo.issues[0].depending_text, [])
  1721. self.assertEqual(repo.issues[0].blocking_text, [])
  1722. self.assertEqual(repo.issues[0].milestone, "Next Release")
  1723. self.assertEqual(repo.issues[0].priority, None)
  1724. self.assertEqual(
  1725. repo.milestones, {"Next Release": {"active": True, "date": None}}
  1726. )
  1727. self.assertEqual(repo.issues[0].status, "Closed")
  1728. self.assertEqual(repo.issues[0].close_status, "Fixed")
  1729. self.assertIsNotNone(repo.issues[0].closed_at)
  1730. self.assertEqual(
  1731. repo.issues[0].comments[-1].comment,
  1732. "**Metadata Update from @pingou**:\n"
  1733. "- Issue close_status updated to: Fixed\n"
  1734. "- Issue status updated to: Closed (was: Open)",
  1735. )
  1736. def test_update_ticket_from_git(self):
  1737. """Test the update_ticket_from_git method from pagure.lib.git."""
  1738. tests.create_projects(self.session)
  1739. repo = pagure.lib.query.get_authorized_project(self.session, "test")
  1740. # Set some priorities to the project
  1741. repo.priorities = {"1": "High", "2": "Normal"}
  1742. self.session.add(repo)
  1743. self.session.commit()
  1744. # Before
  1745. self.assertEqual(len(repo.issues), 0)
  1746. self.assertEqual(repo.issues, [])
  1747. data = {
  1748. "status": "Open",
  1749. "title": "foo",
  1750. "comments": [],
  1751. "content": "bar",
  1752. "date_created": "1426500263",
  1753. "user": {
  1754. "name": "pingou",
  1755. "emails": ["pingou@fedoraproject.org"],
  1756. "full_url": "http://localhost.localdomain/user/pingou",
  1757. },
  1758. "milestone": "Next Release",
  1759. "priority": 1,
  1760. }
  1761. self.assertRaises(
  1762. pagure.exceptions.PagureException,
  1763. pagure.lib.git.update_ticket_from_git,
  1764. self.session,
  1765. reponame="foobar",
  1766. namespace=None,
  1767. username=None,
  1768. issue_uid="foobar",
  1769. json_data=data,
  1770. agent="pingou",
  1771. )
  1772. pagure.lib.git.update_ticket_from_git(
  1773. self.session,
  1774. reponame="test",
  1775. namespace=None,
  1776. username=None,
  1777. issue_uid="foobar",
  1778. json_data=data,
  1779. agent="pingou",
  1780. )
  1781. self.session.commit()
  1782. # After 1 insertion
  1783. self.assertEqual(len(repo.issues), 1)
  1784. self.assertEqual(repo.issues[0].id, 1)
  1785. self.assertEqual(repo.issues[0].uid, "foobar")
  1786. self.assertEqual(repo.issues[0].title, "foo")
  1787. self.assertEqual(repo.issues[0].depending_text, [])
  1788. self.assertEqual(repo.issues[0].blocking_text, [])
  1789. self.assertEqual(repo.issues[0].milestone, "Next Release")
  1790. self.assertEqual(repo.issues[0].priority, 1)
  1791. self.assertIsNone(repo.issues[0].closed_at)
  1792. self.assertEqual(
  1793. repo.milestones, {"Next Release": {"active": True, "date": None}}
  1794. )
  1795. data["title"] = "fake issue for tests"
  1796. pagure.lib.git.update_ticket_from_git(
  1797. self.session,
  1798. reponame="test",
  1799. namespace=None,
  1800. username=None,
  1801. issue_uid="foobar",
  1802. json_data=data,
  1803. agent="pingou",
  1804. )
  1805. self.session.commit()
  1806. # After edit
  1807. self.assertEqual(len(repo.issues), 1)
  1808. self.assertEqual(repo.issues[0].id, 1)
  1809. self.assertEqual(repo.issues[0].uid, "foobar")
  1810. self.assertEqual(repo.issues[0].title, "fake issue for tests")
  1811. self.assertEqual(repo.issues[0].depending_text, [])
  1812. self.assertEqual(repo.issues[0].blocking_text, [])
  1813. self.assertEqual(repo.issues[0].priority, 1)
  1814. self.assertIsNone(repo.issues[0].closed_at)
  1815. data = {
  1816. "status": "Closed",
  1817. "close_status": "Fixed",
  1818. "closed_at": "1426595225",
  1819. "title": "Rename pagure",
  1820. "full_url": "http://localhost.localdomain/test/issue/20",
  1821. "private": False,
  1822. "content": "This is too much of a conflict with the book",
  1823. "user": {
  1824. "fullname": "Pierre-YvesChibon",
  1825. "name": "pingou",
  1826. "default_email": "pingou@fedoraproject.org",
  1827. "emails": ["pingou@fedoraproject.org"],
  1828. "full_url": "http://localhost.localdomain/user/pingou",
  1829. },
  1830. "id": 20,
  1831. "blocks": [1],
  1832. "depends": [3, 4],
  1833. "date_created": "1426595224",
  1834. "milestone": "Future",
  1835. "priority": 1,
  1836. "comments": [
  1837. {
  1838. "comment": "Nirik:\r\n\r\n- sourceforge++ \r\n- "
  1839. "gitmaker\r\n- mastergit \r\n- hostomatic\r\n- "
  1840. "gitcorp\r\n- git-keiretsu \r\n- gitbuffet\r\n- "
  1841. "cogitator\r\n- cogitate\r\n\r\nrandomuser:\r\n\r\n- "
  1842. "COLLABORATRON5000\r\n- git-sm\\u00f6rg\\u00e5sbord\r\n- "
  1843. "thislittlegittywenttomarket\r\n- git-o-rama\r\n- "
  1844. "gitsundheit",
  1845. "date_created": "1426595224",
  1846. "id": 250,
  1847. "parent": None,
  1848. "user": {
  1849. "fullname": "Pierre-YvesChibon",
  1850. "name": "pingou",
  1851. "default_email": "pingou@fedoraproject.org",
  1852. "emails": ["pingou@fedoraproject.org"],
  1853. "full_url": "http://localhost.localdomain/user/pingou",
  1854. },
  1855. },
  1856. {
  1857. "comment": "Nirik:\r\n\r\n- sourceforge++ \r\n- "
  1858. "gitmaker\r\n- mastergit \r\n- hostomatic\r\n- "
  1859. "gitcorp\r\n- git-keiretsu \r\n- gitbuffet\r\n- "
  1860. "cogitator\r\n- cogitate\r\n\r\nrandomuser:\r\n\r\n- "
  1861. "COLLABORATRON5000\r\n- git-sm\\u00f6rg\\u00e5sbord\r\n- "
  1862. "thislittlegittywenttomarket\r\n- git-o-rama\r\n- "
  1863. "gitsundheit",
  1864. "date_created": "1426595340",
  1865. "id": 324,
  1866. "parent": None,
  1867. "user": {
  1868. "fullname": "Ralph Bean",
  1869. "name": "ralph",
  1870. "default_email": "ralph@fedoraproject.org",
  1871. "emails": ["ralph@fedoraproject.org"],
  1872. "full_url": "http://localhost.localdomain/user/pingou",
  1873. },
  1874. },
  1875. ],
  1876. }
  1877. pagure.lib.git.update_ticket_from_git(
  1878. self.session,
  1879. reponame="test",
  1880. namespace=None,
  1881. username=None,
  1882. issue_uid="foobar2",
  1883. json_data=data,
  1884. agent="pingou",
  1885. )
  1886. # After second insertion
  1887. self.assertEqual(len(repo.issues), 2)
  1888. self.assertEqual(repo.issues[0].uid, "foobar")
  1889. self.assertEqual(repo.issues[0].title, "fake issue for tests")
  1890. self.assertEqual(repo.issues[0].depending_text, [20])
  1891. self.assertEqual(repo.issues[0].blocking_text, [])
  1892. self.assertEqual(repo.issues[0].status, "Open")
  1893. self.assertIsNone(repo.issues[0].close_status)
  1894. self.assertIsNone(repo.issues[0].closed_at)
  1895. # New one
  1896. self.assertEqual(repo.issues[1].uid, "foobar2")
  1897. self.assertEqual(repo.issues[1].title, "Rename pagure")
  1898. self.assertEqual(repo.issues[1].depending_text, [])
  1899. self.assertEqual(repo.issues[1].blocking_text, [1])
  1900. self.assertEqual(repo.issues[1].milestone, "Future")
  1901. self.assertEqual(repo.issues[1].status, "Closed")
  1902. self.assertEqual(repo.issues[1].close_status, "Fixed")
  1903. self.assertIsNotNone(repo.issues[1].closed_at)
  1904. self.assertDictEqual(
  1905. repo.milestones,
  1906. {
  1907. "Future": {"active": True, "date": None},
  1908. "Next Release": {"active": True, "date": None},
  1909. },
  1910. )
  1911. def test_update_request_from_git(self):
  1912. """Test the update_request_from_git method from pagure.lib.git."""
  1913. tests.create_projects(self.session)
  1914. tests.create_projects_git(os.path.join(self.path, "repos"))
  1915. repo = pagure.lib.query._get_project(self.session, "test")
  1916. namespaced_repo = pagure.lib.query._get_project(
  1917. self.session, "test3", namespace="somenamespace"
  1918. )
  1919. # Before
  1920. self.assertEqual(len(repo.requests), 0)
  1921. self.assertEqual(repo.requests, [])
  1922. self.assertEqual(len(namespaced_repo.requests), 0)
  1923. self.assertEqual(namespaced_repo.requests, [])
  1924. data = {
  1925. "status": True,
  1926. "uid": "d4182a2ac2d541d884742d3037c26e56",
  1927. "project": {
  1928. "custom_keys": [],
  1929. "parent": None,
  1930. "settings": {
  1931. "issue_tracker": True,
  1932. "project_documentation": True,
  1933. "pull_requests": True,
  1934. },
  1935. "name": "test",
  1936. "date_created": "1426500194",
  1937. "tags": [],
  1938. "user": {
  1939. "fullname": "Pierre-YvesChibon",
  1940. "name": "pingou",
  1941. "default_email": "pingou@fedoraproject.org",
  1942. "emails": ["pingou@fedoraproject.org"],
  1943. "full_url": "http://localhost.localdomain/user/pingou",
  1944. },
  1945. "id": 1,
  1946. "description": "test project",
  1947. "full_url": "http://localhost.localdomain/test",
  1948. },
  1949. "commit_stop": "eface8e13bc2a08a3fb22af9a72a8c90e36b8b89",
  1950. "user": {
  1951. "fullname": "Pierre-YvesChibon",
  1952. "name": "pingou",
  1953. "default_email": "pingou@fedoraproject.org",
  1954. "emails": ["pingou@fedoraproject.org"],
  1955. "full_url": "http://localhost.localdomain/user/pingou",
  1956. },
  1957. "id": 7,
  1958. "comments": [
  1959. {
  1960. "comment": "really?",
  1961. "user": {
  1962. "fullname": "Pierre-YvesChibon",
  1963. "name": "pingou",
  1964. "default_email": "pingou@fedoraproject.org",
  1965. "emails": ["pingou@fedoraproject.org"],
  1966. "full_url": "http://localhost.localdomain/user/pingou",
  1967. },
  1968. "parent": None,
  1969. "date_created": "1426843778",
  1970. "commit": "fa72f315373ec5f98f2b08c8ffae3645c97aaad2",
  1971. "line": 5,
  1972. "id": 1,
  1973. "filename": "test",
  1974. },
  1975. {
  1976. "comment": "Again ?",
  1977. "user": {
  1978. "fullname": "Pierre-YvesChibon",
  1979. "name": "pingou",
  1980. "default_email": "pingou@fedoraproject.org",
  1981. "emails": ["pingou@fedoraproject.org"],
  1982. "full_url": "http://localhost.localdomain/user/pingou",
  1983. },
  1984. "parent": None,
  1985. "date_created": "1426866781",
  1986. "commit": "94ebaf900161394059478fd88aec30e59092a1d7",
  1987. "line": 5,
  1988. "id": 2,
  1989. "filename": "test2",
  1990. },
  1991. {
  1992. "comment": "Should be fine in fact",
  1993. "user": {
  1994. "fullname": "Pierre-YvesChibon",
  1995. "name": "pingou",
  1996. "default_email": "pingou@fedoraproject.org",
  1997. "emails": ["pingou@fedoraproject.org"],
  1998. "full_url": "http://localhost.localdomain/user/pingou",
  1999. },
  2000. "parent": None,
  2001. "date_created": "1426866950",
  2002. "commit": "94ebaf900161394059478fd88aec30e59092a1d7",
  2003. "line": 5,
  2004. "id": 3,
  2005. "filename": "test2",
  2006. },
  2007. ],
  2008. "branch_from": "master",
  2009. "title": "test request",
  2010. "commit_start": "788efeaaf86bde8618f594a8181abb402e1dd904",
  2011. "repo_from": {
  2012. "parent": {
  2013. "custom_keys": [],
  2014. "parent": None,
  2015. "name": "test",
  2016. "date_created": "1426500194",
  2017. "tags": [],
  2018. "user": {
  2019. "fullname": "Pierre-YvesChibon",
  2020. "name": "pingou",
  2021. "default_email": "pingou@fedoraproject.org",
  2022. "emails": ["pingou@fedoraproject.org"],
  2023. "full_url": "http://localhost.localdomain/user/pingou",
  2024. },
  2025. "settings": {
  2026. "issue_tracker": True,
  2027. "project_documentation": True,
  2028. "pull_requests": True,
  2029. },
  2030. "id": 1,
  2031. "description": "test project",
  2032. "full_url": "http://localhost.localdomain/test",
  2033. },
  2034. "settings": {
  2035. "issue_tracker": True,
  2036. "project_documentation": True,
  2037. "pull_requests": True,
  2038. },
  2039. "name": "test",
  2040. "date_created": "1426843440",
  2041. "custom_keys": [],
  2042. "tags": [],
  2043. "user": {
  2044. "fullname": "fake user",
  2045. "name": "fake",
  2046. "default_email": "fake@fedoraproject.org",
  2047. "emails": ["fake@fedoraproject.org"],
  2048. "full_url": "http://localhost.localdomain/user/fake",
  2049. },
  2050. "full_url": "http://localhost.localdomain/fork/fake/test",
  2051. "id": 6,
  2052. "description": "test project",
  2053. },
  2054. "branch": "master",
  2055. "date_created": "1426843732",
  2056. }
  2057. self.assertRaises(
  2058. pagure.exceptions.PagureException,
  2059. pagure.lib.git.update_request_from_git,
  2060. self.session,
  2061. reponame="foobar",
  2062. namespace=None,
  2063. username=None,
  2064. request_uid="d4182a2ac2d541d884742d3037c26e56",
  2065. json_data=data,
  2066. )
  2067. pagure.lib.git.update_request_from_git(
  2068. self.session,
  2069. reponame="test",
  2070. namespace=None,
  2071. username=None,
  2072. request_uid="d4182a2ac2d541d884742d3037c26e56",
  2073. json_data=data,
  2074. )
  2075. self.session.commit()
  2076. # After 1 st insertion
  2077. self.assertEqual(len(repo.requests), 1)
  2078. self.assertEqual(repo.requests[0].id, 7)
  2079. self.assertEqual(
  2080. repo.requests[0].uid, "d4182a2ac2d541d884742d3037c26e56"
  2081. )
  2082. self.assertEqual(repo.requests[0].title, "test request")
  2083. self.assertEqual(len(repo.requests[0].comments), 3)
  2084. data = {
  2085. "status": True,
  2086. "uid": "d4182a2ac2d541d884742d3037c26e57",
  2087. "project": {
  2088. "parent": None,
  2089. "name": "test",
  2090. "custom_keys": [],
  2091. "date_created": "1426500194",
  2092. "full_url": "http://localhost.localdomain/test",
  2093. "tags": [],
  2094. "user": {
  2095. "fullname": "Pierre-YvesChibon",
  2096. "name": "pingou",
  2097. "default_email": "pingou@fedoraproject.org",
  2098. "emails": ["pingou@fedoraproject.org"],
  2099. "full_url": "http://localhost.localdomain/user/pingou",
  2100. },
  2101. "settings": {
  2102. "issue_tracker": True,
  2103. "project_documentation": True,
  2104. "pull_requests": True,
  2105. },
  2106. "id": 1,
  2107. "description": "test project",
  2108. },
  2109. "commit_stop": "eface8e13bc2a08a3fb22af9a72a8c90e36b8b89",
  2110. "user": {
  2111. "fullname": "Pierre-YvesChibon",
  2112. "name": "pingou",
  2113. "default_email": "pingou@fedoraproject.org",
  2114. "emails": ["pingou@fedoraproject.org"],
  2115. "full_url": "http://localhost.localdomain/user/pingou",
  2116. },
  2117. "id": 4,
  2118. "comments": [],
  2119. "branch_from": "master",
  2120. "title": "test request #2",
  2121. "commit_start": "788efeaaf86bde8618f594a8181abb402e1dd904",
  2122. "repo_from": {
  2123. "parent": {
  2124. "parent": None,
  2125. "name": "test",
  2126. "full_url": "http://localhost.localdomain/test",
  2127. "custom_keys": [],
  2128. "date_created": "1426500194",
  2129. "tags": [],
  2130. "user": {
  2131. "fullname": "Pierre-YvesChibon",
  2132. "name": "pingou",
  2133. "default_email": "pingou@fedoraproject.org",
  2134. "emails": ["pingou@fedoraproject.org"],
  2135. "full_url": "http://localhost.localdomain/user/pingou",
  2136. },
  2137. "settings": {
  2138. "issue_tracker": True,
  2139. "project_documentation": True,
  2140. "pull_requests": True,
  2141. },
  2142. "id": 1,
  2143. "description": "test project",
  2144. },
  2145. "settings": {
  2146. "issue_tracker": True,
  2147. "project_documentation": True,
  2148. "pull_requests": True,
  2149. },
  2150. "name": "test",
  2151. "date_created": "1426843440",
  2152. "custom_keys": [],
  2153. "tags": [],
  2154. "user": {
  2155. "fullname": "fake user",
  2156. "name": "fake",
  2157. "default_email": "fake@fedoraproject.org",
  2158. "emails": ["fake@fedoraproject.org"],
  2159. "full_url": "http://localhost.localdomain/user/fake",
  2160. },
  2161. "project_docs": True,
  2162. "id": 6,
  2163. "description": "test project",
  2164. "full_url": "http://localhost.localdomain/fork/fake/test",
  2165. },
  2166. "branch": "master",
  2167. "date_created": "1426843745",
  2168. }
  2169. pagure.lib.git.update_request_from_git(
  2170. self.session,
  2171. reponame="test",
  2172. namespace=None,
  2173. username=None,
  2174. request_uid="d4182a2ac2d541d884742d3037c26e57",
  2175. json_data=data,
  2176. )
  2177. self.session.commit()
  2178. # After 2 nd insertion
  2179. self.assertEqual(len(repo.requests), 2)
  2180. self.assertEqual(repo.requests[0].id, 7)
  2181. self.assertEqual(
  2182. repo.requests[0].uid, "d4182a2ac2d541d884742d3037c26e56"
  2183. )
  2184. self.assertEqual(repo.requests[0].title, "test request")
  2185. self.assertEqual(len(repo.requests[0].comments), 3)
  2186. # 2 entry
  2187. self.assertEqual(repo.requests[1].id, 4)
  2188. self.assertEqual(
  2189. repo.requests[1].uid, "d4182a2ac2d541d884742d3037c26e57"
  2190. )
  2191. self.assertEqual(repo.requests[1].title, "test request #2")
  2192. self.assertEqual(len(repo.requests[1].comments), 0)
  2193. data = {
  2194. "status": True,
  2195. "uid": "d4182a2ac2d541d884742d3037c26e58",
  2196. "full_url": "http://localhost.localdomain/test/pull-request/5",
  2197. "project": {
  2198. "parent": None,
  2199. "name": "test3",
  2200. "full_url": "http://localhost.localdomain/somenamespace/test3",
  2201. "custom_keys": [],
  2202. "namespace": "somenamespace",
  2203. "date_created": "1426500194",
  2204. "tags": [],
  2205. "user": {
  2206. "fullname": "Pierre-YvesChibon",
  2207. "name": "pingou",
  2208. "default_email": "pingou@fedoraproject.org",
  2209. "emails": ["pingou@fedoraproject.org"],
  2210. "full_url": "http://localhost.localdomain/user/pingou",
  2211. },
  2212. "settings": {
  2213. "issue_tracker": True,
  2214. "project_documentation": True,
  2215. "pull_requests": True,
  2216. },
  2217. "id": 3,
  2218. "description": "namespaced test project",
  2219. },
  2220. "commit_stop": "eface8e13bc2a08a3fb22af9a72a8c90e36b8b89",
  2221. "user": {
  2222. "fullname": "Pierre-YvesChibon",
  2223. "name": "pingou",
  2224. "default_email": "pingou@fedoraproject.org",
  2225. "emails": ["pingou@fedoraproject.org"],
  2226. "full_url": "http://localhost.localdomain/user/pingou",
  2227. },
  2228. "id": 5,
  2229. "comments": [],
  2230. "branch_from": "master",
  2231. "title": "test request to namespaced repo",
  2232. "commit_start": "788efeaaf86bde8618f594a8181abb402e1dd904",
  2233. "repo_from": {
  2234. "parent": {
  2235. "parent": None,
  2236. "name": "test",
  2237. "full_url": "http://localhost.localdomain/test",
  2238. "custom_keys": [],
  2239. "date_created": "1426500194",
  2240. "tags": [],
  2241. "user": {
  2242. "fullname": "Pierre-YvesChibon",
  2243. "name": "pingou",
  2244. "default_email": "pingou@fedoraproject.org",
  2245. "emails": ["pingou@fedoraproject.org"],
  2246. "full_url": "http://localhost.localdomain/user/pingou",
  2247. },
  2248. "settings": {
  2249. "issue_tracker": True,
  2250. "project_documentation": True,
  2251. "pull_requests": True,
  2252. },
  2253. "id": 1,
  2254. "description": "test project",
  2255. },
  2256. "settings": {
  2257. "issue_tracker": True,
  2258. "project_documentation": True,
  2259. "pull_requests": True,
  2260. },
  2261. "name": "test",
  2262. "full_url": "http://localhost.localdomain/test",
  2263. "date_created": "1426843440",
  2264. "custom_keys": [],
  2265. "tags": [],
  2266. "user": {
  2267. "fullname": "fake user",
  2268. "name": "fake",
  2269. "default_email": "fake@fedoraproject.org",
  2270. "emails": ["fake@fedoraproject.org"],
  2271. "full_url": "http://localhost.localdomain/user/pingou",
  2272. },
  2273. "project_docs": True,
  2274. "id": 6,
  2275. "description": "test project",
  2276. },
  2277. "branch": "master",
  2278. "date_created": "1426843745",
  2279. }
  2280. pagure.lib.git.update_request_from_git(
  2281. self.session,
  2282. reponame="test3",
  2283. namespace="somenamespace",
  2284. username=None,
  2285. request_uid="d4182a2ac2d541d884742d3037c26e58",
  2286. json_data=data,
  2287. )
  2288. self.session.commit()
  2289. self.assertEqual(len(namespaced_repo.requests), 1)
  2290. self.assertEqual(namespaced_repo.requests[0].id, 5)
  2291. self.assertEqual(
  2292. namespaced_repo.requests[0].uid, "d4182a2ac2d541d884742d3037c26e58"
  2293. )
  2294. self.assertEqual(
  2295. namespaced_repo.requests[0].title,
  2296. "test request to namespaced repo",
  2297. )
  2298. def test_update_ticket_from_git_with_boards(self):
  2299. """Test the update_ticket_from_git method from pagure.lib.git."""
  2300. tests.create_projects(self.session)
  2301. tests.create_projects_git(os.path.join(self.path, "repos"))
  2302. repo = pagure.lib.query._get_project(self.session, "test")
  2303. namespaced_repo = pagure.lib.query._get_project(
  2304. self.session, "test3", namespace="somenamespace"
  2305. )
  2306. # Before
  2307. self.assertEqual(len(repo.issues), 0)
  2308. self.assertEqual(repo.issues, [])
  2309. self.assertEqual(len(namespaced_repo.issues), 0)
  2310. self.assertEqual(namespaced_repo.issues, [])
  2311. self.assertEqual(namespaced_repo.boards, [])
  2312. data = {
  2313. "assignee": None,
  2314. "blocks": [],
  2315. "boards": [
  2316. {
  2317. "board": {
  2318. "active": True,
  2319. "name": "dev",
  2320. "status": [
  2321. {
  2322. "bg_color": "#FFB300",
  2323. "close": False,
  2324. "close_status": None,
  2325. "default": True,
  2326. "name": "Backlog",
  2327. },
  2328. {
  2329. "bg_color": "#ca0eef",
  2330. "close": False,
  2331. "close_status": None,
  2332. "default": False,
  2333. "name": "In Progress",
  2334. },
  2335. {
  2336. "bg_color": "#34d240",
  2337. "close": True,
  2338. "close_status": "Fixed",
  2339. "default": False,
  2340. "name": "Done",
  2341. },
  2342. ],
  2343. "tag": {
  2344. "tag": "dev",
  2345. "tag_color": "DeepBlueSky",
  2346. "tag_description": "",
  2347. },
  2348. "full_url": "http://localhost.localdomain/somenamespace/test3/boards/dev",
  2349. },
  2350. "rank": 2,
  2351. "status": {
  2352. "bg_color": "#ca0eef",
  2353. "close": False,
  2354. "close_status": None,
  2355. "name": "In Progress",
  2356. },
  2357. }
  2358. ],
  2359. "close_status": None,
  2360. "closed_at": None,
  2361. "closed_by": None,
  2362. "comments": [
  2363. {
  2364. "comment": "Issue tagged with: dev",
  2365. "date_created": "1594654596",
  2366. "edited_on": None,
  2367. "editor": None,
  2368. "id": 1,
  2369. "notification": True,
  2370. "parent": None,
  2371. "reactions": {},
  2372. "user": {
  2373. "default_email": "bar@pingou.com",
  2374. "emails": ["bar@pingou.com", "foo@pingou.com"],
  2375. "fullname": "PY C",
  2376. "name": "pingou",
  2377. "url_path": "user/pingou",
  2378. "full_url": "http://localhost.localdomain/user/pingou",
  2379. },
  2380. }
  2381. ],
  2382. "content": "We should work on this for the second time",
  2383. "custom_fields": [],
  2384. "date_created": "1594654596",
  2385. "depends": [],
  2386. "id": 2,
  2387. "full_url": "http://localhost.localdomain/somenamespace/test3/issue/2",
  2388. "last_updated": "1594654596",
  2389. "milestone": None,
  2390. "priority": None,
  2391. "private": False,
  2392. "related_prs": [],
  2393. "status": "Open",
  2394. "tags": ["dev"],
  2395. "title": "Test issue #2",
  2396. "user": {
  2397. "default_email": "foo@bar.com",
  2398. "emails": ["foo@bar.com"],
  2399. "fullname": "foo bar",
  2400. "name": "foo",
  2401. "url_path": "user/foo",
  2402. "full_url": "http://localhost.localdomain/user/pingou",
  2403. },
  2404. }
  2405. pagure.lib.git.update_ticket_from_git(
  2406. self.session,
  2407. reponame="test3",
  2408. namespace="somenamespace",
  2409. username=None,
  2410. issue_uid="d4182a2ac2d541d884742d3037c26e57",
  2411. json_data=data,
  2412. agent="pingou",
  2413. )
  2414. self.session.commit()
  2415. # After insertion
  2416. self.assertEqual(len(namespaced_repo.issues), 1)
  2417. self.assertEqual(namespaced_repo.issues[0].id, 2)
  2418. self.assertEqual(
  2419. namespaced_repo.issues[0].uid, "d4182a2ac2d541d884742d3037c26e57"
  2420. )
  2421. self.assertEqual(namespaced_repo.issues[0].title, "Test issue #2")
  2422. self.assertEqual(len(namespaced_repo.issues[0].comments), 2)
  2423. self.assertEqual(namespaced_repo.issues[0].tags_text, ["dev"])
  2424. self.assertEqual(len(namespaced_repo.issues[0].boards_issues), 1)
  2425. self.assertEqual(len(namespaced_repo.boards), 1)
  2426. def test_update_ticket_from_git_with_boards_twice(self):
  2427. """Test the update_ticket_from_git method from pagure.lib.git."""
  2428. tests.create_projects(self.session)
  2429. tests.create_projects_git(os.path.join(self.path, "repos"))
  2430. repo = pagure.lib.query._get_project(self.session, "test")
  2431. namespaced_repo = pagure.lib.query._get_project(
  2432. self.session, "test3", namespace="somenamespace"
  2433. )
  2434. # Before
  2435. self.assertEqual(len(repo.issues), 0)
  2436. self.assertEqual(repo.issues, [])
  2437. self.assertEqual(len(namespaced_repo.issues), 0)
  2438. self.assertEqual(namespaced_repo.issues, [])
  2439. self.assertEqual(namespaced_repo.boards, [])
  2440. data = {
  2441. "assignee": None,
  2442. "blocks": [],
  2443. "boards": [
  2444. {
  2445. "board": {
  2446. "active": True,
  2447. "name": "dev",
  2448. "status": [
  2449. {
  2450. "bg_color": "#FFB300",
  2451. "close": False,
  2452. "close_status": None,
  2453. "default": True,
  2454. "name": "Backlog",
  2455. },
  2456. {
  2457. "bg_color": "#ca0eef",
  2458. "close": False,
  2459. "close_status": None,
  2460. "default": False,
  2461. "name": "In Progress",
  2462. },
  2463. {
  2464. "bg_color": "#34d240",
  2465. "close": True,
  2466. "close_status": "Fixed",
  2467. "default": False,
  2468. "name": "Done",
  2469. },
  2470. ],
  2471. "tag": {
  2472. "tag": "dev",
  2473. "tag_color": "DeepBlueSky",
  2474. "tag_description": "",
  2475. },
  2476. },
  2477. "rank": 2,
  2478. "status": {
  2479. "bg_color": "#ca0eef",
  2480. "close": False,
  2481. "close_status": None,
  2482. "name": "In Progress",
  2483. },
  2484. "full_url": "http://localhost.localdomain/somenamespace/test3/boards/dev",
  2485. }
  2486. ],
  2487. "close_status": None,
  2488. "closed_at": None,
  2489. "closed_by": None,
  2490. "comments": [
  2491. {
  2492. "comment": "Issue tagged with: dev",
  2493. "date_created": "1594654596",
  2494. "edited_on": None,
  2495. "editor": None,
  2496. "id": 1,
  2497. "notification": True,
  2498. "parent": None,
  2499. "reactions": {},
  2500. "user": {
  2501. "default_email": "bar@pingou.com",
  2502. "emails": ["bar@pingou.com", "foo@pingou.com"],
  2503. "fullname": "PY C",
  2504. "name": "pingou",
  2505. "url_path": "user/pingou",
  2506. "full_url": "http://localhost.localdomain/user/pingou",
  2507. },
  2508. }
  2509. ],
  2510. "content": "We should work on this for the second time",
  2511. "custom_fields": [],
  2512. "date_created": "1594654596",
  2513. "depends": [],
  2514. "id": 2,
  2515. "full_url": "http://localhost.localdomain/somenamespace/test3/issue/2",
  2516. "last_updated": "1594654596",
  2517. "milestone": None,
  2518. "priority": None,
  2519. "private": False,
  2520. "related_prs": [],
  2521. "status": "Open",
  2522. "tags": ["dev"],
  2523. "title": "Test issue #2",
  2524. "user": {
  2525. "default_email": "foo@bar.com",
  2526. "emails": ["foo@bar.com"],
  2527. "fullname": "foo bar",
  2528. "name": "foo",
  2529. "url_path": "user/foo",
  2530. "full_url": "http://localhost.localdomain/user/foo",
  2531. },
  2532. }
  2533. pagure.lib.git.update_ticket_from_git(
  2534. self.session,
  2535. reponame="test3",
  2536. namespace="somenamespace",
  2537. username=None,
  2538. issue_uid="d4182a2ac2d541d884742d3037c26e57",
  2539. json_data=data,
  2540. agent="pingou",
  2541. )
  2542. self.session.commit()
  2543. # After first run
  2544. self.assertEqual(len(namespaced_repo.issues), 1)
  2545. self.assertEqual(namespaced_repo.issues[0].id, 2)
  2546. self.assertEqual(
  2547. namespaced_repo.issues[0].uid, "d4182a2ac2d541d884742d3037c26e57"
  2548. )
  2549. self.assertEqual(namespaced_repo.issues[0].title, "Test issue #2")
  2550. self.assertEqual(len(namespaced_repo.issues[0].comments), 2)
  2551. self.assertEqual(namespaced_repo.issues[0].tags_text, ["dev"])
  2552. self.assertEqual(len(namespaced_repo.issues[0].boards_issues), 1)
  2553. self.assertEqual(namespaced_repo.issues[0].boards_issues[0].rank, 2)
  2554. self.assertEqual(len(namespaced_repo.boards), 1)
  2555. # Second run with a different rank
  2556. data["boards"][0]["rank"] = 7
  2557. pagure.lib.git.update_ticket_from_git(
  2558. self.session,
  2559. reponame="test3",
  2560. namespace="somenamespace",
  2561. username=None,
  2562. issue_uid="d4182a2ac2d541d884742d3037c26e57",
  2563. json_data=data,
  2564. agent="pingou",
  2565. )
  2566. self.session.commit()
  2567. # After insertion
  2568. self.assertEqual(len(namespaced_repo.issues), 1)
  2569. self.assertEqual(namespaced_repo.issues[0].id, 2)
  2570. self.assertEqual(
  2571. namespaced_repo.issues[0].uid, "d4182a2ac2d541d884742d3037c26e57"
  2572. )
  2573. self.assertEqual(namespaced_repo.issues[0].title, "Test issue #2")
  2574. self.assertEqual(len(namespaced_repo.issues[0].comments), 2)
  2575. self.assertEqual(namespaced_repo.issues[0].tags_text, ["dev"])
  2576. self.assertEqual(len(namespaced_repo.issues[0].boards_issues), 1)
  2577. self.assertEqual(namespaced_repo.issues[0].boards_issues[0].rank, 7)
  2578. self.assertEqual(len(namespaced_repo.boards), 1)
  2579. def test_update_request_from_git(self):
  2580. """Test the update_request_from_git method from pagure.lib.git."""
  2581. tests.create_projects(self.session)
  2582. tests.create_projects_git(os.path.join(self.path, "repos"))
  2583. repo = pagure.lib.query._get_project(self.session, "test")
  2584. namespaced_repo = pagure.lib.query._get_project(
  2585. self.session, "test3", namespace="somenamespace"
  2586. )
  2587. # Before
  2588. self.assertEqual(len(repo.requests), 0)
  2589. self.assertEqual(repo.requests, [])
  2590. self.assertEqual(len(namespaced_repo.requests), 0)
  2591. self.assertEqual(namespaced_repo.requests, [])
  2592. data = {
  2593. "status": True,
  2594. "uid": "d4182a2ac2d541d884742d3037c26e57",
  2595. "full_url": "http://localhost.localdomain/test/pull-request/4",
  2596. "project": {
  2597. "parent": None,
  2598. "name": "test",
  2599. "full_url": "http://localhost.localdomain/test",
  2600. "custom_keys": [],
  2601. "date_created": "1426500194",
  2602. "tags": [],
  2603. "user": {
  2604. "fullname": "Pierre-YvesChibon",
  2605. "name": "pingou",
  2606. "default_email": "pingou@fedoraproject.org",
  2607. "emails": ["pingou@fedoraproject.org"],
  2608. "full_url": "http://localhost.localdomain/user/pingou",
  2609. },
  2610. "settings": {
  2611. "issue_tracker": True,
  2612. "project_documentation": True,
  2613. "pull_requests": True,
  2614. },
  2615. "id": 1,
  2616. "description": "test project",
  2617. },
  2618. "commit_stop": "eface8e13bc2a08a3fb22af9a72a8c90e36b8b89",
  2619. "user": {
  2620. "fullname": "Pierre-YvesChibon",
  2621. "name": "pingou",
  2622. "default_email": "pingou@fedoraproject.org",
  2623. "emails": ["pingou@fedoraproject.org"],
  2624. "full_url": "http://localhost.localdomain/user/pingou",
  2625. },
  2626. "id": 4,
  2627. "comments": [],
  2628. "branch_from": "master",
  2629. "title": "test request #2",
  2630. "commit_start": "788efeaaf86bde8618f594a8181abb402e1dd904",
  2631. "repo_from": {
  2632. "parent": {
  2633. "parent": None,
  2634. "name": "test",
  2635. "full_url": "http://localhost.localdomain/test",
  2636. "custom_keys": [],
  2637. "date_created": "1426500194",
  2638. "tags": [],
  2639. "user": {
  2640. "fullname": "Pierre-YvesChibon",
  2641. "name": "pingou",
  2642. "default_email": "pingou@fedoraproject.org",
  2643. "emails": ["pingou@fedoraproject.org"],
  2644. "full_url": "http://localhost.localdomain/user/pingou",
  2645. },
  2646. "settings": {
  2647. "issue_tracker": True,
  2648. "project_documentation": True,
  2649. "pull_requests": True,
  2650. },
  2651. "id": 1,
  2652. "description": "test project",
  2653. },
  2654. "settings": {
  2655. "issue_tracker": True,
  2656. "project_documentation": True,
  2657. "pull_requests": True,
  2658. },
  2659. "full_url": "http://localhost.localdomain/fork/fake/test",
  2660. "name": "test",
  2661. "date_created": "1426843440",
  2662. "custom_keys": [],
  2663. "tags": [],
  2664. "user": {
  2665. "fullname": "fake user",
  2666. "name": "fake",
  2667. "default_email": "fake@fedoraproject.org",
  2668. "emails": ["fake@fedoraproject.org"],
  2669. "full_url": "http://localhost.localdomain/user/fake",
  2670. },
  2671. "project_docs": True,
  2672. "id": 6,
  2673. "description": "test project",
  2674. },
  2675. "branch": "master",
  2676. "date_created": "1426843745",
  2677. "tags": ["WIP", "core"],
  2678. }
  2679. pagure.lib.git.update_request_from_git(
  2680. self.session,
  2681. reponame="test",
  2682. namespace=None,
  2683. username=None,
  2684. request_uid="d4182a2ac2d541d884742d3037c26e57",
  2685. json_data=data,
  2686. )
  2687. self.session.commit()
  2688. # After insertion
  2689. self.assertEqual(repo.requests[0].id, 4)
  2690. self.assertEqual(
  2691. repo.requests[0].uid, "d4182a2ac2d541d884742d3037c26e57"
  2692. )
  2693. self.assertEqual(repo.requests[0].title, "test request #2")
  2694. self.assertEqual(len(repo.requests[0].comments), 0)
  2695. self.assertEqual(repo.requests[0].tags_text, ["WIP", "core"])
  2696. def test_read_git_lines(self):
  2697. """Test the read_git_lines method of pagure.lib.git."""
  2698. self.test_update_git()
  2699. gitrepo = os.path.join(
  2700. self.path, "repos", "tickets", "test_ticket_repo.git"
  2701. )
  2702. output = pagure.lib.git.read_git_lines(
  2703. ["log", "-1", "--pretty='%s'"], gitrepo
  2704. )
  2705. self.assertEqual(len(output), 1)
  2706. self.assertTrue(output[0].startswith("'Updated issue "))
  2707. self.assertTrue(output[0].endswith(": Test issue'"))
  2708. # Keeping the new line symbol
  2709. output = pagure.lib.git.read_git_lines(
  2710. ["log", "-1", "--pretty='%s'"], gitrepo, keepends=True
  2711. )
  2712. self.assertEqual(len(output), 1)
  2713. self.assertTrue(output[0].endswith(": Test issue'\n"))
  2714. def test_get_revs_between(self):
  2715. """Test the get_revs_between method of pagure.lib.git."""
  2716. self.test_update_git()
  2717. gitrepo = os.path.join(
  2718. self.path, "repos", "tickets", "test_ticket_repo.git"
  2719. )
  2720. output = pagure.lib.git.read_git_lines(
  2721. ["log", "-3", "--pretty='%H'"], gitrepo
  2722. )
  2723. self.assertEqual(len(output), 2)
  2724. from_hash = output[1].replace("'", "")
  2725. # Case 1, repo BASE is null and HEAD is equal to from_hash
  2726. to_hash = "0"
  2727. output1 = pagure.lib.git.get_revs_between(
  2728. to_hash, from_hash, gitrepo, "refs/heads/master"
  2729. )
  2730. self.assertEqual(output1, [from_hash])
  2731. # Case 2, get revs between two commits (to_hash, from_hash)
  2732. to_hash = output[0].replace("'", "")
  2733. output2 = pagure.lib.git.get_revs_between(
  2734. to_hash, from_hash, gitrepo, "refs/heads/master"
  2735. )
  2736. self.assertEqual(output2, [to_hash])
  2737. # Case 3, get revs between two commits (from_hash, to_hash)
  2738. output3 = pagure.lib.git.get_revs_between(
  2739. from_hash, to_hash, gitrepo, "refs/heads/master"
  2740. )
  2741. self.assertEqual(output3, [to_hash])
  2742. # Case 4, get revs between two commits on two different branches
  2743. newgitrepo = tempfile.mkdtemp(prefix="pagure-")
  2744. newrepo = pygit2.clone_repository(gitrepo, newgitrepo)
  2745. newrepo.create_branch("feature", newrepo.head.peel())
  2746. with open(os.path.join(newgitrepo, "sources"), "w") as stream:
  2747. stream.write("foo\n bar")
  2748. newrepo.index.add("sources")
  2749. newrepo.index.write()
  2750. # Commits the files added
  2751. tree = newrepo.index.write_tree()
  2752. author = pygit2.Signature("Alice Author", "alice@authors.tld")
  2753. committer = pygit2.Signature("Cecil Committer", "cecil@committers.tld")
  2754. newrepo.create_commit(
  2755. "refs/heads/feature", # the name of the reference to update
  2756. author,
  2757. committer,
  2758. "Add sources file for testing",
  2759. # binary string representing the tree object ID
  2760. tree,
  2761. # list of binary strings representing parents of the new commit
  2762. [to_hash],
  2763. )
  2764. branch_commit = newrepo.revparse_single("refs/heads/feature")
  2765. # Push to origin
  2766. ori_remote = newrepo.remotes[0]
  2767. PagureRepo.push(ori_remote, "refs/heads/feature")
  2768. # Remove the clone
  2769. shutil.rmtree(newgitrepo)
  2770. output4 = pagure.lib.git.get_revs_between(
  2771. "0", branch_commit.oid.hex, gitrepo, "refs/heads/feature"
  2772. )
  2773. self.assertEqual(output4, [branch_commit.oid.hex])
  2774. def test_get_author(self):
  2775. """Test the get_author method of pagure.lib.git."""
  2776. self.test_update_git()
  2777. gitrepo = os.path.join(
  2778. self.path, "repos", "tickets", "test_ticket_repo.git"
  2779. )
  2780. output = pagure.lib.git.read_git_lines(
  2781. ["log", "-3", "--pretty='%H'"], gitrepo
  2782. )
  2783. self.assertEqual(len(output), 2)
  2784. for githash in output:
  2785. githash = githash.replace("'", "")
  2786. output = pagure.lib.git.get_author(githash, gitrepo)
  2787. self.assertEqual(output, "pagure")
  2788. def get_author_email(self):
  2789. """Test the get_author_email method of pagure.lib.git."""
  2790. self.test_update_git()
  2791. gitrepo = os.path.join(self.path, "tickets", "test_ticket_repo.git")
  2792. output = pagure.lib.git.read_git_lines(
  2793. ["log", "-3", "--pretty='%H'"], gitrepo
  2794. )
  2795. self.assertEqual(len(output), 2)
  2796. for githash in output:
  2797. githash = githash.replace("'", "")
  2798. output = pagure.lib.git.get_author_email(githash, gitrepo)
  2799. self.assertEqual(output, "pagure")
  2800. def test_get_changed_files(self):
  2801. """Test the get_changed_files method of pagure.lib.git."""
  2802. self.test_update_git()
  2803. repo = pagure.lib.query.get_authorized_project(
  2804. self.session, "test_ticket_repo"
  2805. )
  2806. issue = pagure.lib.query.search_issues(self.session, repo, issueid=1)
  2807. gitrepo = os.path.join(
  2808. self.path, "repos", "tickets", "test_ticket_repo.git"
  2809. )
  2810. output = pagure.lib.git.read_git_lines(
  2811. ["log", "-3", "--pretty='%H'"], gitrepo
  2812. )
  2813. self.assertEqual(len(output), 2)
  2814. hash0 = output[0].replace("'", "")
  2815. hash1 = output[1].replace("'", "")
  2816. # Case 1: hash1 => hash0
  2817. output1 = pagure.lib.git.get_changed_files(hash0, hash1, gitrepo)
  2818. self.assertEqual(output1, {issue.uid: "M"})
  2819. # Case 2: hash0 => hash1
  2820. output2 = pagure.lib.git.get_changed_files(hash1, hash0, gitrepo)
  2821. self.assertEqual(output2, {issue.uid: "M"})
  2822. # Case 3: hash0 => hash0
  2823. output3 = pagure.lib.git.get_changed_files(hash0, hash0, gitrepo)
  2824. self.assertEqual(output3, {})
  2825. # Case 4: NULL => hash0
  2826. output4 = pagure.lib.git.get_changed_files(hash0, "", gitrepo)
  2827. self.assertEqual(output4, {})
  2828. # Case 5: NULL => NULL
  2829. output5 = pagure.lib.git.get_changed_files("", "", gitrepo)
  2830. self.assertEqual(output5, {})
  2831. def test_get_repo_name(self):
  2832. """Test the get_repo_name method of pagure.lib.git."""
  2833. def runtest(reponame, *path):
  2834. gitrepo = os.path.join(self.path, "repos", *path)
  2835. os.makedirs(gitrepo)
  2836. repo_name = pagure.lib.git.get_repo_name(gitrepo)
  2837. self.assertEqual(repo_name, reponame)
  2838. runtest("test_ticket_repo", "tickets", "test_ticket_repo.git")
  2839. runtest("test", "test.git")
  2840. runtest("foo.test", "foo.test.git")
  2841. def test_get_username(self):
  2842. """Test the get_username method of pagure.lib.git."""
  2843. def runtest(username, *path):
  2844. gitrepo = os.path.join(self.path, "repos", *path)
  2845. os.makedirs(gitrepo)
  2846. repo_username = pagure.lib.git.get_username(gitrepo)
  2847. self.assertEqual(repo_username, username)
  2848. runtest(None, "tickets", "test_ticket_repo.git")
  2849. runtest(None, "test.git")
  2850. runtest(None, "foo.test.git")
  2851. runtest("pingou", "forks", "pingou", "foo.test.git")
  2852. runtest("pingou", "forks", "pingou", "bar/foo.test.git")
  2853. def test_get_repo_namespace(self):
  2854. """Test the get_repo_namespace method of pagure.lib.git."""
  2855. def runtest(namespace, *path):
  2856. gitrepo = os.path.join(self.path, "repos", *path)
  2857. if not os.path.exists(gitrepo):
  2858. os.makedirs(gitrepo)
  2859. repo_namespace = pagure.lib.git.get_repo_namespace(gitrepo)
  2860. self.assertEqual(repo_namespace, namespace)
  2861. runtest(None, "test_ticket_repo.git")
  2862. runtest("foo/bar/baz", "foo", "bar", "baz", "test.git")
  2863. runtest(None, "foo.test.git")
  2864. runtest(None, "forks", "user", "foo.test.git")
  2865. runtest("bar", "forks", "user", "bar", "foo.test.git")
  2866. runtest("ns/bar", "forks", "user", "ns", "bar", "foo.test.git")
  2867. runtest("bar", "forks", "user", "bar", "foo.test.git")
  2868. def test_update_custom_fields_from_json(self):
  2869. """Test the update_custom_fields_from_json method of lib.git"""
  2870. tests.create_projects(self.session)
  2871. repo = pagure.lib.query._get_project(self.session, "test")
  2872. # Create issues to play with
  2873. pagure.lib.query.new_issue(
  2874. session=self.session,
  2875. repo=repo,
  2876. title="Test issue",
  2877. content="We should work on this",
  2878. user="pingou",
  2879. issue_uid="someuid",
  2880. )
  2881. self.session.commit()
  2882. issue = pagure.lib.query.get_issue_by_uid(self.session, "someuid")
  2883. # Fake json data, currently without custom_fields
  2884. # This should bring no new custom_fields to the issue
  2885. json_data = {
  2886. "status": "Open",
  2887. "title": "Test issue",
  2888. "private": False,
  2889. "content": "We should work on this",
  2890. "user": {
  2891. "fullname": "PY C",
  2892. "name": "pingou",
  2893. "default_email": "bar@pingou.com",
  2894. "emails": ["bar@pingou.com"],
  2895. },
  2896. "id": 1,
  2897. "blocks": [],
  2898. "depends": [],
  2899. "date_created": "1234567",
  2900. "comments": [],
  2901. }
  2902. pagure.lib.git.update_custom_field_from_json(
  2903. self.session, repo, issue, json_data
  2904. )
  2905. updated_issue = pagure.lib.query.get_issue_by_uid(
  2906. self.session, "someuid"
  2907. )
  2908. self.assertEqual(updated_issue.to_json().get("custom_fields"), [])
  2909. custom_fields = [
  2910. {
  2911. "name": "custom1",
  2912. "key_type": "text",
  2913. "value": "value1",
  2914. "key_data": None,
  2915. },
  2916. {
  2917. "name": "custom2",
  2918. "key_type": "text",
  2919. "value": "value2",
  2920. "key_data": None,
  2921. },
  2922. ]
  2923. # Again, Fake the json data but, with custom_fields in it
  2924. # The updated issue should have the custom_fields as
  2925. # was in the json_data
  2926. json_data = {
  2927. "status": "Open",
  2928. "title": "Test issue",
  2929. "private": False,
  2930. "content": "We should work on this",
  2931. "user": {
  2932. "fullname": "PY C",
  2933. "name": "pingou",
  2934. "default_email": "bar@pingou.com",
  2935. "emails": ["bar@pingou.com"],
  2936. },
  2937. "id": 1,
  2938. "blocks": [],
  2939. "depends": [],
  2940. "date_created": "1234567",
  2941. "comments": [],
  2942. "custom_fields": custom_fields,
  2943. }
  2944. pagure.lib.git.update_custom_field_from_json(
  2945. self.session, repo, issue, json_data
  2946. )
  2947. updated_issue = pagure.lib.query.get_issue_by_uid(
  2948. self.session, "someuid"
  2949. )
  2950. custom_fields_of_issue = updated_issue.to_json().get("custom_fields")
  2951. self.assertEqual(custom_fields_of_issue, custom_fields)
  2952. @patch("pagure.lib.notify.send_email")
  2953. @patch("pagure.lib.git.update_git")
  2954. def test_merge_pull_request_no_master(self, email_f, up_git):
  2955. """Test the merge_pull_request function when there are no master
  2956. branch in the repo."""
  2957. email_f.return_value = True
  2958. up_git.return_value = True
  2959. gitfolder = os.path.join(self.path, "repos")
  2960. docfolder = os.path.join(self.path, "docs")
  2961. ticketfolder = os.path.join(self.path, "tickets")
  2962. requestfolder = os.path.join(self.path, "requests")
  2963. # Create project
  2964. item = pagure.lib.model.Project(
  2965. user_id=1, # pingou
  2966. name="test",
  2967. description="test project",
  2968. hook_token="aaabbbwww",
  2969. )
  2970. self.session.add(item)
  2971. self.session.commit()
  2972. repo = pagure.lib.query.get_authorized_project(self.session, "test")
  2973. gitrepo = os.path.join(gitfolder, repo.path)
  2974. docrepo = os.path.join(docfolder, repo.path)
  2975. ticketrepo = os.path.join(ticketfolder, repo.path)
  2976. requestrepo = os.path.join(requestfolder, repo.path)
  2977. os.makedirs(os.path.join(self.path, "repos", "forks", "foo"))
  2978. self.gitrepo = os.path.join(self.path, "repos", "test.git")
  2979. os.makedirs(self.gitrepo)
  2980. repo_obj = pygit2.init_repository(self.gitrepo, bare=True)
  2981. # Fork the project
  2982. task = pagure.lib.query.fork_project(
  2983. session=self.session, user="foo", repo=repo
  2984. )
  2985. self.session.commit()
  2986. self.assertEqual(
  2987. task.get(),
  2988. {
  2989. "endpoint": "ui_ns.view_repo",
  2990. "repo": "test",
  2991. "username": "foo",
  2992. "namespace": None,
  2993. },
  2994. )
  2995. # Create repo, with some content
  2996. self.gitrepo = os.path.join(
  2997. self.path, "repos", "forks", "foo", "test.git"
  2998. )
  2999. tests.add_content_git_repo(self.gitrepo, branch="feature")
  3000. fork_repo = pagure.lib.query.get_authorized_project(
  3001. self.session, "test", user="foo"
  3002. )
  3003. # Create a PR to play with
  3004. req = pagure.lib.query.new_pull_request(
  3005. session=self.session,
  3006. repo_from=fork_repo,
  3007. branch_from="feature",
  3008. repo_to=repo,
  3009. branch_to="master",
  3010. title="test PR",
  3011. user="pingou",
  3012. requestuid="foobar",
  3013. requestid=None,
  3014. status="Open",
  3015. notify=True,
  3016. )
  3017. self.assertEqual(req.id, 1)
  3018. self.assertEqual(req.title, "test PR")
  3019. # `master` branch not found
  3020. msg = pagure.lib.git.merge_pull_request(
  3021. self.session, request=req, username="pingou", domerge=False
  3022. )
  3023. self.assertEqual(msg, "FFORWARD")
  3024. @patch("pagure.lib.notify.send_email")
  3025. @patch("pagure.lib.git.update_git")
  3026. def test_merge_pull_request_closed(self, email_f, up_git):
  3027. """Test the merge_pull_request function when the PR was already
  3028. closed/merged."""
  3029. email_f.return_value = True
  3030. up_git.return_value = True
  3031. gitfolder = os.path.join(self.path, "repos")
  3032. docfolder = os.path.join(self.path, "docs")
  3033. ticketfolder = os.path.join(self.path, "tickets")
  3034. requestfolder = os.path.join(self.path, "requests")
  3035. # Create project
  3036. item = pagure.lib.model.Project(
  3037. user_id=1, # pingou
  3038. name="test",
  3039. description="test project",
  3040. hook_token="aaabbbwww",
  3041. )
  3042. self.session.add(item)
  3043. self.session.commit()
  3044. repo = pagure.lib.query.get_authorized_project(self.session, "test")
  3045. os.makedirs(os.path.join(self.path, "repos", "forks", "foo"))
  3046. self.gitrepo = os.path.join(self.path, "repos", "test.git")
  3047. os.makedirs(self.gitrepo)
  3048. repo_obj = pygit2.init_repository(self.gitrepo, bare=True)
  3049. tests.add_content_git_repo(self.gitrepo, branch="master")
  3050. # Fork the project
  3051. task = pagure.lib.query.fork_project(
  3052. session=self.session, user="foo", repo=repo
  3053. )
  3054. self.session.commit()
  3055. self.assertEqual(
  3056. task.get(),
  3057. {
  3058. "endpoint": "ui_ns.view_repo",
  3059. "repo": "test",
  3060. "username": "foo",
  3061. "namespace": None,
  3062. },
  3063. )
  3064. # Create repo, with some content
  3065. self.gitrepo = os.path.join(
  3066. self.path, "repos", "forks", "foo", "test.git"
  3067. )
  3068. tests.add_content_git_repo(self.gitrepo, branch="feature")
  3069. fork_repo = pagure.lib.query.get_authorized_project(
  3070. self.session, "test", user="foo"
  3071. )
  3072. # Create a PR to play with
  3073. req = pagure.lib.query.new_pull_request(
  3074. session=self.session,
  3075. repo_from=fork_repo,
  3076. branch_from="feature",
  3077. repo_to=repo,
  3078. branch_to="master",
  3079. title="test PR",
  3080. user="pingou",
  3081. requestuid="foobar",
  3082. requestid=None,
  3083. status="Open",
  3084. notify=True,
  3085. )
  3086. self.assertEqual(req.id, 1)
  3087. self.assertEqual(req.title, "test PR")
  3088. # Close the PR before we ask to merge it
  3089. req.status = "Closed"
  3090. req.closed_by_id = 2 # id:2 == foo
  3091. req.closed_at = datetime.datetime(2017, 10, 20, 12, 32, 10)
  3092. self.session.add(req)
  3093. self.session.commit()
  3094. # PR already closed
  3095. six.assertRaisesRegex(
  3096. self,
  3097. pagure.exceptions.PagureException,
  3098. "This pull-request was merged or closed by foo",
  3099. pagure.lib.git.merge_pull_request,
  3100. self.session,
  3101. request=req,
  3102. username="pingou",
  3103. domerge=False,
  3104. )
  3105. @patch("subprocess.Popen")
  3106. def test_generate_gitolite_acls(self, popen):
  3107. """Test calling generate_gitolite_acls."""
  3108. pagure.SESSION = self.session
  3109. pagure.lib.git.SESSION = self.session
  3110. pagure.config.config["GITOLITE_HOME"] = "/tmp"
  3111. proc = MagicMock()
  3112. proc.communicate.return_value = (1, 2)
  3113. proc.returncode = 0
  3114. popen.return_value = proc
  3115. helper = pagure.lib.git_auth.get_git_auth_helper("gitolite3")
  3116. helper.generate_acls(project=None)
  3117. popen.assert_called_with(
  3118. "HOME=/tmp gitolite compile && "
  3119. "HOME=/tmp gitolite trigger POST_COMPILE",
  3120. cwd="/tmp",
  3121. shell=True,
  3122. stderr=-1,
  3123. stdout=-1,
  3124. )
  3125. def test_is_forced_push_new_branch(self):
  3126. self.assertFalse(
  3127. pagure.lib.git.is_forced_push(
  3128. "0000000000000000000000000000000000000000",
  3129. "^0e6e0b6c931d65ee22f67205a53933d841c6eeff",
  3130. "path/is/not/important",
  3131. )
  3132. )
  3133. def test_read_output(self):
  3134. here = os.path.dirname(os.path.realpath(__file__))
  3135. # This should't block
  3136. self.assertTrue(
  3137. pagure.lib.git.read_output(["git", "rev-list", "--all"], here)
  3138. )
  3139. @patch("pagure.utils.get_repo_path")
  3140. def test_update_pull_ref(self, get_repo_path):
  3141. fake_pr = MagicMock()
  3142. fake_pr.uid = "1234567"
  3143. fake_pr.branch_from = "master"
  3144. fake_pr.id = 6
  3145. fake_pr.user = MagicMock()
  3146. fake_pr.user.user = "pingou"
  3147. fake_pr.project = "doesnt_matter_mocked_out"
  3148. projects = tests.create_projects_git(
  3149. os.path.join(self.path, "repos"), bare=True
  3150. )
  3151. tests.add_content_git_repo(projects[0])
  3152. tests.add_content_git_repo(projects[1])
  3153. orig = pygit2.Repository(projects[0])
  3154. fork = pygit2.Repository(projects[1])
  3155. get_repo_path.return_value = projects[0]
  3156. # make sure that creating works the first time
  3157. pagure.lib.git.update_pull_ref(fake_pr, fork)
  3158. oldhex = fork.references["refs/heads/master"].peel().hex
  3159. self.assertEqual(
  3160. orig.references["refs/pull/6/head"].peel().hex, oldhex
  3161. )
  3162. # make sure that updating works correctly
  3163. tests.add_content_git_repo(projects[1], append="foobar")
  3164. newhex = fork.references["refs/heads/master"].peel().hex
  3165. self.assertNotEqual(oldhex, newhex)
  3166. pagure.lib.git.update_pull_ref(fake_pr, fork)
  3167. self.assertEqual(
  3168. orig.references["refs/pull/6/head"].peel().hex, newhex
  3169. )
  3170. # make sure the function works fine even if there's a leftover
  3171. # ref from previous failed run of the function
  3172. with patch("pygit2.remote.RemoteCollection.delete"):
  3173. pagure.lib.git.update_pull_ref(fake_pr, fork)
  3174. self.assertIsNotNone(fork.remotes["pingou_1234567"])
  3175. tests.add_content_git_repo(projects[1], append="foobarbaz")
  3176. newesthex = fork.references["refs/heads/master"].peel().hex
  3177. self.assertNotEqual(newhex, newesthex)
  3178. pagure.lib.git.update_pull_ref(fake_pr, fork)
  3179. self.assertEqual(
  3180. orig.references["refs/pull/6/head"].peel().hex, newesthex
  3181. )
  3182. class PagureLibGitCommitToPatchtests(tests.Modeltests):
  3183. """Tests for pagure.lib.git"""
  3184. maxDiff = None
  3185. def setUp(self):
  3186. """Set up the environment for the tests."""
  3187. super(PagureLibGitCommitToPatchtests, self).setUp()
  3188. # Create a git repo to play with
  3189. self.gitrepo = os.path.join(self.path, "repos", "test_repo.git")
  3190. os.makedirs(self.gitrepo)
  3191. repo = pygit2.init_repository(self.gitrepo)
  3192. # Create a file in that git repo
  3193. with open(os.path.join(self.gitrepo, "sources"), "w") as stream:
  3194. stream.write("foo\n bar")
  3195. repo.index.add("sources")
  3196. repo.index.write()
  3197. # Commits the files added
  3198. tree = repo.index.write_tree()
  3199. author = pygit2.Signature("Alice Author", "alice@authors.tld")
  3200. committer = pygit2.Signature("Cecil Committer", "cecil@committers.tld")
  3201. repo.create_commit(
  3202. "refs/heads/master", # the name of the reference to update
  3203. author,
  3204. committer,
  3205. "Add sources file for testing",
  3206. # binary string representing the tree object ID
  3207. tree,
  3208. # list of binary strings representing parents of the new commit
  3209. [],
  3210. )
  3211. self.first_commit = repo.revparse_single("HEAD")
  3212. # Edit the sources file again
  3213. with open(os.path.join(self.gitrepo, "sources"), "w") as stream:
  3214. stream.write("foo\n bar\nbaz\n boose")
  3215. repo.index.add("sources")
  3216. repo.index.write()
  3217. # Commits the files added
  3218. tree = repo.index.write_tree()
  3219. author = pygit2.Signature("Alice Author", "alice@authors.tld")
  3220. committer = pygit2.Signature("Cecil Committer", "cecil@committers.tld")
  3221. repo.create_commit(
  3222. "refs/heads/master", # the name of the reference to update
  3223. author,
  3224. committer,
  3225. "Add baz and boose to the sources\n\n There are more objects to "
  3226. "consider",
  3227. # binary string representing the tree object ID
  3228. tree,
  3229. # list of binary strings representing parents of the new commit
  3230. [self.first_commit.oid.hex],
  3231. )
  3232. self.second_commit = repo.revparse_single("HEAD")
  3233. # Add empty commit
  3234. repo.create_commit(
  3235. "refs/heads/master", # the name of the reference to update
  3236. author,
  3237. committer,
  3238. "Empty commit",
  3239. # binary string representing the tree object ID
  3240. tree,
  3241. # list of binary strings representing parents of the new commit
  3242. [self.second_commit.oid.hex],
  3243. )
  3244. self.third_commit = repo.revparse_single("HEAD")
  3245. def test_commit_to_patch_first_commit(self):
  3246. """Test the commit_to_patch function of pagure.lib.git."""
  3247. repo = pygit2.init_repository(self.gitrepo)
  3248. patch = pagure.lib.git.commit_to_patch(repo, self.first_commit)
  3249. exp = r"""Mon Sep 17 00:00:00 2001
  3250. From: Alice Author <alice@authors.tld>
  3251. Subject: Add sources file for testing
  3252. ---
  3253. diff --git a/sources b/sources
  3254. new file mode 100644
  3255. index 0000000..9f44358
  3256. --- /dev/null
  3257. +++ b/sources
  3258. @@ -0,0 +1,2 @@
  3259. +foo
  3260. + bar
  3261. \ No newline at end of file
  3262. """
  3263. npatch = []
  3264. for row in patch.split("\n"):
  3265. if row.startswith("Date:"):
  3266. continue
  3267. if row.startswith("From "):
  3268. row = row.split(" ", 2)[2]
  3269. npatch.append(row)
  3270. patch = "\n".join(npatch)
  3271. self.assertEqual(patch, exp)
  3272. def test_commit_to_patch_single_commit(self):
  3273. """Test the commit_to_patch function of pagure.lib.git."""
  3274. repo = pygit2.init_repository(self.gitrepo)
  3275. patch = pagure.lib.git.commit_to_patch(repo, self.second_commit)
  3276. exp = r"""Mon Sep 17 00:00:00 2001
  3277. From: Alice Author <alice@authors.tld>
  3278. Subject: Add baz and boose to the sources
  3279. There are more objects to consider
  3280. ---
  3281. diff --git a/sources b/sources
  3282. index 9f44358..2a552bb 100644
  3283. --- a/sources
  3284. +++ b/sources
  3285. @@ -1,2 +1,4 @@
  3286. foo
  3287. - bar
  3288. \ No newline at end of file
  3289. + bar
  3290. +baz
  3291. + boose
  3292. \ No newline at end of file
  3293. """
  3294. npatch = []
  3295. for row in patch.split("\n"):
  3296. if row.startswith("Date:"):
  3297. continue
  3298. if row.startswith("From "):
  3299. row = row.split(" ", 2)[2]
  3300. npatch.append(row)
  3301. patch = "\n".join(npatch)
  3302. self.assertEqual(patch, exp)
  3303. def test_commit_to_patch_2_commits(self):
  3304. """Test the commit_to_patch function of pagure.lib.git."""
  3305. repo = pygit2.init_repository(self.gitrepo)
  3306. patch = pagure.lib.git.commit_to_patch(
  3307. repo, [self.first_commit, self.second_commit]
  3308. )
  3309. exp = r"""Mon Sep 17 00:00:00 2001
  3310. From: Alice Author <alice@authors.tld>
  3311. Subject: [PATCH 1/2] Add sources file for testing
  3312. ---
  3313. diff --git a/sources b/sources
  3314. new file mode 100644
  3315. index 0000000..9f44358
  3316. --- /dev/null
  3317. +++ b/sources
  3318. @@ -0,0 +1,2 @@
  3319. +foo
  3320. + bar
  3321. \ No newline at end of file
  3322. Mon Sep 17 00:00:00 2001
  3323. From: Alice Author <alice@authors.tld>
  3324. Subject: [PATCH 2/2] Add baz and boose to the sources
  3325. There are more objects to consider
  3326. ---
  3327. diff --git a/sources b/sources
  3328. index 9f44358..2a552bb 100644
  3329. --- a/sources
  3330. +++ b/sources
  3331. @@ -1,2 +1,4 @@
  3332. foo
  3333. - bar
  3334. \ No newline at end of file
  3335. + bar
  3336. +baz
  3337. + boose
  3338. \ No newline at end of file
  3339. """
  3340. npatch = []
  3341. for row in patch.split("\n"):
  3342. if row.startswith("Date:"):
  3343. continue
  3344. if row.startswith("From "):
  3345. row = row.split(" ", 2)[2]
  3346. npatch.append(row)
  3347. patch = "\n".join(npatch)
  3348. self.assertEqual(patch, exp)
  3349. def test_commit_to_patch_first_commit_diff(self):
  3350. """Test the commit_to_patch function of pagure.lib.git."""
  3351. repo = pygit2.init_repository(self.gitrepo)
  3352. patch = pagure.lib.git.commit_to_patch(
  3353. repo, self.first_commit, diff_view=True
  3354. )
  3355. exp = r"""diff --git a/sources b/sources
  3356. new file mode 100644
  3357. index 0000000..9f44358
  3358. --- /dev/null
  3359. +++ b/sources
  3360. @@ -0,0 +1,2 @@
  3361. +foo
  3362. + bar
  3363. \ No newline at end of file
  3364. """
  3365. npatch = []
  3366. for row in patch.split("\n"):
  3367. if row.startswith("Date:"):
  3368. continue
  3369. if row.startswith("From "):
  3370. row = row.split(" ", 2)[2]
  3371. npatch.append(row)
  3372. patch = "\n".join(npatch)
  3373. self.assertEqual(patch, exp)
  3374. def test_commit_to_patch_single_commit_diff(self):
  3375. """Test the commit_to_patch function of pagure.lib.git."""
  3376. repo = pygit2.init_repository(self.gitrepo)
  3377. patch = pagure.lib.git.commit_to_patch(
  3378. repo, self.second_commit, diff_view=True
  3379. )
  3380. exp = r"""diff --git a/sources b/sources
  3381. index 9f44358..2a552bb 100644
  3382. --- a/sources
  3383. +++ b/sources
  3384. @@ -1,2 +1,4 @@
  3385. foo
  3386. - bar
  3387. \ No newline at end of file
  3388. + bar
  3389. +baz
  3390. + boose
  3391. \ No newline at end of file
  3392. """
  3393. npatch = []
  3394. for row in patch.split("\n"):
  3395. if row.startswith("Date:"):
  3396. continue
  3397. if row.startswith("From "):
  3398. row = row.split(" ", 2)[2]
  3399. npatch.append(row)
  3400. patch = "\n".join(npatch)
  3401. self.assertEqual(patch, exp)
  3402. def test_commit_to_patch_two_commits_diff(self):
  3403. """Test the commit_to_patch function of pagure.lib.git."""
  3404. repo = pygit2.init_repository(self.gitrepo)
  3405. patch = pagure.lib.git.commit_to_patch(
  3406. repo, [self.first_commit, self.second_commit], diff_view=True
  3407. )
  3408. exp = r"""diff --git a/sources b/sources
  3409. new file mode 100644
  3410. index 0000000..9f44358
  3411. --- /dev/null
  3412. +++ b/sources
  3413. @@ -0,0 +1,2 @@
  3414. +foo
  3415. + bar
  3416. \ No newline at end of file
  3417. diff --git a/sources b/sources
  3418. index 9f44358..2a552bb 100644
  3419. --- a/sources
  3420. +++ b/sources
  3421. @@ -1,2 +1,4 @@
  3422. foo
  3423. - bar
  3424. \ No newline at end of file
  3425. + bar
  3426. +baz
  3427. + boose
  3428. \ No newline at end of file
  3429. """
  3430. npatch = []
  3431. for row in patch.split("\n"):
  3432. if row.startswith("Date:"):
  3433. continue
  3434. if row.startswith("From "):
  3435. row = row.split(" ", 2)[2]
  3436. npatch.append(row)
  3437. patch = "\n".join(npatch)
  3438. self.assertEqual(patch, exp)
  3439. def test_commit_to_patch_first_commit_diff_separated(self):
  3440. """Test the commit_to_patch function of pagure.lib.git."""
  3441. repo = pygit2.init_repository(self.gitrepo)
  3442. patches = pagure.lib.git.commit_to_patch(
  3443. repo, self.first_commit, diff_view=True, separated=True
  3444. )
  3445. exp = r"""diff --git a/sources b/sources
  3446. new file mode 100644
  3447. index 0000000..9f44358
  3448. --- /dev/null
  3449. +++ b/sources
  3450. @@ -0,0 +1,2 @@
  3451. +foo
  3452. + bar
  3453. \ No newline at end of file
  3454. """
  3455. output = []
  3456. for patch in patches:
  3457. npatch = []
  3458. for row in patch.split("\n"):
  3459. if row.startswith("Date:"):
  3460. continue
  3461. if row.startswith("From "):
  3462. row = row.split(" ", 2)[2]
  3463. npatch.append(row)
  3464. patch = "\n".join(npatch)
  3465. output.append(patch)
  3466. self.assertEqual(output, [exp])
  3467. def test_commit_to_patch_single_commit_diff_separated(self):
  3468. """Test the commit_to_patch function of pagure.lib.git."""
  3469. repo = pygit2.init_repository(self.gitrepo)
  3470. patches = pagure.lib.git.commit_to_patch(
  3471. repo, self.second_commit, diff_view=True, separated=True
  3472. )
  3473. exp = r"""diff --git a/sources b/sources
  3474. index 9f44358..2a552bb 100644
  3475. --- a/sources
  3476. +++ b/sources
  3477. @@ -1,2 +1,4 @@
  3478. foo
  3479. - bar
  3480. \ No newline at end of file
  3481. + bar
  3482. +baz
  3483. + boose
  3484. \ No newline at end of file
  3485. """
  3486. output = []
  3487. for patch in patches:
  3488. npatch = []
  3489. for row in patch.split("\n"):
  3490. if row.startswith("Date:"):
  3491. continue
  3492. if row.startswith("From "):
  3493. row = row.split(" ", 2)[2]
  3494. npatch.append(row)
  3495. patch = "\n".join(npatch)
  3496. output.append(patch)
  3497. self.assertEqual(output, [exp])
  3498. def test_commit_to_patch_two_commits_diff_separated(self):
  3499. """Test the commit_to_patch function of pagure.lib.git."""
  3500. repo = pygit2.init_repository(self.gitrepo)
  3501. patches = pagure.lib.git.commit_to_patch(
  3502. repo,
  3503. [self.first_commit, self.second_commit],
  3504. diff_view=True,
  3505. separated=True,
  3506. )
  3507. exp = [
  3508. r"""diff --git a/sources b/sources
  3509. new file mode 100644
  3510. index 0000000..9f44358
  3511. --- /dev/null
  3512. +++ b/sources
  3513. @@ -0,0 +1,2 @@
  3514. +foo
  3515. + bar
  3516. \ No newline at end of file
  3517. """,
  3518. r"""diff --git a/sources b/sources
  3519. index 9f44358..2a552bb 100644
  3520. --- a/sources
  3521. +++ b/sources
  3522. @@ -1,2 +1,4 @@
  3523. foo
  3524. - bar
  3525. \ No newline at end of file
  3526. + bar
  3527. +baz
  3528. + boose
  3529. \ No newline at end of file
  3530. """,
  3531. ]
  3532. output = []
  3533. for patch in patches:
  3534. npatch = []
  3535. for row in patch.split("\n"):
  3536. if row.startswith("Date:"):
  3537. continue
  3538. if row.startswith("From "):
  3539. row = row.split(" ", 2)[2]
  3540. npatch.append(row)
  3541. patch = "\n".join(npatch)
  3542. output.append(patch)
  3543. self.assertEqual(output, exp)
  3544. def test_commit_to_patch_empty_commit(self):
  3545. """Test the commit_to_path function of pagure.lib.git."""
  3546. repo = pygit2.init_repository(self.gitrepo)
  3547. patch = pagure.lib.git.commit_to_patch(repo, self.third_commit)
  3548. exp = ""
  3549. self.assertEqual(patch, exp)
  3550. def test_commit_to_patch_empty_commit_diff(self):
  3551. """Test the commit_to_patch function of pagure.lib.git."""
  3552. repo = pygit2.init_repository(self.gitrepo)
  3553. patch = pagure.lib.git.commit_to_patch(
  3554. repo, self.third_commit, diff_view=True
  3555. )
  3556. exp = ""
  3557. self.assertEqual(patch, exp)
  3558. if __name__ == "__main__":
  3559. unittest.main(verbosity=2)