Guest User

Untitled

a guest
May 11th, 2016
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 258.66 KB | None | 0 0
  1. Executing section Default...
  2. Executing section py-analysis...
  3.  
  4. liberapay/security/authentication.py
  5. | 36| def•sign_in_with_form_data(body,•state):
  6. | 37| ••••p•=•None
  7. | 38| ••••_,•website•=•state['_'],•state['website']
  8. | 39|
  9. | 40| ••••if•body.get('log-in.id'):
  10. | 41| ••••••••id•=•body.pop('log-in.id')
  11. | 42| ••••••••k•=•'email'•if•'@'•in•id•else•'username'
  12. | 43| ••••••••p•=•Participant.authenticate(
  13. | 44| ••••••••••••k,•'password',
  14. | 45| ••••••••••••id,•body.pop('log-in.password')
  15. | 46| ••••••••)
  16. | 47| ••••••••if•not•p:
  17. | 48| ••••••••••••state['sign-in.error']•=•_("Bad•username•or•password.")
  18. | 49| ••••••••if•p•and•p.status•==•'closed':
  19. | 50| ••••••••••••p.update_status('active')
  20. | 51|
  21. | 52| ••••elif•body.get('sign-in.username'):
  22. | 53| ••••••••if•body.pop('sign-in.terms')•!=•'agree':
  23. | 54| ••••••••••••raise•Response(400,•'you•have•to•agree•to•the•terms')
  24. | 55| ••••••••kind•=•body.pop('sign-in.kind')
  25. | 56| ••••••••if•kind•not•i[WARNING][15:05:49] Bear RadonBear failed to run. Take a look at debug messages for further information.
  26. n•('individual',•'organization'):
  27. | 57| ••••••••••••raise•Response(400,•'bad•kind')
  28. | 58| ••••••••with•website.db.get_cursor()•as•c:
  29. | 59| ••••••••••••p•=•Participant.make_active(
  30. | 60| ••••••••••••••••body.pop('sign-in.username'),•kind,•body.pop('sign-in.password'),
  31. | 61| ••••••••••••••••cursor=c
  32. | 62| ••••••••••••)
  33. | 63| ••••••••••••p.add_email(body.pop('sign-in.email'),•cursor=c)
  34. | 64| ••••••••p.authenticated•=•True
  35. | 65|
  36. | 66| ••••elif•body.get('email-login.email'):
  37. | 67| ••••••••email•=•body.pop('email-login.email')
  38. | 68| ••••••••p•=•Participant._from_thing('email',•email)
  39. | 69| ••••••••if•p:
  40. | 70| ••••••••••••p.start_session()
  41. | 71| ••••••••••••qs•=•{'log-in.id':•p.id,•'log-in.token':•p.session_token}
  42. | 72| ••••••••••••p.send_email(
  43. | 73| ••••••••••••••••'password_reset',
  44. | 74| ••••••••••••••••email=email,
  45. | 75| ••••••••••••••••link=p.url('settings/',•qs),
  46. | 76| ••••••••••••••••link_validity=SESSION_TIMEOUT,
  47. | 77| ••••••••••••)
  48. | 78| ••••••••••••state['email-login.sent-to']•=•email
  49. | 79| ••••••••else:
  50. | 80| ••••••••••••state['sign-in.error']•=•_(
  51. | 81| ••••••••••••••••"We•didn't•find•any•account•whose•primary•email•address•is•{0}.",
  52. | 82| ••••••••••••••••email
  53. | 83| ••••••••••••)
  54. | 84| ••••••••p•=•None
  55. | 85|
  56. | 86| ••••return•p
  57. | | [NORMAL] RadonBear:
  58. | | sign_in_with_form_data has a cyclomatic complexity of C
  59.  
  60. liberapay/security/authentication.py
  61. | 95| def•authenticate_user_if_possible(request,•state,•user,•_):
  62. | 96| ••••"""This•signs•the•user•in.
  63. | 97| ••••"""
  64. | 98| ••••if•reque[WARNING][15:05:49] Bear RadonBear failed to run. Take a look at debug messages for further information.
  65. st.line.uri.startswith('/assets/'[WARNING][15:05:49] Bear RadonBear failed to run. Take a look at debug messages for further information.
  66. ):
  67. | 99| ••••••••return
  68. | 100|
  69. | 101| ••••#•HTTP•auth
  70. | 102| ••••if•'Authorization'•in•request.headers:
  71. | 103| ••••••••header•=•request.headers['authorization']
  72. | 104| ••••••••if•not•header.startswith('Basic•'):
  73. | 105| ••••••••••••ra[WARNING][15:05:49] Bear RadonBear failed to run. Take a look at debug messages for further information.
  74. ise•Response(401,•'Unsupported•authentication•method')
  75. | 106| •[WARNING][15:05:49] Bear RadonBear failed to run. Take a look at debug messages for further information.
  76. •••••••try:
  77. | 107| ••••••••••••creds•=•binascii.a2b_base64(header[len('Basic•'):]).split(':',•1)
  78. | 108| ••••••••except•binascii.Error:
  79. | 109| ••••••••••••raise•Response(400,•'Malformed•"Authorization"•header')
  80. | 110| ••••••••participant•=•Participant.authenticate('id',•'password',•*creds)
  81. | 111| ••••••••if•not•participant:
  82. | 112| ••••••••••••raise•Response(401)
  83. | 113| ••••••••return•{'user':•participant}
  84. | 114|
  85. | 115| ••••#•Cookie•and•form•auth
  86. | 116| ••••#•We•want•to•try•cookie•auth•first,•but•we•want•form•auth•to•supersede•it
  87. | 117| ••••p•=•None
  88. | 118| ••••response•=•state.setdefault('response',•Response())
  89. | 119| ••••if•SESSION•in•request.headers.cookie:
  90. | 120| ••••••••creds•=•request.headers.cookie[SESSION].value.split(':',•1)
  91. | 121| ••••••••p•=•Participant.authenticate('id',•'session',•*creds)
  92. | 122| ••••••••if•p:
  93. | 123| ••••••••••••state['user']•=•p
  94. | 124| ••••session_p,•p•=•p,•None
  95. | 125| ••••session_suffix•=•''
  96. | 126| ••••redirect_url•=•request.line.uri
  97. | 127| ••••if•request.method•==•'POST':
  98. | 128| ••••••••body•=•_get_body(request)
  99. | 129| ••••••••if•body:
  100. | 130| ••••••••••••p•=•sign_in_with_form_data(body,•state)
  101. | 131| ••••••••••••carry_on•=•body.pop('email-login.carry-on',•None)
  102. | 132| ••••••••••••if•not•p•and•carry_on:
  103. | 133| ••••••••••••••••p_email•=•session_p•and•(
  104. | 134| ••••••••••••••••••••session_p.email•or•session_p.get_emails()[0].address
  105. | 135| ••••••••••••••••)
  106. | 136| ••••••••••••••••if•p_email•!=•carry_on:
  107. | 137| ••••••••••••••••••••state['email-login.carry-on']•=•carry_on
  108. | 138| ••••••••••••••••••••raise•AuthRequired
  109. | 139| ••••••••••••redirect_url•=•body.get('sign-in.back-to')•or•redirect_url
  110. | 140| ••••elif•request.method•==•'GET'•and•request.qs.get('log-in.id'):
  111. | 141| ••••••••id,•token•=•request.qs.pop('log-in.id'),•request.qs.pop('log-in.token')
  112. | 142| ••••••••p•=•Participant.authenticate('id',•'session',•id,•token)
  113. | 143| ••••••••if•not•p•and•(not•session_p•or•session_p.id•!=•id):
  114. | 144| ••••••••••••raise•Response(400,•_("This•login•link•is•expired•or•invalid."))
  115. | 145| ••••••••else:
  116. | 146| ••••••••••••qs•=•'?'•+•urlencode(request.qs,•doseq=True)•if•request.qs•else•''
  117. | 147| ••••••••••••redirect_url•=•request.path.raw•+•qs
  118. | 148| ••••••••••••session_p•=•p
  119. | 149| ••••••••••••session_suffix•=•'.em'
  120. | 150| ••••if•p:
  121. | 151| ••••••••if•session_p:
  122. | 152| ••••••••••••session_p.sign_out(response.headers.cookie)
  123. | 153| ••••••••p.sign_in(response.headers.cookie,•session_suffix)
  124. | 154| ••••••••state['user']•=•p
  125. | 155| ••••••••if•request.body.pop('form.repost',•None)•!=•'true':
  126. | 156| ••••••••••••response.redirect(redirect_url)
  127. | | [NORMAL] RadonBear:
  128. | | authenticate_user_if_possible has a cyclomatic complexity of D
  129.  
  130. liberapay/models/participant.py
  131. | 168| ••••@classmethod
  132. | 169| ••••def•authenticate(cls,•k1,•k2,•v1=None,•v2=None):
  133. | 170| ••••••••assert•k1•in•('id',•'username',•'email')
  134. | 171| ••••••••if•not•(v1•and•v2):
  135. | 172| ••••••••••••return
  136. | 173| ••••••••if•k1•==•'username':
  137. | 174| ••••••••••••k1•=•'lower(username)'
  138. | 175| ••••••••••••v1•=•v1.lower()
  139. | 176| ••••••••p•=•cls._from_thing(k1,•v1)
  140. | 177| ••••••••if•not•p:
  141. | 178| ••••••••••••return
  142. | 179| ••••••••if•k2•==•'session':
  143. | 180| ••••••••••••if•not•p.session_token:
  144. | 181| ••••••••••••••••return
  145. | 182| ••••••••••••if•p.session_expires•<•utcnow():
  146. | 183| ••••••••••••••••return
  147. | 184| ••••••••••••if•constant_time_compare(p.session_token,•v2):
  148. | 185| ••••••••••••••••p.authenticated•=•True
  149. | 186| ••••••••••••••••return•p
  150. | 187| ••••••••elif•k2•==•'password':
  151. | 188| ••••••••••••if•not•p.password:
  152. | 189| ••••••••••••••••return
  153. | 190| ••••••••••••algo,•rounds,•salt,•hashed•=•p.password.split('$',•3)
  154. | 191| ••••••••••••rounds•=•int(rounds)
  155. | 192| ••••••••••••salt,•hashed•=•b64decode(salt),•b64decode(hashed)
  156. | 193| ••••••••••••if•cls._hash_password(v2,•algo,•salt,•rounds)•==•hashed:
  157. | 194| ••••••••••••••••p.authenticated•=•True
  158. | 195| ••••••••••••••••return•p
  159. | | [NORMAL] RadonBear:
  160. | | authenticate has a cyclomatic complexity of C
  161.  
  162. liberapay/models/participant.py
  163. | 524| ••••def•add_email(self,•email,•cursor=None):
  164. | 525| ••••••••"""
  165. | 526| ••••••••••••This•is•called•when
  166. | 527| ••••••••••••1)•Adding•a•new•email•address
  167. | 528| ••••••••••••2)•Resending•the•verification•email•for•an•unverified•email•address
  168. | 529|
  169. | 530| ••••••••••••Returns•the•number•of•emails•sent.
  170. | 531| ••••••••"""
  171. | 532|
  172. | 533| ••••••••if•not•EMAIL_RE.match(email):
  173. | 534| ••••••••••••raise•BadEmailAddress(email)
  174. | 535|
  175. | 536| ••••••••#•Check•that•this•address•isn't•already•verified
  176. | 537| ••••••••owner•=•(cursor•or•self.db).one("""
  177. | 538| ••••••••••••SELECT•participant
  178. | 539| ••••••••••••••FROM•emails
  179. | 540| •••••••••••••WHERE•address•=•%(email)s
  180. | 541| •••••••••••••••AND•verified•IS•true
  181. | 542| ••••••••""",•locals())
  182. | 543| ••••••••if•owner:
  183. | 544| ••••••••••••if•owner•==•self.id:
  184. | 545| ••••••••••••••••return•0
  185. | 546| ••••••••••••else:
  186. | 547| ••••••••••••••••raise•EmailAlreadyTaken(email)
  187. | 548|
  188. | 549| ••••••••if•len(self.get_emails())•>•9:
  189. | 550| ••••••••••••raise•TooManyEmailAddresses(email)
  190. | 551|
  191. | 552| ••••••••nonce•=•str(uuid.uuid4())
  192. | 553| ••••••••added_time•=•utcnow()
  193. | 554| ••••••••try:
  194. | 555| ••••••••••••with•self.db.get_cursor(cursor)•as•c:
  195. | 556| ••••••••••••••••self.add_event(c,•'add_email',•email)
  196. | 557| ••••••••••••••••c.run("""
  197. | 558| ••••••••••••••••••••INSERT•INTO•emails
  198. | 559| ••••••••••••••••••••••••••••••••(address,•nonce,•added_time,•participant)
  199. | 560| •••••••••••••••••••••••••VALUES•(%s,•%s,•%s,•%s)
  200. | 561| ••••••••••••••••""",•(email,•nonce,•added_time,•self.id))
  201. | 562| ••••••••except•IntegrityError:
  202. | 563| ••••••••••••nonce•=•(cursor•or•self.db).one("""
  203. | 564| ••••••••••••••••UPDATE•emails
  204. | 565| •••••••••••••••••••SET•added_time=%s
  205. | 566| •••••••••••••••••WHERE•participant=%s
  206. | 567| •••••••••••••••••••AND•address=%s
  207. | 568| •••••••••••••••••••AND•verified•IS•NULL
  208. | 569| •••••••••••••RETURNING•nonce
  209. | 570| ••••••••••••""",•(added_time,•self.id,•email))
  210. | 571| ••••••••••••if•not•nonce:
  211. | 572| ••••••••••••••••return•self.add_email(email)
  212. | 573|
  213. | 574| ••••••••scheme•=•website.canonical_scheme
  214. | 575| ••••••••host•=•website.canonical_host
  215. | 576| ••••••••username•=•self.username
  216. | 577| ••••••••base64_email•=•b64encode_s(email)
  217. | 578| ••••••••link•=•"{scheme}://{host}/{username}/emails/verify.html?email64={base64_email}&nonce={nonce}"
  218. | 579| ••••••••r•=•self.send_email('verification',•email=email,•link=link.format(**locals()))
  219. | 580| ••••••••assert•r•==•1•#•Make•sure•the•verification•email•was•sent
  220. | 581|
  221. | 582| ••••••••if•self.email:
  222. | 583| ••••••••••••self.send_email('verification_notice',•new_email=email)
  223. | 584| ••••••••••••return•2
  224. | 585| ••••••••else:
  225. | 586| ••••••••••••self.update_avatar(cursor=cursor)
  226. | 587|
  227. | 588| ••••••••return•1
  228. | | [NORMAL] RadonBear:
  229. | | add_email has a cyclomatic complexity of C
  230.  
  231. liberapay/models/participant.py
  232. |1017| ••••def•update_avatar(self,•src=None,•cursor=None):
  233. |1018| ••••••••if•self.status•==•'stub':
  234. |1019| ••••••••••••assert•src•is•None
  235. |1020|
  236. |1021| ••••••••src•=•self.avatar_src•if•src•is•None•else•src
  237. |1022| ••••••••platform,•key•=•src.split(':',•1)•if•src•else•(None,•None)
  238. |1023| ••••••••email•=•self.avatar_email•or•self.email•or•self.get_any_email(cursor)
  239. |1024|
  240. |1025| ••••••••if•platform•==•'libravatar'•or•platform•is•None•and•email:
  241. |1026| ••••••••••••if•not•email:
  242. |1027| ••••••••••••••••return
  243. |1028| ••••••••••••avatar_id•=•md5(email.strip().lower()).hexdigest()
  244. |1029| ••••••••••••avatar_url•=•'https://seccdn.libravatar.org/avatar/'+avatar_id
  245. |1030| ••••••••••••avatar_url•+=•AVATAR_QUERY
  246. |1031|
  247. |1032| ••••••••elif•platform•is•None:
  248. |1033| ••••••••••••avatar_url•=•(cursor•or•self.db).one("""
  249. |1034| ••••••••••••••••SELECT•avatar_url
  250. |1035| ••••••••••••••••••FROM•elsewhere
  251. |1036| •••••••••••••••••WHERE•participant•=•%s
  252. |1037| ••••••••••••••ORDER•BY•platform•=•'github'•DESC,
  253. |1038| •••••••••••••••••••••••avatar_url•LIKE•'%%libravatar.org%%'•DESC,
  254. |1039| •••••••••••••••••••••••avatar_url•LIKE•'%%gravatar.com%%'•DESC
  255. |1040| •••••••••••••••••LIMIT•1
  256. |1041| ••••••••••••""",•(self.id,))
  257. |1042|
  258. |1043| ••••••••else:
  259. |1044| ••••••••••••avatar_url•=•(cursor•or•self.db).one("""
  260. |1045| ••••••••••••••••SELECT•avatar_url
  261. |1046| ••••••••••••••••••FROM•elsewhere
  262. |1047| •••••••••••••••••WHERE•participant•=•%s
  263. |1048| •••••••••••••••••••AND•platform•=•%s
  264. |1049| ••••••••••••••••--•AND•user_id•=•%%s••--•not•implemented•yet
  265. |1050| ••••••••••••""",•(self.id,•platform))
  266. |1051|
  267. |1052| ••••••••if•not•avatar_url:
  268. |1053| ••••••••••••return
  269. |1054|
  270. |1055| ••••••••(cursor•or•self.db).run("""
  271. |1056| ••••••••••••UPDATE•participants
  272. |1057| •••••••••••••••SET•avatar_url•=•%s
  273. |1058| •••••••••••••••••,•avatar_src•=•%s
  274. |1059| •••••••••••••WHERE•id•=•%s
  275. |1060| ••••••••""",•(avatar_url,•src,•self.id))
  276. |1061| ••••••••self.set_attributes(avatar_src=src,•avatar_url=avatar_url)
  277. |1062|
  278. |1063| ••••••••return•avatar_url
  279. | | [NORMAL] RadonBear:
  280. | | update_avatar has a cyclomatic complexity of C
  281.  
  282. liberapay/models/participant.py
  283. |1174| ••••def•set_tip_to(self,•tippee,•amount,•update_self=True,•update_tippee=True,•cursor=None):
  284. |1175| ••••••••"""Given•a•Participant•or•username,•and•amount•as•str,•returns•a•dict.
  285. |1176|
  286. |1177| ••••••••We•INSERT•instead•of•UPDATE,•so•that•we•have•history•to•explore.•The
  287. |1178| ••••••••COALESCE•function•returns•the•first•of•its•arguments•that•is•not•NULL.
  288. |1179| ••••••••The•effect•here•is•to•stamp•all•tips•with•the•timestamp•of•the•first
  289. |1180| ••••••••tip•from•this•user•to•that.•I•believe•this•is•used•to•determine•the
  290. |1181| ••••••••order•of•transfers•during•payday.
  291. |1182|
  292. |1183| ••••••••The•dict•returned•represents•the•row•inserted•in•the•tips•table,•with
  293. |1184| ••••••••an•additional•boolean•indicating•whether•this•is•the•first•time•this
  294. |1185| ••••••••tipper•has•tipped•(we•want•to•track•that•as•part•of•our•conversion
  295. |1186| ••••••••funnel).
  296. |1187|
  297. |1188| ••••••••"""
  298. |1189| ••••••••assert•self.status•==•'active'••#•sanity•check
  299. |1190|
  300. |1191| ••••••••if•isinstance(tippee,•AccountElsewhere):
  301. |1192| ••••••••••••tippee•=•tippee.participant
  302. |1193| ••••••••elif•not•isinstance(tippee,•Participant):
  303. |1194| ••••••••••••tippee,•u•=•Participant.from_username(tippee),•tippee
  304. |1195| ••••••••••••if•not•tippee:
  305. |1196| ••••••••••••••••raise•NoTippee(u)
  306. |1197|
  307. |1198| ••••••••if•self.id•==•tippee.id:
  308. |1199| ••••••••••••raise•NoSelfTipping
  309. |1200|
  310. |1201| ••••••••amount•=•Decimal(amount)••#•May•raise•InvalidOperation
  311. |1202| ••••••••if•amount•!=•0•and•amount•<•MIN_TIP•or•amount•>•MAX_TIP:
  312. |1203| ••••••••••••raise•BadAmount(amount)
  313. |1204|
  314. |1205| ••••••••if•not•tippee.accepts_tips•and•amount•!=•0:
  315. |1206| ••••••••••••raise•UserDoesntAcceptTips(tippee.username)
  316. |1207|
  317. |1208| ••••••••#•Insert•tip
  318. |1209| ••••••••NEW_TIP•=•"""\
  319. |1210|
  320. |1211| ••••••••••••INSERT•INTO•tips
  321. |1212| ••••••••••••••••••••••••(ctime,•tipper,•tippee,•amount)
  322. |1213| •••••••••••••••••VALUES•(•COALESCE•((•SELECT•ctime
  323. |1214| ••••••••••••••••••••••••••••••••••••••••FROM•tips
  324. |1215| •••••••••••••••••••••••••••••••••••••••WHERE•(tipper=%(tipper)s•AND•tippee=%(tippee)s)
  325. |1216| •••••••••••••••••••••••••••••••••••••••LIMIT•1
  326. |1217| ••••••••••••••••••••••••••••••••••••••),•CURRENT_TIMESTAMP)
  327. |1218| ••••••••••••••••••••••••,•%(tipper)s,•%(tippee)s,•%(amount)s
  328. |1219| •••••••••••••••••••••••••)
  329. |1220| ••••••••••••••RETURNING•*
  330. |1221| ••••••••••••••••••••••,•(•SELECT•count(*)•=•0•FROM•tips•WHERE•tipper=%(tipper)s•)•AS•first_time_tipper
  331. |1222| ••••••••••••••••••••••,•(•SELECT•join_time•IS•NULL•FROM•participants•WHERE•id•=•%(tippee)s•)•AS•is_pledge
  332. |1223|
  333. |1224| ••••••••"""
  334. |1225| ••••••••args•=•dict(tipper=self.id,•tippee=tippee.id,•amount=amount)
  335. |1226| ••••••••t•=•(cursor•or•self.db).one(NEW_TIP,•args)._asdict()
  336. |1227|
  337. |1228| ••••••••if•update_self:
  338. |1229| ••••••••••••#•Update•giving•amount•of•tipper
  339. |1230| ••••••••••••updated•=•self.update_giving(cursor)
  340. |1231| ••••••••••••for•u•in•updated:
  341. |1232| ••••••••••••••••if•u.id•==•t['id']:
  342. |1233| ••••••••••••••••••••t['is_funded']•=•u.is_funded
  343. |1234| ••••••••if•update_tippee:
  344. |1235| ••••••••••••#•Update•receiving•amount•of•tippee
  345. |1236| ••••••••••••tippee.update_receiving(cursor)
  346. |1237|
  347. |1238| ••••••••return•t
  348. | | [NORMAL] RadonBear:
  349. | | set_tip_to has a cyclomatic complexity of C
  350.  
  351. liberapay/models/participant.py
  352. |1463| ••••def•take_over(self,•account,•have_confirmation=False):
  353. |1464| ••••••••"""Given•an•AccountElsewhere•or•a•tuple•(platform_name,•user_id),
  354. |1465| ••••••••associate•an•elsewhere•account.
  355. |1466|
  356. |1467| ••••••••Returns•None•or•raises•NeedConfirmation.
  357. |1468|
  358. |1469| ••••••••This•method•associates•an•account•on•another•platform•(GitHub,•Twitter,
  359. |1470| ••••••••etc.)•with•the•given•Liberapay•participant.•Every•account•elsewhere•has•an
  360. |1471| ••••••••associated•Liberapay•participant•account,•even•if•its•only•a•stub
  361. |1472| ••••••••participant•(it•allows•us•to•track•pledges•to•that•account•should•they
  362. |1473| ••••••••ever•decide•to•join•Liberapay).
  363. |1474|
  364. |1475| ••••••••In•certain•circumstances,•we•want•to•present•the•user•with•a
  365. |1476| ••••••••confirmation•before•proceeding•to•transfer•the•account•elsewhere•to
  366. |1477| ••••••••the•new•Liberapay•account;•NeedConfirmation•is•the•signal•to•request
  367. |1478| ••••••••confirmation.
  368. |1479| ••••••••"""
  369. |1480|
  370. |1481| ••••••••if•isinstance(account,•AccountElsewhere):
  371. |1482| ••••••••••••platform,•user_id•=•account.platform,•account.user_id
  372. |1483| ••••••••else:
  373. |1484| ••••••••••••platform,•user_id•=•map(str,•account)
  374. |1485|
  375. |1486| ••••••••CREATE_TEMP_TABLE_FOR_TIPS•=•"""
  376. |1487| ••••••••••••CREATE•TEMP•TABLE•temp_tips•ON•COMMIT•drop•AS
  377. |1488| ••••••••••••••••SELECT•ctime,•tipper,•tippee,•amount,•is_funded
  378. |1489| ••••••••••••••••••FROM•current_tips
  379. |1490| •••••••••••••••••WHERE•(tippee•=•%(dead)s•OR•tippee•=•%(live)s)
  380. |1491| •••••••••••••••••••AND•amount•>•0;
  381. |1492| ••••••••"""
  382. |1493|
  383. |1494| ••••••••CONSOLIDATE_TIPS_RECEIVING•=•"""
  384. |1495| ••••••••••••--•Create•a•new•set•of•tips,•one•for•each•current•tip•*to*•either
  385. |1496| ••••••••••••--•the•dead•or•the•live•account.•If•a•user•was•tipping•both•the
  386. |1497| ••••••••••••--•dead•and•the•live•account,•then•we•create•one•new•combined•tip
  387. |1498| ••••••••••••--•to•the•live•account•(via•the•GROUP•BY•and•sum()).
  388. |1499| ••••••••••••INSERT•INTO•tips•(ctime,•tipper,•tippee,•amount,•is_funded)
  389. |1500| •••••••••••••••••SELECT•min(ctime),•tipper,•%(live)s•AS•tippee,•sum(amount),•bool_and(is_funded)
  390. |1501| •••••••••••••••••••FROM•temp_tips
  391. |1502| ••••••••••••••••••WHERE•(tippee•=•%(dead)s•OR•tippee•=•%(live)s)
  392. |1503| ••••••••••••••••••••••••--•Include•tips•*to*•either•the•dead•or•live•account.
  393. |1504| ••••••••••••••••AND•NOT•(tipper•=•%(dead)s•OR•tipper•=•%(live)s)
  394. |1505| ••••••••••••••••••••••••--•Don't•include•tips•*from*•the•dead•or•live•account,
  395. |1506| ••••••••••••••••••••••••--•lest•we•convert•cross-tipping•to•self-tipping.
  396. |1507| •••••••••••••••GROUP•BY•tipper
  397. |1508| ••••••••"""
  398. |1509|
  399. |1510| ••••••••ZERO_OUT_OLD_TIPS_RECEIVING•=•"""
  400. |1511| ••••••••••••INSERT•INTO•tips•(ctime,•tipper,•tippee,•amount)
  401. |1512| ••••••••••••••••SELECT•ctime,•tipper,•tippee,•0•AS•amount
  402. |1513| ••••••••••••••••••FROM•temp_tips
  403. |1514| •••••••••••••••••WHERE•tippee=%s
  404. |1515| ••••••••"""
  405. |1516|
  406. |1517| ••••••••with•self.db.get_cursor()•as•cursor:
  407. |1518|
  408. |1519| ••••••••••••#•Load•the•existing•connection
  409. |1520| ••••••••••••#•Every•account•elsewhere•has•at•least•a•stub•participant•account
  410. |1521| ••••••••••••#•on•Liberapay.
  411. |1522| ••••••••••••elsewhere•=•cursor.one("""
  412. |1523| ••••••••••••••••SELECT•e.*::elsewhere_with_participant
  413. |1524| ••••••••••••••••••FROM•elsewhere•e
  414. |1525| ••••••••••••••••••JOIN•participants•p•ON•p.id•=•e.participant
  415. |1526| •••••••••••••••••WHERE•e.platform=%s•AND•e.user_id=%s
  416. |1527| ••••••••••••""",•(platform,•user_id),•default=Exception)
  417. |1528| ••••••••••••other•=•elsewhere.participant
  418. |1529|
  419. |1530| ••••••••••••if•self.id•==•other.id:
  420. |1531| ••••••••••••••••#•this•is•a•no•op•-•trying•to•take•over•itself
  421. |1532| ••••••••••••••••return
  422. |1533|
  423. |1534| ••••••••••••#•Save•old•tips•so•we•can•notify•patrons•that•they've•been•claimed
  424. |1535| ••••••••••••old_tips•=•other.get_tips_receiving()•if•other.status•==•'stub'•else•None
  425. |1536|
  426. |1537| ••••••••••••#•Make•sure•we•have•user•confirmation•if•needed.
  427. |1538| ••••••••••••#•==============================================
  428. |1539| ••••••••••••#•We•need•confirmation•if•any•of•these•are•true:
  429. |1540| ••••••••••••#
  430. |1541| ••••••••••••#•••-•the•other•participant•is•not•a•stub;•we•are•taking•the
  431. |1542| ••••••••••••#•••••••account•elsewhere•away•from•another•viable•participant
  432. |1543| ••••••••••••#
  433. |1544| ••••••••••••#•••-•we•already•have•an•account•elsewhere•connected•from•the•given
  434. |1545| ••••••••••••#•••••••platform,•and•it•will•be•handed•off•to•a•new•stub
  435. |1546| ••••••••••••#•••••••participant
  436. |1547|
  437. |1548| ••••••••••••other_is_a_real_participant•=•other.status•!=•'stub'
  438. |1549|
  439. |1550| ••••••••••••we_already_have_that_kind_of_account•=•cursor.one("""
  440. |1551| ••••••••••••••••SELECT•true
  441. |1552| ••••••••••••••••••FROM•elsewhere
  442. |1553| •••••••••••••••••WHERE•participant=%s•AND•platform=%s
  443. |1554| ••••••••••••""",•(self.id,•platform),•default=False)
  444. |1555|
  445. |1556| ••••••••••••need_confirmation•=•NeedConfirmation(
  446. |1557| ••••••••••••••••other_is_a_real_participant,
  447. |1558| ••••••••••••••••we_already_have_that_kind_of_account,
  448. |1559| ••••••••••••)
  449. |1560| ••••••••••••if•need_confirmation•and•not•have_confirmation:
  450. |1561| ••••••••••••••••raise•need_confirmation
  451. |1562|
  452. |1563| ••••••••••••#•Move•any•old•account•out•of•the•way
  453. |1564| ••••••••••••if•we_already_have_that_kind_of_account:
  454. |1565| ••••••••••••••••new_stub•=•Participant.make_stub(cursor)
  455. |1566| ••••••••••••••••cursor.run(•"UPDATE•elsewhere•SET•participant=%s•"
  456. |1567| ••••••••••••••••••••••••••••"WHERE•platform=%s•AND•participant=%s"
  457. |1568| ••••••••••••••••••••••••••,•(new_stub.id,•platform,•self.id)
  458. |1569| •••••••••••••••••••••••••••)
  459. |1570|
  460. |1571| ••••••••••••#•Do•the•deal
  461. |1572| ••••••••••••cursor.run(•"UPDATE•elsewhere•SET•participant=%s•"
  462. |1573| ••••••••••••••••••••••••"WHERE•platform=%s•AND•user_id=%s"
  463. |1574| ••••••••••••••••••••••,•(self.id,•platform,•user_id)
  464. |1575| •••••••••••••••••••••••)
  465. |1576|
  466. |1577| ••••••••••••#•Turn•pledges•into•actual•tips
  467. |1578| ••••••••••••if•old_tips:
  468. |1579| ••••••••••••••••x,•y•=•self.id,•other.id
  469. |1580| ••••••••••••••••cursor.run(CREATE_TEMP_TABLE_FOR_TIPS,•dict(live=x,•dead=y))
  470. |1581| ••••••••••••••••cursor.run(CONSOLIDATE_TIPS_RECEIVING,•dict(live=x,•dead=y))
  471. |1582| ••••••••••••••••cursor.run(ZERO_OUT_OLD_TIPS_RECEIVING,•(other.id,))
  472. |1583|
  473. |1584| ••••••••••••#•Try•to•delete•the•stub•account,•or•prevent•new•pledges•to•it
  474. |1585| ••••••••••••if•not•other_is_a_real_participant:
  475. |1586| ••••••••••••••••cursor.run("""
  476. |1587| ••••••••••••••••••••DO•$$
  477. |1588| ••••••••••••••••••••BEGIN
  478. |1589| ••••••••••••••••••••••••DELETE•FROM•participants•WHERE•id•=•%(dead)s;
  479. |1590| ••••••••••••••••••••EXCEPTION•WHEN•OTHERS•THEN
  480. |1591| ••••••••••••••••••••••••UPDATE•participants
  481. |1592| •••••••••••••••••••••••••••SET•goal•=•-1
  482. |1593| •••••••••••••••••••••••••WHERE•id•=•%(dead)s;
  483. |1594| ••••••••••••••••••••END;
  484. |1595| ••••••••••••••••••••$$•LANGUAGE•plpgsql;
  485. |1596| ••••••••••••••••""",•dict(dead=other.id))
  486. |1597|
  487. |1598| ••••••••••••#•Log•the•event
  488. |1599| ••••••••••••payload•=•dict(platform=platform,•user_id=user_id,•owner=other.id)
  489. |1600| ••••••••••••self.add_event(cursor,•'take-over',•payload)
  490. |1601|
  491. |1602| ••••••••if•old_tips:
  492. |1603| ••••••••••••self.notify_patrons(elsewhere,•tips=old_tips)
  493. |1604|
  494. |1605| ••••••••self.update_avatar()
  495. |1606|
  496. |1607| ••••••••#•Note:•the•order•matters•here,•receiving•needs•to•be•updated•before•giving
  497. |1608| ••••••••self.update_receiving()
  498. |1609| ••••••••self.update_giving()
  499. | | [NORMAL] RadonBear:
  500. | | take_over has a cyclomatic complexity of C
  501.  
  502. liberapay/billing/payday.py
  503. | 94| ••••def•shuffle(self,•log_dir=''):
  504. | 95| ••••••••self.transfers_filename•=•log_dir+'payday-%s_transfers.pickle'•%•self.id
  505. | 96| ••••••••if•os.path.exists(self.transfers_filename):
  506. | 97| ••••••••••••with•open(self.transfers_filename,•'rb')•as•f:
  507. | 98| ••••••••••••••••transfers•=•pickle.load(f)
  508. | 99| ••••••••••••done•=•self.db.all("""
  509. | 100| ••••••••••••••••SELECT•*
  510. | 101| ••••••••••••••••••FROM•transfers•t
  511. | 102| •••••••••••••••••WHERE•t.timestamp•>=•%(ts_start)s;
  512. | 103| ••••••••••••""",•dict(ts_start=self.ts_start))
  513. | 104| ••••••••••••done•=•set((t.tipper,•t.tippee,•t.context,•t.team)•for•t•in•done)
  514. | 105| ••••••••••••transfers•=•[t•for•t•in•transfers•if•(t.tipper,•t.tippee,•t.context,•t.team)•not•in•done]
  515. | 106| ••••••••else:
  516. | 107| ••••••••••••with•self.db.get_cursor()•as•cursor:
  517. | 108| ••••••••••••••••self.prepare(cursor,•self.ts_start)
  518. | 109| ••••••••••••••••self.transfer_virtually(cursor)
  519. | 110| ••••••••••••••••transfers•=•[NS(t._asdict())•for•t•in•cursor.all("""
  520. | 111| ••••••••••••••••••••SELECT•t.*
  521. | 112| •••••••••••••••••••••••••,•p.mangopay_user_id•AS•tipper_mango_id
  522. | 113| •••••••••••••••••••••••••,•p2.mangopay_user_id•AS•tippee_mango_id
  523. | 114| •••••••••••••••••••••••••,•p.mangopay_wallet_id•AS•tipper_wallet_id
  524. | 115| •••••••••••••••••••••••••,•p2.mangopay_wallet_id•AS•tippee_wallet_id
  525. | 116| ••••••••••••••••••••••FROM•payday_transfers•t
  526. | 117| ••••••••••••••••••••••JOIN•participants•p•ON•p.id•=•t.tipper
  527. | 118| ••••••••••••••••••••••JOIN•participants•p2•ON•p2.id•=•t.tippee
  528. | 119| ••••••••••••••••""")]
  529. | 120| ••••••••••••••••self.check_balances(cursor)
  530. | 121| ••••••••••••••••with•open(self.transfers_filename,•'wb')•as•f:
  531. | 122| ••••••••••••••••••••pickle.dump(transfers,•f)
  532. | 123| ••••••••••••••••if•self.id•>•1:
  533. | 124| ••••••••••••••••••••previous_ts_start•=•self.db.one("""
  534. | 125| ••••••••••••••••••••••••SELECT•ts_start
  535. | 126| ••••••••••••••••••••••••••FROM•paydays
  536. | 127| •••••••••••••••••••••••••WHERE•id•=•%s
  537. | 128| ••••••••••••••••••••""",•(self.id•-•1,))
  538. | 129| ••••••••••••••••else:
  539. | 130| ••••••••••••••••••••previous_ts_start•=•constants.EPOCH
  540. | 131| ••••••••••••••••assert•previous_ts_start
  541. | 132| ••••••••••••••••ts_start•=•self.ts_start
  542. | 133| ••••••••••••••••cursor.run("""
  543. | 134| ••••••••••••••••••••WITH•week_exchanges•AS•(
  544. | 135| •••••••••••••••••••••••••••••SELECT•e.*
  545. | 136| •••••••••••••••••••••••••••••••FROM•exchanges•e
  546. | 137| ••••••••••••••••••••••••••••••WHERE•e.timestamp•<•%(ts_start)s
  547. | 138| ••••••••••••••••••••••••••••••••AND•e.timestamp•>=•%(previous_ts_start)s
  548. | 139| ••••••••••••••••••••••••••••••••AND•status•<>•'failed'
  549. | 140| •••••••••••••••••••••••••)
  550. | 141| ••••••••••••••••••••UPDATE•paydays
  551. | 142| •••••••••••••••••••••••SET•nparticipants•=•(SELECT•count(*)•FROM•payday_participants)
  552. | 143| •••••••••••••••••••••••••,•nusers•=•(
  553. | 144| •••••••••••••••••••••••••••••••SELECT•count(*)
  554. | 145| •••••••••••••••••••••••••••••••••FROM•participants
  555. | 146| ••••••••••••••••••••••••••••••••WHERE•kind•IN•('individual',•'organization')
  556. | 147| ••••••••••••••••••••••••••••••••••AND•join_time•<•%(ts_start)s
  557. | 148| ••••••••••••••••••••••••••••••••••AND•status•=•'active'
  558. | 149| •••••••••••••••••••••••••••)
  559. | 150| •••••••••••••••••••••••••,•week_deposits•=•(
  560. | 151| •••••••••••••••••••••••••••••••SELECT•COALESCE(sum(amount),•0)
  561. | 152| •••••••••••••••••••••••••••••••••FROM•week_exchanges
  562. | 153| ••••••••••••••••••••••••••••••••WHERE•amount•>•0
  563. | 154| •••••••••••••••••••••••••••)
  564. | 155| •••••••••••••••••••••••••,•week_withdrawals•=•(
  565. | 156| •••••••••••••••••••••••••••••••SELECT•COALESCE(-sum(amount),•0)
  566. | 157| •••••••••••••••••••••••••••••••••FROM•week_exchanges
  567. | 158| ••••••••••••••••••••••••••••••••WHERE•amount•<•0
  568. | 159| •••••••••••••••••••••••••••)
  569. | 160| •••••••••••••••••••••WHERE•ts_end='1970-01-01T00:00:00+00'::timestamptz;
  570. | 161| ••••••••••••••••""",•locals())
  571. | 162| ••••••••••••self.clean_up()
  572. | 163|
  573. | 164| ••••••••self.transfer_for_real(transfers)
  574. | 165|
  575. | 166| ••••••••self.db.self_check()
  576. | | [NORMAL] RadonBear:
  577. | | shuffle has a cyclomatic complexity of C
  578.  
  579. liberapay/billing/payday.py
  580. | 552| ••••def•notify_participants(self):
  581. | 553| ••••••••previous_ts_end•=•self.db.one("""
  582. | 554| ••••••••••••SELECT•ts_end
  583. | 555| ••••••••••••••FROM•paydays
  584. | 556| •••••••••••••WHERE•ts_start•<•%s
  585. | 557| ••••••••••ORDER•BY•ts_end•DESC
  586. | 558| •••••••••••••LIMIT•1
  587. | 559| ••••••••""",•(self.ts_start,),•default=constants.BIRTHDAY)
  588. | 560|
  589. | 561| ••••••••#•Income•notifications
  590. | 562| ••••••••r•=•self.db.all("""
  591. | 563| ••••••••••••SELECT•tippee,•json_agg(t)•AS•transfers
  592. | 564| ••••••••••••••FROM•transfers•t
  593. | 565| •••••••••••••WHERE•"timestamp"•>•%s
  594. | 566| •••••••••••••••AND•"timestamp"•<=•%s
  595. | 567| ••••••••••GROUP•BY•tippee
  596. | 568| ••••••••""",•(previous_ts_end,•self.ts_end))
  597. | 569| ••••••••for•tippee_id,•transfers•in•r:
  598. | 570| ••••••••••••successes•=•[t•for•t•in•transfers•if•t['status']•==•'succeeded']
  599. | 571| ••••••••••••if•not•successes:
  600. | 572| ••••••••••••••••continue
  601. | 573| ••••••••••••by_team•=•{k:•sum(t['amount']•for•t•in•v)
  602. | 574| •••••••••••••••••••••••for•k,•v•in•group_by(successes,•'team').items()}
  603. | 575| ••••••••••••personal•=•by_team.pop(None,•0)
  604. | 576| ••••••••••••by_team•=•{Participant.from_id(k).username:•v•for•k,•v•in•by_team.items()}
  605. | 577| ••••••••••••Participant.from_id(tippee_id).notify(
  606. | 578| ••••••••••••••••'income',
  607. | 579| ••••••••••••••••total=sum(t['amount']•for•t•in•successes),
  608. | 580| ••••••••••••••••personal=personal,
  609. | 581| ••••••••••••••••by_team=by_team,
  610. | 582| ••••••••••••)
  611. | 583|
  612. | 584| ••••••••#•Identity-required•notifications
  613. | 585| ••••••••participants•=•self.db.all("""
  614. | 586| ••••••••••••SELECT•p.*::participants
  615. | 587| ••••••••••••••FROM•participants•p
  616. | 588| •••••••••••••WHERE•mangopay_user_id•IS•NULL
  617. | 589| •••••••••••••••AND•kind•IN•('individual',•'organization')
  618. | 590| •••••••••••••••AND•(p.goal•IS•NULL•OR•p.goal•>=•0)
  619. | 591| •••••••••••••••AND•EXISTS•(
  620. | 592| •••••••••••••••••••••SELECT•1
  621. | 593| •••••••••••••••••••••••FROM•current_tips•t
  622. | 594| •••••••••••••••••••••••JOIN•participants•p2•ON•p2.id•=•t.tipper
  623. | 595| ••••••••••••••••••••••WHERE•t.tippee•=•p.id
  624. | 596| ••••••••••••••••••••••••AND•t.amount•>•0
  625. | 597| ••••••••••••••••••••••••AND•p2.balance•>•t.amount
  626. | 598| •••••••••••••••••••)
  627. | 599| ••••••••""")
  628. | 600| ••••••••for•p•in•participants:
  629. | 601| ••••••••••••p.notify('identity_required',•force_email=True)
  630. | 602|
  631. | 603| ••••••••#•Low-balance•notifications
  632. | 604| ••••••••participants•=•self.db.all("""
  633. | 605| ••••••••••••SELECT•p.*::participants
  634. | 606| ••••••••••••••FROM•participants•p
  635. | 607| •••••••••••••WHERE•balance•<•(
  636. | 608| •••••••••••••••••••••SELECT•sum(amount)
  637. | 609| •••••••••••••••••••••••FROM•current_tips•t
  638. | 610| •••••••••••••••••••••••JOIN•participants•p2•ON•p2.id•=•t.tippee
  639. | 611| ••••••••••••••••••••••WHERE•t.tipper•=•p.id
  640. | 612| ••••••••••••••••••••••••AND•p2.mangopay_user_id•IS•NOT•NULL
  641. | 613| ••••••••••••••••••••••••AND•p2.status•=•'active'
  642. | 614| •••••••••••••••••••)
  643. | 615| •••••••••••••••AND•EXISTS•(
  644. | 616| •••••••••••••••••••••SELECT•1
  645. | 617| •••••••••••••••••••••••FROM•transfers•t
  646. | 618| ••••••••••••••••••••••WHERE•t.tipper•=•p.id
  647. | 619| ••••••••••••••••••••••••AND•t.timestamp•>•%s
  648. | 620| ••••••••••••••••••••••••AND•t.timestamp•<=•%s
  649. | 621| ••••••••••••••••••••••••AND•t.status•=•'succeeded'
  650. | 622| •••••••••••••••••••)
  651. | 623| ••••••••""",•(previous_ts_end,•self.ts_end))
  652. | 624| ••••••••for•p•in•participants:
  653. | 625| ••••••••••••p.notify('low_balance')
  654. | | [NORMAL] RadonBear:
  655. | | notify_participants has a cyclomatic complexity of C
  656.  
  657. liberapay/wireup.py
  658. | 279| def•load_i18n(canonical_host,•canonical_scheme,•project_root,•tell_sentry):
  659. | 280| ••••#•Load•the•locales
  660. | 281| ••••localeDir•=•os.path.join(project_root,•'i18n',•'core')
  661. | 282| ••••locales•=•LOCALES
  662. | 283| ••••for•file•in•os.listdir(localeDir):
  663. | 284| ••••••••try:
  664. | 285| ••••••••••••parts•=•file.split(".")
  665. | 286| ••••••••••••if•not•(len(parts)•==•2•and•parts[1]•==•"po"):
  666. | 287| ••••••••••••••••continue
  667. | 288| ••••••••••••lang•=•parts[0]
  668. | 289| ••••••••••••with•open(os.path.join(localeDir,•file))•as•f:
  669. | 290| ••••••••••••••••l•=•locales[lang.lower()]•=•Locale(lang)
  670. | 291| ••••••••••••••••c•=•l.catalog•=•read_po(f)
  671. | 292| ••••••••••••••••c.plural_func•=•get_function_from_rule(c.plural_expr)
  672. | 293| ••••••••••••••••try:
  673. | 294| ••••••••••••••••••••l.countries•=•make_sorted_dict(COUNTRIES,•l.territories)
  674. | 295| ••••••••••••••••except•KeyError:
  675. | 296| ••••••••••••••••••••l.countries•=•COUNTRIES
  676. | 297| ••••••••••••••••try:
  677. | 298| ••••••••••••••••••••l.languages_2•=•make_sorted_dict(LANGUAGES_2,•l.languages)
  678. | 299| ••••••••••••••••except•KeyError:
  679. | 300| ••••••••••••••••••••l.languages_2•=•LANGUAGES_2
  680. | 301| ••••••••except•Exception•as•e:
  681. | 302| ••••••••••••tell_sentry(e,•{},•allow_reraise=True)
  682. | 303|
  683. | 304| ••••#•Prepare•a•unique•and•sorted•list•for•use•in•the•language•switcher
  684. | 305| ••••for•l•in•locales.values():
  685. | 306| ••••••••strings•=•[m.string•for•m•in•l.catalog]
  686. | 307| ••••••••l.completion•=•sum(1•for•s•in•strings•if•s)•/•len(strings)
  687. | 308| ••••loc_url•=•canonical_scheme+'://%s.'+canonical_host
  688. | 309| ••••lang_list•=•sorted(
  689. | 310| ••••••••(
  690. | 311| ••••••••••••(l.completion,•l.language,•l.language_name.title(),•loc_url•%•l.language)
  691. | 312| ••••••••••••for•l•in•set(locales.values())
  692. | 313| ••••••••),
  693. | 314| ••••••••key=lambda•t:•(-t[0],•t[1]),
  694. | 315| ••••)
  695. | 316|
  696. | 317| ••••#•Add•aliases
  697. | 318| ••••for•k,•v•in•list(locales.items()):
  698. | 319| ••••••••locales.setdefault(ALIASES.get(k,•k),•v)
  699. | 320| ••••••••locales.setdefault(ALIASES_R.get(k,•k),•v)
  700. | 321| ••••for•k,•v•in•list(locales.items()):
  701. | 322| ••••••••locales.setdefault(k.split('_',•1)[0],•v)
  702. | 323|
  703. | 324| ••••#•Patch•the•locales•to•look•less•formal
  704. | 325| ••••locales['fr'].currency_formats[None]•=•parse_pattern('#,##0.00\u202f\xa4')
  705. | 326| ••••locales['fr'].currency_symbols['USD']•=•'$'
  706. | 327|
  707. | 328| ••••#•Load•the•markdown•files
  708. | 329| ••••docs•=•{}
  709. | 330| ••••heading_re•=•re.compile(r'^(#+•)',•re.M)
  710. | 331| ••••for•path•in•find_files(os.path.join(project_root,•'i18n'),•'*.md'):
  711. | 332| ••••••••d,•b•=•os.path.split(path)
  712. | 333| ••••••••doc•=•os.path.basename(d)
  713. | 334| ••••••••lang•=•b[:-3]
  714. | 335| ••••••••with•open(path,•'rb')•as•f:
  715. | 336| ••••••••••••md•=•f.read().decode('utf8')
  716. | 337| ••••••••••••if•md.startswith('#•'):
  717. | 338| ••••••••••••••••md•=•'\n'.join(md.split('\n')[1:]).strip()
  718. | 339| ••••••••••••••••md•=•heading_re.sub(r'##\1',•md)
  719. | 340| ••••••••••••docs.setdefault(doc,•{}).__setitem__(lang,•markdown.render(md))
  720. | 341|
  721. | 342| ••••return•{'docs':•docs,•'lang_list':•lang_list,•'locales':•locales}
  722. | | [NORMAL] RadonBear:
  723. | | load_i18n has a cyclomatic complexity of C
  724.  
  725. liberapay/utils/history.py
  726. | 66| def•iter_payday_events(db,•participant,•year=None):
  727. | 67| ••••"""Yields•payday•events•for•the•given•participant.
  728. | 68| ••••"""
  729. | 69| ••••current_year•=•datetime.utcnow().year
  730. | 70| ••••year•=•year•or•current_year
  731. | 71|
  732. | 72| ••••id•=•participant.id
  733. | 73| ••••exchanges•=•db.all("""
  734. | 74| ••••••••SELECT•*
  735. | 75| ••••••••••FROM•exchanges
  736. | 76| •••••••••WHERE•participant=%(id)s
  737. | 77| •••••••••••AND•extract(year•from•timestamp)•=•%(year)s
  738. | 78| ••••""",•locals(),•back_as=dict)
  739. | 79| ••••transfers•=•db.all("""
  740. | 80| ••••••••SELECT•t.*,•p.username,•(SELECT•username•FROM•participants•WHERE•id•=•team)•AS•team_name
  741. | 81| ••••••••••FROM•transfers•t
  742. | 82| ••••••••••JOIN•participants•p•ON•p.id•=•tipper
  743. | 83| •••••••••WHERE•t.tippee=%(id)s
  744. | 84| •••••••••••AND•extract(year•from•t.timestamp)•=•%(year)s
  745. | 85| ••••••••UNION•ALL
  746. | 86| ••••••••SELECT•t.*,•p.username,•(SELECT•username•FROM•participants•WHERE•id•=•team)•AS•team_name
  747. | 87| ••••••••••FROM•transfers•t
  748. | 88| ••••••••••JOIN•participants•p•ON•p.id•=•tippee
  749. | 89| •••••••••WHERE•t.tipper=%(id)s
  750. | 90| •••••••••••AND•extract(year•from•t.timestamp)•=•%(year)s
  751. | 91| ••••""",•locals(),•back_as=dict)
  752. | 92|
  753. | 93| ••••if•not•(exchanges•or•transfers):
  754. | 94| ••••••••return
  755. | 95|
  756. | 96| ••••if•transfers:
  757. | 97| ••••••••yield•dict(
  758. | 98| ••••••••••••kind='totals',
  759. | 99| ••••••••••••given=sum(t['amount']•for•t•in•transfers•if•t['tipper']•==•id•and•t['status']•==•'succeeded'),
  760. | 100| ••••••••••••received=sum(t['amount']•for•t•in•transfers•if•t['tippee']•==•id•and•t['status']•==•'succeeded'),
  761. | 101| ••••••••)
  762. | 102|
  763. | 103| ••••payday_dates•=•db.all("""
  764. | 104| ••••••••SELECT•ts_start::date
  765. | 105| ••••••••••FROM•paydays
  766. | 106| ••••••ORDER•BY•ts_start•ASC
  767. | 107| ••••""")
  768. | 108|
  769. | 109| ••••balance•=•get_end_of_year_balance(db,•participant,•year,•current_year)
  770. | 110| ••••prev_date•=•None
  771. | 111| ••••get_timestamp•=•lambda•e:•e['timestamp']
  772. | 112| ••••events•=•sorted(exchanges+transfers,•key=get_timestamp,•reverse=True)
  773. | 113| ••••for•event•in•events:
  774. | 114|
  775. | 115| ••••••••event['balance']•=•balance
  776. | 116|
  777. | 117| ••••••••event_date•=•event['timestamp'].date()
  778. | 118| ••••••••if•event_date•!=•prev_date:
  779. | 119| ••••••••••••if•prev_date:
  780. | 120| ••••••••••••••••yield•dict(kind='day-close',•balance=balance)
  781. | 121| ••••••••••••day_open•=•dict(kind='day-open',•date=event_date,•balance=balance)
  782. | 122| ••••••••••••if•payday_dates:
  783. | 123| ••••••••••••••••while•payday_dates•and•payday_dates[-1]•>•event_date:
  784. | 124| ••••••••••••••••••••payday_dates.pop()
  785. | 125| ••••••••••••••••payday_date•=•payday_dates[-1]•if•payday_dates•else•None
  786. | 126| ••••••••••••••••if•event_date•==•payday_date:
  787. | 127| ••••••••••••••••••••day_open['payday_number']•=•len(payday_dates)•-•1
  788. | 128| ••••••••••••yield•day_open
  789. | 129| ••••••••••••prev_date•=•event_date
  790. | 130|
  791. | 131| ••••••••if•'fee'•in•event:
  792. | 132| ••••••••••••if•event['amount']•>•0:
  793. | 133| ••••••••••••••••kind•=•'charge'
  794. | 134| ••••••••••••••••if•event['status']•in•(None,•'succeeded'):
  795. | 135| ••••••••••••••••••••balance•-=•event['amount']
  796. | 136| ••••••••••••else:
  797. | 137| ••••••••••••••••kind•=•'credit'
  798. | 138| ••••••••••••••••if•event['status']•!=•'failed':
  799. | 139| ••••••••••••••••••••balance•-=•event['amount']•-•event['fee']
  800. | 140| ••••••••else:
  801. | 141| ••••••••••••kind•=•'transfer'
  802. | 142| ••••••••••••if•event['status']•!=•'succeeded':
  803. | 143| ••••••••••••••••pass
  804. | 144| ••••••••••••elif•event['tippee']•==•id:
  805. | 145| ••••••••••••••••balance•-=•event['amount']
  806. | 146| ••••••••••••else:
  807. | 147| ••••••••••••••••balance•+=•event['amount']
  808. | 148| ••••••••event['kind']•=•kind
  809. | 149|
  810. | 150| ••••••••yield•event
  811. | 151|
  812. | 152| ••••yield•dict(kind='day-close',•balance=balance)
  813. | | [NORMAL] RadonBear:
  814. | | iter_payday_events has a cyclomatic complexity of D
  815.  
  816. liberapay/utils/__init__.py
  817. | 29| def•get_participant(state,•restrict=True,•redirect_stub=True,•allow_member=False):
  818. | 30| ••••"""Given•a•Request,•raise•Response•or•return•Participant.
  819. | 31|
  820. | 32| ••••If•restrict•is•True•then•we'll•restrict•access•to•owners•and•admins.
  821. | 33|
  822. | 34| ••••"""
  823. | 35| ••••request•=•state['request']
  824. | 36| ••••user•=•state['user']
  825. | 37| ••••slug•=•request.line.uri.path['username']
  826. | 38| ••••_•=•state['_']
  827. | 39|
  828. | 40| ••••if•restrict•and•user.ANON:
  829. | 41| ••••••••raise•AuthRequired
  830. | 42|
  831. | 43| ••••if•slug.startswith('~'):
  832. | 44| ••••••••thing•=•'id'
  833. | 45| ••••••••value•=•slug[1:]
  834. | 46| ••••••••participant•=•user•if•user•and•str(user.id)•==•value•else•None
  835. | 47| ••••else:
  836. | 48| ••••••••thing•=•'lower(username)'
  837. | 49| ••••••••value•=•slug.lower()
  838. | 50| ••••••••participant•=•user•if•user•and•user.username.lower()•==•value•else•None
  839. | 51|
  840. | 52| ••••if•participant•is•None:
  841. | 53| ••••••••from•liberapay.models.participant•import•Participant••#•avoid•circular•import
  842. | 54| ••••••••participant•=•Participant._from_thing(thing,•value)•if•value•else•None
  843. | 55| ••••••••if•participant•is•None•or•participant.kind•==•'community':
  844. | 56| ••••••••••••raise•Response(404)
  845. | 57|
  846. | 58| ••••if•request.method•in•('GET',•'HEAD'):
  847. | 59| ••••••••if•slug•!=•participant.username:
  848. | 60| ••••••••••••canon•=•'/'•+•participant.username•+•request.line.uri[len(slug)+1:]
  849. | 61| ••••••••••••raise•Response(302,•headers={'Location':•canon})
  850. | 62|
  851. | 63| ••••status•=•participant.status
  852. | 64| ••••if•status•==•'closed':
  853. | 65| ••••••••if•user.is_admin:
  854. | 66| ••••••••••••return•participant
  855. | 67| ••••••••raise•Response(410)
  856. | 68| ••••elif•status•==•'stub':
  857. | 69| ••••••••if•redirect_stub:
  858. | 70| ••••••••••••to•=•participant.resolve_stub()
  859. | 71| ••••••••••••assert•to
  860. | 72| ••••••••••••raise•Response(302,•headers={'Location':•to})
  861. | 73|
  862. | 74| ••••if•restrict:
  863. | 75| ••••••••if•participant•!=•user:
  864. | 76| ••••••••••••if•allow_member•and•participant.kind•==•'group'•and•user.member_of(participant):
  865. | 77| ••••••••••••••••pass
  866. | 78| ••••••••••••elif•not•user.is_admin:
  867. | 79| ••••••••••••••••raise•Response(403,•_("You•are•not•authorized•to•access•this•page."))
  868. | 80|
  869. | 81| ••••return•participant
  870. | | [NORMAL] RadonBear:
  871. | | get_participant has a cyclomatic complexity of D
  872.  
  873. liberapay/billing/exchanges.py
  874. | 261| def•propagate_exchange(cursor,•participant,•exchange,•route,•error,•amount):
  875. | 262| ••••"""Propagates•an•exchange's•result•to•the•participant's•balance•and•the
  876. | 263| ••••route's•status.
  877. | 264| ••••"""
  878. | 265| ••••route.update_error(error•or•'')
  879. | 266|
  880. | 267| ••••new_balance•=•cursor.one("""
  881. | 268| ••••••••UPDATE•participants
  882. | 269| •••••••••••SET•balance=(balance•+•%s)
  883. | 270| •••••••••WHERE•id=%s
  884. | 271| •••••RETURNING•balance
  885. | 272| ••••""",•(amount,•participant.id))
  886. | 273|
  887. | 274| ••••if•amount•<•0•and•new_balance•<•0:
  888. | 275| ••••••••raise•NegativeBalance
  889. | 276|
  890. | 277| ••••if•amount•<•0:
  891. | 278| ••••••••bundles•=•cursor.all("""
  892. | 279| ••••••••••••LOCK•TABLE•cash_bundles•IN•EXCLUSIVE•MODE;
  893. | 280| ••••••••••••SELECT•*
  894. | 281| ••••••••••••••FROM•cash_bundles
  895. | 282| •••••••••••••WHERE•owner•=•%s
  896. | 283| •••••••••••••••AND•ts•<•now()•-•INTERVAL•%s
  897. | 284| ••••••••••ORDER•BY•ts
  898. | 285| ••••••••""",•(participant.id,•QUARANTINE))
  899. | 286| ••••••••withdrawable•=•sum(b.amount•for•b•in•bundles)
  900. | 287| ••••••••x•=•-amount
  901. | 288| ••••••••if•x•>•withdrawable:
  902. | 289| ••••••••••••raise•NotEnoughWithdrawableMoney(Money(withdrawable,•'EUR'))
  903. | 290| ••••••••for•b•in•bundles:
  904. | 291| ••••••••••••if•x•>=•b.amount:
  905. | 292| ••••••••••••••••cursor.run("""
  906. | 293| ••••••••••••••••••••INSERT•INTO•e2e_transfers
  907. | 294| ••••••••••••••••••••••••••••••••(origin,•withdrawal,•amount)
  908. | 295| •••••••••••••••••••••••••VALUES•(%s,•%s,•%s)
  909. | 296| ••••••••••••••••""",•(b.origin,•exchange.id,•b.amount))
  910. | 297| ••••••••••••••••cursor.run("DELETE•FROM•cash_bundles•WHERE•id•=•%s",•(b.id,))
  911. | 298| ••••••••••••••••x•-=•b.amount
  912. | 299| ••••••••••••••••if•x•==•0:
  913. | 300| ••••••••••••••••••••break
  914. | 301| ••••••••••••else:
  915. | 302| ••••••••••••••••assert•x•>•0
  916. | 303| ••••••••••••••••cursor.run("""
  917. | 304| ••••••••••••••••••••INSERT•INTO•e2e_transfers
  918. | 305| ••••••••••••••••••••••••••••••••(origin,•withdrawal,•amount)
  919. | 306| •••••••••••••••••••••••••VALUES•(%s,•%s,•%s)
  920. | 307| ••••••••••••••••""",•(b.origin,•exchange.id,•x))
  921. | 308| ••••••••••••••••cursor.run("""
  922. | 309| ••••••••••••••••••••UPDATE•cash_bundles
  923. | 310| •••••••••••••••••••••••SET•amount•=•(amount•-•%s)
  924. | 311| •••••••••••••••••••••WHERE•id•=•%s
  925. | 312| ••••••••••••••••""",•(x,•b.id))
  926. | 313| ••••••••••••••••break
  927. | 314| ••••elif•amount•>•0:
  928. | 315| ••••••••cursor.run("""
  929. | 316| ••••••••••••INSERT•INTO•cash_bundles
  930. | 317| ••••••••••••••••••••••••(owner,•origin,•amount,•ts)
  931. | 318| •••••••••••••••••VALUES•(%s,•%s,•%s,•%s)
  932. | 319| ••••••••""",•(participant.id,•exchange.id,•amount,•exchange.timestamp))
  933. | 320|
  934. | 321| ••••participant.set_attributes(balance=new_balance)
  935. | 322|
  936. | 323| ••••if•amount•!=•0:
  937. | 324| ••••••••participant.update_giving_and_tippees(cursor)
  938. | | [NORMAL] RadonBear:
  939. | | propagate_exchange has a cyclomatic complexity of C
  940.  
  941. liberapay/billing/exchanges.py
  942. | 413| def•sync_with_mangopay(db):
  943. | 414| ••••"""We•can•get•out•of•sync•with•MangoPay•if•record_exchange_result•wasn't
  944. | 415| ••••completed.•This•is•where•we•fix•that.
  945. | 416| ••••"""
  946. | 417| ••••check_db(db)
  947. | 418|
  948. | 419| ••••exchanges•=•db.all("SELECT•*•FROM•exchanges•WHERE•status•=•'pre'")
  949. | 420| ••••for•e•in•exchanges:
  950. | 421| ••••••••p•=•Participant.from_id(e.participant)
  951. | 422| ••••••••transactions•=•mangoapi.users.GetTransactions(p.mangopay_user_id)
  952. | 423| ••••••••transactions•=•[x•for•x•in•transactions•if•x.Tag•==•str(e.id)]
  953. | 424| ••••••••assert•len(transactions)•<•2
  954. | 425| ••••••••if•transactions:
  955. | 426| ••••••••••••t•=•transactions[0]
  956. | 427| ••••••••••••error•=•repr_error(t)
  957. | 428| ••••••••••••status•=•t.Status.lower()
  958. | 429| ••••••••••••assert•(not•error)•^•(status•==•'failed')
  959. | 430| ••••••••••••record_exchange_result(db,•e.id,•status,•error,•p)
  960. | 431| ••••••••else:
  961. | 432| ••••••••••••#•The•exchange•didn't•happen
  962. | 433| ••••••••••••if•e.amount•<•0:
  963. | 434| ••••••••••••••••#•Mark•it•as•failed•if•it•was•a•credit
  964. | 435| ••••••••••••••••record_exchange_result(db,•e.id,•'failed',•'interrupted',•p)
  965. | 436| ••••••••••••else:
  966. | 437| ••••••••••••••••#•Otherwise•forget•about•it
  967. | 438| ••••••••••••••••db.run("DELETE•FROM•exchanges•WHERE•id=%s",•(e.id,))
  968. | 439|
  969. | 440| ••••transfers•=•db.all("SELECT•*•FROM•transfers•WHERE•status•=•'pre'")
  970. | 441| ••••for•t•in•transfers:
  971. | 442| ••••••••tipper•=•Participant.from_id(t.tipper)
  972. | 443| ••••••••transactions•=•mangoapi.wallets.GetTransactions(tipper.mangopay_wallet_id)
  973. | 444| ••••••••transactions•=•[x•for•x•in•transactions•if•x.Type•==•'TRANSFER'•and•x.Tag•==•str(t.id)]
  974. | 445| ••••••••assert•len(transactions)•<•2
  975. | 446| ••••••••if•transactions:
  976. | 447| ••••••••••••record_transfer_result(db,•t.id,•transactions[0])
  977. | 448| ••••••••else:
  978. | 449| ••••••••••••#•The•transfer•didn't•happen,•remove•it
  979. | 450| ••••••••••••db.run("DELETE•FROM•transfers•WHERE•id•=•%s",•(t.id,))
  980. | 451|
  981. | 452| ••••check_db(db)
  982. | | [NORMAL] RadonBear:
  983. | | sync_with_mangopay has a cyclomatic complexity of C
  984.  
  985. tests/py/test_callbacks.py
  986. | 18| ••••@patch('mangopaysdk.tools.apipayouts.ApiPayOuts.Get')
  987. | 19| ••••def•test_payout_callback(self,•Get):
  988. | 20| ••••••••homer,•ba•=•self.homer,•self.homer_route
  989. | 21| ••••••••for•status•in•('succeeded',•'failed'):
  990. | 22| ••••••••••••status_up•=•status.upper()
  991. | 23| ••••••••••••error•=•'FOO'•if•status•==•'failed'•else•None
  992. | 24| ••••••••••••self.make_exchange('mango-cc',•10,•0,•homer)
  993. | 25| ••••••••••••e_id•=•record_exchange(self.db,•ba,•-10,•0,•0,•homer,•'pre')
  994. | 26| ••••••••••••assert•homer.balance•==•0
  995. | 27| ••••••••••••homer.close(None)
  996. | 28| ••••••••••••assert•homer.status•==•'closed'
  997. | 29| ••••••••••••qs•=•"EventType=PAYOUT_NORMAL_"+status_up+"&RessourceId=123456790"
  998. | 30| ••••••••••••payout•=•PayOut()
  999. | 31| ••••••••••••payout.Status•=•status_up
  1000. | 32| ••••••••••••payout.ResultCode•=•'000001'•if•error•else•'000000'
  1001. | 33| ••••••••••••payout.ResultMessage•=•error
  1002. | 34| ••••••••••••payout.AuthorId•=•homer.mangopay_user_id
  1003. | 35| ••••••••••••payout.Tag•=•str(e_id)
  1004. | 36| ••••••••••••Get.return_value•=•payout
  1005. | 37| ••••••••••••r•=•self.callback(qs,•csrf_token=False)
  1006. | 38| ••••••••••••assert•b'csrf_token'•not•in•r.headers.cookie
  1007. | 39| ••••••••••••assert•r.code•==•200,•r.text
  1008. | 40| ••••••••••••homer•=•homer.refetch()
  1009. | 41| ••••••••••••if•status•==•'succeeded':
  1010. | 42| ••••••••••••••••assert•homer.balance•==•0
  1011. | 43| ••••••••••••••••assert•homer.status•==•'closed'
  1012. | 44| ••••••••••••else:
  1013. | 45| ••••••••••••••••assert•homer.balance•==•10
  1014. | 46| ••••••••••••••••assert•homer.status•==•'active'
  1015. | 47| ••••••••••••••••emails•=•self.get_emails()
  1016. | 48| ••••••••••••••••assert•len(emails)•==•1
  1017. | 49| ••••••••••••••••assert•emails[0]['to'][0]•==•'homer•<%s>'•%•homer.email
  1018. | 50| ••••••••••••••••assert•'fail'•in•emails[0]['subject']
  1019. | 51| ••••••••••••homer.update_status('active')••#•reset•for•next•loop•run
  1020. | | [NORMAL] RadonBear:
  1021. | | test_payout_callback has a cyclomatic complexity of C
  1022.  
  1023. liberapay/utils/fake_data.py
  1024. | 160| def•populate_db(website,•num_participants=100,•num_tips=200,•num_teams=5,•num_transfers=5000,•num_communities=20):
  1025. | 161| ••••"""Populate•DB•with•fake•data.
  1026. | 162| ••••"""
  1027. | 163| ••••db•=•website.db
  1028. | 164|
  1029. | 165| ••••print("Making•Participants")
  1030. | 166| ••••participants•=•[]
  1031. | 167| ••••for•i•in•range(num_participants):
  1032. | 168| ••••••••participants.append(fake_participant(db))
  1033. | 169|
  1034. | 170| ••••print("Making•Teams")
  1035. | 171| ••••teams•=•[]
  1036. | 172| ••••for•i•in•range(num_teams):
  1037. | 173| ••••••••team•=•fake_participant(db,•kind="group")
  1038. | 174| ••••••••#Add•1•to•3•members•to•the•team
  1039. | 175| ••••••••members•=•random.sample(participants,•random.randint(1,•3))
  1040. | 176| ••••••••for•p•in•members:
  1041. | 177| ••••••••••••team.add_member(p)
  1042. | 178| ••••••••teams.append(team)
  1043. | 179| ••••participants.extend(teams)
  1044. | 180|
  1045. | 181| ••••print("Making•Elsewheres")
  1046. | 182| ••••platforms•=•[p.name•for•p•in•website.platforms]
  1047. | 183| ••••for•p•in•participants:
  1048. | 184| ••••••••#All•participants•get•between•0•and•3•elsewheres
  1049. | 185| ••••••••num_elsewheres•=•random.randint(0,•3)
  1050. | 186| ••••••••for•platform_name•in•random.sample(platforms,•num_elsewheres):
  1051. | 187| ••••••••••••fake_elsewhere(db,•p,•platform_name)
  1052. | 188|
  1053. | 189| ••••print("Making•Communities")
  1054. | 190| ••••for•i•in•range(num_communities):
  1055. | 191| ••••••••creator•=•random.sample(participants,•1)
  1056. | 192| ••••••••community•=•fake_community(db,•creator[0])
  1057. | 193|
  1058. | 194| ••••••••members•=•random.sample(participants,•random.randint(1,•3))
  1059. | 195| ••••••••for•p•in•members:
  1060. | 196| ••••••••••••p.update_community_status('memberships',•True,•community.id)
  1061. | 197|
  1062. | 198| ••••print("Making•Tips")
  1063. | 199| ••••tips•=•[]
  1064. | 200| ••••for•i•in•range(num_tips):
  1065. | 201| ••••••••tipper,•tippee•=•random.sample(participants,•2)
  1066. | 202| ••••••••tips.append(fake_tip(db,•tipper,•tippee))
  1067. | 203|
  1068. | 204| ••••#•Transfers
  1069. | 205| ••••transfers•=•[]
  1070. | 206| ••••for•i•in•range(num_transfers):
  1071. | 207| ••••••••tipper,•tippee•=•random.sample(participants,•2)
  1072. | 208| ••••••••while•tipper.kind•in•('group',•'community')•or•\
  1073. | 209| ••••••••••••••tippee.kind•in•('group',•'community'):
  1074. | 210| ••••••••••••tipper,•tippee•=•random.sample(participants,•2)
  1075. | 211| ••••••••sys.stdout.write("\rMaking•Transfers•(%i/%i)"•%•(i+1,•num_transfers))
  1076. | 212| ••••••••sys.stdout.flush()
  1077. | 213| ••••••••amount•=•fake_tip_amount()
  1078. | 214| ••••••••ts•=•faker.date_time_this_year()
  1079. | 215| ••••••••fake_exchange(db,•tipper,•amount,•0,•0,•(ts•-•datetime.timedelta(days=1)))
  1080. | 216| ••••••••transfers.append(fake_transfer(db,•tipper,•tippee,•amount,•ts))
  1081. | 217| ••••print("")
  1082. | 218|
  1083. | 219| ••••#•Paydays
  1084. | 220| ••••#•First•determine•the•boundaries•-•min•and•max•date
  1085. | 221| ••••min_date•=•min(min(x.ctime•for•x•in•tips),•\
  1086. | 222| •••••••••••••••••••min(x.timestamp•for•x•in•transfers))
  1087. | 223| ••••max_date•=•max(max(x.ctime•for•x•in•tips),•\
  1088. | 224| •••••••••••••••••••max(x.timestamp•for•x•in•transfers))
  1089. | 225| ••••#•iterate•through•min_date,•max_date•one•week•at•a•time
  1090. | 226| ••••payday_counter•=•1
  1091. | 227| ••••date•=•min_date
  1092. | 228| ••••paydays_total•=•(max_date•-•min_date).days/7•+•1
  1093. | 229| ••••while•date•<•max_date:
  1094. | 230| ••••••••sys.stdout.write("\rMaking•Paydays•(%i/%i)"•%•(payday_counter,•paydays_total))
  1095. | 231| ••••••••sys.stdout.flush()
  1096. | 232| ••••••••payday_counter•+=•1
  1097. | 233| ••••••••end_date•=•date•+•datetime.timedelta(days=7)
  1098. | 234| ••••••••week_tips•=•[x•for•x•in•tips•if•date•<•x.ctime•<•end_date]
  1099. | 235| ••••••••week_transfers•=•[x•for•x•in•transfers•if•date•<•x.timestamp•<•end_date]
  1100. | 236| ••••••••week_participants•=•[x•for•x•in•participants•if•x.join_time•<•end_date]
  1101. | 237| ••••••••actives=set()
  1102. | 238| ••••••••tippers=set()
  1103. | 239| ••••••••for•xfers•in•week_tips,•week_transfers:
  1104. | 240| ••••••••••••actives.update(x.tipper•for•x•in•xfers)
  1105. | 241| ••••••••••••actives.update(x.tippee•for•x•in•xfers)
  1106. | 242| ••••••••••••tippers.update(x.tipper•for•x•in•xfers)
  1107. | 243| ••••••••payday•=•{
  1108. | 244| ••••••••••••'ts_start':•date,
  1109. | 245| ••••••••••••'ts_end':•end_date,
  1110. | 246| ••••••••••••'ntips':•len(week_tips),
  1111. | 247| ••••••••••••'ntransfers':•len(week_transfers),
  1112. | 248| ••••••••••••'nparticipants':•len(week_participants),
  1113. | 249| ••••••••••••'ntippers':•len(tippers),
  1114. | 250| ••••••••••••'nactive':•len(actives),
  1115. | 251| ••••••••••••'transfer_volume':•sum(x.amount•for•x•in•week_transfers)
  1116. | 252| ••••••••}
  1117. | 253| ••••••••_fake_thing(db,•"paydays",•**payday)
  1118. | 254| ••••••••date•=•end_date
  1119. | 255| ••••print("")
  1120. | | [NORMAL] RadonBear:
  1121. | | populate_db has a cyclomatic complexity of D
  1122.  
  1123. liberapay/elsewhere/_base.py
  1124. | 87| ••••def•api_get(self,•path,•sess=None,•error_handler=True,•**kw):
  1125. | 88| ••••••••"""
  1126. | 89| ••••••••Given•a•`path`•(e.g.•/users/foo),•this•function•sends•a•GET•request•to
  1127. | 90| ••••••••the•platform's•API•(e.g.•https://api.github.com/users/foo).
  1128. | 91|
  1129. | 92| ••••••••The•response•is•returned,•after•checking•its•status•code•and•ratelimit
  1130. | 93| ••••••••headers.
  1131. | 94| ••••••••"""
  1132. | 95| ••••••••url•=•self.api_url+path
  1133. | 96| ••••••••is_user_session•=•bool(sess)
  1134. | 97| ••••••••if•not•sess:
  1135. | 98| ••••••••••••sess•=•self.get_auth_session()
  1136. | 99| ••••••••••••api_app_auth_params•=•getattr(self,•'api_app_auth_params',•None)
  1137. | 100| ••••••••••••if•api_app_auth_params:
  1138. | 101| ••••••••••••••••url•+=•'?'•if•'?'•not•in•url•else•'&'
  1139. | 102| ••••••••••••••••url•+=•api_app_auth_params.format(**self.__dict__)
  1140. | 103| ••••••••response•=•sess.get(url,•**kw)
  1141. | 104|
  1142. | 105| ••••••••if•not•is_user_session:
  1143. | 106| ••••••••••••limit,•remaining,•reset•=•self.get_ratelimit_headers(response)
  1144. | 107| ••••••••••••self.log_ratelimit_headers(limit,•remaining,•reset)
  1145. | 108|
  1146. | 109| ••••••••#•Check•response•status
  1147. | 110| ••••••••if•error_handler•is•True:
  1148. | 111| ••••••••••••error_handler•=•self.api_error_handler
  1149. | 112| ••••••••status•=•response.status_code
  1150. | 113| ••••••••if•status•==•401•and•isinstance(self,•PlatformOAuth1)•and•is_user_session:
  1151. | 114| ••••••••••••#•https://tools.ietf.org/html/rfc5849#section-3.2
  1152. | 115| ••••••••••••raise•TokenExpiredError
  1153. | 116| ••••••••if•status•!=•200•and•error_handler:
  1154. | 117| ••••••••••••error_handler(response,•is_user_session)
  1155. | 118|
  1156. | 119| ••••••••return•response
  1157. | | [NORMAL] RadonBear:
  1158. | | api_get has a cyclomatic complexity of C
  1159.  
  1160. tests/py/test_close.py
  1161. | 126| ••••••••alice•=•self.make_participant('alice',•balance=D('10.00'))
  1162. | 127| ••••••••bob•=•self.make_participant('bob')
  1163. | 128| ••••••••carl•=•self.make_participant('carl')
  1164. | 129| ••••••••alice.set_tip_to(bob,•D('3.00'))
  1165. | 130| ••••••••alice.set_tip_to(carl,•D('6.00'))
  1166. | 131| ••••••••with•self.db.get_cursor()•as•cursor:
  1167. | 132| ••••••••••••alice.distribute_balance_as_final_gift(cursor)
  1168. | 133| ••••••••assert•Participant.from_username('bob').balance•==•D('3.33')
  1169.  
  1170. tests/py/test_close.py
  1171. | 138| ••••••••alice•=•self.make_participant('alice',•balance=D('0.00'))
  1172. | 139| ••••••••bob•=•self.make_participant('bob')
  1173. | 140| ••••••••carl•=•self.make_participant('carl')
  1174. | 141| ••••••••alice.set_tip_to(bob,•D('3.00'))
  1175. | 142| ••••••••alice.set_tip_to(carl,•D('6.00'))
  1176. | 143| ••••••••with•self.db.get_cursor()•as•cursor:
  1177. | 144| ••••••••••••alice.distribute_balance_as_final_gift(cursor)
  1178. | 145| ••••••••assert•self.db.one("SELECT•count(*)•FROM•tips")•==•2
  1179. | | [NORMAL] CPDBear:
  1180. | | Duplicate code found.
  1181.  
  1182. tests/py/test_stats.py
  1183. | 43| ••••••••bad_cc.set_tip_to(self.bob,•'3.00')
  1184. | 44| ••••••••expected•=•([[Decimal('1.00'),•1,•Decimal('1.00'),•1,•Decimal('1')]],
  1185. | 45| ••••••••••••••••••••1.0,•Decimal('1.00'))
  1186. | 46| ••••••••actual•=•self.bob.get_tip_distribution()
  1187. | 47| ••••••••assert•actual•==•expected
  1188.  
  1189. tests/py/test_stats.py
  1190. | 52| ••••••••missing_cc.set_tip_to(self.bob,•'3.00')
  1191. | 53| ••••••••expected•=•([[Decimal('1.00'),•1,•Decimal('1.00'),•1,•Decimal('1')]],
  1192. | 54| ••••••••••••••••••••1.0,•Decimal('1.00'))
  1193. | 55| ••••••••actual•=•self.bob.get_tip_distribution()
  1194. | 56| ••••••••assert•actual•==•expected
  1195. | | [NORMAL] CPDBear:
  1196. | | Duplicate code found.
  1197.  
  1198. tests/py/test_billing_exchanges.py
  1199. | 330| ••••••••••••with•self.assertRaises(Foobar):
  1200. | 331| ••••••••••••••••transfer(self.db,•self.janet.id,•self.david.id,•D('10.00'),•'tip')
  1201. | 332| ••••••••t•=•self.db.one("SELECT•*•FROM•transfers")
  1202. | 333| ••••••••assert•t.status•==•'pre'
  1203. | 334| ••••••••sync_with_mangopay(self.db)
  1204.  
  1205. tests/py/test_billing_exchanges.py
  1206. | 345| ••••••••••••with•self.assertRaises(Foobar):
  1207. | 346| ••••••••••••••••transfer(self.db,•self.janet.id,•self.david.id,•D('10.00'),•'tip')
  1208. | 347| ••••••••t•=•self.db.one("SELECT•*•FROM•transfers")
  1209. | 348| ••••••••assert•t.status•==•'pre'
  1210. | 349| ••••••••sync_with_mangopay(self.db)
  1211. | | [NORMAL] CPDBear:
  1212. | | Duplicate code found.
  1213.  
  1214. tests/py/test_close.py
  1215. | 75| ••••def•test_dbafg_distributes_balance_as_final_gift(self):
  1216. | 76| ••••••••alice•=•self.make_participant('alice',•balance=D('10.00'))
  1217. | 77| ••••••••bob•=•self.make_participant('bob')
  1218. | 78| ••••••••carl•=•self.make_participant('carl')
  1219. | 79| ••••••••alice.set_tip_to(bob,•D('3.00'))
  1220. | 80| ••••••••alice.set_tip_to(carl,•D('2.00'))
  1221.  
  1222. tests/py/test_close.py
  1223. | 125| ••••def•test_dbafg_favors_highest_tippee_in_rounding_errors(self):
  1224. | 126| ••••••••alice•=•self.make_participant('alice',•balance=D('10.00'))
  1225. | 127| ••••••••bob•=•self.make_participant('bob')
  1226. | 128| ••••••••carl•=•self.make_participant('carl')
  1227. | 129| ••••••••alice.set_tip_to(bob,•D('3.00'))
  1228. | 130| ••••••••alice.set_tip_to(carl,•D('6.00'))
  1229. | | [NORMAL] CPDBear:
  1230. | | Duplicate code found.
  1231.  
  1232. tests/py/test_elsewhere.py
  1233. | 38| ••••••••alice•=•self.make_participant('alice',•elsewhere='twitter')
  1234. | 39|
  1235. | 40| ••••••••gusi.return_value•=•self.client.website.platforms.github.extract_user_info({'id':•2})
  1236. | 41| ••••••••gui.return_value•=•self.client.website.platforms.github.extract_user_info({'id':•1})
  1237. | 42| ••••••••ft.return_value•=•None
  1238.  
  1239. tests/py/test_elsewhere.py
  1240. | 57| ••••••••self.make_participant('bob')
  1241. | 58|
  1242. | 59| ••••••••gusi.return_value•=•self.client.website.platforms.github.extract_user_info({'id':•2})
  1243. | 60| ••••••••gui.return_value•=•self.client.website.platforms.github.extract_user_info({'id':•1})
  1244. | 61| ••••••••ft.return_value•=•None
  1245. | | [NORMAL] CPDBear:
  1246. | | Duplicate code found.
  1247.  
  1248. tests/py/test_utils.py
  1249. | 38| ••••••••state•=•self.client.GET('/Alice/?foo=bar',•return_after='dispatch_request_to_filesystem',
  1250. | 39| ••••••••••••••••••••••••••••••••want='state')
  1251. | 40| ••••••••with•self.assertRaises(Response)•as•cm:
  1252. | 41| ••••••••••••utils.get_participant(state,•restrict=False)
  1253. | 42| ••••••••r•=•cm.exception
  1254. | 43| ••••••••assert•r.code•==•302
  1255. | 44| ••••••••assert•r.headers['Location']•==•'/alice/?foo=bar'
  1256.  
  1257. tests/py/test_utils.py
  1258. | 48| ••••••••state•=•self.client.GET('/~1/?x=2',•return_after='dispatch_request_to_filesystem',
  1259. | 49| ••••••••••••••••••••••••••••••••want='state')
  1260. | 50| ••••••••with•self.assertRaises(Response)•as•cm:
  1261. | 51| ••••••••••••utils.get_participant(state,•restrict=False)
  1262. | 52| ••••••••r•=•cm.exception
  1263. | 53| ••••••••assert•r.code•==•302
  1264. | 54| ••••••••assert•r.headers['Location']•==•'/alice/?x=2'
  1265. | | [NORMAL] CPDBear:
  1266. | | Duplicate code found.
  1267.  
  1268. tests/py/test_billing_payday.py
  1269. | 230| ••••••••self.db.run("UPDATE•participants•SET•goal•=•-1•WHERE•username='homer'")
  1270. | 231| ••••••••payday•=•Payday.start()
  1271. | 232| ••••••••with•self.db.get_cursor()•as•cursor:
  1272. | 233| ••••••••••••payday.prepare(cursor,•payday.ts_start)
  1273. | 234| ••••••••••••payday.transfer_virtually(cursor)
  1274. | 235| ••••••••••••new_balances•=•self.get_new_balances(cursor)
  1275. | 236| ••••••••••••assert•new_balances[self.janet.id]•==•20
  1276.  
  1277. tests/py/test_billing_payday.py
  1278. | 252| ••••••••self.david.set_tip_to(self.homer,•D('0.50'))
  1279. | 253| ••••••••payday•=•Payday.start()
  1280. | 254| ••••••••with•self.db.get_cursor()•as•cursor:
  1281. | 255| ••••••••••••payday.prepare(cursor,•payday.ts_start)
  1282. | 256| ••••••••••••payday.transfer_virtually(cursor)
  1283. | 257| ••••••••••••new_balances•=•self.get_new_balances(cursor)
  1284. | 258| ••••••••••••assert•new_balances[self.david.id]•==•D('0.49')
  1285. | | [NORMAL] CPDBear:
  1286. | | Duplicate code found.
  1287.  
  1288. tests/py/test_billing_payday.py
  1289. | 252| ••••••••self.david.set_tip_to(self.homer,•D('0.50'))
  1290. | 253| ••••••••payday•=•Payday.start()
  1291. | 254| ••••••••with•self.db.get_cursor()•as•cursor:
  1292. | 255| ••••••••••••payday.prepare(cursor,•payday.ts_start)
  1293. | 256| ••••••••••••payday.transfer_virtually(cursor)
  1294. | 257| ••••••••••••new_balances•=•self.get_new_balances(cursor)
  1295. | 258| ••••••••••••assert•new_balances[self.david.id]•==•D('0.49')
  1296.  
  1297. tests/py/test_billing_payday.py
  1298. | 269| ••••••••self.david.set_tip_to(self.homer,•D('20'))••#•Should•be•unfunded
  1299. | 270|
  1300. | 271| ••••••••payday•=•Payday.start()
  1301. | 272| ••••••••with•self.db.get_cursor()•as•cursor:
  1302. | 273| ••••••••••••payday.prepare(cursor,•payday.ts_start)
  1303. | 274| ••••••••••••payday.transfer_virtually(cursor)
  1304. | 275| ••••••••••••new_balances•=•self.get_new_balances(cursor)
  1305. | | [NORMAL] CPDBear:
  1306. | | Duplicate code found.
  1307.  
  1308. tests/py/test_billing_payday.py
  1309. | 230| ••••••••self.db.run("UPDATE•participants•SET•goal•=•-1•WHERE•username='homer'")
  1310. | 231| ••••••••payday•=•Payday.start()
  1311. | 232| ••••••••with•self.db.get_cursor()•as•cursor:
  1312. | 233| ••••••••••••payday.prepare(cursor,•payday.ts_start)
  1313. | 234| ••••••••••••payday.transfer_virtually(cursor)
  1314. | 235| ••••••••••••new_balances•=•self.get_new_balances(cursor)
  1315. | 236| ••••••••••••assert•new_balances[self.janet.id]•==•20
  1316.  
  1317. tests/py/test_billing_payday.py
  1318. | 269| ••••••••self.david.set_tip_to(self.homer,•D('20'))••#•Should•be•unfunded
  1319. | 270|
  1320. | 271| ••••••••payday•=•Payday.start()
  1321. | 272| ••••••••with•self.db.get_cursor()•as•cursor:
  1322. | 273| ••••••••••••payday.prepare(cursor,•payday.ts_start)
  1323. | 274| ••••••••••••payday.transfer_virtually(cursor)
  1324. | 275| ••••••••••••new_balances•=•self.get_new_balances(cursor)
  1325. | | [NORMAL] CPDBear:
  1326. | | Duplicate code found.
  1327.  
  1328. tests/py/test_close.py
  1329. | 75| ••••def•test_dbafg_distributes_balance_as_final_gift(self):
  1330. | 76| ••••••••alice•=•self.make_participant('alice',•balance=D('10.00'))
  1331. | 77| ••••••••bob•=•self.make_participant('bob')
  1332. | 78| ••••••••carl•=•self.make_participant('carl')
  1333. | 79| ••••••••alice.set_tip_to(bob,•D('3.00'))
  1334.  
  1335. tests/py/test_close.py
  1336. | 112| ••••def•test_dbafg_skips_zero_tips(self):
  1337. | 113| ••••••••alice•=•self.make_participant('alice',•balance=D('10.00'))
  1338. | 114| ••••••••bob•=•self.make_participant('bob')
  1339. | 115| ••••••••carl•=•self.make_participant('carl')
  1340. | 116| ••••••••alice.set_tip_to(bob,•D('0.00'))
  1341.  
  1342. tests/py/test_close.py
  1343. | 125| ••••def•test_dbafg_favors_highest_tippee_in_rounding_errors(self):
  1344. | 126| ••••••••alice•=•self.make_participant('alice',•balance=D('10.00'))
  1345. | 127| ••••••••bob•=•self.make_participant('bob')
  1346. | 128| ••••••••carl•=•self.make_participant('carl')
  1347. | 129| ••••••••alice.set_tip_to(bob,•D('3.00'))
  1348. | | [NORMAL] CPDBear:
  1349. | | Duplicate code found.
  1350.  
  1351. tests/py/test_close.py
  1352. | 78| ••••••••carl•=•self.make_participant('carl')
  1353. | 79| ••••••••alice.set_tip_to(bob,•D('3.00'))
  1354. | 80| ••••••••alice.set_tip_to(carl,•D('2.00'))
  1355. | 81| ••••••••with•self.db.get_cursor()•as•cursor:
  1356. | 82| ••••••••••••alice.distribute_balance_as_final_gift(cursor)
  1357. | 83| ••••••••assert•Participant.from_username('bob').balance•==•D('6.00')
  1358.  
  1359. tests/py/test_close.py
  1360. | 103| ••••••••carl•=•self.make_stub()
  1361. | 104| ••••••••alice.set_tip_to(bob,•D('3.00'))
  1362. | 105| ••••••••alice.set_tip_to(carl,•D('2.00'))
  1363. | 106| ••••••••with•self.db.get_cursor()•as•cursor:
  1364. | 107| ••••••••••••alice.distribute_balance_as_final_gift(cursor)
  1365. | 108| ••••••••assert•Participant.from_id(bob.id).balance•==•D('10.00')
  1366. | | [NORMAL] CPDBear:
  1367. | | Duplicate code found.
  1368.  
  1369. tests/py/test_close.py
  1370. | 20| ••••••••alice•=•self.make_participant('alice',•balance=D('10.00'))
  1371. | 21| ••••••••bob•=•self.make_participant('bob')
  1372. | 22| ••••••••carl•=•self.make_participant('carl')
  1373. | 23|
  1374. | 24| ••••••••alice.set_tip_to(bob,•D('3.00'))
  1375.  
  1376. tests/py/test_close.py
  1377. | 76| ••••••••alice•=•self.make_participant('alice',•balance=D('10.00'))
  1378. | 77| ••••••••bob•=•self.make_participant('bob')
  1379. | 78| ••••••••carl•=•self.make_participant('carl')
  1380. | 79| ••••••••alice.set_tip_to(bob,•D('3.00'))
  1381. | 80| ••••••••alice.set_tip_to(carl,•D('2.00'))
  1382.  
  1383. tests/py/test_close.py
  1384. | 126| ••••••••alice•=•self.make_participant('alice',•balance=D('10.00'))
  1385. | 127| ••••••••bob•=•self.make_participant('bob')
  1386. | 128| ••••••••carl•=•self.make_participant('carl')
  1387. | 129| ••••••••alice.set_tip_to(bob,•D('3.00'))
  1388. | 130| ••••••••alice.set_tip_to(carl,•D('6.00'))
  1389. | | [NORMAL] CPDBear:
  1390. | | Duplicate code found.
  1391.  
  1392. tests/py/test_pages.py
  1393. | 202| ••••••••r•=•self.client.POST('/janeway/identity',•data,•**kw)
  1394. | 203| ••••••••assert•r.code•==•200,•r.text
  1395. | 204| ••••••••janeway•=•janeway.refetch()
  1396. | 205| ••••••••assert•janeway.mangopay_user_id
  1397. | 206|
  1398. | 207| ••••••••#•Edit•the•natural•user
  1399. | 208| ••••••••data2•=•dict(data,•Nationality='US')
  1400.  
  1401. tests/py/test_pages.py
  1402. | 221| ••••••••r•=•self.client.POST('/janeway/identity',•data,•**kw)
  1403. | 222| ••••••••assert•r.code•==•200,•r.text
  1404. | 223| ••••••••janeway•=•janeway.refetch()
  1405. | 224| ••••••••assert•janeway.mangopay_user_id
  1406. | 225|
  1407. | 226| ••••••••#•Edit•the•legal•user
  1408. | 227| ••••••••data2•=•dict(data,•LegalPersonType='ORGANIZATION')
  1409. | | [NORMAL] CPDBear:
  1410. | | Duplicate code found.
  1411.  
  1412. tests/py/test_close.py
  1413. | 89| ••••••••bob•=•self.make_stub()
  1414. | 90| ••••••••carl•=•self.make_stub()
  1415. | 91| ••••••••alice.set_tip_to(bob,•D('3.00'))
  1416. | 92| ••••••••alice.set_tip_to(carl,•D('2.00'))
  1417. | 93| ••••••••with•self.db.get_cursor()•as•cursor:
  1418.  
  1419. tests/py/test_close.py
  1420. | 102| ••••••••bob•=•self.make_participant('bob')
  1421. | 103| ••••••••carl•=•self.make_stub()
  1422. | 104| ••••••••alice.set_tip_to(bob,•D('3.00'))
  1423. | 105| ••••••••alice.set_tip_to(carl,•D('2.00'))
  1424. | 106| ••••••••with•self.db.get_cursor()•as•cursor:
  1425. | | [NORMAL] CPDBear:
  1426. | | Duplicate code found.
  1427.  
  1428. tests/py/test_communities.py
  1429. | 83| ••••••••response•=•self.client.POST('/for/test/unsubscribe',•auth_as=self.bob,
  1430. | 84| ••••••••••••••••••••••••••••••••••••xhr=True)
  1431. | 85|
  1432. | 86| ••••••••response•=•self.client.GET('/bob/communities.json',•auth_as=self.bob)
  1433. | 87|
  1434. | 88| ••••••••assert•len(json.loads(response.body))•==•0
  1435.  
  1436. tests/py/test_communities.py
  1437. | 100| ••••••••response•=•self.client.POST('/for/test/leave',•auth_as=self.bob,
  1438. | 101| ••••••••••••••••••••••••••••••••••••xhr=True)
  1439. | 102|
  1440. | 103| ••••••••response•=•self.client.GET('/bob/communities.json',•auth_as=self.bob)
  1441. | 104|
  1442. | 105| ••••••••assert•len(json.loads(response.body))•==•0
  1443. | | [NORMAL] CPDBear:
  1444. | | Duplicate code found.
  1445.  
  1446. tests/py/test_pages.py
  1447. | 208| ••••••••data2•=•dict(data,•Nationality='US')
  1448. | 209| ••••••••r•=•self.client.POST('/janeway/identity',•data2,•**kw)
  1449. | 210| ••••••••assert•r.code•==•200,•r.text
  1450. | 211| ••••••••janeway2•=•janeway.refetch()
  1451. | 212| ••••••••assert•janeway2.mangopay_user_id•==•janeway.mangopay_user_id
  1452.  
  1453. tests/py/test_pages.py
  1454. | 227| ••••••••data2•=•dict(data,•LegalPersonType='ORGANIZATION')
  1455. | 228| ••••••••r•=•self.client.POST('/janeway/identity',•data2,•**kw)
  1456. | 229| ••••••••assert•r.code•==•200,•r.text
  1457. | 230| ••••••••janeway2•=•janeway.refetch()
  1458. | 231| ••••••••assert•janeway2.mangopay_user_id•==•janeway.mangopay_user_id
  1459. | | [NORMAL] CPDBear:
  1460. | | Duplicate code found.
  1461.  
  1462. tests/py/test_public_json.py
  1463. | 104| ••••def•test_authenticated_user_gets_self_for_self(self):
  1464. | 105| ••••••••alice•=•self.make_participant('alice',•balance=100)
  1465. | 106| ••••••••bob•=•self.make_participant('bob')
  1466. | 107|
  1467. | 108| ••••••••alice.set_tip_to(bob,•'3.00')
  1468. | 109|
  1469. | 110| ••••••••raw•=•self.client.GET('/bob/public.json',•auth_as=bob).body
  1470.  
  1471. tests/py/test_public_json.py
  1472. | 123| ••••def•test_jsonp_works(self):
  1473. | 124| ••••••••alice•=•self.make_participant('alice',•balance=100)
  1474. | 125| ••••••••bob•=•self.make_participant('bob')
  1475. | 126|
  1476. | 127| ••••••••alice.set_tip_to(bob,•'3.00')
  1477. | 128|
  1478. | 129| ••••••••raw•=•self.client.GET('/bob/public.json?callback=foo',•auth_as=bob).body
  1479. | | [NORMAL] CPDBear:
  1480. | | Duplicate code found.
  1481.  
  1482. tests/py/test_take.py
  1483. | 78| ••••def•test_get_members(self):
  1484. | 79| ••••••••team•=•self.make_team()
  1485. | 80| ••••••••alice•=•self.make_participant('alice')
  1486. | 81| ••••••••self.take_last_week(team,•alice,•'40.00')
  1487. | 82| ••••••••team.set_take_for(alice,•D('42.00'),•team)
  1488.  
  1489. tests/py/test_take.py
  1490. | 120| ••••def•test_changes_to_team_receiving_affect_members_take(self):
  1491. | 121| ••••••••team•=•self.make_team()
  1492. | 122| ••••••••alice•=•self.make_participant('alice')
  1493. | 123| ••••••••self.take_last_week(team,•alice,•'40.00')
  1494. | 124| ••••••••team.set_take_for(alice,•D('42.00'),•alice)
  1495. | | [NORMAL] CPDBear:
  1496. | | Duplicate code found.
  1497.  
  1498. tests/py/test_charts_json.py
  1499. | 60| ••••••••••••••••••••••}
  1500. | 61| •••••••••••••••••••,•{•"date":•today()
  1501. | 62| •••••••••••••••••••••,•"npatrons":•2
  1502. | 63| •••••••••••••••••••••,•"receipts":•3.00
  1503. | 64| ••••••••••••••••••••••}
  1504. | 65| ••••••••••••••••••••]
  1505. | 66| ••••••••actual•=•json.loads(self.client.GET('/carl/charts.json').body)
  1506. | 67|
  1507. | 68| ••••••••assert•actual•==•expected
  1508. | 69|
  1509. | 70| ••••def•test_sandwiched_tipless_payday_comes_through(self):
  1510.  
  1511. tests/py/test_charts_json.py
  1512. | 89| ••••••••••••••••••••••}
  1513. | 90| •••••••••••••••••••,•{•"date":•today()
  1514. | 91| •••••••••••••••••••••,•"npatrons":•2
  1515. | 92| •••••••••••••••••••••,•"receipts":•3.00
  1516. | 93| ••••••••••••••••••••••}
  1517. | 94| ••••••••••••••••••••]
  1518. | 95| ••••••••actual•=•json.loads(self.client.GET('/carl/charts.json').body)
  1519. | 96|
  1520. | 97| ••••••••assert•actual•==•expected
  1521. | 98|
  1522. | 99| ••••def•test_out_of_band_transfer_gets_included_with_prior_payday(self):
  1523.  
  1524. tests/py/test_charts_json.py
  1525. | 115| ••••••••••••••••••••••}
  1526. | 116| •••••••••••••••••••,•{•"date":•today()
  1527. | 117| •••••••••••••••••••••,•"npatrons":•2
  1528. | 118| •••••••••••••••••••••,•"receipts":•3.00
  1529. | 119| ••••••••••••••••••••••}
  1530. | 120| ••••••••••••••••••••]
  1531. | 121| ••••••••actual•=•json.loads(self.client.GET('/carl/charts.json').body)
  1532. | 122|
  1533. | 123| ••••••••assert•actual•==•expected
  1534. | 124|
  1535. | 125| ••••def•test_never_received_gives_empty_array(self):
  1536. | | [NORMAL] CPDBear:
  1537. | | Duplicate code found.
  1538.  
  1539. tests/py/test_utils.py
  1540. | 29| ••••••••state•=•self.client.GET('/~/',•return_after='dispatch_request_to_filesystem',
  1541. | 30| ••••••••••••••••••••••••••••••••want='state')
  1542. | 31| ••••••••with•self.assertRaises(Response)•as•cm:
  1543. | 32| ••••••••••••utils.get_participant(state,•restrict=False)
  1544. | 33| ••••••••r•=•cm.exception
  1545. | 34| ••••••••assert•r.code•==•404
  1546.  
  1547. tests/py/test_utils.py
  1548. | 38| ••••••••state•=•self.client.GET('/Alice/?foo=bar',•return_after='dispatch_request_to_filesystem',
  1549. | 39| ••••••••••••••••••••••••••••••••want='state')
  1550. | 40| ••••••••with•self.assertRaises(Response)•as•cm:
  1551. | 41| ••••••••••••utils.get_participant(state,•restrict=False)
  1552. | 42| ••••••••r•=•cm.exception
  1553. | 43| ••••••••assert•r.code•==•302
  1554.  
  1555. tests/py/test_utils.py
  1556. | 48| ••••••••state•=•self.client.GET('/~1/?x=2',•return_after='dispatch_request_to_filesystem',
  1557. | 49| ••••••••••••••••••••••••••••••••want='state')
  1558. | 50| ••••••••with•self.assertRaises(Response)•as•cm:
  1559. | 51| ••••••••••••utils.get_participant(state,•restrict=False)
  1560. | 52| ••••••••r•=•cm.exception
  1561. | 53| ••••••••assert•r.code•==•302
  1562. | | [NORMAL] CPDBear:
  1563. | | Duplicate code found.
  1564.  
  1565. tests/py/test_close.py
  1566. | 20| ••••••••alice•=•self.make_participant('alice',•balance=D('10.00'))
  1567. | 21| ••••••••bob•=•self.make_participant('bob')
  1568. | 22| ••••••••carl•=•self.make_participant('carl')
  1569. | 23|
  1570. | 24| ••••••••alice.set_tip_to(bob,•D('3.00'))
  1571.  
  1572. tests/py/test_close.py
  1573. | 113| ••••••••alice•=•self.make_participant('alice',•balance=D('10.00'))
  1574. | 114| ••••••••bob•=•self.make_participant('bob')
  1575. | 115| ••••••••carl•=•self.make_participant('carl')
  1576. | 116| ••••••••alice.set_tip_to(bob,•D('0.00'))
  1577. | 117| ••••••••alice.set_tip_to(carl,•D('2.00'))
  1578. | | [NORMAL] CPDBear:
  1579. | | Duplicate code found.
  1580.  
  1581. tests/py/test_public_json.py
  1582. | 26| •••••••••••••••••••••••••••••••••••••,•hide_giving=True
  1583. | 27| •••••••••••••••••••••••••••••••••••••)
  1584. | 28| ••••••••bob•=•self.make_participant('bob')
  1585. | 29| ••••••••alice.set_tip_to(bob,•'1.00')
  1586. | 30| ••••••••data•=•json.loads(self.client.GET('/alice/public.json').body)
  1587. | 31|
  1588. | 32| ••••••••assert•data['giving']•==•None
  1589.  
  1590. tests/py/test_public_json.py
  1591. | 37| •••••••••••••••••••••••••••••••••••••,•hide_receiving=True
  1592. | 38| •••••••••••••••••••••••••••••••••••••)
  1593. | 39| ••••••••bob•=•self.make_participant('bob')
  1594. | 40| ••••••••alice.set_tip_to(bob,•'1.00')
  1595. | 41| ••••••••data•=•json.loads(self.client.GET('/alice/public.json').body)
  1596. | 42|
  1597. | 43| ••••••••assert•data['receiving']•==•None
  1598. | | [NORMAL] CPDBear:
  1599. | | Duplicate code found.
  1600.  
  1601. tests/py/test_charts_json.py
  1602. | 40| ••••••••expected•=•[•{•"date":•today()
  1603. | 41| •••••••••••••••••••••,•"npatrons":•2
  1604. | 42| •••••••••••••••••••••,•"receipts":•3.00
  1605. | 43| ••••••••••••••••••••••}
  1606. | 44| ••••••••••••••••••••]
  1607. | 45| ••••••••actual•=•json.loads(self.client.GET('/carl/charts.json').body)
  1608. | 46|
  1609. | 47| ••••••••assert•actual•==•expected
  1610. | 48|
  1611. | 49| ••••def•test_second_payday_comes_through(self):
  1612.  
  1613. tests/py/test_charts_json.py
  1614. | 61| •••••••••••••••••••,•{•"date":•today()
  1615. | 62| •••••••••••••••••••••,•"npatrons":•2
  1616. | 63| •••••••••••••••••••••,•"receipts":•3.00
  1617. | 64| ••••••••••••••••••••••}
  1618. | 65| ••••••••••••••••••••]
  1619. | 66| ••••••••actual•=•json.loads(self.client.GET('/carl/charts.json').body)
  1620. | 67|
  1621. | 68| ••••••••assert•actual•==•expected
  1622. | 69|
  1623. | 70| ••••def•test_sandwiched_tipless_payday_comes_through(self):
  1624.  
  1625. tests/py/test_charts_json.py
  1626. | 90| •••••••••••••••••••,•{•"date":•today()
  1627. | 91| •••••••••••••••••••••,•"npatrons":•2
  1628. | 92| •••••••••••••••••••••,•"receipts":•3.00
  1629. | 93| ••••••••••••••••••••••}
  1630. | 94| ••••••••••••••••••••]
  1631. | 95| ••••••••actual•=•json.loads(self.client.GET('/carl/charts.json').body)
  1632. | 96|
  1633. | 97| ••••••••assert•actual•==•expected
  1634. | 98|
  1635. | 99| ••••def•test_out_of_band_transfer_gets_included_with_prior_payday(self):
  1636.  
  1637. tests/py/test_charts_json.py
  1638. | 116| •••••••••••••••••••,•{•"date":•today()
  1639. | 117| •••••••••••••••••••••,•"npatrons":•2
  1640. | 118| •••••••••••••••••••••,•"receipts":•3.00
  1641. | 119| ••••••••••••••••••••••}
  1642. | 120| ••••••••••••••••••••]
  1643. | 121| ••••••••actual•=•json.loads(self.client.GET('/carl/charts.json').body)
  1644. | 122|
  1645. | 123| ••••••••assert•actual•==•expected
  1646. | 124|
  1647. | 125| ••••def•test_never_received_gives_empty_array(self):
  1648. | | [NORMAL] CPDBear:
  1649. | | Duplicate code found.
  1650.  
  1651. liberapay/models/participant.py
  1652. | 87| ••••••••if•kw:
  1653. | 88| ••••••••••••cols,•vals•=•zip(*kw.items())
  1654. | 89| ••••••••••••cols•=•',•'.join(cols)
  1655. | 90| ••••••••••••placeholders•=•',•'.join(['%s']*len(vals))
  1656.  
  1657. liberapay/utils/fake_data.py
  1658. | 20| def•_fake_thing(db,•tablename,•**kw):
  1659. | 21| ••••cols,•vals•=•zip(*kw.items())
  1660. | 22| ••••cols•=•',•'.join(cols)
  1661. | 23| ••••placeholders•=•',•'.join(['%s']*len(vals))
  1662. | | [NORMAL] CPDBear:
  1663. | | Duplicate code found.
  1664.  
  1665. tests/py/test_teams.py
  1666. | 82| ••••••••r•=•self.client.PxST('/about/teams',•{'name':•'Team'},•auth_as=alice)
  1667. | 83| ••••••••assert•r.code•==•302
  1668. | 84| ••••••••assert•r.headers['Location']•==•'/Team/edit'
  1669. | 85| ••••••••t•=•Participant.from_username('Team')
  1670.  
  1671. tests/py/test_teams.py
  1672. | 95| ••••••••r•=•self.client.PxST('/about/teams',•{'name':•'Team'},•auth_as=alice)
  1673. | 96| ••••••••assert•r.code•==•302
  1674. | 97| ••••••••assert•r.headers['Location']•==•'/Team/edit'
  1675. | 98| ••••••••t•=•t.refetch()
  1676. | | [NORMAL] CPDBear:
  1677. | | Duplicate code found.
  1678.  
  1679. tests/py/test_close.py
  1680. | 76| ••••••••alice•=•self.make_participant('alice',•balance=D('10.00'))
  1681. | 77| ••••••••bob•=•self.make_participant('bob')
  1682. | 78| ••••••••carl•=•self.make_participant('carl')
  1683. | 79| ••••••••alice.set_tip_to(bob,•D('3.00'))
  1684. | 80| ••••••••alice.set_tip_to(carl,•D('2.00'))
  1685.  
  1686. tests/py/test_close.py
  1687. | 138| ••••••••alice•=•self.make_participant('alice',•balance=D('0.00'))
  1688. | 139| ••••••••bob•=•self.make_participant('bob')
  1689. | 140| ••••••••carl•=•self.make_participant('carl')
  1690. | 141| ••••••••alice.set_tip_to(bob,•D('3.00'))
  1691. | 142| ••••••••alice.set_tip_to(carl,•D('6.00'))
  1692. | | [NORMAL] CPDBear:
  1693. | | Duplicate code found.
  1694.  
  1695. tests/py/test_take.py
  1696. | 50| ••••def•test_take_can_double(self):
  1697. | 51| ••••••••team•=•self.make_team()
  1698. | 52| ••••••••alice•=•self.make_participant('alice')
  1699. | 53| ••••••••self.take_last_week(team,•alice,•'40.00')
  1700. | 54| ••••••••team.set_take_for(alice,•D('80.00'),•alice)
  1701.  
  1702. tests/py/test_take.py
  1703. | 78| ••••def•test_get_members(self):
  1704. | 79| ••••••••team•=•self.make_team()
  1705. | 80| ••••••••alice•=•self.make_participant('alice')
  1706. | 81| ••••••••self.take_last_week(team,•alice,•'40.00')
  1707. | 82| ••••••••team.set_take_for(alice,•D('42.00'),•team)
  1708.  
  1709. tests/py/test_take.py
  1710. | 120| ••••def•test_changes_to_team_receiving_affect_members_take(self):
  1711. | 121| ••••••••team•=•self.make_team()
  1712. | 122| ••••••••alice•=•self.make_participant('alice')
  1713. | 123| ••••••••self.take_last_week(team,•alice,•'40.00')
  1714. | 124| ••••••••team.set_take_for(alice,•D('42.00'),•alice)
  1715. | | [NORMAL] CPDBear:
  1716. | | Duplicate code found.
  1717.  
  1718. tests/py/test_take.py
  1719. | 130| ••••def•test_changes_to_others_take_affects_members_take(self):
  1720. | 131| ••••••••team•=•self.make_team()
  1721. | 132|
  1722. | 133| ••••••••alice•=•self.make_participant('alice')
  1723. | 134| ••••••••self.take_last_week(team,•alice,•'30.00')
  1724. | 135| ••••••••team.set_take_for(alice,•D('40.00'),•alice)
  1725.  
  1726. tests/py/test_take.py
  1727. | 147| ••••def•test_changes_to_others_take_can_increase_members_take(self):
  1728. | 148| ••••••••team•=•self.make_team()
  1729. | 149|
  1730. | 150| ••••••••alice•=•self.make_participant('alice')
  1731. | 151| ••••••••self.take_last_week(team,•alice,•'30.00')
  1732. | 152| ••••••••team.set_take_for(alice,•D('25.00'),•alice)
  1733. | | [NORMAL] CPDBear:
  1734. | | Duplicate code found.
  1735.  
  1736. tests/py/test_participant.py
  1737. | 338| ••••def•test_only_latest_tip_counts(self):
  1738. | 339| ••••••••alice•=•self.make_participant('alice',•balance=100)
  1739. | 340| ••••••••bob•=•self.make_participant('bob',•balance=100)
  1740. | 341| ••••••••carl•=•self.make_participant('carl')
  1741.  
  1742. tests/py/test_public_json.py
  1743. | 90| ••••def•test_authenticated_user_gets_zero_if_they_dont_tip(self):
  1744. | 91| ••••••••alice•=•self.make_participant('alice',•balance=100)
  1745. | 92| ••••••••bob•=•self.make_participant('bob',•balance=100)
  1746. | 93| ••••••••carl•=•self.make_participant('carl')
  1747. | | [NORMAL] CPDBear:
  1748. | | Duplicate code found.
  1749.  
  1750. liberapay/models/participant.py
  1751. | 88| ••••••••••••cols,•vals•=•zip(*kw.items())
  1752. | 89| ••••••••••••cols•=•',•'.join(cols)
  1753. | 90| ••••••••••••placeholders•=•',•'.join(['%s']*len(vals))
  1754.  
  1755. liberapay/testing/__init__.py
  1756. | 188| ••••••••cols,•vals•=•zip(*kw.items())
  1757. | 189| ••••••••cols•=•',•'.join(cols)
  1758. | 190| ••••••••placeholders•=•',•'.join(['%s']*len(vals))
  1759.  
  1760. liberapay/utils/fake_data.py
  1761. | 21| ••••cols,•vals•=•zip(*kw.items())
  1762. | 22| ••••cols•=•',•'.join(cols)
  1763. | 23| ••••placeholders•=•',•'.join(['%s']*len(vals))
  1764. | | [NORMAL] CPDBear:
  1765. | | Duplicate code found.
  1766.  
  1767. tests/py/test_participant.py
  1768. | 338| ••••def•test_only_latest_tip_counts(self):
  1769. | 339| ••••••••alice•=•self.make_participant('alice',•balance=100)
  1770. | 340| ••••••••bob•=•self.make_participant('bob',•balance=100)
  1771. | 341| ••••••••carl•=•self.make_participant('carl')
  1772.  
  1773. tests/py/test_public_json.py
  1774. | 73| ••••def•test_authenticated_user_doesnt_get_other_peoples_tips(self):
  1775. | 74| ••••••••alice•=•self.make_participant('alice',•balance=100)
  1776. | 75| ••••••••bob•=•self.make_participant('bob',•balance=100)
  1777. | 76| ••••••••carl•=•self.make_participant('carl',•balance=100)
  1778.  
  1779. tests/py/test_public_json.py
  1780. | 90| ••••def•test_authenticated_user_gets_zero_if_they_dont_tip(self):
  1781. | 91| ••••••••alice•=•self.make_participant('alice',•balance=100)
  1782. | 92| ••••••••bob•=•self.make_participant('bob',•balance=100)
  1783. | 93| ••••••••carl•=•self.make_participant('carl')
  1784. | | [NORMAL] CPDBear:
  1785. | | Duplicate code found.
  1786.  
  1787. tests/py/test_close.py
  1788. | 78| ••••••••carl•=•self.make_participant('carl')
  1789. | 79| ••••••••alice.set_tip_to(bob,•D('3.00'))
  1790. | 80| ••••••••alice.set_tip_to(carl,•D('2.00'))
  1791. | 81| ••••••••with•self.db.get_cursor()•as•cursor:
  1792.  
  1793. tests/py/test_close.py
  1794. | 90| ••••••••carl•=•self.make_stub()
  1795. | 91| ••••••••alice.set_tip_to(bob,•D('3.00'))
  1796. | 92| ••••••••alice.set_tip_to(carl,•D('2.00'))
  1797. | 93| ••••••••with•self.db.get_cursor()•as•cursor:
  1798. | | [NORMAL] CPDBear:
  1799. | | Duplicate code found.
  1800.  
  1801. tests/py/test_communities.py
  1802. | 77| ••••••••response•=•self.client.POST('/for/test/subscribe',•auth_as=self.bob,
  1803. | 78| ••••••••••••••••••••••••••••••••••••xhr=True)
  1804. | 79|
  1805. | 80| ••••••••r•=•json.loads(response.body)
  1806. | 81| ••••••••assert•r•==•{}
  1807. | 82|
  1808. | 83| ••••••••response•=•self.client.POST('/for/test/unsubscribe',•auth_as=self.bob,
  1809.  
  1810. tests/py/test_communities.py
  1811. | 94| ••••••••response•=•self.client.POST('/for/test/join',•auth_as=self.bob,
  1812. | 95| ••••••••••••••••••••••••••••••••••••xhr=True)
  1813. | 96|
  1814. | 97| ••••••••r•=•json.loads(response.body)
  1815. | 98| ••••••••assert•r•==•{}
  1816. | 99|
  1817. | 100| ••••••••response•=•self.client.POST('/for/test/leave',•auth_as=self.bob,
  1818. | | [NORMAL] CPDBear:
  1819. | | Duplicate code found.
  1820.  
  1821. tests/py/test_charts_json.py
  1822. | 53| ••••••••self.bob.set_tip_to(self.carl,•'0.00')
  1823. | 54|
  1824. | 55| ••••••••self.run_payday()•••#•second
  1825. | 56|
  1826. | 57| ••••••••expected•=•[•{•"date":•today()
  1827. | 58| •••••••••••••••••••••,•"npatrons":•1•#•most•recent•first
  1828. | 59| •••••••••••••••••••••,•"receipts":•5.00
  1829. | 60| ••••••••••••••••••••••}
  1830. | 61| •••••••••••••••••••,•{•"date":•today()
  1831. | 62| •••••••••••••••••••••,•"npatrons":•2
  1832.  
  1833. tests/py/test_charts_json.py
  1834. | 79| ••••••••self.alice.set_tip_to(self.carl,•'5.00')
  1835. | 80| ••••••••self.run_payday()•••#•third
  1836. | 81|
  1837. | 82| ••••••••expected•=•[•{•"date":•today()
  1838. | 83| •••••••••••••••••••••,•"npatrons":•1•#•most•recent•first
  1839. | 84| •••••••••••••••••••••,•"receipts":•5.00
  1840. | 85| ••••••••••••••••••••••}
  1841. | 86| •••••••••••••••••••,•{•"date":•today()
  1842. | 87| •••••••••••••••••••••,•"npatrons":•0
  1843. | 88| •••••••••••••••••••••,•"receipts":•0.00
  1844. | | [NORMAL] CPDBear:
  1845. | | Duplicate code found.
  1846.  
  1847. tests/py/test_tips_json.py
  1848. | 40| ••••••••response•=•self.client.GET('/test_tipper/tips.json',•auth_as=test_tipper)
  1849. | 41| ••••••••assert•response.code•==•200
  1850. | 42| ••••••••assert•len(json.loads(response.body))•==•tippees
  1851.  
  1852. tests/py/test_tips_json.py
  1853. | 47| ••••••••response•=•self.client.GET('/test_tipper/tips.json',•auth_as=test_tipper)
  1854. | 48|
  1855. | 49| ••••••••assert•response.code•==•200
  1856. | | [NORMAL] CPDBear:
  1857. | | Duplicate code found.
  1858.  
  1859. liberapay/elsewhere/facebook.py
  1860. | 1| from•__future__•import•absolute_import,•division,•print_function,•unicode_literals
  1861. | 2|
  1862. | 3| from•liberapay.elsewhere._base•import•PlatformOAuth2
  1863. | 4| from•liberapay.elsewhere._extractors•import•key
  1864. | 5| from•liberapay.elsewhere._paginators•import•keys_paginator
  1865.  
  1866. liberapay/elsewhere/gitlab.py
  1867. | 1| from•__future__•import•absolute_import,•division,•print_function,•unicode_literals
  1868. | 2|
  1869. | 3| from•liberapay.elsewhere._base•import•PlatformOAuth2
  1870. | 4| from•liberapay.elsewhere._extractors•import•key
  1871. | 5| from•liberapay.elsewhere._paginators•import•header_links_paginator
  1872. | | [NORMAL] CPDBear:
  1873. | | Duplicate code found.
  1874.  
  1875. tests/py/test_billing_payday.py
  1876. | 163| ••••••••••••('Payday•started•at•{}.'.format(ts_start)),
  1877. | 164| ••••••••••••('Prepared•the•DB.'),
  1878. | 165| ••••••••]
  1879. | 166| ••••••••expected_logging_call_args.reverse()
  1880. | 167| ••••••••for•args,•_•in•log.call_args_list:
  1881. | 168| ••••••••••••assert•args[0]•==•expected_logging_call_args.pop()
  1882.  
  1883. tests/py/test_billing_payday.py
  1884. | 189| ••••••••••••('Payday•started•at•{}.'.format(second_ts_start)),
  1885. | 190| ••••••••••••('Prepared•the•DB.'),
  1886. | 191| ••••••••]
  1887. | 192| ••••••••expected_logging_call_args.reverse()
  1888. | 193| ••••••••for•args,•_•in•log.call_args_list:
  1889. | 194| ••••••••••••assert•args[0]•==•expected_logging_call_args.pop()
  1890. | | [NORMAL] CPDBear:
  1891. | | Duplicate code found.
  1892.  
  1893. tests/py/test_billing_payday.py
  1894. | 315| ••••••••self.clear_tables()
  1895. | 316| ••••••••team•=•self.make_participant('team',•kind='group')
  1896. | 317| ••••••••alice•=•self.make_participant('alice')
  1897. | 318| ••••••••team.set_take_for(alice,•D('1.00'),•alice)
  1898.  
  1899. tests/py/test_billing_payday.py
  1900. | 341| ••••••••self.clear_tables()
  1901. | 342| ••••••••team•=•self.make_participant('team',•kind='group')
  1902. | 343| ••••••••alice•=•self.make_participant('alice')
  1903. | 344| ••••••••team.set_take_for(alice,•D('0.79'),•alice)
  1904. | | [NORMAL] CPDBear:
  1905. | | Duplicate code found.
  1906.  
  1907. tests/py/test_billing_payday.py
  1908. | 372| ••••••••team.set_take_for(bob,•D('0.75'),•bob)
  1909. | 373|
  1910. | 374| ••••••••Payday.start().run()
  1911. | 375|
  1912. | 376| ••••••••d•=•dict(self.db.all("SELECT•username,•balance•FROM•participants"))
  1913. | 377| ••••••••expected•=•{
  1914. | 378| ••••••••••••'alice':•D('7.75'),••#•8•-•0.50•+•0.25
  1915.  
  1916. tests/py/test_billing_payday.py
  1917. | 390| ••••••••team.set_take_for(bob,•D('1.00'),•bob)
  1918. | 391|
  1919. | 392| ••••••••Payday.start().run()
  1920. | 393|
  1921. | 394| ••••••••d•=•dict(self.db.all("SELECT•username,•balance•FROM•participants"))
  1922. | 395| ••••••••expected•=•{
  1923. | 396| ••••••••••••'alice':•D('0.00'),
  1924. | | [NORMAL] CPDBear:
  1925. | | Duplicate code found.
  1926.  
  1927. tests/py/test_elsewhere.py
  1928. | 45| ••••••••cookie•=•b64encode_s(json.dumps(['query_data',•'connect',•b64encode_s(then),•'2']))
  1929. | 46| ••••••••response•=•self.client.GxT('/on/github/associate?state=deadbeef',
  1930. | 47| •••••••••••••••••••••••••••••••••••auth_as=alice,
  1931. | 48| •••••••••••••••••••••••••••••••••••cookies={b'github_deadbeef':•cookie})
  1932. | 49| ••••••••assert•response.code•==•302,•response.text
  1933.  
  1934. tests/py/test_elsewhere.py
  1935. | 63| ••••••••cookie•=•b64encode_s(json.dumps(['query_data',•'connect',•'',•'2']))
  1936. | 64| ••••••••response•=•self.client.GxT('/on/github/associate?state=deadbeef',
  1937. | 65| •••••••••••••••••••••••••••••••••••auth_as=alice,
  1938. | 66| •••••••••••••••••••••••••••••••••••cookies={b'github_deadbeef':•cookie})
  1939. | 67| ••••••••assert•response.code•==•302
  1940. | | [NORMAL] CPDBear:
  1941. | | Duplicate code found.
  1942.  
  1943. tests/py/test_participant.py
  1944. | 289| ••••def•test_stt_returns_False_for_second_time_tipper(self):
  1945. | 290| ••••••••alice•=•self.make_participant('alice',•balance=100)
  1946. | 291| ••••••••bob•=•self.make_participant('bob')
  1947. | 292| ••••••••alice.set_tip_to(bob,•'1.00')
  1948.  
  1949. tests/py/test_public_json.py
  1950. | 10| ••••def•test_anonymous(self):
  1951. | 11| ••••••••alice•=•self.make_participant('alice',•balance=100)
  1952. | 12| ••••••••bob•=•self.make_participant('bob')
  1953. | 13|
  1954.  
  1955. tests/py/test_public_json.py
  1956. | 60| ••••def•test_authenticated_user_gets_their_tip(self):
  1957. | 61| ••••••••alice•=•self.make_participant('alice',•balance=100)
  1958. | 62| ••••••••bob•=•self.make_participant('bob')
  1959. | 63|
  1960. | | [NORMAL] CPDBear:
  1961. | | Duplicate code found.
  1962.  
  1963. tests/py/test_participant.py
  1964. | 357| ••••def•test_receiving_is_zero_for_patrons(self):
  1965. | 358| ••••••••alice•=•self.make_participant('alice',•balance=100)
  1966. | 359| ••••••••bob•=•self.make_participant('bob')
  1967. | 360| ••••••••alice.set_tip_to(bob,•'3.00')
  1968.  
  1969. tests/py/test_public_json.py
  1970. | 104| ••••def•test_authenticated_user_gets_self_for_self(self):
  1971. | 105| ••••••••alice•=•self.make_participant('alice',•balance=100)
  1972. | 106| ••••••••bob•=•self.make_participant('bob')
  1973. | 107|
  1974.  
  1975. tests/py/test_public_json.py
  1976. | 123| ••••def•test_jsonp_works(self):
  1977. | 124| ••••••••alice•=•self.make_participant('alice',•balance=100)
  1978. | 125| ••••••••bob•=•self.make_participant('bob')
  1979. | 126|
  1980. | | [NORMAL] CPDBear:
  1981. | | Duplicate code found.
  1982.  
  1983. tests/py/test_search.py
  1984. | 16| ••••••••response•=•self.client.GET('/search.json?q=alice&scope=usernames')
  1985. | 17| ••••••••data•=•json.loads(response.body)['usernames']
  1986. | 18| ••••••••assert•len(data)•==•1
  1987. | 19| ••••••••assert•data[0]['username']•==•'alice'
  1988. | 20|
  1989. | 21| ••••def•test_get_stub_user(self):
  1990.  
  1991. tests/py/test_search.py
  1992. | 29| ••••••••response•=•self.client.GET('/search.json?q=alicia&scope=usernames')
  1993. | 30| ••••••••data•=•json.loads(response.body)['usernames']
  1994. | 31| ••••••••assert•len(data)•==•1
  1995. | 32| ••••••••assert•data[0]['username']•==•'alice'
  1996. | 33|
  1997. | 34| ••••def•test_hide_from_search(self):
  1998. | | [NORMAL] CPDBear:
  1999. | | Duplicate code found.
  2000.  
  2001. tests/py/test_close.py
  2002. | 155| ••••••••alice.set_tip_to(self.make_participant('bob'),•D('1.00'))
  2003. | 156| ••••••••ntips•=•lambda:•self.db.one("SELECT•count(*)•FROM•current_tips•"
  2004. | 157| ••••••••••••••••••••••••••••••••••••"WHERE•tipper=%s•AND•amount•>•0",
  2005. | 158| ••••••••••••••••••••••••••••••••••••(alice.id,))
  2006. | 159| ••••••••assert•ntips()•==•1
  2007.  
  2008. tests/py/test_close.py
  2009. | 189| ••••••••alice.set_tip_to(self.make_participant('francis'),•D('1.00'))
  2010. | 190| ••••••••ntips•=•lambda:•self.db.one("SELECT•count(*)•FROM•current_tips•"
  2011. | 191| ••••••••••••••••••••••••••••••••••••"WHERE•tipper=%s•AND•amount•>•0",
  2012. | 192| ••••••••••••••••••••••••••••••••••••(alice.id,))
  2013. | 193| ••••••••assert•ntips()•==•5
  2014. | | [NORMAL] CPDBear:
  2015. | | Duplicate code found.
  2016.  
  2017. tests/py/test_close.py
  2018. | 75| ••••def•test_dbafg_distributes_balance_as_final_gift(self):
  2019. | 76| ••••••••alice•=•self.make_participant('alice',•balance=D('10.00'))
  2020. | 77| ••••••••bob•=•self.make_participant('bob')
  2021. | 78| ••••••••carl•=•self.make_participant('carl')
  2022.  
  2023. tests/py/test_close.py
  2024. | 100| ••••def•test_dbafg_gives_all_to_claimed(self):
  2025. | 101| ••••••••alice•=•self.make_participant('alice',•balance=D('10.00'))
  2026. | 102| ••••••••bob•=•self.make_participant('bob')
  2027. | 103| ••••••••carl•=•self.make_stub()
  2028.  
  2029. tests/py/test_close.py
  2030. | 112| ••••def•test_dbafg_skips_zero_tips(self):
  2031. | 113| ••••••••alice•=•self.make_participant('alice',•balance=D('10.00'))
  2032. | 114| ••••••••bob•=•self.make_participant('bob')
  2033. | 115| ••••••••carl•=•self.make_participant('carl')
  2034.  
  2035. tests/py/test_close.py
  2036. | 125| ••••def•test_dbafg_favors_highest_tippee_in_rounding_errors(self):
  2037. | 126| ••••••••alice•=•self.make_participant('alice',•balance=D('10.00'))
  2038. | 127| ••••••••bob•=•self.make_participant('bob')
  2039. | 128| ••••••••carl•=•self.make_participant('carl')
  2040. | | [NORMAL] CPDBear:
  2041. | | Duplicate code found.
  2042.  
  2043. tests/py/test_close.py
  2044. | 79| ••••••••alice.set_tip_to(bob,•D('3.00'))
  2045. | 80| ••••••••alice.set_tip_to(carl,•D('2.00'))
  2046. | 81| ••••••••with•self.db.get_cursor()•as•cursor:
  2047. | 82| ••••••••••••alice.distribute_balance_as_final_gift(cursor)
  2048. | 83| ••••••••assert•Participant.from_username('bob').balance•==•D('6.00')
  2049.  
  2050. tests/py/test_close.py
  2051. | 104| ••••••••alice.set_tip_to(bob,•D('3.00'))
  2052. | 105| ••••••••alice.set_tip_to(carl,•D('2.00'))
  2053. | 106| ••••••••with•self.db.get_cursor()•as•cursor:
  2054. | 107| ••••••••••••alice.distribute_balance_as_final_gift(cursor)
  2055. | 108| ••••••••assert•Participant.from_id(bob.id).balance•==•D('10.00')
  2056.  
  2057. tests/py/test_close.py
  2058. | 116| ••••••••alice.set_tip_to(bob,•D('0.00'))
  2059. | 117| ••••••••alice.set_tip_to(carl,•D('2.00'))
  2060. | 118| ••••••••with•self.db.get_cursor()•as•cursor:
  2061. | 119| ••••••••••••alice.distribute_balance_as_final_gift(cursor)
  2062. | 120| ••••••••assert•self.db.one("SELECT•count(*)•FROM•tips•WHERE•tippee=%s",•(bob.id,))•==•1
  2063. | | [NORMAL] CPDBear:
  2064. | | Duplicate code found.
  2065.  
  2066. tests/py/test_close.py
  2067. | 80| ••••••••alice.set_tip_to(carl,•D('2.00'))
  2068. | 81| ••••••••with•self.db.get_cursor()•as•cursor:
  2069. | 82| ••••••••••••alice.distribute_balance_as_final_gift(cursor)
  2070. | 83| ••••••••assert•Participant.from_username('bob').balance•==•D('6.00')
  2071.  
  2072. tests/py/test_close.py
  2073. | 130| ••••••••alice.set_tip_to(carl,•D('6.00'))
  2074. | 131| ••••••••with•self.db.get_cursor()•as•cursor:
  2075. | 132| ••••••••••••alice.distribute_balance_as_final_gift(cursor)
  2076. | 133| ••••••••assert•Participant.from_username('bob').balance•==•D('3.33')
  2077. | | [NORMAL] CPDBear:
  2078. | | Duplicate code found.
  2079.  
  2080. tests/py/test_close.py
  2081. | 96| ••••••••assert•Participant.from_id(bob.id).balance•==•D('0.00')
  2082. | 97| ••••••••assert•Participant.from_id(carl.id).balance•==•D('0.00')
  2083. | 98| ••••••••assert•Participant.from_id(alice.id).balance•==•D('10.00')
  2084.  
  2085. tests/py/test_close.py
  2086. | 108| ••••••••assert•Participant.from_id(bob.id).balance•==•D('10.00')
  2087. | 109| ••••••••assert•Participant.from_id(carl.id).balance•==•D('0.00')
  2088. | 110| ••••••••assert•Participant.from_id(alice.id).balance•==•D('0.00')
  2089. | | [NORMAL] CPDBear:
  2090. | | Duplicate code found.
  2091.  
  2092. tests/py/test_billing_payday.py
  2093. | 322| ••••••••charlie.set_tip_to(team,•D('0.26'))
  2094. | 323|
  2095. | 324| ••••••••Payday.start().run()
  2096. | 325|
  2097. | 326| ••••••••d•=•dict(self.db.all("SELECT•username,•balance•FROM•participants"))
  2098. | 327| ••••••••expected•=•{
  2099. | 328| ••••••••••••'alice':•D('0.13'),
  2100.  
  2101. tests/py/test_billing_payday.py
  2102. | 350| ••••••••dan.set_tip_to(team,•D('5.00'))
  2103. | 351|
  2104. | 352| ••••••••Payday.start().run()
  2105. | 353|
  2106. | 354| ••••••••d•=•dict(self.db.all("SELECT•username,•balance•FROM•participants"))
  2107. | 355| ••••••••expected•=•{
  2108. | 356| ••••••••••••'alice':•D('0.79'),
  2109. | | [NORMAL] CPDBear:
  2110. | | Duplicate code found.
  2111.  
  2112. liberapay/elsewhere/_base.py
  2113. | 212| ••••••••••••page_url•=•self.api_team_members_path.format(
  2114. | 213| ••••••••••••••••user_id=quote(account.user_id),
  2115. | 214| ••••••••••••••••user_name=quote(account.user_name•or•''),
  2116. | 215| ••••••••••••)
  2117. | 216| ••••••••r•=•self.api_get(page_url)
  2118.  
  2119. liberapay/elsewhere/_base.py
  2120. | 248| ••••••••••••page_url•=•self.api_friends_path.format(
  2121. | 249| ••••••••••••••••user_id=quote(account.user_id),
  2122. | 250| ••••••••••••••••user_name=quote(account.user_name•or•''),
  2123. | 251| ••••••••••••)
  2124. | 252| ••••••••r•=•self.api_get(page_url,•sess=sess)
  2125. | | [NORMAL] CPDBear:
  2126. | | Duplicate code found.
  2127.  
  2128. tests/py/test_participant.py
  2129. | 289| ••••def•test_stt_returns_False_for_second_time_tipper(self):
  2130. | 290| ••••••••alice•=•self.make_participant('alice',•balance=100)
  2131. | 291| ••••••••bob•=•self.make_participant('bob')
  2132. | 292| ••••••••alice.set_tip_to(bob,•'1.00')
  2133.  
  2134. tests/py/test_participant.py
  2135. | 357| ••••def•test_receiving_is_zero_for_patrons(self):
  2136. | 358| ••••••••alice•=•self.make_participant('alice',•balance=100)
  2137. | 359| ••••••••bob•=•self.make_participant('bob')
  2138. | 360| ••••••••alice.set_tip_to(bob,•'3.00')
  2139.  
  2140. tests/py/test_public_json.py
  2141. | 10| ••••def•test_anonymous(self):
  2142. | 11| ••••••••alice•=•self.make_participant('alice',•balance=100)
  2143. | 12| ••••••••bob•=•self.make_participant('bob')
  2144. | 13|
  2145.  
  2146. tests/py/test_public_json.py
  2147. | 60| ••••def•test_authenticated_user_gets_their_tip(self):
  2148. | 61| ••••••••alice•=•self.make_participant('alice',•balance=100)
  2149. | 62| ••••••••bob•=•self.make_participant('bob')
  2150. | 63|
  2151.  
  2152. tests/py/test_public_json.py
  2153. | 104| ••••def•test_authenticated_user_gets_self_for_self(self):
  2154. | 105| ••••••••alice•=•self.make_participant('alice',•balance=100)
  2155. | 106| ••••••••bob•=•self.make_participant('bob')
  2156. | 107|
  2157.  
  2158. tests/py/test_public_json.py
  2159. | 123| ••••def•test_jsonp_works(self):
  2160. | 124| ••••••••alice•=•self.make_participant('alice',•balance=100)
  2161. | 125| ••••••••bob•=•self.make_participant('bob')
  2162. | 126|
  2163. | | [NORMAL] CPDBear:
  2164. | | Duplicate code found.
  2165.  
  2166. tests/py/test_communities.py
  2167. | 54| ••••••••response•=•self.client.GET('/alice/communities.json',•auth_as=self.alice)
  2168. | 55|
  2169. | 56| ••••••••assert•len(json.loads(response.body))•==•0
  2170.  
  2171. tests/py/test_communities.py
  2172. | 59| ••••••••response•=•self.client.GET('/alice/communities.json',•auth_as=self.alice)
  2173. | 60| ••••••••assert•len(json.loads(response.body))•==•0
  2174. | 61|
  2175. | | [NORMAL] CPDBear:
  2176. | | Duplicate code found.
  2177.  
  2178. tests/py/test_billing_payday.py
  2179. | 322| ••••••••charlie.set_tip_to(team,•D('0.26'))
  2180. | 323|
  2181. | 324| ••••••••Payday.start().run()
  2182. | 325|
  2183. | 326| ••••••••d•=•dict(self.db.all("SELECT•username,•balance•FROM•participants"))
  2184. | 327| ••••••••expected•=•{
  2185. | 328| ••••••••••••'alice':•D('0.13'),
  2186.  
  2187. tests/py/test_billing_payday.py
  2188. | 350| ••••••••dan.set_tip_to(team,•D('5.00'))
  2189. | 351|
  2190. | 352| ••••••••Payday.start().run()
  2191. | 353|
  2192. | 354| ••••••••d•=•dict(self.db.all("SELECT•username,•balance•FROM•participants"))
  2193. | 355| ••••••••expected•=•{
  2194. | 356| ••••••••••••'alice':•D('0.79'),
  2195.  
  2196. tests/py/test_billing_payday.py
  2197. | 372| ••••••••team.set_take_for(bob,•D('0.75'),•bob)
  2198. | 373|
  2199. | 374| ••••••••Payday.start().run()
  2200. | 375|
  2201. | 376| ••••••••d•=•dict(self.db.all("SELECT•username,•balance•FROM•participants"))
  2202. | 377| ••••••••expected•=•{
  2203. | 378| ••••••••••••'alice':•D('7.75'),••#•8•-•0.50•+•0.25
  2204.  
  2205. tests/py/test_billing_payday.py
  2206. | 390| ••••••••team.set_take_for(bob,•D('1.00'),•bob)
  2207. | 391|
  2208. | 392| ••••••••Payday.start().run()
  2209. | 393|
  2210. | 394| ••••••••d•=•dict(self.db.all("SELECT•username,•balance•FROM•participants"))
  2211. | 395| ••••••••expected•=•{
  2212. | 396| ••••••••••••'alice':•D('0.00'),
  2213. | | [NORMAL] CPDBear:
  2214. | | Duplicate code found.
  2215.  
  2216. tests/py/test_take.py
  2217. | 38| ••••def•test_team_member_is_team_member(self):
  2218. | 39| ••••••••team•=•self.make_team()
  2219. | 40| ••••••••alice•=•self.make_participant('alice')
  2220. | 41| ••••••••self.take_last_week(team,•alice,•'40.00')
  2221. | 42| ••••••••assert•alice.member_of(team)
  2222.  
  2223. tests/py/test_take.py
  2224. | 44| ••••def•test_cant_grow_tip_a_lot(self):
  2225. | 45| ••••••••team•=•self.make_team()
  2226. | 46| ••••••••alice•=•self.make_participant('alice')
  2227. | 47| ••••••••self.take_last_week(team,•alice,•'40.00')
  2228. | 48| ••••••••assert•team.set_take_for(alice,•D('100.00'),•alice)•==•80
  2229. | | [NORMAL] CPDBear:
  2230. | | Duplicate code found.
  2231.  
  2232. tests/py/test_take.py
  2233. | 135| ••••••••team.set_take_for(alice,•D('40.00'),•alice)
  2234. | 136|
  2235. | 137| ••••••••bob•=•self.make_participant('bob')
  2236. | 138| ••••••••self.take_last_week(team,•bob,•'50.00')
  2237. | 139| ••••••••team.set_take_for(bob,•D('60.00'),•bob)
  2238.  
  2239. tests/py/test_take.py
  2240. | 152| ••••••••team.set_take_for(alice,•D('25.00'),•alice)
  2241. | 153|
  2242. | 154| ••••••••bob•=•self.make_participant('bob')
  2243. | 155| ••••••••self.take_last_week(team,•bob,•'50.00')
  2244. | 156| ••••••••team.set_take_for(bob,•D('100.00'),•bob)
  2245. | | [NORMAL] CPDBear:
  2246. | | Duplicate code found.
  2247.  
  2248. tests/py/test_email.py
  2249. | 225| ••••••••Participant.dequeue_emails()
  2250. | 226| ••••••••assert•self.mailer.call_count•==•1
  2251. | 227| ••••••••last_email•=•self.get_last_email()
  2252. | 228| ••••••••assert•last_email['to'][0]•==•'larry•<larry@example.com>'
  2253.  
  2254. tests/py/test_email_notifs.py
  2255. | 21| ••••••••Participant.dequeue_emails()
  2256. | 22| ••••••••assert•self.mailer.call_count•==•1
  2257. | 23| ••••••••last_email•=•self.get_last_email()
  2258. | 24| ••••••••assert•last_email['to'][0]•==•'bob•<bob@example.com>'
  2259. | | [NORMAL] CPDBear:
  2260. | | Duplicate code found.
  2261.  
  2262. tests/py/test_close.py
  2263. | 20| ••••••••alice•=•self.make_participant('alice',•balance=D('10.00'))
  2264. | 21| ••••••••bob•=•self.make_participant('bob')
  2265. | 22| ••••••••carl•=•self.make_participant('carl')
  2266. | 23|
  2267. | 24| ••••••••alice.set_tip_to(bob,•D('3.00'))
  2268.  
  2269. tests/py/test_close.py
  2270. | 138| ••••••••alice•=•self.make_participant('alice',•balance=D('0.00'))
  2271. | 139| ••••••••bob•=•self.make_participant('bob')
  2272. | 140| ••••••••carl•=•self.make_participant('carl')
  2273. | 141| ••••••••alice.set_tip_to(bob,•D('3.00'))
  2274. | 142| ••••••••alice.set_tip_to(carl,•D('6.00'))
  2275. | | [NORMAL] CPDBear:
  2276. | | Duplicate code found.
  2277.  
  2278. tests/py/test_public_json.py
  2279. | 11| ••••••••alice•=•self.make_participant('alice',•balance=100)
  2280. | 12| ••••••••bob•=•self.make_participant('bob')
  2281. | 13|
  2282. | 14| ••••••••alice.set_tip_to(bob,•'1.00')
  2283. | 15|
  2284. | 16| ••••••••data•=•json.loads(self.client.GET('/bob/public.json').body)
  2285.  
  2286. tests/py/test_public_json.py
  2287. | 27| •••••••••••••••••••••••••••••••••••••)
  2288. | 28| ••••••••bob•=•self.make_participant('bob')
  2289. | 29| ••••••••alice.set_tip_to(bob,•'1.00')
  2290. | 30| ••••••••data•=•json.loads(self.client.GET('/alice/public.json').body)
  2291. | 31|
  2292. | 32| ••••••••assert•data['giving']•==•None
  2293.  
  2294. tests/py/test_public_json.py
  2295. | 38| •••••••••••••••••••••••••••••••••••••)
  2296. | 39| ••••••••bob•=•self.make_participant('bob')
  2297. | 40| ••••••••alice.set_tip_to(bob,•'1.00')
  2298. | 41| ••••••••data•=•json.loads(self.client.GET('/alice/public.json').body)
  2299. | 42|
  2300. | 43| ••••••••assert•data['receiving']•==•None
  2301. | | [NORMAL] CPDBear:
  2302. | | Duplicate code found.
  2303.  
  2304. tests/py/test_billing_payday.py
  2305. | 209| ••••••••""")
  2306. | 210| ••••••••payday•=•Payday.start()
  2307. | 211| ••••••••with•self.db.get_cursor()•as•cursor:
  2308. | 212| ••••••••••••payday.prepare(cursor,•payday.ts_start)
  2309.  
  2310. tests/py/test_billing_payday.py
  2311. | 230| ••••••••self.db.run("UPDATE•participants•SET•goal•=•-1•WHERE•username='homer'")
  2312. | 231| ••••••••payday•=•Payday.start()
  2313. | 232| ••••••••with•self.db.get_cursor()•as•cursor:
  2314. | 233| ••••••••••••payday.prepare(cursor,•payday.ts_start)
  2315.  
  2316. tests/py/test_billing_payday.py
  2317. | 252| ••••••••self.david.set_tip_to(self.homer,•D('0.50'))
  2318. | 253| ••••••••payday•=•Payday.start()
  2319. | 254| ••••••••with•self.db.get_cursor()•as•cursor:
  2320. | 255| ••••••••••••payday.prepare(cursor,•payday.ts_start)
  2321.  
  2322. tests/py/test_billing_payday.py
  2323. | 269| ••••••••self.david.set_tip_to(self.homer,•D('20'))••#•Should•be•unfunded
  2324. | 270|
  2325. | 271| ••••••••payday•=•Payday.start()
  2326. | 272| ••••••••with•self.db.get_cursor()•as•cursor:
  2327. | | [NORMAL] CPDBear:
  2328. | | Duplicate code found.
  2329.  
  2330. tests/py/test_billing_payday.py
  2331. | 314| ••••def•test_underfunded_team(self):
  2332. | 315| ••••••••self.clear_tables()
  2333. | 316| ••••••••team•=•self.make_participant('team',•kind='group')
  2334. | 317| ••••••••alice•=•self.make_participant('alice')
  2335.  
  2336. tests/py/test_billing_payday.py
  2337. | 384| ••••def•test_unfunded_tip_to_team_doesnt_cause_NegativeBalance(self):
  2338. | 385| ••••••••self.clear_tables()
  2339. | 386| ••••••••team•=•self.make_participant('team',•kind='group')
  2340. | 387| ••••••••alice•=•self.make_participant('alice')
  2341. | | [NORMAL] CPDBear:
  2342. | | Duplicate code found.
  2343.  
  2344. tests/py/test_take.py
  2345. | 38| ••••def•test_team_member_is_team_member(self):
  2346. | 39| ••••••••team•=•self.make_team()
  2347. | 40| ••••••••alice•=•self.make_participant('alice')
  2348. | 41| ••••••••self.take_last_week(team,•alice,•'40.00')
  2349.  
  2350. tests/py/test_take.py
  2351. | 44| ••••def•test_cant_grow_tip_a_lot(self):
  2352. | 45| ••••••••team•=•self.make_team()
  2353. | 46| ••••••••alice•=•self.make_participant('alice')
  2354. | 47| ••••••••self.take_last_week(team,•alice,•'40.00')
  2355.  
  2356. tests/py/test_take.py
  2357. | 50| ••••def•test_take_can_double(self):
  2358. | 51| ••••••••team•=•self.make_team()
  2359. | 52| ••••••••alice•=•self.make_participant('alice')
  2360. | 53| ••••••••self.take_last_week(team,•alice,•'40.00')
  2361.  
  2362. tests/py/test_take.py
  2363. | 57| ••••def•test_take_can_double_but_not_a_penny_more(self):
  2364. | 58| ••••••••team•=•self.make_team()
  2365. | 59| ••••••••alice•=•self.make_participant('alice')
  2366. | 60| ••••••••self.take_last_week(team,•alice,•'40.00')
  2367.  
  2368. tests/py/test_take.py
  2369. | 78| ••••def•test_get_members(self):
  2370. | 79| ••••••••team•=•self.make_team()
  2371. | 80| ••••••••alice•=•self.make_participant('alice')
  2372. | 81| ••••••••self.take_last_week(team,•alice,•'40.00')
  2373.  
  2374. tests/py/test_take.py
  2375. | 89| ••••def•test_taking_and_receiving_are_updated_correctly(self):
  2376. | 90| ••••••••team•=•self.make_team()
  2377. | 91| ••••••••alice•=•self.make_participant('alice')
  2378. | 92| ••••••••self.take_last_week(team,•alice,•'40.00')
  2379.  
  2380. tests/py/test_take.py
  2381. | 120| ••••def•test_changes_to_team_receiving_affect_members_take(self):
  2382. | 121| ••••••••team•=•self.make_team()
  2383. | 122| ••••••••alice•=•self.make_participant('alice')
  2384. | 123| ••••••••self.take_last_week(team,•alice,•'40.00')
  2385. | | [NORMAL] CPDBear:
  2386. | | Duplicate code found.
  2387.  
  2388. tests/py/test_billing_payday.py
  2389. | 39| ••••••••alice•=•self.make_participant('alice',•balance=100)
  2390. | 40| ••••••••bob•=•self.make_participant('bob')
  2391. | 41| ••••••••carl•=•self.make_participant('carl',•balance=1.56)
  2392.  
  2393. tests/py/test_participant.py
  2394. | 316| ••••••••alice•=•self.make_participant('alice',•balance=100)
  2395. | 317| ••••••••bob•=•self.make_participant('bob')
  2396. | 318| ••••••••carl•=•self.make_participant('carl',•last_bill_result="Fail!")
  2397. | | [NORMAL] CPDBear:
  2398. | | Duplicate code found.
  2399.  
  2400. tests/py/test_search.py
  2401. | 10| ••••••••response•=•self.client.GET('/search.json?q=alice&scope=usernames')
  2402. | 11| ••••••••data•=•json.loads(response.body)['usernames']
  2403. | 12| ••••••••assert•data•==•[]
  2404.  
  2405. tests/py/test_search.py
  2406. | 36| ••••••••response•=•self.client.GET('/search.json?q=alice&scope=usernames')
  2407. | 37| ••••••••data•=•json.loads(response.body)['usernames']
  2408. | 38| ••••••••assert•data•==•[]
  2409. | | [NORMAL] CPDBear:
  2410. | | Duplicate code found.
  2411.  
  2412. liberapay/models/account_elsewhere.py
  2413. | 116| ••••••••cols,•vals•=•zip(*i.__dict__.items())
  2414. | 117| ••••••••cols•=•',•'.join(cols)
  2415. | 118| ••••••••placeholders•=•',•'.join(['%s']*len(vals))
  2416.  
  2417. liberapay/models/participant.py
  2418. | 88| ••••••••••••cols,•vals•=•zip(*kw.items())
  2419. | 89| ••••••••••••cols•=•',•'.join(cols)
  2420. | 90| ••••••••••••placeholders•=•',•'.join(['%s']*len(vals))
  2421.  
  2422. liberapay/models/participant.py
  2423. | 112| ••••••••cols,•vals•=•zip(*d.items())
  2424. | 113| ••••••••cols•=•',•'.join(cols)
  2425. | 114| ••••••••placeholders•=•',•'.join(['%s']*len(vals))
  2426.  
  2427. liberapay/testing/__init__.py
  2428. | 188| ••••••••cols,•vals•=•zip(*kw.items())
  2429. | 189| ••••••••cols•=•',•'.join(cols)
  2430. | 190| ••••••••placeholders•=•',•'.join(['%s']*len(vals))
  2431.  
  2432. liberapay/utils/fake_data.py
  2433. | 21| ••••cols,•vals•=•zip(*kw.items())
  2434. | 22| ••••cols•=•',•'.join(cols)
  2435. | 23| ••••placeholders•=•',•'.join(['%s']*len(vals))
  2436. | | [NORMAL] CPDBear:
  2437. | | Duplicate code found.
  2438.  
  2439. tests/py/test_teams.py
  2440. | 44| ••••••••r•=•self.client.PxST('/A-Team/membership/accept',•auth_as=self.bob)
  2441. | 45| ••••••••assert•r.code•==•302
  2442. | 46| ••••••••is_member•=•self.bob.member_of(self.a_team)
  2443. | 47| ••••••••assert•is_member•is•True
  2444.  
  2445. tests/py/test_teams.py
  2446. | 61| ••••••••r•=•self.client.PxST('/A-Team/membership/refuse',•auth_as=self.bob)
  2447. | 62| ••••••••assert•r.code•==•302
  2448. | 63| ••••••••is_member•=•self.bob.member_of(self.a_team)
  2449. | 64| ••••••••assert•is_member•is•False
  2450. | | [NORMAL] CPDBear:
  2451. | | Duplicate code found.
  2452.  
  2453. tests/py/test_hooks.py
  2454. | 116| ••••def•test_error_spt_works(self):
  2455. | 117| ••••••••r•=•self.client.POST('/',•csrf_token=False,•raise_immediately=False)
  2456. | 118| ••••••••assert•r.code•==•403
  2457.  
  2458. tests/py/test_hooks.py
  2459. | 146| ••••def•test_no_csrf_cookie(self):
  2460. | 147| ••••••••r•=•self.client.POST('/',•csrf_token=False,•raise_immediately=False)
  2461. | 148| ••••••••assert•r.code•==•403
  2462. | | [NORMAL] CPDBear:
  2463. | | Duplicate code found.
  2464.  
  2465. tests/py/test_close.py
  2466. | 153| ••••def•test_ctg_clears_tips_giving(self):
  2467. | 154| ••••••••alice•=•self.make_participant('alice')
  2468. | 155| ••••••••alice.set_tip_to(self.make_participant('bob'),•D('1.00'))
  2469.  
  2470. tests/py/test_close.py
  2471. | 183| ••••def•test_ctg_clears_multiple_tips_giving(self):
  2472. | 184| ••••••••alice•=•self.make_participant('alice')
  2473. | 185| ••••••••alice.set_tip_to(self.make_participant('bob'),•D('1.00'))
  2474. | | [NORMAL] CPDBear:
  2475. | | Duplicate code found.
  2476.  
  2477. tests/py/test_communities.py
  2478. | 25| class•TestCommunitiesJson(Harness):
  2479. | 26|
  2480. | 27| ••••def•setUp(self):
  2481. | 28| ••••••••Harness.setUp(self)
  2482. | 29| ••••••••self.alice•=•self.make_participant("alice")
  2483. | 30| ••••••••self.c_id•=•str(self.alice.create_community('test').id)
  2484.  
  2485. tests/py/test_communities.py
  2486. | 63| class•TestCommunityActions(Harness):
  2487. | 64|
  2488. | 65| ••••def•setUp(self):
  2489. | 66| ••••••••Harness.setUp(self)
  2490. | 67| ••••••••self.alice•=•self.make_participant("alice")
  2491. | 68| ••••••••self.bob•=•self.make_participant("bob")
  2492.  
  2493. tests/py/test_communities.py
  2494. | 108| class•TestCommunityEdit(Harness):
  2495. | 109|
  2496. | 110| ••••def•setUp(self):
  2497. | 111| ••••••••Harness.setUp(self)
  2498. | 112| ••••••••self.alice•=•self.make_participant("alice")
  2499. | 113| ••••••••self.community•=•Community.create('test',•self.alice.id)
  2500. | | [NORMAL] CPDBear:
  2501. | | Duplicate code found.
  2502.  
  2503. tests/py/test_communities.py
  2504. | 42| •••••••••••••••••••••••••••••••••••,•xhr=True
  2505. | 43| ••••••••••••••••••••••••••••••••••••)
  2506. | 44|
  2507. | 45| ••••••••r•=•json.loads(response.body)
  2508. | 46| ••••••••assert•r•==•{}
  2509. | 47|
  2510. | 48| ••••••••response•=•self.client.POST(•'/alice/communities.json'
  2511.  
  2512. tests/py/test_communities.py
  2513. | 77| ••••••••response•=•self.client.POST('/for/test/subscribe',•auth_as=self.bob,
  2514. | 78| ••••••••••••••••••••••••••••••••••••xhr=True)
  2515. | 79|
  2516. | 80| ••••••••r•=•json.loads(response.body)
  2517. | 81| ••••••••assert•r•==•{}
  2518. | 82|
  2519. | 83| ••••••••response•=•self.client.POST('/for/test/unsubscribe',•auth_as=self.bob,
  2520.  
  2521. tests/py/test_communities.py
  2522. | 94| ••••••••response•=•self.client.POST('/for/test/join',•auth_as=self.bob,
  2523. | 95| ••••••••••••••••••••••••••••••••••••xhr=True)
  2524. | 96|
  2525. | 97| ••••••••r•=•json.loads(response.body)
  2526. | 98| ••••••••assert•r•==•{}
  2527. | 99|
  2528. | 100| ••••••••response•=•self.client.POST('/for/test/leave',•auth_as=self.bob,
  2529. | | [NORMAL] CPDBear:
  2530. | | Duplicate code found.
  2531.  
  2532. tests/py/test_billing_payday.py
  2533. | 314| ••••def•test_underfunded_team(self):
  2534. | 315| ••••••••self.clear_tables()
  2535. | 316| ••••••••team•=•self.make_participant('team',•kind='group')
  2536. | 317| ••••••••alice•=•self.make_participant('alice')
  2537.  
  2538. tests/py/test_billing_payday.py
  2539. | 364| ••••def•test_mutual_tipping_through_teams(self):
  2540. | 365| ••••••••self.clear_tables()
  2541. | 366| ••••••••team•=•self.make_participant('team',•kind='group')
  2542. | 367| ••••••••alice•=•self.make_participant('alice',•balance=8)
  2543.  
  2544. tests/py/test_billing_payday.py
  2545. | 384| ••••def•test_unfunded_tip_to_team_doesnt_cause_NegativeBalance(self):
  2546. | 385| ••••••••self.clear_tables()
  2547. | 386| ••••••••team•=•self.make_participant('team',•kind='group')
  2548. | 387| ••••••••alice•=•self.make_participant('alice')
  2549. | | [NORMAL] CPDBear:
  2550. | | Duplicate code found.
  2551.  
  2552. tests/py/test_pages.py
  2553. | 131| ••••def•test_giving_page(self):
  2554. | 132| ••••••••alice•=•self.make_participant('alice')
  2555. | 133| ••••••••bob•=•self.make_participant('bob')
  2556. | 134| ••••••••alice.set_tip_to(bob,•"1.00")
  2557.  
  2558. tests/py/test_pages.py
  2559. | 149| ••••def•test_giving_page_shows_cancelled(self):
  2560. | 150| ••••••••alice•=•self.make_participant('alice')
  2561. | 151| ••••••••bob•=•self.make_participant('bob')
  2562. | 152| ••••••••alice.set_tip_to(bob,•"1.00")
  2563. | | [NORMAL] CPDBear:
  2564. | | Duplicate code found.
  2565.  
  2566. tests/py/test_take.py
  2567. | 64| ••••def•test_increase_is_based_on_nominal_take_last_week(self):
  2568. | 65| ••••••••team•=•self.make_team()
  2569. | 66| ••••••••alice•=•self.make_participant('alice')
  2570. | 67| ••••••••self.take_last_week(team,•alice,•'20.00',•actual_amount='15.03')
  2571.  
  2572. tests/py/test_take.py
  2573. | 166| ••••def•test_gtlwf_works_during_payday(self):
  2574. | 167| ••••••••team•=•self.make_team()
  2575. | 168| ••••••••alice•=•self.make_participant('alice')
  2576. | 169| ••••••••self.take_last_week(team,•alice,•'20.00')
  2577. | | [NORMAL] CPDBear:
  2578. | | Duplicate code found.
  2579.  
  2580. tests/py/test_participant.py
  2581. | 401| ••••••••unclaimed•=•self.make_elsewhere('bitbucket',•'1234',•'alice')
  2582. | 402| ••••••••stub•=•Participant.from_username(unclaimed.participant.username)
  2583. | 403| ••••••••actual•=•stub.resolve_stub()
  2584. | 404| ••••••••assert•actual•==•"/on/bitbucket/alice/"
  2585.  
  2586. tests/py/test_participant.py
  2587. | 407| ••••••••unclaimed•=•self.make_elsewhere('github',•'1234',•'alice')
  2588. | 408| ••••••••stub•=•Participant.from_username(unclaimed.participant.username)
  2589. | 409| ••••••••actual•=•stub.resolve_stub()
  2590. | 410| ••••••••assert•actual•==•"/on/github/alice/"
  2591.  
  2592. tests/py/test_participant.py
  2593. | 413| ••••••••unclaimed•=•self.make_elsewhere('twitter',•'1234',•'alice')
  2594. | 414| ••••••••stub•=•Participant.from_username(unclaimed.participant.username)
  2595. | 415| ••••••••actual•=•stub.resolve_stub()
  2596. | 416| ••••••••assert•actual•==•"/on/twitter/alice/"
  2597. | | [NORMAL] CPDBear:
  2598. | | Duplicate code found.
  2599.  
  2600. liberapay/models/participant.py
  2601. | 48| from•liberapay.models.account_elsewhere•import•AccountElsewhere
  2602. | 49| from•liberapay.models.community•import•Community
  2603. | 50| from•liberapay.models.exchange_route•import•ExchangeRoute
  2604. | 51| from•liberapay.notifications•import•EVENTS
  2605.  
  2606. liberapay/wireup.py
  2607. | 23| from•liberapay.models.account_elsewhere•import•AccountElsewhere
  2608. | 24| from•liberapay.models.community•import•Community
  2609. | 25| from•liberapay.models.exchange_route•import•ExchangeRoute
  2610. | 26| from•liberapay.models.participant•import•Participant
  2611. | | [NORMAL] CPDBear:
  2612. | | Duplicate code found.
  2613.  
  2614. tests/py/test_close.py
  2615. | 20| ••••••••alice•=•self.make_participant('alice',•balance=D('10.00'))
  2616. | 21| ••••••••bob•=•self.make_participant('bob')
  2617. | 22| ••••••••carl•=•self.make_participant('carl')
  2618.  
  2619. tests/py/test_close.py
  2620. | 101| ••••••••alice•=•self.make_participant('alice',•balance=D('10.00'))
  2621. | 102| ••••••••bob•=•self.make_participant('bob')
  2622. | 103| ••••••••carl•=•self.make_stub()
  2623. | | [NORMAL] CPDBear:
  2624. | | Duplicate code found.
  2625.  
  2626. tests/py/test_close.py
  2627. | 157| ••••••••••••••••••••••••••••••••••••"WHERE•tipper=%s•AND•amount•>•0",
  2628. | 158| ••••••••••••••••••••••••••••••••••••(alice.id,))
  2629. | 159| ••••••••assert•ntips()•==•1
  2630. | 160| ••••••••with•self.db.get_cursor()•as•cursor:
  2631. | 161| ••••••••••••alice.clear_tips_giving(cursor)
  2632.  
  2633. tests/py/test_close.py
  2634. | 205| ••••••••••••••••••••••••••••••••••••"WHERE•tippee=%s•AND•amount•>•0",
  2635. | 206| ••••••••••••••••••••••••••••••••••••(alice.id,))
  2636. | 207| ••••••••assert•ntips()•==•1
  2637. | 208| ••••••••with•self.db.get_cursor()•as•cursor:
  2638. | 209| ••••••••••••alice.clear_tips_receiving(cursor)
  2639. | | [NORMAL] CPDBear:
  2640. | | Duplicate code found.
  2641.  
  2642. tests/py/test_close.py
  2643. | 169| ••••••••ntips•=•lambda:•self.db.one("SELECT•count(*)•FROM•tips•WHERE•tipper=%s",•(alice.id,))
  2644. | 170| ••••••••assert•ntips()•==•2
  2645. | 171| ••••••••with•self.db.get_cursor()•as•cursor:
  2646. | 172| ••••••••••••alice.clear_tips_giving(cursor)
  2647.  
  2648. tests/py/test_close.py
  2649. | 217| ••••••••ntips•=•lambda:•self.db.one("SELECT•count(*)•FROM•tips•WHERE•tippee=%s",•(alice.id,))
  2650. | 218| ••••••••assert•ntips()•==•2
  2651. | 219| ••••••••with•self.db.get_cursor()•as•cursor:
  2652. | 220| ••••••••••••alice.clear_tips_receiving(cursor)
  2653. | | [NORMAL] CPDBear:
  2654. | | Duplicate code found.
  2655.  
  2656. tests/py/test_close.py
  2657. | 177| ••••••••ntips•=•lambda:•self.db.one("SELECT•count(*)•FROM•tips•WHERE•tipper=%s",•(alice.id,))
  2658. | 178| ••••••••assert•ntips()•==•0
  2659. | 179| ••••••••with•self.db.get_cursor()•as•cursor:
  2660. | 180| ••••••••••••alice.clear_tips_giving(cursor)
  2661.  
  2662. tests/py/test_close.py
  2663. | 225| ••••••••ntips•=•lambda:•self.db.one("SELECT•count(*)•FROM•tips•WHERE•tippee=%s",•(alice.id,))
  2664. | 226| ••••••••assert•ntips()•==•0
  2665. | 227| ••••••••with•self.db.get_cursor()•as•cursor:
  2666. | 228| ••••••••••••alice.clear_tips_receiving(cursor)
  2667. | | [NORMAL] CPDBear:
  2668. | | Duplicate code found.
  2669.  
  2670. tests/py/test_close.py
  2671. | 191| ••••••••••••••••••••••••••••••••••••"WHERE•tipper=%s•AND•amount•>•0",
  2672. | 192| ••••••••••••••••••••••••••••••••••••(alice.id,))
  2673. | 193| ••••••••assert•ntips()•==•5
  2674. | 194| ••••••••with•self.db.get_cursor()•as•cursor:
  2675. | 195| ••••••••••••alice.clear_tips_giving(cursor)
  2676.  
  2677. tests/py/test_close.py
  2678. | 239| ••••••••••••••••••••••••••••••••••••"WHERE•tippee=%s•AND•amount•>•0",
  2679. | 240| ••••••••••••••••••••••••••••••••••••(alice.id,))
  2680. | 241| ••••••••assert•ntips()•==•5
  2681. | 242| ••••••••with•self.db.get_cursor()•as•cursor:
  2682. | 243| ••••••••••••alice.clear_tips_receiving(cursor)
  2683. | | [NORMAL] CPDBear:
  2684. | | Duplicate code found.
  2685.  
  2686. tests/py/test_close.py
  2687. | 203| ••••••••self.make_participant('bob').set_tip_to(alice,•D('1.00'))
  2688. | 204| ••••••••ntips•=•lambda:•self.db.one("SELECT•count(*)•FROM•current_tips•"
  2689. | 205| ••••••••••••••••••••••••••••••••••••"WHERE•tippee=%s•AND•amount•>•0",
  2690. | 206| ••••••••••••••••••••••••••••••••••••(alice.id,))
  2691. | 207| ••••••••assert•ntips()•==•1
  2692.  
  2693. tests/py/test_close.py
  2694. | 237| ••••••••self.make_participant('francis').set_tip_to(alice,•D('5.00'))
  2695. | 238| ••••••••ntips•=•lambda:•self.db.one("SELECT•count(*)•FROM•current_tips•"
  2696. | 239| ••••••••••••••••••••••••••••••••••••"WHERE•tippee=%s•AND•amount•>•0",
  2697. | 240| ••••••••••••••••••••••••••••••••••••(alice.id,))
  2698. | 241| ••••••••assert•ntips()•==•5
  2699. | | [NORMAL] CPDBear:
  2700. | | Duplicate code found.
  2701.  
  2702. tests/py/test_billing_exchanges.py
  2703. | 326| ••••def•test_sync_with_mangopay_transfers(self):
  2704. | 327| ••••••••self.make_exchange('mango-cc',•10,•0,•self.janet)
  2705. | 328| ••••••••with•mock.patch('liberapay.billing.exchanges.record_transfer_result')•as•rtr:
  2706.  
  2707. tests/py/test_billing_exchanges.py
  2708. | 340| ••••def•test_sync_with_mangopay_deletes_transfers_that_didnt_happen(self):
  2709. | 341| ••••••••self.make_exchange('mango-cc',•10,•0,•self.janet)
  2710. | 342| ••••••••with•mock.patch('liberapay.billing.exchanges.record_transfer_result')•as•rtr•\
  2711. | | [NORMAL] CPDBear:
  2712. | | Duplicate code found.
  2713.  
  2714. tests/py/test_take.py
  2715. | 38| ••••def•test_team_member_is_team_member(self):
  2716. | 39| ••••••••team•=•self.make_team()
  2717. | 40| ••••••••alice•=•self.make_participant('alice')
  2718. | 41| ••••••••self.take_last_week(team,•alice,•'40.00')
  2719.  
  2720. tests/py/test_take.py
  2721. | 44| ••••def•test_cant_grow_tip_a_lot(self):
  2722. | 45| ••••••••team•=•self.make_team()
  2723. | 46| ••••••••alice•=•self.make_participant('alice')
  2724. | 47| ••••••••self.take_last_week(team,•alice,•'40.00')
  2725.  
  2726. tests/py/test_take.py
  2727. | 50| ••••def•test_take_can_double(self):
  2728. | 51| ••••••••team•=•self.make_team()
  2729. | 52| ••••••••alice•=•self.make_participant('alice')
  2730. | 53| ••••••••self.take_last_week(team,•alice,•'40.00')
  2731.  
  2732. tests/py/test_take.py
  2733. | 57| ••••def•test_take_can_double_but_not_a_penny_more(self):
  2734. | 58| ••••••••team•=•self.make_team()
  2735. | 59| ••••••••alice•=•self.make_participant('alice')
  2736. | 60| ••••••••self.take_last_week(team,•alice,•'40.00')
  2737.  
  2738. tests/py/test_take.py
  2739. | 64| ••••def•test_increase_is_based_on_nominal_take_last_week(self):
  2740. | 65| ••••••••team•=•self.make_team()
  2741. | 66| ••••••••alice•=•self.make_participant('alice')
  2742. | 67| ••••••••self.take_last_week(team,•alice,•'20.00',•actual_amount='15.03')
  2743.  
  2744. tests/py/test_take.py
  2745. | 71| ••••def•test_if_last_week_is_less_than_one_can_increase_to_one(self):
  2746. | 72| ••••••••team•=•self.make_team()
  2747. | 73| ••••••••alice•=•self.make_participant('alice')
  2748. | 74| ••••••••self.take_last_week(team,•alice,•'0.01')
  2749.  
  2750. tests/py/test_take.py
  2751. | 78| ••••def•test_get_members(self):
  2752. | 79| ••••••••team•=•self.make_team()
  2753. | 80| ••••••••alice•=•self.make_participant('alice')
  2754. | 81| ••••••••self.take_last_week(team,•alice,•'40.00')
  2755.  
  2756. tests/py/test_take.py
  2757. | 89| ••••def•test_taking_and_receiving_are_updated_correctly(self):
  2758. | 90| ••••••••team•=•self.make_team()
  2759. | 91| ••••••••alice•=•self.make_participant('alice')
  2760. | 92| ••••••••self.take_last_week(team,•alice,•'40.00')
  2761.  
  2762. tests/py/test_take.py
  2763. | 120| ••••def•test_changes_to_team_receiving_affect_members_take(self):
  2764. | 121| ••••••••team•=•self.make_team()
  2765. | 122| ••••••••alice•=•self.make_participant('alice')
  2766. | 123| ••••••••self.take_last_week(team,•alice,•'40.00')
  2767.  
  2768. tests/py/test_take.py
  2769. | 130| ••••def•test_changes_to_others_take_affects_members_take(self):
  2770. | 131| ••••••••team•=•self.make_team()
  2771. | 132|
  2772. | 133| ••••••••alice•=•self.make_participant('alice')
  2773.  
  2774. tests/py/test_take.py
  2775. | 147| ••••def•test_changes_to_others_take_can_increase_members_take(self):
  2776. | 148| ••••••••team•=•self.make_team()
  2777. | 149|
  2778. | 150| ••••••••alice•=•self.make_participant('alice')
  2779.  
  2780. tests/py/test_take.py
  2781. | 166| ••••def•test_gtlwf_works_during_payday(self):
  2782. | 167| ••••••••team•=•self.make_team()
  2783. | 168| ••••••••alice•=•self.make_participant('alice')
  2784. | 169| ••••••••self.take_last_week(team,•alice,•'20.00')
  2785. | | [NORMAL] CPDBear:
  2786. | | Duplicate code found.
  2787.  
  2788. tests/py/test_elsewhere.py
  2789. | 63| ••••••••cookie•=•b64encode_s(json.dumps(['query_data',•'connect',•'',•'2']))
  2790. | 64| ••••••••response•=•self.client.GxT('/on/github/associate?state=deadbeef',
  2791.  
  2792. tests/py/test_elsewhere.py
  2793. | 74| ••••••••cookie•=•b64encode_s(json.dumps(['query_data',•'connect',•'',•'2']))
  2794. | 75| ••••••••response•=•self.client.GxT(url,•auth_as=alice,
  2795. | | [NORMAL] CPDBear:
  2796. | | Duplicate code found.
  2797.  
  2798. tests/py/test_elsewhere.py
  2799. | 211| ••••••••user_info•=•platform.extract_user_info(user_info_examples.twitter())
  2800. | 212| ••••••••account•=•AccountElsewhere.upsert(user_info)
  2801. | 213| ••••••••friends,•nfriends,•pages_urls•=•platform.get_friends_for(account)
  2802. | 214| ••••••••assert•nfriends•>•0
  2803.  
  2804. tests/py/test_elsewhere.py
  2805. | 218| ••••••••user_info•=•platform.extract_user_info(user_info_examples.github())
  2806. | 219| ••••••••account•=•AccountElsewhere.upsert(user_info)
  2807. | 220| ••••••••friends,•nfriends,•pages_urls•=•platform.get_friends_for(account)
  2808. | 221| ••••••••assert•nfriends•>•0
  2809. | | [NORMAL] CPDBear:
  2810. | | Duplicate code found.
  2811.  
  2812. tests/py/test_participant.py
  2813. | 42| ••••def•test_empty_stub_is_deleted(self):
  2814. | 43| ••••••••alice•=•self.make_participant('alice')
  2815. | 44| ••••••••bob•=•self.make_elsewhere('twitter',•2,•'bob')
  2816. | 45| ••••••••alice.take_over(bob)
  2817.  
  2818. tests/py/test_participant.py
  2819. | 57| ••••def•test_zero_cross_tip_doesnt_become_self_tip(self):
  2820. | 58| ••••••••alice•=•self.make_participant('alice')
  2821. | 59| ••••••••bob•=•self.make_elsewhere('twitter',•2,•'bob')
  2822. | 60| ••••••••alice.set_tip_to(bob.participant,•'1.00')
  2823. | | [NORMAL] CPDBear:
  2824. | | Duplicate code found.
  2825.  
  2826. liberapay/elsewhere/facebook.py
  2827. | 1| from•__future__•import•absolute_import,•division,•print_function,•unicode_literals
  2828. | 2|
  2829. | 3| from•liberapay.elsewhere._base•import•PlatformOAuth2
  2830. | 4| from•liberapay.elsewhere._extractors•import•key
  2831.  
  2832. liberapay/elsewhere/gitlab.py
  2833. | 1| from•__future__•import•absolute_import,•division,•print_function,•unicode_literals
  2834. | 2|
  2835. | 3| from•liberapay.elsewhere._base•import•PlatformOAuth2
  2836. | 4| from•liberapay.elsewhere._extractors•import•key
  2837.  
  2838. liberapay/elsewhere/linuxfr.py
  2839. | 1| from•__future__•import•absolute_import,•division,•print_function,•unicode_literals
  2840. | 2|
  2841. | 3| from•liberapay.elsewhere._base•import•PlatformOAuth2
  2842. | 4| from•liberapay.elsewhere._extractors•import•key
  2843. | | [NORMAL] CPDBear:
  2844. | | Duplicate code found.
  2845.  
  2846. tests/py/test_stats.py
  2847. | 32| ••••••••carl.set_tip_to(self.bob,•'3.00')
  2848. | 33| ••••••••expected•=•([
  2849. | 34| ••••••••••••[Decimal('1.00'),•1,•Decimal('1.00'),•0.5,•Decimal('0.25')],
  2850.  
  2851. tests/py/test_stats.py
  2852. | 43| ••••••••bad_cc.set_tip_to(self.bob,•'3.00')
  2853. | 44| ••••••••expected•=•([[Decimal('1.00'),•1,•Decimal('1.00'),•1,•Decimal('1')]],
  2854. | 45| ••••••••••••••••••••1.0,•Decimal('1.00'))
  2855.  
  2856. tests/py/test_stats.py
  2857. | 52| ••••••••missing_cc.set_tip_to(self.bob,•'3.00')
  2858. | 53| ••••••••expected•=•([[Decimal('1.00'),•1,•Decimal('1.00'),•1,•Decimal('1')]],
  2859. | 54| ••••••••••••••••••••1.0,•Decimal('1.00'))
  2860. | | [NORMAL] CPDBear:
  2861. | | Duplicate code found.
  2862.  
  2863. tests/py/test_communities.py
  2864. | 7| from•liberapay.testing•import•Harness
  2865. | 8|
  2866. | 9|
  2867. | 10| class•Tests(Harness):
  2868. | 11|
  2869. | 12| ••••def•setUp(self):
  2870. | 13| ••••••••Harness.setUp(self)
  2871. | 14|
  2872.  
  2873. tests/py/test_hooks.py
  2874. | 14| from•liberapay.testing•import•Harness
  2875. | 15|
  2876. | 16|
  2877. | 17| class•Tests(Harness):
  2878. | 18|
  2879. | 19| ••••def•setUp(self):
  2880. | 20| ••••••••Harness.setUp(self)
  2881. | 21| ••••••••self.client.website.canonical_scheme•=•'https'
  2882.  
  2883. tests/py/test_teams.py
  2884. | 5| from•liberapay.testing•import•Harness
  2885. | 6|
  2886. | 7|
  2887. | 8| class•Tests(Harness):
  2888. | 9|
  2889. | 10| ••••def•setUp(self):
  2890. | 11| ••••••••Harness.setUp(self)
  2891. | 12| ••••••••self.a_team•=•self.make_participant('A-Team',•kind='group')
  2892. | | [NORMAL] CPDBear:
  2893. | | Duplicate code found.
  2894.  
  2895. tests/py/test_utils.py
  2896. | 16| ••••••••state•=•self.client.GET('/alice/',•return_after='dispatch_request_to_filesystem',
  2897. | 17| ••••••••••••••••••••••••••••••••want='state')
  2898. | 18| ••••••••actual•=•utils.get_participant(state,•restrict=False)
  2899. | 19| ••••••••assert•actual•==•expected
  2900. | 20|
  2901. | 21| ••••def•test_get_participant_gets_participant_from_id(self):
  2902.  
  2903. tests/py/test_utils.py
  2904. | 23| ••••••••state•=•self.client.POST('/~1/',•return_after='dispatch_request_to_filesystem',
  2905. | 24| •••••••••••••••••••••••••••••••••want='state')
  2906. | 25| ••••••••actual•=•utils.get_participant(state,•restrict=False)
  2907. | 26| ••••••••assert•actual•==•expected
  2908. | 27|
  2909. | 28| ••••def•test_get_participant_raises_404_for_missing_id(self):
  2910. | | [NORMAL] CPDBear:
  2911. | | Duplicate code found.
  2912.  
  2913. tests/py/test_billing_payday.py
  2914. | 37| ••••def•test_update_cached_amounts(self):
  2915. | 38| ••••••••team•=•self.make_participant('team',•kind='group')
  2916. | 39| ••••••••alice•=•self.make_participant('alice',•balance=100)
  2917.  
  2918. tests/py/test_close.py
  2919. | 18| ••••def•test_close_closes(self):
  2920. | 19| ••••••••team•=•self.make_participant('team',•kind='group')
  2921. | 20| ••••••••alice•=•self.make_participant('alice',•balance=D('10.00'))
  2922. | | [NORMAL] CPDBear:
  2923. | | Duplicate code found.
  2924.  
  2925. tests/py/test_close.py
  2926. | 43| ••••••••alice•=•self.make_participant('alice')
  2927. | 44| ••••••••body•=•self.client.GET('/alice/settings/close',•auth_as=alice).text
  2928. | 45| ••••••••assert•'Personal•Information'•in•body
  2929.  
  2930. tests/py/test_close.py
  2931. | 49| ••••••••alice•=•self.make_participant('alice')
  2932. | 50| ••••••••body•=•self.client.GET('/alice/settings/close',•auth_as=alice).text
  2933. | 51| ••••••••assert•'Personal•Information'•not•in•body
  2934. | | [NORMAL] CPDBear:
  2935. | | Duplicate code found.
  2936.  
  2937. tests/py/test_close.py
  2938. | 113| ••••••••alice•=•self.make_participant('alice',•balance=D('10.00'))
  2939. | 114| ••••••••bob•=•self.make_participant('bob')
  2940. | 115| ••••••••carl•=•self.make_participant('carl')
  2941. | 116| ••••••••alice.set_tip_to(bob,•D('0.00'))
  2942.  
  2943. tests/py/test_close.py
  2944. | 138| ••••••••alice•=•self.make_participant('alice',•balance=D('0.00'))
  2945. | 139| ••••••••bob•=•self.make_participant('bob')
  2946. | 140| ••••••••carl•=•self.make_participant('carl')
  2947. | 141| ••••••••alice.set_tip_to(bob,•D('3.00'))
  2948. | | [NORMAL] CPDBear:
  2949. | | Duplicate code found.
  2950.  
  2951. tests/py/test_close.py
  2952. | 117| ••••••••alice.set_tip_to(carl,•D('2.00'))
  2953. | 118| ••••••••with•self.db.get_cursor()•as•cursor:
  2954. | 119| ••••••••••••alice.distribute_balance_as_final_gift(cursor)
  2955. | 120| ••••••••assert•self.db.one("SELECT•count(*)•FROM•tips•WHERE•tippee=%s",•(bob.id,))•==•1
  2956.  
  2957. tests/py/test_close.py
  2958. | 142| ••••••••alice.set_tip_to(carl,•D('6.00'))
  2959. | 143| ••••••••with•self.db.get_cursor()•as•cursor:
  2960. | 144| ••••••••••••alice.distribute_balance_as_final_gift(cursor)
  2961. | 145| ••••••••assert•self.db.one("SELECT•count(*)•FROM•tips")•==•2
  2962. | | [NORMAL] CPDBear:
  2963. | | Duplicate code found.
  2964.  
  2965. tests/py/test_close.py
  2966. | 121| ••••••••assert•Participant.from_username('bob').balance•==•D('0.00')
  2967. | 122| ••••••••assert•Participant.from_username('carl').balance•==•D('10.00')
  2968.  
  2969. tests/py/test_close.py
  2970. | 146| ••••••••assert•Participant.from_username('bob').balance•==•D('0.00')
  2971. | 147| ••••••••assert•Participant.from_username('carl').balance•==•D('0.00')
  2972. | | [NORMAL] CPDBear:
  2973. | | Duplicate code found.
  2974.  
  2975. tests/py/test_settings.py
  2976. | 27| ••••••••self.hit_edit(data=ALL_ON)
  2977. | 28| ••••••••alice•=•Participant.from_id(self.alice.id)
  2978. | 29| ••••••••for•k•in•PRIVACY_FIELDS:
  2979. | 30| ••••••••••••assert•getattr(alice,•k)•is•True
  2980.  
  2981. tests/py/test_settings.py
  2982. | 33| ••••••••self.hit_edit(data=ALL_OFF)
  2983. | 34| ••••••••alice•=•Participant.from_id(self.alice.id)
  2984. | 35| ••••••••for•k•in•PRIVACY_FIELDS:
  2985. | 36| ••••••••••••assert•getattr(alice,•k)•is•False
  2986. | | [NORMAL] CPDBear:
  2987. | | Duplicate code found.
  2988.  
  2989. tests/py/test_pages.py
  2990. | 172| ••••••••eid•=•self.make_exchange('mango-ba',•19,•0,•self.david,•'failed',•error)
  2991. | 173| ••••••••r•=•self.client.GET('/david/wallet/payout/?exchange_id=%s'•%•eid,
  2992. | 174| ••••••••••••••••••••••••••••auth_as=self.david)
  2993. | 175| ••••••••assert•r.code•==•200
  2994. | 176| ••••••••assert•error•in•r.body.decode('utf8')
  2995.  
  2996. tests/py/test_pages.py
  2997. | 179| ••••••••eid•=•self.make_exchange('mango-ba',•19,•0,•self.david)
  2998. | 180| ••••••••r•=•self.client.GET('/david/wallet/payout/?exchange_id=%s'•%•eid,
  2999. | 181| ••••••••••••••••••••••••••••auth_as=self.david)
  3000. | 182| ••••••••assert•r.code•==•200
  3001. | 183| ••••••••assert•'€19'•in•r.body.decode('utf8')
  3002. | | [NORMAL] CPDBear:
  3003. | | Duplicate code found.
  3004.  
  3005. tests/py/test_participant.py
  3006. | 51| ••••••••alice•=•self.make_participant('alice',•elsewhere='twitter')
  3007. | 52| ••••••••bob•=•self.make_elsewhere('twitter',•2,•'bob')
  3008. | 53| ••••••••alice.set_tip_to(bob.participant,•'1.00')
  3009. | 54| ••••••••alice.take_over(bob,•have_confirmation=True)
  3010.  
  3011. tests/py/test_participant.py
  3012. | 58| ••••••••alice•=•self.make_participant('alice')
  3013. | 59| ••••••••bob•=•self.make_elsewhere('twitter',•2,•'bob')
  3014. | 60| ••••••••alice.set_tip_to(bob.participant,•'1.00')
  3015. | 61| ••••••••alice.set_tip_to(bob.participant,•'0.00')
  3016. | | [NORMAL] CPDBear:
  3017. | | Duplicate code found.
  3018.  
  3019. tests/py/test_participant.py
  3020. | 401| ••••••••unclaimed•=•self.make_elsewhere('bitbucket',•'1234',•'alice')
  3021. | 402| ••••••••stub•=•Participant.from_username(unclaimed.participant.username)
  3022. | 403| ••••••••actual•=•stub.resolve_stub()
  3023. | 404| ••••••••assert•actual•==•"/on/bitbucket/alice/"
  3024.  
  3025. tests/py/test_participant.py
  3026. | 407| ••••••••unclaimed•=•self.make_elsewhere('github',•'1234',•'alice')
  3027. | 408| ••••••••stub•=•Participant.from_username(unclaimed.participant.username)
  3028. | 409| ••••••••actual•=•stub.resolve_stub()
  3029. | 410| ••••••••assert•actual•==•"/on/github/alice/"
  3030.  
  3031. tests/py/test_participant.py
  3032. | 413| ••••••••unclaimed•=•self.make_elsewhere('twitter',•'1234',•'alice')
  3033. | 414| ••••••••stub•=•Participant.from_username(unclaimed.participant.username)
  3034. | 415| ••••••••actual•=•stub.resolve_stub()
  3035. | 416| ••••••••assert•actual•==•"/on/twitter/alice/"
  3036.  
  3037. tests/py/test_participant.py
  3038. | 419| ••••••••unclaimed•=•self.make_elsewhere('openstreetmap',•'1',•'alice')
  3039. | 420| ••••••••stub•=•Participant.from_username(unclaimed.participant.username)
  3040. | 421| ••••••••actual•=•stub.resolve_stub()
  3041. | 422| ••••••••assert•actual•==•"/on/openstreetmap/alice/"
  3042. | | [NORMAL] CPDBear:
  3043. | | Duplicate code found.
  3044.  
  3045. tests/py/test_search.py
  3046. | 15| ••••••••self.make_participant('alice')
  3047. | 16| ••••••••response•=•self.client.GET('/search.json?q=alice&scope=usernames')
  3048. | 17| ••••••••data•=•json.loads(response.body)['usernames']
  3049. | 18| ••••••••assert•len(data)•==•1
  3050.  
  3051. tests/py/test_search.py
  3052. | 35| ••••••••self.make_participant('alice',•hide_from_search=True)
  3053. | 36| ••••••••response•=•self.client.GET('/search.json?q=alice&scope=usernames')
  3054. | 37| ••••••••data•=•json.loads(response.body)['usernames']
  3055. | 38| ••••••••assert•data•==•[]
  3056. | | [NORMAL] CPDBear:
  3057. | | Duplicate code found.
  3058.  
  3059. liberapay/elsewhere/facebook.py
  3060. | 1| from•__future__•import•absolute_import,•division,•print_function,•unicode_literals
  3061. | 2|
  3062. | 3| from•liberapay.elsewhere._base•import•PlatformOAuth2
  3063. | 4| from•liberapay.elsewhere._extractors•import•key
  3064.  
  3065. liberapay/elsewhere/gitlab.py
  3066. | 1| from•__future__•import•absolute_import,•division,•print_function,•unicode_literals
  3067. | 2|
  3068. | 3| from•liberapay.elsewhere._base•import•PlatformOAuth2
  3069. | 4| from•liberapay.elsewhere._extractors•import•key
  3070.  
  3071. liberapay/elsewhere/google.py
  3072. | 1| from•__future__•import•absolute_import,•division,•print_function,•unicode_literals
  3073. | 2|
  3074. | 3| from•liberapay.elsewhere._base•import•PlatformOAuth2
  3075. | 4| from•liberapay.elsewhere._extractors•import•any_key,•key
  3076.  
  3077. liberapay/elsewhere/linuxfr.py
  3078. | 1| from•__future__•import•absolute_import,•division,•print_function,•unicode_literals
  3079. | 2|
  3080. | 3| from•liberapay.elsewhere._base•import•PlatformOAuth2
  3081. | 4| from•liberapay.elsewhere._extractors•import•key
  3082. | | [NORMAL] CPDBear:
  3083. | | Duplicate code found.
  3084.  
  3085. tests/py/test_email.py
  3086. | 48| ••••••••self.hit_email_spt('add-email',•'alice@example.com')
  3087. | 49| ••••••••assert•self.mailer.call_count•==•1
  3088. | 50| ••••••••last_email•=•self.get_last_email()
  3089. | 51| ••••••••assert•last_email['to'][0]•==•'alice•<alice@example.com>'
  3090.  
  3091. tests/py/test_email.py
  3092. | 225| ••••••••Participant.dequeue_emails()
  3093. | 226| ••••••••assert•self.mailer.call_count•==•1
  3094. | 227| ••••••••last_email•=•self.get_last_email()
  3095. | 228| ••••••••assert•last_email['to'][0]•==•'larry•<larry@example.com>'
  3096.  
  3097. tests/py/test_email_notifs.py
  3098. | 21| ••••••••Participant.dequeue_emails()
  3099. | 22| ••••••••assert•self.mailer.call_count•==•1
  3100. | 23| ••••••••last_email•=•self.get_last_email()
  3101. | 24| ••••••••assert•last_email['to'][0]•==•'bob•<bob@example.com>'
  3102. | | [NORMAL] CPDBear:
  3103. | | Duplicate code found.
  3104.  
  3105. tests/py/test_email.py
  3106. | 91| ••••••••self.hit_email_spt('add-email',•address)
  3107. | 92| ••••••••nonce•=•self.alice.get_email(address).nonce
  3108. | 93| ••••••••r•=•self.alice.verify_email(address,•nonce)
  3109.  
  3110. tests/py/test_email.py
  3111. | 104| ••••••••""",•(self.alice.id,))
  3112. | 105| ••••••••nonce•=•self.alice.get_email(address).nonce
  3113. | 106| ••••••••r•=•self.alice.verify_email(address,•nonce)
  3114. | | [NORMAL] CPDBear:
  3115. | | Duplicate code found.
  3116.  
  3117. liberapay/billing/exchanges.py
  3118. | 148| ••••••••return•record_exchange_result(db,•e_id,•payout.Status.lower(),•repr_error(payout),•participant)
  3119. | 149| ••••except•Exception•as•e:
  3120. | 150| ••••••••error•=•repr_exception(e)
  3121. | 151| ••••••••return•record_exchange_result(db,•e_id,•'failed',•error,•participant)
  3122.  
  3123. liberapay/billing/exchanges.py
  3124. | 185| ••••••••payin•=•mangoapi.payIns.Create(payin)
  3125. | 186| ••••except•Exception•as•e:
  3126. | 187| ••••••••error•=•repr_exception(e)
  3127. | 188| ••••••••return•record_exchange_result(db,•e_id,•'failed',•error,•participant)
  3128. | | [NORMAL] CPDBear:
  3129. | | Duplicate code found.
  3130.  
  3131. tests/py/test_close.py
  3132. | 168| ••••••••alice.set_tip_to(bob,•D('0.00'))
  3133. | 169| ••••••••ntips•=•lambda:•self.db.one("SELECT•count(*)•FROM•tips•WHERE•tipper=%s",•(alice.id,))
  3134. | 170| ••••••••assert•ntips()•==•2
  3135.  
  3136. tests/py/test_close.py
  3137. | 176| ••••••••alice•=•self.make_participant('alice')
  3138. | 177| ••••••••ntips•=•lambda:•self.db.one("SELECT•count(*)•FROM•tips•WHERE•tipper=%s",•(alice.id,))
  3139. | 178| ••••••••assert•ntips()•==•0
  3140. | | [NORMAL] CPDBear:
  3141. | | Duplicate code found.
  3142.  
  3143. tests/py/test_close.py
  3144. | 216| ••••••••bob.set_tip_to(alice,•D('0.00'))
  3145. | 217| ••••••••ntips•=•lambda:•self.db.one("SELECT•count(*)•FROM•tips•WHERE•tippee=%s",•(alice.id,))
  3146. | 218| ••••••••assert•ntips()•==•2
  3147.  
  3148. tests/py/test_close.py
  3149. | 224| ••••••••alice•=•self.make_participant('alice')
  3150. | 225| ••••••••ntips•=•lambda:•self.db.one("SELECT•count(*)•FROM•tips•WHERE•tippee=%s",•(alice.id,))
  3151. | 226| ••••••••assert•ntips()•==•0
  3152. | | [NORMAL] CPDBear:
  3153. | | Duplicate code found.
  3154.  
  3155. tests/py/test_communities.py
  3156. | 10| class•Tests(Harness):
  3157. | 11|
  3158. | 12| ••••def•setUp(self):
  3159. | 13| ••••••••Harness.setUp(self)
  3160. | 14|
  3161.  
  3162. tests/py/test_settings.py
  3163. | 13| class•TestPrivacy(Harness):
  3164. | 14|
  3165. | 15| ••••def•setUp(self):
  3166. | 16| ••••••••Harness.setUp(self)
  3167. | 17| ••••••••self.alice•=•self.make_participant('alice')
  3168. | | [NORMAL] CPDBear:
  3169. | | Duplicate code found.
  3170.  
  3171. tests/py/test_billing_exchanges.py
  3172. | 290| ••••••••••••••••charge(self.db,•self.janet,•CHARGE_MIN,•'http://localhost/')
  3173. | 291| ••••••••exchange•=•self.db.one("SELECT•*•FROM•exchanges")
  3174. | 292| ••••••••assert•exchange.status•==•'pre'
  3175. | 293| ••••••••sync_with_mangopay(self.db)
  3176.  
  3177. tests/py/test_billing_exchanges.py
  3178. | 303| ••••••••••••••••charge(self.db,•self.janet,•D('33.67'),•'http://localhost/')
  3179. | 304| ••••••••exchange•=•self.db.one("SELECT•*•FROM•exchanges")
  3180. | 305| ••••••••assert•exchange.status•==•'pre'
  3181. | 306| ••••••••sync_with_mangopay(self.db)
  3182. | | [NORMAL] CPDBear:
  3183. | | Duplicate code found.
  3184.  
  3185. tests/py/test_billing_payday.py
  3186. | 341| ••••••••self.clear_tables()
  3187. | 342| ••••••••team•=•self.make_participant('team',•kind='group')
  3188. | 343| ••••••••alice•=•self.make_participant('alice')
  3189.  
  3190. tests/py/test_billing_payday.py
  3191. | 385| ••••••••self.clear_tables()
  3192. | 386| ••••••••team•=•self.make_participant('team',•kind='group')
  3193. | 387| ••••••••alice•=•self.make_participant('alice')
  3194. | | [NORMAL] CPDBear:
  3195. | | Duplicate code found.
  3196.  
  3197. liberapay/elsewhere/_extractors.py
  3198. | 82| ••••••••••••••••msg•%=•(path,•self.name,•ET.tostring(info))
  3199. | 83| ••••••••••••••••log(msg)
  3200. | 84| ••••••••••••••••raise•ValueError(msg)
  3201.  
  3202. liberapay/elsewhere/_extractors.py
  3203. | 104| ••••••••••••msg•%=•(path,•self.name,•ET.tostring(info))
  3204. | 105| ••••••••••••log(msg)
  3205. | 106| ••••••••••••raise•ValueError(msg)
  3206. | | [NORMAL] CPDBear:
  3207. | | Duplicate code found.
  3208.  
  3209. tests/py/test_pages.py
  3210. | 120| ••••def•test_sign_out_overwrites_session_cookie(self):
  3211. | 121| ••••••••alice•=•self.make_participant('alice')
  3212. | 122| ••••••••response•=•self.client.PxST('/sign-out.html',•auth_as=alice)
  3213.  
  3214. tests/py/test_pages.py
  3215. | 126| ••••def•test_sign_out_doesnt_redirect_xhr(self):
  3216. | 127| ••••••••alice•=•self.make_participant('alice')
  3217. | 128| ••••••••response•=•self.client.PxST('/sign-out.html',•auth_as=alice,•xhr=True)
  3218. | | [NORMAL] CPDBear:
  3219. | | Duplicate code found.
  3220.  
  3221. liberapay/elsewhere/openstreetmap.py
  3222. | 1| from•__future__•import•absolute_import,•division,•print_function,•unicode_literals
  3223. | 2|
  3224. | 3| from•liberapay.elsewhere._base•import•PlatformOAuth1
  3225. | 4| from•liberapay.elsewhere._extractors•import•not_available,•xpath
  3226.  
  3227. liberapay/elsewhere/twitter.py
  3228. | 1| from•__future__•import•absolute_import,•division,•print_function,•unicode_literals
  3229. | 2|
  3230. | 3| from•liberapay.elsewhere._base•import•PlatformOAuth1
  3231. | 4| from•liberapay.elsewhere._extractors•import•key,•not_available
  3232. | | [NORMAL] CPDBear:
  3233. | | Duplicate code found.
  3234.  
  3235. tests/py/test_elsewhere.py
  3236. | 183| ••••••••response•=•self.client.GxT(url,•auth_as=self.bob)
  3237. | 184| ••••••••assert•response.code•==•400
  3238. | 185| ••••••••assert•'bad•connect•token'•in•response.text
  3239. | 186|
  3240. | 187| ••••••••response•=•self.client.GET(url,•auth_as=self.bob,•cookies=self.connect_cookie)
  3241.  
  3242. tests/py/test_elsewhere.py
  3243. | 197| ••••••••response•=•self.client.PxST('/on/take-over.html',•data=data,•auth_as=self.bob)
  3244. | 198| ••••••••assert•response.code•==•400
  3245. | 199| ••••••••assert•'bad•connect•token'•in•response.text
  3246. | 200|
  3247. | 201| ••••••••response•=•self.client.PxST('/on/take-over.html',•data=data,•auth_as=self.bob,
  3248. | | [NORMAL] CPDBear:
  3249. | | Duplicate code found.
  3250.  
  3251. tests/py/test_participant.py
  3252. | 280| ••••def•test_stt_works_for_donations(self):
  3253. | 281| ••••••••alice•=•self.make_participant('alice',•balance=100)
  3254. | 282| ••••••••bob•=•self.make_participant('bob')
  3255.  
  3256. tests/py/test_participant.py
  3257. | 289| ••••def•test_stt_returns_False_for_second_time_tipper(self):
  3258. | 290| ••••••••alice•=•self.make_participant('alice',•balance=100)
  3259. | 291| ••••••••bob•=•self.make_participant('bob')
  3260.  
  3261. tests/py/test_participant.py
  3262. | 302| ••••def•test_stt_doesnt_allow_just_any_ole_amount(self):
  3263. | 303| ••••••••alice•=•self.make_participant('alice',•balance=100)
  3264. | 304| ••••••••bob•=•self.make_participant('bob')
  3265.  
  3266. tests/py/test_participant.py
  3267. | 315| ••••def•test_only_funded_tips_count(self):
  3268. | 316| ••••••••alice•=•self.make_participant('alice',•balance=100)
  3269. | 317| ••••••••bob•=•self.make_participant('bob')
  3270.  
  3271. tests/py/test_participant.py
  3272. | 357| ••••def•test_receiving_is_zero_for_patrons(self):
  3273. | 358| ••••••••alice•=•self.make_participant('alice',•balance=100)
  3274. | 359| ••••••••bob•=•self.make_participant('bob')
  3275.  
  3276. tests/py/test_public_json.py
  3277. | 10| ••••def•test_anonymous(self):
  3278. | 11| ••••••••alice•=•self.make_participant('alice',•balance=100)
  3279. | 12| ••••••••bob•=•self.make_participant('bob')
  3280.  
  3281. tests/py/test_public_json.py
  3282. | 60| ••••def•test_authenticated_user_gets_their_tip(self):
  3283. | 61| ••••••••alice•=•self.make_participant('alice',•balance=100)
  3284. | 62| ••••••••bob•=•self.make_participant('bob')
  3285.  
  3286. tests/py/test_public_json.py
  3287. | 104| ••••def•test_authenticated_user_gets_self_for_self(self):
  3288. | 105| ••••••••alice•=•self.make_participant('alice',•balance=100)
  3289. | 106| ••••••••bob•=•self.make_participant('bob')
  3290.  
  3291. tests/py/test_public_json.py
  3292. | 123| ••••def•test_jsonp_works(self):
  3293. | 124| ••••••••alice•=•self.make_participant('alice',•balance=100)
  3294. | 125| ••••••••bob•=•self.make_participant('bob')
  3295. | | [NORMAL] CPDBear:
  3296. | | Duplicate code found.
  3297.  
  3298. tests/py/test_participant.py
  3299. | 338| ••••def•test_only_latest_tip_counts(self):
  3300. | 339| ••••••••alice•=•self.make_participant('alice',•balance=100)
  3301. | 340| ••••••••bob•=•self.make_participant('bob',•balance=100)
  3302.  
  3303. tests/py/test_participant.py
  3304. | 351| ••••def•test_receiving_includes_taking_when_updated_from_set_tip_to(self):
  3305. | 352| ••••••••alice•=•self.make_participant('alice',•balance=100)
  3306. | 353| ••••••••bob•=•self.make_participant('bob',•taking=Decimal('42.00'))
  3307.  
  3308. tests/py/test_public_json.py
  3309. | 73| ••••def•test_authenticated_user_doesnt_get_other_peoples_tips(self):
  3310. | 74| ••••••••alice•=•self.make_participant('alice',•balance=100)
  3311. | 75| ••••••••bob•=•self.make_participant('bob',•balance=100)
  3312.  
  3313. tests/py/test_public_json.py
  3314. | 90| ••••def•test_authenticated_user_gets_zero_if_they_dont_tip(self):
  3315. | 91| ••••••••alice•=•self.make_participant('alice',•balance=100)
  3316. | 92| ••••••••bob•=•self.make_participant('bob',•balance=100)
  3317. | | [NORMAL] CPDBear:
  3318. | | Duplicate code found.
  3319.  
  3320. tests/py/test_search.py
  3321. | 10| ••••••••response•=•self.client.GET('/search.json?q=alice&scope=usernames')
  3322. | 11| ••••••••data•=•json.loads(response.body)['usernames']
  3323. | 12| ••••••••assert•data•==•[]
  3324.  
  3325. tests/py/test_search.py
  3326. | 16| ••••••••response•=•self.client.GET('/search.json?q=alice&scope=usernames')
  3327. | 17| ••••••••data•=•json.loads(response.body)['usernames']
  3328. | 18| ••••••••assert•len(data)•==•1
  3329. | | [NORMAL] CPDBear:
  3330. | | Duplicate code found.
  3331.  
  3332. tests/py/test_tips_json.py
  3333. | 24| •••••••••••••••••••••••••••••••••••,•auth_as=test_tipper
  3334. | 25| ••••••••••••••••••••••••••••••••••••)
  3335. | 26|
  3336. | 27| ••••••••assert•response.code•==•200
  3337. | 28| ••••••••assert•len(json.loads(response.body))•==•2
  3338.  
  3339. tests/py/test_tips_json.py
  3340. | 40| ••••••••response•=•self.client.GET('/test_tipper/tips.json',•auth_as=test_tipper)
  3341. | 41| ••••••••assert•response.code•==•200
  3342. | 42| ••••••••assert•len(json.loads(response.body))•==•tippees
  3343. | 43|
  3344. | 44| ••••def•test_get_response(self):
  3345.  
  3346. tests/py/test_tips_json.py
  3347. | 47| ••••••••response•=•self.client.GET('/test_tipper/tips.json',•auth_as=test_tipper)
  3348. | 48|
  3349. | 49| ••••••••assert•response.code•==•200
  3350. | 50| ••••••••assert•len(json.loads(response.body))•==•0•#•empty•array
  3351. | 51|
  3352. | | [NORMAL] CPDBear:
  3353. | | Duplicate code found.
  3354.  
  3355. tests/py/test_email.py
  3356. | 222| ••••••••larry.queue_email("verification",•link='https://example.com/larry')
  3357. | 223|
  3358. | 224| ••••••••assert•self.db.one("SELECT•spt_name•FROM•email_queue")•==•"verification"
  3359. | 225| ••••••••Participant.dequeue_emails()
  3360. | 226| ••••••••assert•self.mailer.call_count•==•1
  3361.  
  3362. tests/py/test_email.py
  3363. | 235| ••••••••larry.queue_email("verification")
  3364. | 236|
  3365. | 237| ••••••••assert•self.db.one("SELECT•spt_name•FROM•email_queue")•==•"verification"
  3366. | 238| ••••••••Participant.dequeue_emails()
  3367. | 239| ••••••••assert•self.mailer.call_count•==•0
  3368. | | [NORMAL] CPDBear:
  3369. | | Duplicate code found.
  3370.  
  3371. tests/py/test_close.py
  3372. | 91| ••••••••alice.set_tip_to(bob,•D('3.00'))
  3373. | 92| ••••••••alice.set_tip_to(carl,•D('2.00'))
  3374. | 93| ••••••••with•self.db.get_cursor()•as•cursor:
  3375.  
  3376. tests/py/test_close.py
  3377. | 116| ••••••••alice.set_tip_to(bob,•D('0.00'))
  3378. | 117| ••••••••alice.set_tip_to(carl,•D('2.00'))
  3379. | 118| ••••••••with•self.db.get_cursor()•as•cursor:
  3380. | | [NORMAL] CPDBear:
  3381. | | Duplicate code found.
  3382.  
  3383. tests/py/test_close.py
  3384. | 160| ••••••••with•self.db.get_cursor()•as•cursor:
  3385. | 161| ••••••••••••alice.clear_tips_giving(cursor)
  3386. | 162| ••••••••assert•ntips()•==•0
  3387. | 163|
  3388. | 164| ••••def•test_ctg_doesnt_duplicate_zero_tips(self):
  3389.  
  3390. tests/py/test_close.py
  3391. | 179| ••••••••with•self.db.get_cursor()•as•cursor:
  3392. | 180| ••••••••••••alice.clear_tips_giving(cursor)
  3393. | 181| ••••••••assert•ntips()•==•0
  3394. | 182|
  3395. | 183| ••••def•test_ctg_clears_multiple_tips_giving(self):
  3396.  
  3397. tests/py/test_close.py
  3398. | 194| ••••••••with•self.db.get_cursor()•as•cursor:
  3399. | 195| ••••••••••••alice.clear_tips_giving(cursor)
  3400. | 196| ••••••••assert•ntips()•==•0
  3401. | 197|
  3402. | 198|
  3403. | | [NORMAL] CPDBear:
  3404. | | Duplicate code found.
  3405.  
  3406. tests/py/test_close.py
  3407. | 208| ••••••••with•self.db.get_cursor()•as•cursor:
  3408. | 209| ••••••••••••alice.clear_tips_receiving(cursor)
  3409. | 210| ••••••••assert•ntips()•==•0
  3410. | 211|
  3411. | 212| ••••def•test_ctr_doesnt_duplicate_zero_tips(self):
  3412.  
  3413. tests/py/test_close.py
  3414. | 227| ••••••••with•self.db.get_cursor()•as•cursor:
  3415. | 228| ••••••••••••alice.clear_tips_receiving(cursor)
  3416. | 229| ••••••••assert•ntips()•==•0
  3417. | 230|
  3418. | 231| ••••def•test_ctr_clears_multiple_tips_receiving(self):
  3419.  
  3420. tests/py/test_close.py
  3421. | 242| ••••••••with•self.db.get_cursor()•as•cursor:
  3422. | 243| ••••••••••••alice.clear_tips_receiving(cursor)
  3423. | 244| ••••••••assert•ntips()•==•0
  3424. | 245|
  3425. | 246|
  3426. | | [NORMAL] CPDBear:
  3427. | | Duplicate code found.
  3428.  
  3429. tests/py/test_communities.py
  3430. | 10| class•Tests(Harness):
  3431. | 11|
  3432. | 12| ••••def•setUp(self):
  3433. | 13| ••••••••Harness.setUp(self)
  3434. | 14|
  3435.  
  3436. tests/py/test_communities.py
  3437. | 25| class•TestCommunitiesJson(Harness):
  3438. | 26|
  3439. | 27| ••••def•setUp(self):
  3440. | 28| ••••••••Harness.setUp(self)
  3441. | 29| ••••••••self.alice•=•self.make_participant("alice")
  3442.  
  3443. tests/py/test_communities.py
  3444. | 63| class•TestCommunityActions(Harness):
  3445. | 64|
  3446. | 65| ••••def•setUp(self):
  3447. | 66| ••••••••Harness.setUp(self)
  3448. | 67| ••••••••self.alice•=•self.make_participant("alice")
  3449.  
  3450. tests/py/test_communities.py
  3451. | 108| class•TestCommunityEdit(Harness):
  3452. | 109|
  3453. | 110| ••••def•setUp(self):
  3454. | 111| ••••••••Harness.setUp(self)
  3455. | 112| ••••••••self.alice•=•self.make_participant("alice")
  3456.  
  3457. tests/py/test_settings.py
  3458. | 13| class•TestPrivacy(Harness):
  3459. | 14|
  3460. | 15| ••••def•setUp(self):
  3461. | 16| ••••••••Harness.setUp(self)
  3462. | 17| ••••••••self.alice•=•self.make_participant('alice')
  3463. | | [NORMAL] CPDBear:
  3464. | | Duplicate code found.
  3465.  
  3466. tests/py/test_billing_exchanges.py
  3467. | 145| ••••••••janet•=•Participant.from_id(self.janet.id)
  3468. | 146| ••••••••assert•self.janet.balance•==•janet.balance•==•0
  3469.  
  3470. tests/py/test_billing_exchanges.py
  3471. | 241| ••••••••janet•=•Participant.from_id(self.janet.id)
  3472. | 242| ••••••••assert•self.janet.balance•==•janet.balance•==•0
  3473. | | [NORMAL] CPDBear:
  3474. | | Duplicate code found.
  3475.  
  3476. tests/py/test_billing_exchanges.py
  3477. | 154| ••••••••bob•=•self.make_participant('bob')
  3478. | 155| ••••••••with•self.assertRaises(AssertionError):
  3479. | 156| ••••••••••••charge(self.db,•bob,•D('10.00'),•'http://localhost/')
  3480.  
  3481. tests/py/test_billing_exchanges.py
  3482. | 159| ••••••••bob•=•self.make_participant('bob',•last_bill_result='invalidated')
  3483. | 160| ••••••••with•self.assertRaises(AssertionError):
  3484. | 161| ••••••••••••charge(self.db,•bob,•D('10.00'),•'http://localhost/')
  3485. | | [NORMAL] CPDBear:
  3486. | | Duplicate code found.
  3487.  
  3488. liberapay/elsewhere/facebook.py
  3489. | 31| ••••x_user_id•=•key('id')
  3490. | 32| ••••x_user_name•=•key('username')
  3491. | 33| ••••x_display_name•=•key('name')
  3492. | 34| ••••x_email•=•key('email')
  3493.  
  3494. liberapay/elsewhere/gitlab.py
  3495. | 34| ••••x_user_id•=•key('id')
  3496. | 35| ••••x_user_name•=•key('username')
  3497. | 36| ••••x_display_name•=•key('name')
  3498. | 37| ••••x_email•=•key('email')
  3499. | | [NORMAL] CPDBear:
  3500. | | Duplicate code found.
  3501.  
  3502. tests/py/test_public_json.py
  3503. | 51| ••••••••self.make_participant('alice',•balance=100)
  3504. | 52| ••••••••data•=•json.loads(self.client.GET('/alice/public.json').body)
  3505. | 53| ••••••••assert•data['goal']•==•None
  3506.  
  3507. tests/py/test_public_json.py
  3508. | 56| ••••••••self.make_participant('alice',•balance=100,•goal=1)
  3509. | 57| ••••••••data•=•json.loads(self.client.GET('/alice/public.json').body)
  3510. | 58| ••••••••assert•data['goal']•==•'1.00'
  3511. | | [NORMAL] CPDBear:
  3512. | | Duplicate code found.
  3513.  
  3514. tests/py/test_public_json.py
  3515. | 97| ••••••••raw•=•self.client.GET('/carl/public.json',•auth_as=alice).body
  3516. | 98|
  3517. | 99| ••••••••data•=•json.loads(raw)
  3518. | 100|
  3519. | 101| ••••••••assert•data['receiving']•==•'3.00'
  3520. | 102| ••••••••assert•data['my_tip']•==•'0.00'
  3521.  
  3522. tests/py/test_public_json.py
  3523. | 110| ••••••••raw•=•self.client.GET('/bob/public.json',•auth_as=bob).body
  3524. | 111|
  3525. | 112| ••••••••data•=•json.loads(raw)
  3526. | 113|
  3527. | 114| ••••••••assert•data['receiving']•==•'3.00'
  3528. | 115| ••••••••assert•data['my_tip']•==•'self'
  3529. | | [NORMAL] CPDBear:
  3530. | | Duplicate code found.
  3531.  
  3532. tests/py/test_billing_payday.py
  3533. | 341| ••••••••self.clear_tables()
  3534. | 342| ••••••••team•=•self.make_participant('team',•kind='group')
  3535. | 343| ••••••••alice•=•self.make_participant('alice')
  3536.  
  3537. tests/py/test_billing_payday.py
  3538. | 365| ••••••••self.clear_tables()
  3539. | 366| ••••••••team•=•self.make_participant('team',•kind='group')
  3540. | 367| ••••••••alice•=•self.make_participant('alice',•balance=8)
  3541. | | [NORMAL] CPDBear:
  3542. | | Duplicate code found.
  3543.  
  3544. liberapay/elsewhere/_extractors.py
  3545. | 53| def•key(k,•clean=lambda•a:•a):
  3546. | 54| ••••def•f(self,•extracted,•info,•*default):
  3547. | 55| ••••••••try:
  3548.  
  3549. liberapay/elsewhere/_extractors.py
  3550. | 76| def•xpath(path,•attr=None,•clean=lambda•a:•a):
  3551. | 77| ••••def•f(self,•extracted,•info,•*default):
  3552. | 78| ••••••••try:
  3553. | | [NORMAL] CPDBear:
  3554. | | Duplicate code found.
  3555.  
  3556. tests/py/test_participant.py
  3557. | 280| ••••def•test_stt_works_for_donations(self):
  3558. | 281| ••••••••alice•=•self.make_participant('alice',•balance=100)
  3559. | 282| ••••••••bob•=•self.make_participant('bob')
  3560.  
  3561. tests/py/test_participant.py
  3562. | 289| ••••def•test_stt_returns_False_for_second_time_tipper(self):
  3563. | 290| ••••••••alice•=•self.make_participant('alice',•balance=100)
  3564. | 291| ••••••••bob•=•self.make_participant('bob')
  3565.  
  3566. tests/py/test_participant.py
  3567. | 302| ••••def•test_stt_doesnt_allow_just_any_ole_amount(self):
  3568. | 303| ••••••••alice•=•self.make_participant('alice',•balance=100)
  3569. | 304| ••••••••bob•=•self.make_participant('bob')
  3570.  
  3571. tests/py/test_participant.py
  3572. | 315| ••••def•test_only_funded_tips_count(self):
  3573. | 316| ••••••••alice•=•self.make_participant('alice',•balance=100)
  3574. | 317| ••••••••bob•=•self.make_participant('bob')
  3575.  
  3576. tests/py/test_participant.py
  3577. | 338| ••••def•test_only_latest_tip_counts(self):
  3578. | 339| ••••••••alice•=•self.make_participant('alice',•balance=100)
  3579. | 340| ••••••••bob•=•self.make_participant('bob',•balance=100)
  3580.  
  3581. tests/py/test_participant.py
  3582. | 351| ••••def•test_receiving_includes_taking_when_updated_from_set_tip_to(self):
  3583. | 352| ••••••••alice•=•self.make_participant('alice',•balance=100)
  3584. | 353| ••••••••bob•=•self.make_participant('bob',•taking=Decimal('42.00'))
  3585.  
  3586. tests/py/test_participant.py
  3587. | 357| ••••def•test_receiving_is_zero_for_patrons(self):
  3588. | 358| ••••••••alice•=•self.make_participant('alice',•balance=100)
  3589. | 359| ••••••••bob•=•self.make_participant('bob')
  3590.  
  3591. tests/py/test_public_json.py
  3592. | 10| ••••def•test_anonymous(self):
  3593. | 11| ••••••••alice•=•self.make_participant('alice',•balance=100)
  3594. | 12| ••••••••bob•=•self.make_participant('bob')
  3595.  
  3596. tests/py/test_public_json.py
  3597. | 60| ••••def•test_authenticated_user_gets_their_tip(self):
  3598. | 61| ••••••••alice•=•self.make_participant('alice',•balance=100)
  3599. | 62| ••••••••bob•=•self.make_participant('bob')
  3600.  
  3601. tests/py/test_public_json.py
  3602. | 73| ••••def•test_authenticated_user_doesnt_get_other_peoples_tips(self):
  3603. | 74| ••••••••alice•=•self.make_participant('alice',•balance=100)
  3604. | 75| ••••••••bob•=•self.make_participant('bob',•balance=100)
  3605.  
  3606. tests/py/test_public_json.py
  3607. | 90| ••••def•test_authenticated_user_gets_zero_if_they_dont_tip(self):
  3608. | 91| ••••••••alice•=•self.make_participant('alice',•balance=100)
  3609. | 92| ••••••••bob•=•self.make_participant('bob',•balance=100)
  3610.  
  3611. tests/py/test_public_json.py
  3612. | 104| ••••def•test_authenticated_user_gets_self_for_self(self):
  3613. | 105| ••••••••alice•=•self.make_participant('alice',•balance=100)
  3614. | 106| ••••••••bob•=•self.make_participant('bob')
  3615.  
  3616. tests/py/test_public_json.py
  3617. | 123| ••••def•test_jsonp_works(self):
  3618. | 124| ••••••••alice•=•self.make_participant('alice',•balance=100)
  3619. | 125| ••••••••bob•=•self.make_participant('bob')
  3620. | | [NORMAL] CPDBear:
  3621. | | Duplicate code found.
  3622.  
  3623. liberapay/elsewhere/facebook.py
  3624. | 1| from•__future__•import•absolute_import,•division,•print_function,•unicode_literals
  3625. | 2|
  3626. | 3| from•liberapay.elsewhere._base•import•PlatformOAuth2
  3627. | 4| from•liberapay.elsewhere._extractors•import•key
  3628.  
  3629. liberapay/elsewhere/github.py
  3630. | 1| from•__future__•import•absolute_import,•division,•print_function,•unicode_literals
  3631. | 2|
  3632. | 3| from•liberapay.elsewhere._base•import•PlatformOAuth2
  3633. | 4| from•liberapay.elsewhere._exceptions•import•CantReadMembership
  3634.  
  3635. liberapay/elsewhere/gitlab.py
  3636. | 1| from•__future__•import•absolute_import,•division,•print_function,•unicode_literals
  3637. | 2|
  3638. | 3| from•liberapay.elsewhere._base•import•PlatformOAuth2
  3639. | 4| from•liberapay.elsewhere._extractors•import•key
  3640.  
  3641. liberapay/elsewhere/google.py
  3642. | 1| from•__future__•import•absolute_import,•division,•print_function,•unicode_literals
  3643. | 2|
  3644. | 3| from•liberapay.elsewhere._base•import•PlatformOAuth2
  3645. | 4| from•liberapay.elsewhere._extractors•import•any_key,•key
  3646.  
  3647. liberapay/elsewhere/linuxfr.py
  3648. | 1| from•__future__•import•absolute_import,•division,•print_function,•unicode_literals
  3649. | 2|
  3650. | 3| from•liberapay.elsewhere._base•import•PlatformOAuth2
  3651. | 4| from•liberapay.elsewhere._extractors•import•key
  3652. | | [NORMAL] CPDBear:
  3653. | | Duplicate code found.
  3654.  
  3655. tests/py/test_close.py
  3656. | 47| ••••def•test_close_page_is_not_available_during_payday(self):
  3657. | 48| ••••••••Payday.start()
  3658. | 49| ••••••••alice•=•self.make_participant('alice')
  3659. | 50| ••••••••body•=•self.client.GET('/alice/settings/close',•auth_as=alice).text
  3660.  
  3661. tests/py/test_close.py
  3662. | 66| ••••def•test_cant_post_to_close_page_during_payday(self):
  3663. | 67| ••••••••Payday.start()
  3664. | 68| ••••••••alice•=•self.make_participant('alice')
  3665. | 69| ••••••••body•=•self.client.POST('/alice/settings/close',•auth_as=alice).text
  3666. | | [NORMAL] CPDBear:
  3667. | | Duplicate code found.
  3668.  
  3669. tests/py/test_close.py
  3670. | 75| ••••def•test_dbafg_distributes_balance_as_final_gift(self):
  3671. | 76| ••••••••alice•=•self.make_participant('alice',•balance=D('10.00'))
  3672. | 77| ••••••••bob•=•self.make_participant('bob')
  3673.  
  3674. tests/py/test_close.py
  3675. | 87| ••••def•test_dbafg_needs_claimed_tips(self):
  3676. | 88| ••••••••alice•=•self.make_participant('alice',•balance=D('10.00'))
  3677. | 89| ••••••••bob•=•self.make_stub()
  3678.  
  3679. tests/py/test_close.py
  3680. | 100| ••••def•test_dbafg_gives_all_to_claimed(self):
  3681. | 101| ••••••••alice•=•self.make_participant('alice',•balance=D('10.00'))
  3682. | 102| ••••••••bob•=•self.make_participant('bob')
  3683.  
  3684. tests/py/test_close.py
  3685. | 112| ••••def•test_dbafg_skips_zero_tips(self):
  3686. | 113| ••••••••alice•=•self.make_participant('alice',•balance=D('10.00'))
  3687. | 114| ••••••••bob•=•self.make_participant('bob')
  3688.  
  3689. tests/py/test_close.py
  3690. | 125| ••••def•test_dbafg_favors_highest_tippee_in_rounding_errors(self):
  3691. | 126| ••••••••alice•=•self.make_participant('alice',•balance=D('10.00'))
  3692. | 127| ••••••••bob•=•self.make_participant('bob')
  3693. | | [NORMAL] CPDBear:
  3694. | | Duplicate code found.
  3695.  
  3696. tests/py/test_tip_json.py
  3697. | 63| ••••••••response•=•self.tip(bob,•alice.participant.username,•"10.00")
  3698. | 64| ••••••••data•=•json.loads(response.body)
  3699. | 65| ••••••••assert•response.code•==•200
  3700. | 66| ••••••••assert•data['amount']•==•"10.00"
  3701.  
  3702. tests/py/test_tip_json.py
  3703. | 70| ••••••••response•=•self.tip(bob,•alice.participant.username,•"0.00")
  3704. | 71| ••••••••data•=•json.loads(response.body)
  3705. | 72| ••••••••assert•response.code•==•200
  3706. | 73| ••••••••assert•data['amount']•==•"0.00"
  3707. | | [NORMAL] CPDBear:
  3708. | | Duplicate code found.
  3709.  
  3710. liberapay/elsewhere/_paginators.py
  3711. | 60| ••••••••total_count•=•parsed.get(total_key,•-1)•if•links•else•len(page)
  3712. | 61| ••••••••return•page,•total_count,•links
  3713. | 62| ••••return•f
  3714.  
  3715. liberapay/elsewhere/_paginators.py
  3716. | 88| ••••••••total_count•=•paging.get(total_key,•-1)•if•links•else•len(page)
  3717. | 89| ••••••••return•page,•total_count,•links
  3718. | 90| ••••return•f
  3719. | | [NORMAL] CPDBear:
  3720. | | Duplicate code found.
  3721.  
  3722. tests/py/test_public_json.py
  3723. | 20| ••••••••data•=•json.loads(self.client.GET('/alice/public.json').body)
  3724. | 21| ••••••••assert•data['giving']•==•'1.00'
  3725.  
  3726. tests/py/test_public_json.py
  3727. | 30| ••••••••data•=•json.loads(self.client.GET('/alice/public.json').body)
  3728. | 31|
  3729. | | [NORMAL] CPDBear:
  3730. | | Duplicate code found.
  3731.  
  3732. liberapay/utils/fake_data.py
  3733. | 173| ••••••••team•=•fake_participant(db,•kind="group")
  3734. | 174| ••••••••#Add•1•to•3•members•to•the•team
  3735. | 175| ••••••••members•=•random.sample(participants,•random.randint(1,•3))
  3736. | 176| ••••••••for•p•in•members:
  3737.  
  3738. liberapay/utils/fake_data.py
  3739. | 192| ••••••••community•=•fake_community(db,•creator[0])
  3740. | 193|
  3741. | 194| ••••••••members•=•random.sample(participants,•random.randint(1,•3))
  3742. | 195| ••••••••for•p•in•members:
  3743. | | [NORMAL] CPDBear:
  3744. | | Duplicate code found.
  3745.  
  3746. tests/py/test_charts_json.py
  3747. | 38| ••••••••self.run_payday()•••#•first
  3748. | 39|
  3749. | 40| ••••••••expected•=•[•{•"date":•today()
  3750. | 41| •••••••••••••••••••••,•"npatrons":•2
  3751. | 42| •••••••••••••••••••••,•"receipts":•3.00
  3752. | 43| ••••••••••••••••••••••}
  3753.  
  3754. tests/py/test_charts_json.py
  3755. | 106| ••••••••self.run_payday()•••#•third
  3756. | 107|
  3757. | 108| ••••••••expected•=•[•{•"date":•today()
  3758. | 109| •••••••••••••••••••••,•"npatrons":•2•#•most•recent•first
  3759. | 110| •••••••••••••••••••••,•"receipts":•3.00
  3760. | 111| ••••••••••••••••••••••}
  3761. | | [NORMAL] CPDBear:
  3762. | | Duplicate code found.
  3763.  
  3764. tests/py/test_elsewhere.py
  3765. | 26| ••••def•test_extract_user_info(self):
  3766. | 27| ••••••••for•platform•in•self.platforms:
  3767. | 28| ••••••••••••user_info•=•getattr(user_info_examples,•platform.name)()
  3768.  
  3769. tests/py/test_elsewhere.py
  3770. | 91| ••••def•test_upsert(self):
  3771. | 92| ••••••••for•platform•in•self.platforms:
  3772. | 93| ••••••••••••user_info•=•getattr(user_info_examples,•platform.name)()
  3773. | | [NORMAL] CPDBear:
  3774. | | Duplicate code found.
  3775.  
  3776. tests/py/test_participant.py
  3777. | 50| ••••def•test_cross_tip_doesnt_become_self_tip(self):
  3778. | 51| ••••••••alice•=•self.make_participant('alice',•elsewhere='twitter')
  3779. | 52| ••••••••bob•=•self.make_elsewhere('twitter',•2,•'bob')
  3780.  
  3781. tests/py/test_participant.py
  3782. | 89| ••••def•test_idempotent(self):
  3783. | 90| ••••••••alice•=•self.make_participant('alice',•elsewhere='twitter')
  3784. | 91| ••••••••bob•=•self.make_elsewhere('github',•2,•'bob')
  3785. | | [NORMAL] CPDBear:
  3786. | | Duplicate code found.
  3787.  
  3788. tests/py/test_participant.py
  3789. | 261| ••••def•test_stt_sets_tip_to(self):
  3790. | 262| ••••••••alice•=•self.make_participant('alice',•balance=100)
  3791. | 263| ••••••••bob•=•self.make_stub()
  3792.  
  3793. tests/py/test_participant.py
  3794. | 370| ••••def•test_cant_pledge_to_locked_accounts(self):
  3795. | 371| ••••••••alice•=•self.make_participant('alice',•balance=100)
  3796. | 372| ••••••••bob•=•self.make_stub(goal=-1)
  3797. | | [NORMAL] CPDBear:
  3798. | | Duplicate code found.
  3799.  
  3800. tests/py/test_billing_payday.py
  3801. | 74| ••••••••••••assert•emma.npatrons•==•1
  3802. | 75| ••••••••••••funded_tips•=•self.db.all("SELECT•amount•FROM•tips•WHERE•is_funded•ORDER•BY•id")
  3803. | 76| ••••••••••••assert•funded_tips•==•[3,•6,•0.5,•D('1.20'),•D('0.49'),•5,•2]
  3804. | 77|
  3805.  
  3806. tests/py/test_participant.py
  3807. | 333| ••••••••assert•dana.npatrons•==•1
  3808. | 334|
  3809. | 335| ••••••••funded_tips•=•self.db.all("SELECT•amount•FROM•tips•WHERE•is_funded•ORDER•BY•id")
  3810. | 336| ••••••••assert•funded_tips•==•[3,•6,•5]
  3811. | | [NORMAL] CPDBear:
  3812. | | Duplicate code found.
  3813.  
  3814. tests/py/test_teams.py
  3815. | 60| ••••••••self.a_team.invite(self.bob,•self.alice)
  3816. | 61| ••••••••r•=•self.client.PxST('/A-Team/membership/refuse',•auth_as=self.bob)
  3817.  
  3818. tests/py/test_teams.py
  3819. | 68| ••••••••self.a_team.invite(self.bob,•self.alice)
  3820. | 69|
  3821. | | [NORMAL] CPDBear:
  3822. | | Duplicate code found.
  3823.  
  3824. tests/py/test_billing_payday.py
  3825. | 38| ••••••••team•=•self.make_participant('team',•kind='group')
  3826. | 39| ••••••••alice•=•self.make_participant('alice',•balance=100)
  3827.  
  3828. tests/py/test_billing_payday.py
  3829. | 366| ••••••••team•=•self.make_participant('team',•kind='group')
  3830. | 367| ••••••••alice•=•self.make_participant('alice',•balance=8)
  3831.  
  3832. tests/py/test_close.py
  3833. | 19| ••••••••team•=•self.make_participant('team',•kind='group')
  3834. | 20| ••••••••alice•=•self.make_participant('alice',•balance=D('10.00'))
  3835. | | [NORMAL] CPDBear:
  3836. | | Duplicate code found.
  3837.  
  3838. tests/py/test_close.py
  3839. | 105| ••••••••alice.set_tip_to(carl,•D('2.00'))
  3840. | 106| ••••••••with•self.db.get_cursor()•as•cursor:
  3841. | 107| ••••••••••••alice.distribute_balance_as_final_gift(cursor)
  3842. | 108| ••••••••assert•Participant.from_id(bob.id).balance•==•D('10.00')
  3843.  
  3844. tests/py/test_close.py
  3845. | 130| ••••••••alice.set_tip_to(carl,•D('6.00'))
  3846. | 131| ••••••••with•self.db.get_cursor()•as•cursor:
  3847. | 132| ••••••••••••alice.distribute_balance_as_final_gift(cursor)
  3848. | 133| ••••••••assert•Participant.from_username('bob').balance•==•D('3.33')
  3849. | | [NORMAL] CPDBear:
  3850. | | Duplicate code found.
  3851.  
  3852. tests/py/test_close.py
  3853. | 160| ••••••••with•self.db.get_cursor()•as•cursor:
  3854. | 161| ••••••••••••alice.clear_tips_giving(cursor)
  3855. | 162| ••••••••assert•ntips()•==•0
  3856.  
  3857. tests/py/test_close.py
  3858. | 171| ••••••••with•self.db.get_cursor()•as•cursor:
  3859. | 172| ••••••••••••alice.clear_tips_giving(cursor)
  3860. | 173| ••••••••assert•ntips()•==•2
  3861.  
  3862. tests/py/test_close.py
  3863. | 179| ••••••••with•self.db.get_cursor()•as•cursor:
  3864. | 180| ••••••••••••alice.clear_tips_giving(cursor)
  3865. | 181| ••••••••assert•ntips()•==•0
  3866.  
  3867. tests/py/test_close.py
  3868. | 194| ••••••••with•self.db.get_cursor()•as•cursor:
  3869. | 195| ••••••••••••alice.clear_tips_giving(cursor)
  3870. | 196| ••••••••assert•ntips()•==•0
  3871. | | [NORMAL] CPDBear:
  3872. | | Duplicate code found.
  3873.  
  3874. tests/py/test_close.py
  3875. | 175| ••••def•test_ctg_doesnt_zero_when_theres_no_tip(self):
  3876. | 176| ••••••••alice•=•self.make_participant('alice')
  3877. | 177| ••••••••ntips•=•lambda:•self.db.one("SELECT•count(*)•FROM•tips•WHERE•tipper=%s",•(alice.id,))
  3878.  
  3879. tests/py/test_close.py
  3880. | 223| ••••def•test_ctr_doesnt_zero_when_theres_no_tip(self):
  3881. | 224| ••••••••alice•=•self.make_participant('alice')
  3882. | 225| ••••••••ntips•=•lambda:•self.db.one("SELECT•count(*)•FROM•tips•WHERE•tippee=%s",•(alice.id,))
  3883. | | [NORMAL] CPDBear:
  3884. | | Duplicate code found.
  3885.  
  3886. tests/py/test_close.py
  3887. | 208| ••••••••with•self.db.get_cursor()•as•cursor:
  3888. | 209| ••••••••••••alice.clear_tips_receiving(cursor)
  3889. | 210| ••••••••assert•ntips()•==•0
  3890.  
  3891. tests/py/test_close.py
  3892. | 219| ••••••••with•self.db.get_cursor()•as•cursor:
  3893. | 220| ••••••••••••alice.clear_tips_receiving(cursor)
  3894. | 221| ••••••••assert•ntips()•==•2
  3895.  
  3896. tests/py/test_close.py
  3897. | 227| ••••••••with•self.db.get_cursor()•as•cursor:
  3898. | 228| ••••••••••••alice.clear_tips_receiving(cursor)
  3899. | 229| ••••••••assert•ntips()•==•0
  3900.  
  3901. tests/py/test_close.py
  3902. | 242| ••••••••with•self.db.get_cursor()•as•cursor:
  3903. | 243| ••••••••••••alice.clear_tips_receiving(cursor)
  3904. | 244| ••••••••assert•ntips()•==•0
  3905. | | [NORMAL] CPDBear:
  3906. | | Duplicate code found.
  3907.  
  3908. tests/py/test_billing_payday.py
  3909. | 315| ••••••••self.clear_tables()
  3910. | 316| ••••••••team•=•self.make_participant('team',•kind='group')
  3911. | 317| ••••••••alice•=•self.make_participant('alice')
  3912.  
  3913. tests/py/test_billing_payday.py
  3914. | 341| ••••••••self.clear_tables()
  3915. | 342| ••••••••team•=•self.make_participant('team',•kind='group')
  3916. | 343| ••••••••alice•=•self.make_participant('alice')
  3917.  
  3918. tests/py/test_billing_payday.py
  3919. | 385| ••••••••self.clear_tables()
  3920. | 386| ••••••••team•=•self.make_participant('team',•kind='group')
  3921. | 387| ••••••••alice•=•self.make_participant('alice')
  3922.  
  3923. tests/py/test_history.py
  3924. | 43| ••••••••Payday.start().run()
  3925. | 44| ••••••••team•=•self.make_participant('team',•kind='group')
  3926. | 45| ••••••••alice•=•self.make_participant('alice')
  3927. | | [NORMAL] CPDBear:
  3928. | | Duplicate code found.
  3929.  
  3930. tests/py/test_notifications.py
  3931. | 13| ••••def•test_remove_notification(self):
  3932. | 14| ••••••••alice•=•self.make_participant('alice')
  3933. | 15| ••••••••bob•=•self.make_participant('bob')
  3934. | 16| ••••••••alice.add_notification('abcd')
  3935.  
  3936. tests/py/test_pages.py
  3937. | 131| ••••def•test_giving_page(self):
  3938. | 132| ••••••••alice•=•self.make_participant('alice')
  3939. | 133| ••••••••bob•=•self.make_participant('bob')
  3940. | 134| ••••••••alice.set_tip_to(bob,•"1.00")
  3941.  
  3942. tests/py/test_pages.py
  3943. | 149| ••••def•test_giving_page_shows_cancelled(self):
  3944. | 150| ••••••••alice•=•self.make_participant('alice')
  3945. | 151| ••••••••bob•=•self.make_participant('bob')
  3946. | 152| ••••••••alice.set_tip_to(bob,•"1.00")
  3947. | | [NORMAL] CPDBear:
  3948. | | Duplicate code found.
  3949.  
  3950. tests/py/test_billing_payday.py
  3951. | 318| ••••••••team.set_take_for(alice,•D('1.00'),•alice)
  3952. | 319| ••••••••bob•=•self.make_participant('bob')
  3953. | 320| ••••••••team.set_take_for(bob,•D('1.00'),•bob)
  3954.  
  3955. tests/py/test_billing_payday.py
  3956. | 388| ••••••••alice.set_tip_to(team,•D('1.00'))••#•unfunded•tip
  3957. | 389| ••••••••bob•=•self.make_participant('bob')
  3958. | 390| ••••••••team.set_take_for(bob,•D('1.00'),•bob)
  3959. | | [NORMAL] CPDBear:
  3960. | | Duplicate code found.
  3961.  
  3962. tests/py/test_elsewhere.py
  3963. | 34| ••••@mock.patch('requests_oauthlib.OAuth2Session.fetch_token')
  3964. | 35| ••••@mock.patch('liberapay.elsewhere._base.Platform.get_user_self_info')
  3965. | 36| ••••@mock.patch('liberapay.elsewhere._base.Platform.get_user_info')
  3966. | 37| ••••def•test_connect_success(self,•gui,•gusi,•ft):
  3967.  
  3968. tests/py/test_elsewhere.py
  3969. | 52| ••••@mock.patch('requests_oauthlib.OAuth2Session.fetch_token')
  3970. | 53| ••••@mock.patch('liberapay.elsewhere._base.Platform.get_user_self_info')
  3971. | 54| ••••@mock.patch('liberapay.elsewhere._base.Platform.get_user_info')
  3972. | 55| ••••def•test_connect_might_need_confirmation(self,•gui,•gusi,•ft):
  3973. | | [NORMAL] CPDBear:
  3974. | | Duplicate code found.
  3975.  
  3976. tests/py/test_participant.py
  3977. | 297| ••••def•test_stt_doesnt_allow_self_tipping(self):
  3978. | 298| ••••••••alice•=•self.make_participant('alice',•balance=100)
  3979. | 299| ••••••••with•pytest.raises(NoSelfTipping):
  3980.  
  3981. tests/py/test_participant.py
  3982. | 308| ••••def•test_stt_fails_to_tip_unknown_people(self):
  3983. | 309| ••••••••alice•=•self.make_participant('alice',•balance=100)
  3984. | 310| ••••••••with•pytest.raises(NoTippee):
  3985. | | [NORMAL] CPDBear:
  3986. | | Duplicate code found.
  3987.  
  3988. liberapay/utils/fake_data.py
  3989. | 12| from•liberapay.models.exchange_route•import•ExchangeRoute
  3990. | 13| from•liberapay.models.participant•import•Participant
  3991. | 14| from•liberapay.models•import•community
  3992.  
  3993. liberapay/wireup.py
  3994. | 25| from•liberapay.models.exchange_route•import•ExchangeRoute
  3995. | 26| from•liberapay.models.participant•import•Participant
  3996. | 27| from•liberapay.models•import•DB
  3997. | | [NORMAL] CPDBear:
  3998. | | Duplicate code found.
  3999.  
  4000. liberapay/wireup.py
  4001. | 148| ••••••••k[5:]:•v•for•k,•v•in•app_conf.__dict__.items()•if•k.startswith('smtp_')
  4002.  
  4003. liberapay/wireup.py
  4004. | 250| ••••••••••••k[len(cls.name)+1:]:•v
  4005. | | [NORMAL] CPDBear:
  4006. | | Duplicate code found.
  4007.  
  4008. tests/py/test_email.py
  4009. | 114| ••••••••self.verify_email('alice@example.com',•nonce)
  4010. | 115| ••••••••expected•=•'alice@example.com'
  4011. | 116| ••••••••actual•=•Participant.from_username('alice').email
  4012. | 117| ••••••••assert•expected•==•actual
  4013. | 118|
  4014. | 119| ••••def•test_email_verification_is_backwards_compatible(self):
  4015.  
  4016. tests/py/test_email.py
  4017. | 144| ••••••••self.verify_email('alice@example.net',•nonce)
  4018. | 145| ••••••••expected•=•'alice@example.com'
  4019. | 146| ••••••••actual•=•Participant.from_username('alice').email
  4020. | 147| ••••••••assert•expected•==•actual
  4021. | 148|
  4022. | 149| ••••def•test_nonce_is_reused_when_resending_email(self):
  4023. | | [NORMAL] CPDBear:
  4024. | | Duplicate code found.
  4025.  
  4026. tests/py/test_close.py
  4027. | 94| ••••••••••••with•pytest.raises(alice.NoOneToGiveFinalGiftTo):
  4028. | 95| ••••••••••••••••alice.distribute_balance_as_final_gift(cursor)
  4029. | 96| ••••••••assert•Participant.from_id(bob.id).balance•==•D('0.00')
  4030.  
  4031. tests/py/test_close.py
  4032. | 106| ••••••••with•self.db.get_cursor()•as•cursor:
  4033. | 107| ••••••••••••alice.distribute_balance_as_final_gift(cursor)
  4034. | 108| ••••••••assert•Participant.from_id(bob.id).balance•==•D('10.00')
  4035. | | [NORMAL] CPDBear:
  4036. | | Duplicate code found.
  4037.  
  4038. tests/py/test_settings.py
  4039. | 45| ••••def•test_team_participant_does_show_up_on_explore_teams(self):
  4040. | 46| ••••••••alice•=•Participant.from_username('alice')
  4041. | 47| ••••••••self.make_participant('A-Team',•kind='group').add_member(alice)
  4042.  
  4043. tests/py/test_settings.py
  4044. | 50| ••••def•test_team_participant_doesnt_show_up_on_explore_teams(self):
  4045. | 51| ••••••••alice•=•Participant.from_username('alice')
  4046. | 52| ••••••••self.make_participant('A-Team',•kind='group',•hide_from_search=True).add_member(alice)
  4047. | | [NORMAL] CPDBear:
  4048. | | Duplicate code found.
  4049.  
  4050. tests/py/test_billing_exchanges.py
  4051. | 245| ••••def•test_record_exchange_result_restores_balance_on_error(self):
  4052. | 246| ••••••••homer,•ba•=•self.homer,•self.homer_route
  4053. | 247| ••••••••self.make_exchange('mango-cc',•30,•0,•homer)
  4054.  
  4055. tests/py/test_billing_exchanges.py
  4056. | 254| ••••def•test_record_exchange_result_restores_balance_on_error_with_invalidated_route(self):
  4057. | 255| ••••••••homer,•ba•=•self.homer,•self.homer_route
  4058. | 256| ••••••••self.make_exchange('mango-cc',•37,•0,•homer)
  4059.  
  4060. tests/py/test_billing_exchanges.py
  4061. | 265| ••••def•test_record_exchange_result_doesnt_restore_balance_on_success(self):
  4062. | 266| ••••••••homer,•ba•=•self.homer,•self.homer_route
  4063. | 267| ••••••••self.make_exchange('mango-cc',•50,•0,•homer)
  4064. | | [NORMAL] CPDBear:
  4065. | | Duplicate code found.
  4066.  
  4067. tests/py/test_billing_exchanges.py
  4068. | 291| ••••••••exchange•=•self.db.one("SELECT•*•FROM•exchanges")
  4069. | 292| ••••••••assert•exchange.status•==•'pre'
  4070. | 293| ••••••••sync_with_mangopay(self.db)
  4071. | 294| ••••••••exchange•=•self.db.one("SELECT•*•FROM•exchanges")
  4072.  
  4073. tests/py/test_billing_exchanges.py
  4074. | 318| ••••••••exchange•=•self.db.one("SELECT•*•FROM•exchanges•WHERE•amount•<•0")
  4075. | 319| ••••••••assert•exchange.status•==•'pre'
  4076. | 320| ••••••••sync_with_mangopay(self.db)
  4077. | 321| ••••••••exchange•=•self.db.one("SELECT•*•FROM•exchanges•WHERE•amount•<•0")
  4078. | | [NORMAL] CPDBear:
  4079. | | Duplicate code found.
  4080.  
  4081. tests/py/test_billing_payday.py
  4082. | 365| ••••••••self.clear_tables()
  4083. | 366| ••••••••team•=•self.make_participant('team',•kind='group')
  4084. | 367| ••••••••alice•=•self.make_participant('alice',•balance=8)
  4085.  
  4086. tests/py/test_history.py
  4087. | 43| ••••••••Payday.start().run()
  4088. | 44| ••••••••team•=•self.make_participant('team',•kind='group')
  4089. | 45| ••••••••alice•=•self.make_participant('alice')
  4090. | | [NORMAL] CPDBear:
  4091. | | Duplicate code found.
  4092.  
  4093. liberapay/utils/query_cache.py
  4094. | 121| ••••••••self.locks.checkout.acquire()
  4095. | 122| ••••••••try:••#•critical•section
  4096. | 123| ••••••••••••if•key•in•self.cache:
  4097. | 124|
  4098. | 125| ••••••••••••••••#•Retrieve•an•already•cached•query.
  4099. | 126| ••••••••••••••••#•=================================
  4100. | 127| ••••••••••••••••#•The•cached•entry•may•be•a•dummy.•The•best•way•to•guarantee•we
  4101. | 128| ••••••••••••••••#•will•catch•this•case•is•to•simply•refresh•our•entry•after•we
  4102. | 129| ••••••••••••••••#•acquire•its•lock.
  4103. | 130|
  4104. | 131| ••••••••••••••••entry•=•self.cache[key]
  4105.  
  4106. liberapay/utils/query_cache.py
  4107. | 142| ••••••••••••••••self.locks.checkin.acquire()
  4108. | 143| ••••••••••••••••try:••#•critical•section
  4109. | 144| ••••••••••••••••••••if•key•in•self.cache:
  4110. | 145| ••••••••••••••••••••••••#•Someone•beat•us•to•it.•XXX:•can•this•actually•happen?
  4111. | 146| ••••••••••••••••••••••••entry•=•self.cache[key]
  4112. | 147| ••••••••••••••••••••else:
  4113. | 148| ••••••••••••••••••••••••self.cache[key]•=•dummy
  4114. | 149| ••••••••••••••••••••••••entry•=•dummy
  4115. | 150| ••••••••••••••••finally:
  4116. | 151| ••••••••••••••••••••self.locks.checkin.release()
  4117. | 152|
  4118. | | [NORMAL] CPDBear:
  4119. | | Duplicate code found.
  4120.  
  4121. liberapay/cron.py
  4122. | 26| ••••••••••••••••sleep(period)
  4123. | 27| ••••••••t•=•threading.Thread(target=f)
  4124. | 28| ••••••••t.daemon•=•True
  4125. | 29| ••••••••t.start()
  4126.  
  4127. liberapay/cron.py
  4128. | 43| ••••••••••••••••self(*job,•exclusive=True)
  4129. | 44| ••••••••t•=•threading.Thread(target=f)
  4130. | 45| ••••••••t.daemon•=•True
  4131. | 46| ••••••••t.start()
  4132. | | [NORMAL] CPDBear:
  4133. | | Duplicate code found.
  4134.  
  4135. liberapay/models/exchange_route.py
  4136. | 33| ••••••••""",•locals())
  4137. | 34| ••••••••if•r:
  4138. | 35| ••••••••••••r.__dict__['participant']•=•participant
  4139. | 36| ••••••••return•r
  4140. | 37|
  4141. | 38| ••••@classmethod
  4142. | 39| ••••def•from_address(cls,•participant,•network,•address):
  4143.  
  4144. liberapay/models/exchange_route.py
  4145. | 47| ••••••••""",•locals())
  4146. | 48| ••••••••if•r:
  4147. | 49| ••••••••••••r.__dict__['participant']•=•participant
  4148. | 50| ••••••••return•r
  4149. | 51|
  4150. | 52| ••••@classmethod
  4151. | 53| ••••def•insert(cls,•participant,•network,•address,•error='',•one_off=False):
  4152. | | [NORMAL] CPDBear:
  4153. | | Duplicate code found.
  4154.  
  4155. tests/py/test_public_json.py
  4156. | 29| ••••••••alice.set_tip_to(bob,•'1.00')
  4157. | 30| ••••••••data•=•json.loads(self.client.GET('/alice/public.json').body)
  4158. | 31|
  4159. | 32| ••••••••assert•data['giving']•==•None
  4160.  
  4161. tests/py/test_public_json.py
  4162. | 40| ••••••••alice.set_tip_to(bob,•'1.00')
  4163. | 41| ••••••••data•=•json.loads(self.client.GET('/alice/public.json').body)
  4164. | 42|
  4165. | 43| ••••••••assert•data['receiving']•==•None
  4166.  
  4167. tests/py/test_public_json.py
  4168. | 51| ••••••••self.make_participant('alice',•balance=100)
  4169. | 52| ••••••••data•=•json.loads(self.client.GET('/alice/public.json').body)
  4170. | 53| ••••••••assert•data['goal']•==•None
  4171. | 54|
  4172.  
  4173. tests/py/test_public_json.py
  4174. | 56| ••••••••self.make_participant('alice',•balance=100,•goal=1)
  4175. | 57| ••••••••data•=•json.loads(self.client.GET('/alice/public.json').body)
  4176. | 58| ••••••••assert•data['goal']•==•'1.00'
  4177. | 59|
  4178. | | [NORMAL] CPDBear:
  4179. | | Duplicate code found.
  4180.  
  4181. tests/py/test_public_json.py
  4182. | 66| ••••••••raw•=•self.client.GET('/bob/public.json',•auth_as=alice).body
  4183. | 67|
  4184. | 68| ••••••••data•=•json.loads(raw)
  4185. | 69|
  4186. | 70| ••••••••assert•data['receiving']•==•'1.00'
  4187.  
  4188. tests/py/test_public_json.py
  4189. | 83| ••••••••raw•=•self.client.GET('/dana/public.json',•auth_as=alice).body
  4190. | 84|
  4191. | 85| ••••••••data•=•json.loads(raw)
  4192. | 86|
  4193. | 87| ••••••••assert•data['receiving']•==•'16.00'
  4194.  
  4195. tests/py/test_public_json.py
  4196. | 97| ••••••••raw•=•self.client.GET('/carl/public.json',•auth_as=alice).body
  4197. | 98|
  4198. | 99| ••••••••data•=•json.loads(raw)
  4199. | 100|
  4200. | 101| ••••••••assert•data['receiving']•==•'3.00'
  4201. | | [NORMAL] CPDBear:
  4202. | | Duplicate code found.
  4203.  
  4204. liberapay/elsewhere/_extractors.py
  4205. | 82| ••••••••••••••••msg•%=•(path,•self.name,•ET.tostring(info))
  4206. | 83| ••••••••••••••••log(msg)
  4207. | 84| ••••••••••••••••raise•ValueError(msg)
  4208.  
  4209. liberapay/elsewhere/_extractors.py
  4210. | 90| ••••••••••••msg•%=•(path,•self.name,•ET.tostring(info))
  4211. | 91| ••••••••••••log(msg)
  4212. | 92| ••••••••••••raise•IndexError(msg)
  4213.  
  4214. liberapay/elsewhere/_extractors.py
  4215. | 104| ••••••••••••msg•%=•(path,•self.name,•ET.tostring(info))
  4216. | 105| ••••••••••••log(msg)
  4217. | 106| ••••••••••••raise•ValueError(msg)
  4218. | | [NORMAL] CPDBear:
  4219. | | Duplicate code found.
  4220.  
  4221. tests/py/test_take.py
  4222. | 139| ••••••••team.set_take_for(bob,•D('60.00'),•bob)
  4223. | 140|
  4224. | 141| ••••••••alice•=•Participant.from_username('alice')
  4225. | 142| ••••••••assert•alice.receiving•==•alice.taking•==•40
  4226.  
  4227. tests/py/test_take.py
  4228. | 156| ••••••••team.set_take_for(bob,•D('100.00'),•bob)
  4229. | 157| ••••••••alice•=•Participant.from_username('alice')
  4230. | 158| ••••••••assert•alice.receiving•==•alice.taking•==•20
  4231. | 159|
  4232.  
  4233. tests/py/test_take.py
  4234. | 160| ••••••••team.set_take_for(bob,•D('75.00'),•bob)
  4235. | 161| ••••••••alice•=•Participant.from_username('alice')
  4236. | 162| ••••••••assert•alice.receiving•==•alice.taking•==•25
  4237. | 163|
  4238. | | [NORMAL] CPDBear:
  4239. | | Duplicate code found.
  4240.  
  4241. tests/py/test_sign_in.py
  4242. | 53| ••••def•test_log_in(self):
  4243. | 54| ••••••••password•=•'password'
  4244. | 55| ••••••••alice•=•self.make_participant('alice')
  4245. | 56| ••••••••alice.update_password(password)
  4246.  
  4247. tests/py/test_sign_in.py
  4248. | 68| ••••def•test_log_in_switch_user(self):
  4249. | 69| ••••••••password•=•'password'
  4250. | 70| ••••••••alice•=•self.make_participant('alice')
  4251. | 71| ••••••••alice.update_password(password)
  4252.  
  4253. tests/py/test_sign_in.py
  4254. | 78| ••••def•test_log_in_closed_account(self):
  4255. | 79| ••••••••password•=•'password'
  4256. | 80| ••••••••alice•=•self.make_participant('alice')
  4257. | 81| ••••••••alice.update_password(password)
  4258. | | [NORMAL] CPDBear:
  4259. | | Duplicate code found.
  4260.  
  4261. tests/py/test_sign_in.py
  4262. | 55| ••••••••alice•=•self.make_participant('alice')
  4263. | 56| ••••••••alice.update_password(password)
  4264. | 57| ••••••••self.log_in_and_check(alice,•password)
  4265.  
  4266. tests/py/test_sign_in.py
  4267. | 104| ••••••••alice•=•self.make_participant('alice')
  4268. | 105| ••••••••alice.update_password(password)
  4269. | 106| ••••••••self.log_in_and_check(alice,•password.encode('utf8'))
  4270. | | [NORMAL] CPDBear:
  4271. | | Duplicate code found.
  4272.  
  4273. tests/py/test_close.py
  4274. | 212| ••••def•test_ctr_doesnt_duplicate_zero_tips(self):
  4275. | 213| ••••••••alice•=•self.make_participant('alice')
  4276. | 214| ••••••••bob•=•self.make_participant('bob')
  4277.  
  4278. tests/py/test_notifications.py
  4279. | 13| ••••def•test_remove_notification(self):
  4280. | 14| ••••••••alice•=•self.make_participant('alice')
  4281. | 15| ••••••••bob•=•self.make_participant('bob')
  4282.  
  4283. tests/py/test_pages.py
  4284. | 131| ••••def•test_giving_page(self):
  4285. | 132| ••••••••alice•=•self.make_participant('alice')
  4286. | 133| ••••••••bob•=•self.make_participant('bob')
  4287.  
  4288. tests/py/test_pages.py
  4289. | 149| ••••def•test_giving_page_shows_cancelled(self):
  4290. | 150| ••••••••alice•=•self.make_participant('alice')
  4291. | 151| ••••••••bob•=•self.make_participant('bob')
  4292.  
  4293. tests/py/test_participant.py
  4294. | 65| ••••def•test_do_not_take_over_zero_tips_receiving(self):
  4295. | 66| ••••••••alice•=•self.make_participant('alice')
  4296. | 67| ••••••••bob•=•self.make_participant('bob')
  4297. | | [NORMAL] CPDBear:
  4298. | | Duplicate code found.
  4299.  
  4300. tests/py/test_participant.py
  4301. | 76| ••••def•test_consolidated_tips_receiving(self):
  4302. | 77| ••••••••alice•=•self.make_participant('alice',•balance=1)
  4303. | 78| ••••••••bob•=•self.make_participant('bob',•elsewhere='twitter')
  4304.  
  4305. tests/py/test_participant.py
  4306. | 269| ••••def•test_stt_works_for_pledges(self):
  4307. | 270| ••••••••alice•=•self.make_participant('alice',•balance=1)
  4308. | 271| ••••••••bob•=•self.make_stub()
  4309. | | [NORMAL] CPDBear:
  4310. | | Duplicate code found.
  4311.  
  4312. tests/py/test_participant.py
  4313. | 261| ••••def•test_stt_sets_tip_to(self):
  4314. | 262| ••••••••alice•=•self.make_participant('alice',•balance=100)
  4315. | 263| ••••••••bob•=•self.make_stub()
  4316.  
  4317. tests/py/test_participant.py
  4318. | 280| ••••def•test_stt_works_for_donations(self):
  4319. | 281| ••••••••alice•=•self.make_participant('alice',•balance=100)
  4320. | 282| ••••••••bob•=•self.make_participant('bob')
  4321.  
  4322. tests/py/test_participant.py
  4323. | 289| ••••def•test_stt_returns_False_for_second_time_tipper(self):
  4324. | 290| ••••••••alice•=•self.make_participant('alice',•balance=100)
  4325. | 291| ••••••••bob•=•self.make_participant('bob')
  4326.  
  4327. tests/py/test_participant.py
  4328. | 302| ••••def•test_stt_doesnt_allow_just_any_ole_amount(self):
  4329. | 303| ••••••••alice•=•self.make_participant('alice',•balance=100)
  4330. | 304| ••••••••bob•=•self.make_participant('bob')
  4331.  
  4332. tests/py/test_participant.py
  4333. | 315| ••••def•test_only_funded_tips_count(self):
  4334. | 316| ••••••••alice•=•self.make_participant('alice',•balance=100)
  4335. | 317| ••••••••bob•=•self.make_participant('bob')
  4336.  
  4337. tests/py/test_participant.py
  4338. | 338| ••••def•test_only_latest_tip_counts(self):
  4339. | 339| ••••••••alice•=•self.make_participant('alice',•balance=100)
  4340. | 340| ••••••••bob•=•self.make_participant('bob',•balance=100)
  4341.  
  4342. tests/py/test_participant.py
  4343. | 351| ••••def•test_receiving_includes_taking_when_updated_from_set_tip_to(self):
  4344. | 352| ••••••••alice•=•self.make_participant('alice',•balance=100)
  4345. | 353| ••••••••bob•=•self.make_participant('bob',•taking=Decimal('42.00'))
  4346.  
  4347. tests/py/test_participant.py
  4348. | 357| ••••def•test_receiving_is_zero_for_patrons(self):
  4349. | 358| ••••••••alice•=•self.make_participant('alice',•balance=100)
  4350. | 359| ••••••••bob•=•self.make_participant('bob')
  4351.  
  4352. tests/py/test_participant.py
  4353. | 370| ••••def•test_cant_pledge_to_locked_accounts(self):
  4354. | 371| ••••••••alice•=•self.make_participant('alice',•balance=100)
  4355. | 372| ••••••••bob•=•self.make_stub(goal=-1)
  4356.  
  4357. tests/py/test_participant.py
  4358. | 376| ••••def•test_pledging_isnt_giving(self):
  4359. | 377| ••••••••alice•=•self.make_participant('alice',•balance=100)
  4360. | 378| ••••••••bob•=•self.make_elsewhere('github',•58946,•'bob').participant
  4361.  
  4362. tests/py/test_public_json.py
  4363. | 10| ••••def•test_anonymous(self):
  4364. | 11| ••••••••alice•=•self.make_participant('alice',•balance=100)
  4365. | 12| ••••••••bob•=•self.make_participant('bob')
  4366.  
  4367. tests/py/test_public_json.py
  4368. | 60| ••••def•test_authenticated_user_gets_their_tip(self):
  4369. | 61| ••••••••alice•=•self.make_participant('alice',•balance=100)
  4370. | 62| ••••••••bob•=•self.make_participant('bob')
  4371.  
  4372. tests/py/test_public_json.py
  4373. | 73| ••••def•test_authenticated_user_doesnt_get_other_peoples_tips(self):
  4374. | 74| ••••••••alice•=•self.make_participant('alice',•balance=100)
  4375. | 75| ••••••••bob•=•self.make_participant('bob',•balance=100)
  4376.  
  4377. tests/py/test_public_json.py
  4378. | 90| ••••def•test_authenticated_user_gets_zero_if_they_dont_tip(self):
  4379. | 91| ••••••••alice•=•self.make_participant('alice',•balance=100)
  4380. | 92| ••••••••bob•=•self.make_participant('bob',•balance=100)
  4381.  
  4382. tests/py/test_public_json.py
  4383. | 104| ••••def•test_authenticated_user_gets_self_for_self(self):
  4384. | 105| ••••••••alice•=•self.make_participant('alice',•balance=100)
  4385. | 106| ••••••••bob•=•self.make_participant('bob')
  4386.  
  4387. tests/py/test_public_json.py
  4388. | 123| ••••def•test_jsonp_works(self):
  4389. | 124| ••••••••alice•=•self.make_participant('alice',•balance=100)
  4390. | 125| ••••••••bob•=•self.make_participant('bob')
  4391. | | [NORMAL] CPDBear:
  4392. | | Duplicate code found.
  4393.  
  4394. tests/py/test_billing_payday.py
  4395. | 39| ••••••••alice•=•self.make_participant('alice',•balance=100)
  4396. | 40| ••••••••bob•=•self.make_participant('bob')
  4397.  
  4398. tests/py/test_participant.py
  4399. | 281| ••••••••alice•=•self.make_participant('alice',•balance=100)
  4400. | 282| ••••••••bob•=•self.make_participant('bob')
  4401.  
  4402. tests/py/test_participant.py
  4403. | 290| ••••••••alice•=•self.make_participant('alice',•balance=100)
  4404. | 291| ••••••••bob•=•self.make_participant('bob')
  4405.  
  4406. tests/py/test_participant.py
  4407. | 303| ••••••••alice•=•self.make_participant('alice',•balance=100)
  4408. | 304| ••••••••bob•=•self.make_participant('bob')
  4409.  
  4410. tests/py/test_participant.py
  4411. | 358| ••••••••alice•=•self.make_participant('alice',•balance=100)
  4412. | 359| ••••••••bob•=•self.make_participant('bob')
  4413.  
  4414. tests/py/test_public_json.py
  4415. | 11| ••••••••alice•=•self.make_participant('alice',•balance=100)
  4416. | 12| ••••••••bob•=•self.make_participant('bob')
  4417.  
  4418. tests/py/test_public_json.py
  4419. | 61| ••••••••alice•=•self.make_participant('alice',•balance=100)
  4420. | 62| ••••••••bob•=•self.make_participant('bob')
  4421.  
  4422. tests/py/test_public_json.py
  4423. | 105| ••••••••alice•=•self.make_participant('alice',•balance=100)
  4424. | 106| ••••••••bob•=•self.make_participant('bob')
  4425.  
  4426. tests/py/test_public_json.py
  4427. | 124| ••••••••alice•=•self.make_participant('alice',•balance=100)
  4428. | 125| ••••••••bob•=•self.make_participant('bob')
  4429. | | [NORMAL] CPDBear:
  4430. | | Duplicate code found.
  4431.  
  4432. tests/py/test_search.py
  4433. | 10| ••••••••response•=•self.client.GET('/search.json?q=alice&scope=usernames')
  4434. | 11| ••••••••data•=•json.loads(response.body)['usernames']
  4435. | 12| ••••••••assert•data•==•[]
  4436. | 13|
  4437. | 14| ••••def•test_get_existing_user(self):
  4438.  
  4439. tests/py/test_search.py
  4440. | 23| ••••••••response•=•self.client.GET('/search.json?q=ali&scope=usernames')
  4441. | 24| ••••••••data•=•json.loads(response.body)['usernames']
  4442. | 25| ••••••••assert•data•==•[]
  4443. | 26|
  4444. | 27| ••••def•test_get_fuzzy_match(self):
  4445. | | [NORMAL] CPDBear:
  4446. | | Duplicate code found.
  4447.  
  4448. liberapay/models/participant.py
  4449. |1070| ••••••••••••self.set_attributes(goal=goal)
  4450. |1071| ••••••••••••if•not•self.accepts_tips:
  4451. |1072| ••••••••••••••••self.clear_tips_receiving(c)
  4452. |1073| ••••••••••••••••self.update_receiving(c)
  4453. |1074|
  4454. |1075| ••••def•update_status(self,•status,•cursor=None):
  4455.  
  4456. liberapay/models/participant.py
  4457. |1091| ••••••••••••self.add_event(c,•'set_status',•status)
  4458. |1092| ••••••••••••if•not•self.accepts_tips:
  4459. |1093| ••••••••••••••••self.clear_tips_receiving(c)
  4460. |1094| ••••••••••••••••self.update_receiving(c)
  4461. |1095|
  4462. |1096| ••••def•update_giving_and_tippees(self,•cursor):
  4463. | | [NORMAL] CPDBear:
  4464. | | Duplicate code found.
  4465.  
  4466. tests/py/test_hooks.py
  4467. | 59| ••••••••response•=•self.client.GET(•'/alice/public.json'
  4468. | 60| ••••••••••••••••••••••••••••••••••,•HTTP_AUTHORIZATION=auth_header
  4469. | 61| ••••••••••••••••••••••••••••••••••,•HTTP_X_FORWARDED_PROTO=b'https'
  4470. | 62| ••••••••••••••••••••••••••••••••••,•HTTP_HOST=b'example.com'
  4471. | 63| •••••••••••••••••••••••••••••••••••)
  4472. | 64|
  4473. | 65| ••••••••assert•response.code•==•200
  4474.  
  4475. tests/py/test_hooks.py
  4476. | 71| ••••••••response•=•self.client.GxT(•'/alice/public.json'
  4477. | 72| ••••••••••••••••••••••••••••••••••,•HTTP_AUTHORIZATION=auth_header
  4478. | 73| ••••••••••••••••••••••••••••••••••,•HTTP_X_FORWARDED_PROTO=b'https'
  4479. | 74| ••••••••••••••••••••••••••••••••••,•HTTP_HOST=b'example.com'
  4480. | 75| •••••••••••••••••••••••••••••••••••)
  4481. | 76| ••••••••assert•response.code•==•401
  4482. | 77|
  4483. | | [NORMAL] CPDBear:
  4484. | | Duplicate code found.
  4485.  
  4486. tests/py/test_email.py
  4487. | 112| ••••••••self.hit_email_spt('add-email',•'alice@example.com')
  4488. | 113| ••••••••nonce•=•self.alice.get_email('alice@example.com').nonce
  4489.  
  4490. tests/py/test_email.py
  4491. | 122| ••••••••self.hit_email_spt('add-email',•'alice@example.com')
  4492. | 123| ••••••••nonce•=•self.alice.get_email('alice@example.com').nonce
  4493. | | [NORMAL] CPDBear:
  4494. | | Duplicate code found.
  4495.  
  4496. tests/py/test_email.py
  4497. | 192| ••••••••self.verify_and_change_email('alice@example.com',•'alice@example.net')
  4498. | 193| ••••••••self.verify_and_change_email('alice@example.net',•'alice@example.org')
  4499. | 194| ••••••••self.hit_email_spt('set-primary',•'alice@example.com')
  4500.  
  4501. tests/py/test_email.py
  4502. | 206| ••••••••self.verify_and_change_email('alice@example.com',•'alice@example.net')
  4503. | 207| ••••••••self.verify_and_change_email('alice@example.net',•'alice@example.org')
  4504. | 208| ••••••••self.hit_email_spt('remove',•'alice@example.net')
  4505. | | [NORMAL] CPDBear:
  4506. | | Duplicate code found.
  4507.  
  4508. tests/py/test_close.py
  4509. | 42| ••••def•test_close_page_is_usually_available(self):
  4510. | 43| ••••••••alice•=•self.make_participant('alice')
  4511. | 44| ••••••••body•=•self.client.GET('/alice/settings/close',•auth_as=alice).text
  4512.  
  4513. tests/py/test_pages.py
  4514. | 158| ••••def•test_new_participant_can_edit_profile(self):
  4515. | 159| ••••••••alice•=•self.make_participant('alice')
  4516. | 160| ••••••••body•=•self.client.GET("/alice/",•auth_as=alice).text
  4517. | | [NORMAL] CPDBear:
  4518. | | Duplicate code found.
  4519.  
  4520. tests/py/test_close.py
  4521. | 80| ••••••••alice.set_tip_to(carl,•D('2.00'))
  4522. | 81| ••••••••with•self.db.get_cursor()•as•cursor:
  4523. | 82| ••••••••••••alice.distribute_balance_as_final_gift(cursor)
  4524. | 83| ••••••••assert•Participant.from_username('bob').balance•==•D('6.00')
  4525.  
  4526. tests/py/test_close.py
  4527. | 105| ••••••••alice.set_tip_to(carl,•D('2.00'))
  4528. | 106| ••••••••with•self.db.get_cursor()•as•cursor:
  4529. | 107| ••••••••••••alice.distribute_balance_as_final_gift(cursor)
  4530. | 108| ••••••••assert•Participant.from_id(bob.id).balance•==•D('10.00')
  4531.  
  4532. tests/py/test_close.py
  4533. | 142| ••••••••alice.set_tip_to(carl,•D('6.00'))
  4534. | 143| ••••••••with•self.db.get_cursor()•as•cursor:
  4535. | 144| ••••••••••••alice.distribute_balance_as_final_gift(cursor)
  4536. | 145| ••••••••assert•self.db.one("SELECT•count(*)•FROM•tips")•==•2
  4537. | | [NORMAL] CPDBear:
  4538. | | Duplicate code found.
  4539.  
  4540. tests/py/test_close.py
  4541. | 90| ••••••••carl•=•self.make_stub()
  4542. | 91| ••••••••alice.set_tip_to(bob,•D('3.00'))
  4543. | 92| ••••••••alice.set_tip_to(carl,•D('2.00'))
  4544.  
  4545. tests/py/test_close.py
  4546. | 103| ••••••••carl•=•self.make_stub()
  4547. | 104| ••••••••alice.set_tip_to(bob,•D('3.00'))
  4548. | 105| ••••••••alice.set_tip_to(carl,•D('2.00'))
  4549.  
  4550. tests/py/test_close.py
  4551. | 128| ••••••••carl•=•self.make_participant('carl')
  4552. | 129| ••••••••alice.set_tip_to(bob,•D('3.00'))
  4553. | 130| ••••••••alice.set_tip_to(carl,•D('6.00'))
  4554.  
  4555. tests/py/test_close.py
  4556. | 140| ••••••••carl•=•self.make_participant('carl')
  4557. | 141| ••••••••alice.set_tip_to(bob,•D('3.00'))
  4558. | 142| ••••••••alice.set_tip_to(carl,•D('6.00'))
  4559. | | [NORMAL] CPDBear:
  4560. | | Duplicate code found.
  4561.  
  4562. tests/py/test_close.py
  4563. | 117| ••••••••alice.set_tip_to(carl,•D('2.00'))
  4564. | 118| ••••••••with•self.db.get_cursor()•as•cursor:
  4565. | 119| ••••••••••••alice.distribute_balance_as_final_gift(cursor)
  4566. | 120| ••••••••assert•self.db.one("SELECT•count(*)•FROM•tips•WHERE•tippee=%s",•(bob.id,))•==•1
  4567.  
  4568. tests/py/test_close.py
  4569. | 130| ••••••••alice.set_tip_to(carl,•D('6.00'))
  4570. | 131| ••••••••with•self.db.get_cursor()•as•cursor:
  4571. | 132| ••••••••••••alice.distribute_balance_as_final_gift(cursor)
  4572. | 133| ••••••••assert•Participant.from_username('bob').balance•==•D('3.33')
  4573. | | [NORMAL] CPDBear:
  4574. | | Duplicate code found.
  4575.  
  4576. tests/py/test_public_json.py
  4577. | 20| ••••••••data•=•json.loads(self.client.GET('/alice/public.json').body)
  4578. | 21| ••••••••assert•data['giving']•==•'1.00'
  4579.  
  4580. tests/py/test_public_json.py
  4581. | 41| ••••••••data•=•json.loads(self.client.GET('/alice/public.json').body)
  4582. | 42|
  4583.  
  4584. tests/py/test_public_json.py
  4585. | 52| ••••••••data•=•json.loads(self.client.GET('/alice/public.json').body)
  4586. | 53| ••••••••assert•data['goal']•==•None
  4587.  
  4588. tests/py/test_public_json.py
  4589. | 57| ••••••••data•=•json.loads(self.client.GET('/alice/public.json').body)
  4590. | 58| ••••••••assert•data['goal']•==•'1.00'
  4591. | | [NORMAL] CPDBear:
  4592. | | Duplicate code found.
  4593.  
  4594. tests/py/test_billing_payday.py
  4595. | 284| ••••••••a_team.set_take_for(alice,•D('1.00'),•alice)
  4596. | 285| ••••••••bob•=•self.make_participant('bob')
  4597.  
  4598. tests/py/test_billing_payday.py
  4599. | 318| ••••••••team.set_take_for(alice,•D('1.00'),•alice)
  4600. | 319| ••••••••bob•=•self.make_participant('bob')
  4601. | | [NORMAL] CPDBear:
  4602. | | Duplicate code found.
  4603.  
  4604. tests/py/test_billing_payday.py
  4605. | 286| ••••••••a_team.set_take_for(bob,•D('0.01'),•bob)
  4606. | 287| ••••••••charlie•=•self.make_participant('charlie',•balance=1000)
  4607. | 288| ••••••••charlie.set_tip_to(a_team,•D('1.01'))
  4608.  
  4609. tests/py/test_billing_payday.py
  4610. | 320| ••••••••team.set_take_for(bob,•D('1.00'),•bob)
  4611. | 321| ••••••••charlie•=•self.make_participant('charlie',•balance=1000)
  4612. | 322| ••••••••charlie.set_tip_to(team,•D('0.26'))
  4613. | | [NORMAL] CPDBear:
  4614. | | Duplicate code found.
  4615.  
  4616. tests/py/test_billing_payday.py
  4617. | 318| ••••••••team.set_take_for(alice,•D('1.00'),•alice)
  4618. | 319| ••••••••bob•=•self.make_participant('bob')
  4619. | 320| ••••••••team.set_take_for(bob,•D('1.00'),•bob)
  4620.  
  4621. tests/py/test_billing_payday.py
  4622. | 344| ••••••••team.set_take_for(alice,•D('0.79'),•alice)
  4623. | 345| ••••••••bob•=•self.make_participant('bob')
  4624. | 346| ••••••••team.set_take_for(bob,•D('0.21'),•bob)
  4625. | | [NORMAL] CPDBear:
  4626. | | Duplicate code found.
  4627. Executing section js-analysis...
  4628.  
  4629. js/mangopay.js
  4630. | 468| ••••••••_ajax:•function(settings)•{
  4631. | | [NORMAL] JSComplexityBear:
  4632. | | _ajax has a cyclomatic complexity of 10.
  4633.  
  4634. js/iban.js
  4635. | 158| ••••••••return•this._regex().exec(iban.slice(4)).slice(1).join(separator);
  4636. | 159| ••••};
  4637. | 160|
  4638. | 161| ••••/**
  4639. | 162| •••••*•Convert•the•passed•BBAN•to•an•IBAN•for•this•country•specification.
  4640. | 163| •••••*•Please•note•that•<i>"generation•of•the•IBAN•shall•be•the•exclusive•responsibility•of•the•bank/branch•servicing•the•account"</i>.
  4641. | 164| •••••*•This•method•implements•the•preferred•algorithm•described•in•http://en.wikipedia.org/wiki/International_Bank_Account_Number#Generating_IBAN_check_digits
  4642. | 165| •••••*
  4643.  
  4644. js/iban.js
  4645. | 341| ••••••••return•countryStructure.toBBAN(iban,•separator);
  4646. | 342| ••••};
  4647. | 343|
  4648. | 344| ••••/**
  4649. | 345| •••••*•Convert•the•passed•BBAN•to•an•IBAN•for•this•country•specification.
  4650. | 346| •••••*•Please•note•that•<i>"generation•of•the•IBAN•shall•be•the•exclusive•responsibility•of•the•bank/branch•servicing•the•account"</i>.
  4651. | 347| •••••*•This•method•implements•the•preferred•algorithm•described•in•http://en.wikipedia.org/wiki/International_Bank_Account_Number#Generating_IBAN_check_digits
  4652. | 348| •••••*
  4653. | | [NORMAL] CPDBear:
  4654. | | Duplicate code found.
  4655.  
  4656. js/mangopay.js
  4657. | 512| ••••••••••••••••xmlhttp.open(settings.type,•url,•true);
  4658. | 513| ••••••••••••}•catch•(e)•{
  4659. | 514| ••••••••••••••••if•(settings.crossDomain)
  4660. | 515| ••••••••••••••••••••return•settings.error({ResultCode:•"1000000",•ResultMessage:•"CORS_FAIL"});
  4661. | 516| ••••••••••••••••else
  4662. | 517| ••••••••••••••••••••return•settings.error({ResultCode:•"1000001",•ResultMessage:•"XHR_FAIL"});
  4663.  
  4664. js/mangopay.js
  4665. | 527| ••••••••••••••••xmlhttp.send(settings.type•===•"post"•?•parameters•:•null);
  4666. | 528| ••••••••••••}•catch•(e)•{
  4667. | 529| ••••••••••••••••if•(settings.crossDomain)
  4668. | 530| ••••••••••••••••••••return•settings.error({ResultCode:•"1000000",•ResultMessage:•"CORS_FAIL"});
  4669. | 531| ••••••••••••••••else
  4670. | 532| ••••••••••••••••••••return•settings.error({ResultCode:•"1000001",•ResultMessage:•"XHR_FAIL"});
  4671. | | [NORMAL] CPDBear:
  4672. | | Duplicate code found.
Add Comment
Please, Sign In to add comment