Revision 50f74340 snf-astakos-app/astakos/im/tests/projects.py

b/snf-astakos-app/astakos/im/tests/projects.py
144 144
        self.assertContains(r, "The project application has been received")
145 145
        self.assertRedirects(r, reverse('project_list'))
146 146
        self.assertEqual(ProjectApplication.objects.count(), 1)
147
        app1_id = ProjectApplication.objects.filter().order_by('pk')[0].pk
147
        app1 = ProjectApplication.objects.filter().order_by('pk')[0]
148
        app1_id = app1.pk
149
        project1_id = app1.chain_id
148 150

  
149 151
        # create another one
150 152
        application_data['name'] = 'project2.synnefo.org'
151 153
        r = self.user_client.post(post_url, data=application_data, follow=True)
152
        app2_id = ProjectApplication.objects.filter().order_by('pk')[1].pk
154
        app2 = ProjectApplication.objects.filter().order_by('pk')[1]
155
        project2_id = app2.chain_id
153 156

  
154 157
        # no more applications (LIMIT is 2)
155 158
        r = self.user_client.get(reverse('project_add'), follow=True)
156 159
        self.assertRedirects(r, reverse('project_list'))
157 160
        self.assertContains(r, "You are not allowed to create a new project")
158 161

  
162
        # one project per application
163
        self.assertEqual(Project.objects.count(), 2)
164

  
159 165
        # login
160 166
        self.admin_client.get(reverse("edit_profile"))
161 167
        # admin approves
......
164 170
                                   follow=True)
165 171
        self.assertEqual(r.status_code, 200)
166 172

  
167
        # project created
168
        self.assertEqual(Project.objects.count(), 1)
173
        Q_ACTIVE = Project.o_state_q(Project.O_ACTIVE)
174
        self.assertEqual(Project.objects.filter(Q_ACTIVE).count(), 1)
169 175

  
170 176
        # login
171 177
        self.member_client.get(reverse("edit_profile"))
172
        # cannot join app2 (not approved yet)
173
        join_url = reverse("project_join", kwargs={'chain_id': app2_id})
178
        # cannot join project2 (not approved yet)
179
        join_url = reverse("project_join", kwargs={'chain_id': project2_id})
174 180
        r = self.member_client.post(join_url, follow=True)
175
        self.assertEqual(r.status_code, 403)
176 181

  
177
        # can join app1
182
        # can join project1
178 183
        self.member_client.get(reverse("edit_profile"))
179
        join_url = reverse("project_join", kwargs={'chain_id': app1_id})
184
        join_url = reverse("project_join", kwargs={'chain_id': project1_id})
180 185
        r = self.member_client.post(join_url, follow=True)
181 186
        self.assertEqual(r.status_code, 200)
182 187

  
......
185 190
        memb_id = memberships[0].id
186 191

  
187 192
        reject_member_url = reverse('project_reject_member',
188
                                    kwargs={'chain_id': app1_id, 'memb_id':
189
                                            memb_id})
193
                                    kwargs={'memb_id': memb_id})
190 194
        accept_member_url = reverse('project_accept_member',
191
                                    kwargs={'chain_id': app1_id, 'memb_id':
192
                                            memb_id})
195
                                    kwargs={'memb_id': memb_id})
193 196

  
194 197
        # only project owner is allowed to reject
195 198
        r = self.member_client.post(reject_member_url, follow=True)
......
198 201

  
199 202
        # user (owns project) rejects membership
200 203
        r = self.user_client.post(reject_member_url, follow=True)
201
        self.assertEqual(ProjectMembership.objects.count(), 0)
204
        self.assertEqual(ProjectMembership.objects.any_accepted().count(), 0)
202 205

  
203 206
        # user rejoins
204 207
        self.member_client.get(reverse("edit_profile"))
205 208
        join_url = reverse("project_join", kwargs={'chain_id': app1_id})
206 209
        r = self.member_client.post(join_url, follow=True)
207 210
        self.assertEqual(r.status_code, 200)
208
        self.assertEqual(ProjectMembership.objects.count(), 1)
211
        self.assertEqual(ProjectMembership.objects.requested().count(), 1)
209 212

  
210 213
        # user (owns project) accepts membership
211 214
        r = self.user_client.post(accept_member_url, follow=True)
212
        self.assertEqual(ProjectMembership.objects.count(), 1)
215
        self.assertEqual(ProjectMembership.objects.any_accepted().count(), 1)
213 216
        membership = ProjectMembership.objects.get()
214 217
        self.assertEqual(membership.state, ProjectMembership.ACCEPTED)
215 218

  
......
220 223
        self.assertEqual(newlimit, 200)
221 224

  
222 225
        remove_member_url = reverse('project_remove_member',
223
                                    kwargs={'chain_id': app1_id, 'memb_id':
224
                                            membership.id})
226
                                    kwargs={'memb_id': membership.id})
225 227
        r = self.user_client.post(remove_member_url, follow=True)
226 228
        self.assertEqual(r.status_code, 200)
227 229

  

Also available in: Unified diff