1717along with this program. If not, see <http://www.gnu.org/licenses/>.
1818
1919"""
20-
2120import json
21+ from datetime import timedelta
2222
2323from django .contrib .auth .models import User
24+ from django .db .models import Count , Q
2425from django .test .client import RequestFactory
26+ from django .utils import timezone
2527
26- from dashboard .models import Profile
28+ from dashboard .models import Bounty , BountyFulfillment , Profile
2729from dashboard .views import users_fetch
2830from test_plus .test import TestCase
2931
32+ CURRENT_USERNAME = "asdfasdf"
33+
34+ def setup_bounties ():
35+ owners = [CURRENT_USERNAME , 'user2' ]
36+ for owner in owners :
37+ Bounty .objects .create (
38+ title = 'foo' ,
39+ value_in_token = 3 ,
40+ token_name = 'USDT' ,
41+ web3_created = timezone .now () - timedelta (days = 7 ),
42+ github_url = 'https://github.com/oogetyboogety/gitcointestproject/issues/28' ,
43+ token_address = '0x0' ,
44+ issue_description = 'hello world' ,
45+ bounty_owner_github_username = owner ,
46+ is_open = True ,
47+ accepted = True ,
48+ expires_date = timezone .now () + timedelta (days = 1 , hours = 1 ),
49+ idx_project_length = 5 ,
50+ project_length = 'Months' ,
51+ bounty_type = 'Feature' ,
52+ experience_level = 'Intermediate' ,
53+ raw_data = {},
54+ idx_status = 'submitted' ,
55+ bounty_owner_email = 'asdfasdf@bar.com' ,
56+ current_bounty = True
57+ )
58+
59+ BountyFulfillment .objects .create (
60+ fulfiller_address = '0x0000000000000000000000000000000000000000' ,
61+ fulfiller_email = 'fred@bar.com' ,
62+ fulfiller_github_username = 'user1' ,
63+ fulfiller_name = 'Fred' ,
64+ accepted = True ,
65+ bounty = Bounty .objects .first (),
66+ profile = User .objects .filter (username = 'user1' ).first ().profile
67+ )
68+
69+ BountyFulfillment .objects .create (
70+ fulfiller_address = '0x0000000000000000000000000000000000000000' ,
71+ fulfiller_email = 'fred@bar.com' ,
72+ fulfiller_github_username = 'user19' ,
73+ fulfiller_name = 'Fred' ,
74+ accepted = True ,
75+ bounty = Bounty .objects .last (),
76+ profile = User .objects .last ().profile
77+ )
78+
3079
3180class UsersListTest (TestCase ):
3281 """Define tests for the user list."""
3382
3483 def setUp (self ):
3584 self .request = RequestFactory ()
3685 self .current_user = User .objects .create (
37- password = "asdfasdf" , username = "asdfasdf" )
86+ password = "asdfasdf" , username = CURRENT_USERNAME )
3887 current_user_profile = Profile .objects .create (
39- user = self .current_user , data = {}, hide_profile = False , handle = "asdfasdf" )
88+ user = self .current_user , data = {}, hide_profile = False , handle = CURRENT_USERNAME )
4089
4190 for i in range (20 ):
4291 user = User .objects .create (password = "{}" .format (i ),
@@ -48,3 +97,17 @@ def test_user_list(self):
4897 request = self .request
4998 request .user = self .current_user
5099 assert json .loads (users_fetch (request .get ('/api/v0.1/users_fetch?user={}' .format (self .current_user .id ))).content )['count' ] == 21
100+
101+ def test_default_users_ordering_with_previous_workers_at_the_top (self ):
102+ setup_bounties ()
103+
104+ all_profiles = Profile .objects .annotate (
105+ worked_with = Count (
106+ 'fulfilled' , filter = Q (
107+ fulfilled__accepted = True ,
108+ fulfilled__bounty__bounty_owner_github_username__iexact = CURRENT_USERNAME
109+ )
110+ )
111+ ).order_by ('-worked_with' )
112+
113+ assert all_profiles .values ('user__username' , 'worked_with' )[0 ] == {'user__username' : 'user1' , 'worked_with' : 1 }
0 commit comments