Example #1
0
    def test_duplicate_join_request(self):
        organization = get_test_organization()
        # Should not create another
        initial_request_count = models.JoinRequest.objects.all().count()
        get_test_user()
        # Login
        self.assertTrue(self.client.login(
            username='******', password='******'))

        response = self.client.post(
            reverse(
                'organizations:request_membership',
                kwargs={'slug': organization.slug}
            ), {'pk': organization.pk}, follow=True
        )
        self.assertEqual(response.status_code, 200)
        final_request_count = models.JoinRequest.objects.all().count()
        self.assertEqual(final_request_count, initial_request_count + 1)

        response = self.client.post(
            reverse(
                'organizations:request_membership',
                kwargs={'slug': organization.slug}
            ), {'pk': organization.pk}, follow=True
        )
        self.assertEqual(response.status_code, 200)
        final_request_count = models.JoinRequest.objects.all().count()
        self.assertEqual(final_request_count, initial_request_count + 1)
Example #2
0
    def test_duplicate_join_request(self):
        organization = get_test_organization()
        # Should not create another
        initial_request_count = models.JoinRequest.objects.all().count()
        get_test_user()
        # Login
        self.assertTrue(
            self.client.login(username='******',
                              password='******'))

        response = self.client.post(reverse('organizations:request_membership',
                                            kwargs={'slug':
                                                    organization.slug}),
                                    {'pk': organization.pk},
                                    follow=True)
        self.assertEqual(response.status_code, 200)
        final_request_count = models.JoinRequest.objects.all().count()
        self.assertEqual(final_request_count, initial_request_count + 1)

        response = self.client.post(reverse('organizations:request_membership',
                                            kwargs={'slug':
                                                    organization.slug}),
                                    {'pk': organization.pk},
                                    follow=True)
        self.assertEqual(response.status_code, 200)
        final_request_count = models.JoinRequest.objects.all().count()
        self.assertEqual(final_request_count, initial_request_count + 1)
Example #3
0
    def test_request_to_join(self):
        organization = get_test_organization()
        # GET request should redirect us to the organization's page
        join_url = reverse(
            'organizations:request_membership',
            kwargs={'slug': organization.slug}
        )

        get_response = self.client.get(join_url, follow=True)
        self.assertEqual(get_response.status_code, 200)
        self.assertTemplateUsed("organization_detail")

        initial_request_count = models.JoinRequest.objects.all().count()
        get_test_user()
        # Login
        self.assertTrue(self.client.login(
            username='******', password='******'))

        response = self.client.post(
            reverse(
                'organizations:request_membership',
                kwargs={'slug': organization.slug}
            ), {'pk': organization.pk}, follow=True
        )
        self.assertEqual(response.status_code, 200)
        final_request_count = models.JoinRequest.objects.all().count()
        self.assertEqual(final_request_count, initial_request_count + 1)
Example #4
0
    def test_request_to_join(self):
        organization = get_test_organization()
        # GET request should redirect us to the organization's page
        join_url = reverse('organizations:request_membership',
                           kwargs={'slug': organization.slug})

        get_response = self.client.get(join_url, follow=True)
        self.assertEqual(get_response.status_code, 200)
        self.assertTemplateUsed("organization_detail")

        initial_request_count = models.JoinRequest.objects.all().count()
        get_test_user()
        # Login
        self.assertTrue(
            self.client.login(username='******',
                              password='******'))

        response = self.client.post(reverse('organizations:request_membership',
                                            kwargs={'slug':
                                                    organization.slug}),
                                    {'pk': organization.pk},
                                    follow=True)
        self.assertEqual(response.status_code, 200)
        final_request_count = models.JoinRequest.objects.all().count()
        self.assertEqual(final_request_count, initial_request_count + 1)
Example #5
0
 def test_request_decline_by_admin(self):
     o = get_test_organization()
     request = models.JoinRequest.objects.create(user=get_test_user(),
                                                 organization=o)
     self.assertIsNotNone(request)
     admin_membership = models.OrganizationMembership.objects.create(
         user=get_test_user(), is_admin=True, organization=o)
     request.decline(admin_membership)
     self.assertEqual(request.is_open, False)
Example #6
0
    def test_add_layer(self):
        layer = create_layer('Test Layer', 'Abstract', get_test_user())
        self.assertIsNotNone(layer)

        o = get_test_organization()
        m = models.OrganizationMembership.objects.create(
            user=get_test_user(), organization=o, is_admin=True)
        count = models.OrganizationLayer.objects.all().count()
        o.add_layer(layer, m)
        self.assertEqual(
            count + 1, models.OrganizationLayer.objects.all().count())
Example #7
0
    def test_add_mapstory_helper(self):
        test_mapstory = create_mapstory(get_test_user(), 'Testing Map 01')

        initial_count = models.InitiativeMapStory.objects.all().count()
        o = get_initiative()
        membership = models.InitiativeMembership.objects.create(
            user=get_test_user(), initiative=o, is_admin=True)

        self.assertIsNotNone(o.add_mapstory(test_mapstory, membership))
        self.assertEqual(initial_count + 1,
                         models.InitiativeMapStory.objects.all().count())
Example #8
0
    def test_add_layer(self):
        layer = create_layer('Test Layer', 'Abstract', get_test_user())
        self.assertIsNotNone(layer)

        o = get_initiative()
        m = models.InitiativeMembership.objects.create(
            user=get_test_user(), initiative=o, is_admin=True)
        count = models.InitiativeLayer.objects.all().count()
        o.add_layer(layer, m)
        self.assertEqual(
            count + 1, models.InitiativeLayer.objects.all().count())
Example #9
0
    def test_add_mapstory_helper(self):
        test_mapstory = create_mapstory(get_test_user(), 'Testing Map 01')

        initial_count = models.InitiativeMapStory.objects.all().count()
        o = get_initiative()
        membership = models.InitiativeMembership.objects.create(
            user=get_test_user(), initiative=o, is_admin=True)

        self.assertIsNotNone(o.add_mapstory(test_mapstory, membership))
        self.assertEqual(initial_count + 1,
                         models.InitiativeMapStory.objects.all().count())
Example #10
0
    def test_add_layer(self):
        layer = create_layer('Test Layer', 'Abstract', get_test_user())
        self.assertIsNotNone(layer)

        o = get_initiative()
        m = models.InitiativeMembership.objects.create(user=get_test_user(),
                                                       initiative=o,
                                                       is_admin=True)
        count = models.InitiativeLayer.objects.all().count()
        o.add_layer(layer, m)
        self.assertEqual(count + 1,
                         models.InitiativeLayer.objects.all().count())
Example #11
0
 def test_request_decline_by_admin(self):
     o = get_test_organization()
     request = models.JoinRequest.objects.create(
         user=get_test_user(), organization=o)
     self.assertIsNotNone(request)
     admin_membership = models.OrganizationMembership.objects.create(
         user=get_test_user(),
         is_admin=True,
         organization=o
     )
     request.decline(admin_membership)
     self.assertEqual(request.is_open, False)
Example #12
0
    def test_add_layer(self):
        layer = create_layer('Test Layer', 'Abstract', get_test_user())
        self.assertIsNotNone(layer)

        o = get_test_organization()
        m = models.OrganizationMembership.objects.create(user=get_test_user(),
                                                         organization=o,
                                                         is_admin=True)
        count = models.OrganizationLayer.objects.all().count()
        o.add_layer(layer, m)
        self.assertEqual(count + 1,
                         models.OrganizationLayer.objects.all().count())
Example #13
0
 def test_request_approve_by_admin(self):
     o = get_test_organization()
     request = models.JoinRequest.objects.create(user=get_test_user(),
                                                 organization=o)
     self.assertIsNotNone(request)
     admin_membership = models.OrganizationMembership.objects.create(
         user=get_test_user(), is_admin=True, organization=o)
     membership_count = models.OrganizationMembership.objects.all().count()
     request.approve(admin_membership)
     self.assertEqual(request.is_open, False)
     self.assertEqual(membership_count + 1,
                      models.OrganizationMembership.objects.all().count())
Example #14
0
 def test_request_approve_by_admin(self):
     o = get_test_organization()
     request = models.JoinRequest.objects.create(
         user=get_test_user(), organization=o)
     self.assertIsNotNone(request)
     admin_membership = models.OrganizationMembership.objects.create(
         user=get_test_user(),
         is_admin=True,
         organization=o
     )
     membership_count = models.OrganizationMembership.objects.all().count()
     request.approve(admin_membership)
     self.assertEqual(request.is_open, False)
     self.assertEqual(membership_count + 1,
                      models.OrganizationMembership.objects.all().count())
Example #15
0
    def test_only_manager_can_decline_requests(self):
        o = get_test_organization()
        u = get_test_user()
        o.add_member(u, is_admin=True)

        # Create another user to be added as member
        u2, created = User.objects.get_or_create(
            username='******', email='*****@*****.**'
        )
        u2.set_password('testing_password123')
        u2.save()

        membership_request = models.JoinRequest.objects.create(
            user=u2,
            organization=o,
        )
        self.assertIsNotNone(membership_request)

        self.assertTrue(self.client.login(
            username=u.username, password='******'))
        self.client.post(
            reverse(
                "organizations:approve_membership",
                kwargs={
                    'slug': o.slug
                }
            ),
            data={
                'approval': 'decline',
                'request_pk': membership_request.pk
            }
        )
Example #16
0
 def test_manager_post_form(self):
     o = get_test_organization()
     u = get_test_user()
     o.add_member(u, is_admin=True)
     self.assertTrue(self.client.login(
         username=u.username, password='******'))
     response = self.client.post(
         reverse("organizations:manage", kwargs={'slug': o.slug}),
         follow=True,
         data={
             'name': 'test',
             'slogan': 'test',
             'city': 'test',
             'country': 'test',
             'image': None,
             'about': 'test',
             'url0': 'https://google.com',
             'url1': 'https://google.com',
             'url2': 'https://google.com',
             'facebook': 'https://google.com',
             'twitter': 'https://google.com',
             'linkedin': 'https://google.com',
             'github': 'https://google.com',
             'instagram': 'https://google.com'
         }
     )
     # Should redirect to detail page
     self.assertTrue(200 == response.status_code)
     self.assertTemplateUsed(
         response, "organizations/organization_detail.html")
Example #17
0
    def test_join_request(self):
        ini = get_initiative()
        usr = get_test_user()
        join = models.JoinRequest.objects.create(
            initiative=ini,
            user=usr,
        )
        self.assertIsNotNone(join)
        self.assertEqual(join.initiative.pk, ini.pk)
        self.assertEqual(join.user.pk, usr.pk)
        self.assertEqual(True, join.is_open)
        self.assertIsNone(join.approved_by)

        admin_usr = get_user(
            "some_admin", "*****@*****.**", "adminadmin")
        admin_membership = models.InitiativeMembership.objects.create(
            user=admin_usr,
            initiative=ini,
            is_admin=True
        )
        new_membership = join.approve(admin_membership)
        self.assertIsNotNone(new_membership)
        self.assertFalse(join.is_open)
        self.assertEqual(join.approved_by, admin_membership)
        self.assertFalse(new_membership.is_admin)
        self.assertEqual(new_membership.user.pk, usr.pk)
Example #18
0
    def test_api_add_layer(self):
        ini = get_initiative()
        usr = get_test_user()
        layer = create_layer('Test Layer', 'Abstract', usr)
        models.InitiativeMembership.objects.create(
            initiative=ini,
            user=usr,
            is_admin=True,
        )
        initial_layer_count = models.InitiativeLayer.objects.count()

        # Attempt to login the client
        self.assertTrue(self.client.login(
            username=usr.username, password="******"))

        response = self.client.post(
            reverse(
                'initiatives:add_layer',
                kwargs={
                    'layer_pk': layer.pk,
                    'slug': ini.slug
                }
            ),
            {'data': 'data'}
        )
        self.assertRedirects(
            response,
            expected_url=reverse("initiatives:detail", kwargs={'slug': ini.slug}))
        # Should update the Initiatives's layer count
        self.assertEqual(initial_layer_count + 1,
                         models.InitiativeLayer.objects.count())
Example #19
0
    def test_api_add_layer(self):
        org = get_test_organization()
        usr = get_test_user()
        layer = create_layer('Test Layer', 'Abstract', usr)
        models.OrganizationMembership.objects.create(
            organization=org,
            user=usr,
            is_admin=True,
        )
        initial_layer_count = models.OrganizationLayer.objects.count()

        # Attempt to login the client
        self.assertTrue(
            self.client.login(username=usr.username,
                              password="******"))

        response = self.client.post(
            reverse('organizations:add_layer',
                    kwargs={
                        'layer_pk': layer.pk,
                        'slug': org.slug
                    }), {'data': 'data'})
        self.assertRedirects(response,
                             expected_url=reverse("organizations:detail",
                                                  kwargs={'slug': org.slug}))
        # Should update the Organization's layer count
        self.assertEqual(initial_layer_count + 1,
                         models.OrganizationLayer.objects.count())
Example #20
0
 def test_promote_member_to_admin(self):
     o = get_test_organization()
     u = get_test_user()
     o.add_member(u)
     o.promote_member_to_admin(u)
     m = models.OrganizationMembership.objects.get(user=u, organization=o)
     self.assertTrue(m.is_admin)
Example #21
0
 def test_promote_member_to_admin(self):
     o = get_test_organization()
     u = get_test_user()
     o.add_member(u)
     o.promote_member_to_admin(u)
     m = models.OrganizationMembership.objects.get(user=u, organization=o)
     self.assertTrue(m.is_admin)
Example #22
0
 def test_manager_post_form(self):
     o = get_test_organization()
     u = get_test_user()
     o.add_member(u, is_admin=True)
     self.assertTrue(
         self.client.login(username=u.username,
                           password='******'))
     response = self.client.post(reverse("organizations:manage",
                                         kwargs={'slug': o.slug}),
                                 follow=True,
                                 data={
                                     'name': 'test',
                                     'slogan': 'test',
                                     'city': 'test',
                                     'country': 'test',
                                     'image': None,
                                     'about': 'test',
                                     'url0': 'https://josellausas.com',
                                     'url1': 'https://josellausas.com',
                                     'url2': 'https://josellausas.com',
                                     'facebook': 'https://josellausas.com',
                                     'twitter': 'https://josellausas.com',
                                     'linkedin': 'https://josellausas.com',
                                     'github': 'https://josellausas.com',
                                     'instagram': 'https://josellausas.com'
                                 })
     # Should redirect to detail page
     self.assertTrue(200 == response.status_code)
     self.assertTemplateUsed(response,
                             "organizations/organization_detail.html")
Example #23
0
    def test_deny_membership(self):
        ini = get_initiative()
        usr = get_test_user()
        join = models.JoinRequest.objects.create(
            initiative=ini,
            user=usr,
        )
        self.assertIsNotNone(join)
        self.assertEqual(join.initiative.pk, ini.pk)
        self.assertEqual(join.user.pk, usr.pk)
        self.assertEqual(True, join.is_open)
        self.assertIsNone(join.approved_by)

        admin_usr = get_user("some_admin", "*****@*****.**",
                             "adminadmin")
        admin_membership = models.InitiativeMembership.objects.create(
            user=admin_usr, initiative=ini, is_admin=True)
        new_membership = join.approve(admin_membership)
        self.assertIsNotNone(new_membership)
        self.assertFalse(join.is_open)
        self.assertEqual(join.approved_by, admin_membership)
        self.assertFalse(new_membership.is_admin)
        self.assertEqual(new_membership.user.pk, usr.pk)
        self.assertTrue(
            self.client.login(username='******', password="******"))
        response = self.client.post(reverse('initiatives:approve_membership',
                                            kwargs={'slug': ini.slug}),
                                    follow=True,
                                    data={
                                        'request_pk': join.pk,
                                        'approval': 'decline'
                                    })
        self.assertEqual(200, response.status_code)
Example #24
0
    def test_only_manager_can_decline_requests(self):
        o = get_test_organization()
        u = get_test_user()
        o.add_member(u, is_admin=True)

        # Create another user to be added as member
        u2, created = User.objects.get_or_create(
            username='******', email='*****@*****.**')
        u2.set_password('testing_password123')
        u2.save()

        membership_request = models.JoinRequest.objects.create(
            user=u2,
            organization=o,
        )
        self.assertIsNotNone(membership_request)

        self.assertTrue(
            self.client.login(username=u.username,
                              password='******'))
        self.client.post(reverse("organizations:approve_membership",
                                 kwargs={'slug': o.slug}),
                         data={
                             'approval': 'decline',
                             'request_pk': membership_request.pk
                         })
Example #25
0
 def test_manager_get_access(self):
     o = get_test_organization()
     u = get_test_user()
     o.add_member(u, is_admin=True)
     self.assertTrue(self.client.login(
         username=u.username, password='******'))
     response = self.client.get(
         reverse("organizations:manage", kwargs={'slug': o.slug}))
     self.assertTemplateUsed(response, "organizations/manager.html")
Example #26
0
 def test_set_admin(self):
     o = get_test_organization()
     user = get_test_user()
     # Should have no admins
     self.assertEqual(0, o.get_admin_memberships().count())
     # Needs to be saved before you can add members or admins
     o.add_member(user, is_admin=True)
     admin_memberships = o.get_admin_memberships()
     # Should have 1 admin
     self.assertEqual(1, admin_memberships.count())
Example #27
0
 def test_set_admin(self):
     o = get_test_organization()
     user = get_test_user()
     # Should have no admins
     self.assertEqual(0, o.get_admin_memberships().count())
     # Needs to be saved before you can add members or admins
     o.add_member(user, is_admin=True)
     admin_memberships = o.get_admin_memberships()
     # Should have 1 admin
     self.assertEqual(1, admin_memberships.count())
Example #28
0
 def test_manager_get_access(self):
     o = get_test_organization()
     u = get_test_user()
     o.add_member(u, is_admin=True)
     self.assertTrue(
         self.client.login(username=u.username,
                           password='******'))
     response = self.client.get(
         reverse("organizations:manage", kwargs={'slug': o.slug}))
     self.assertTemplateUsed(response, "organizations/manager.html")
Example #29
0
 def test_manager_page(self):
     admin_usr = get_test_user()
     ini = get_initiative()
     admin_membership = ini.add_member(admin_usr, is_admin=True)
     self.assertTrue(admin_membership.is_admin)
     self.assertTrue(self.login())
     response = self.client.get(reverse('initiatives:manage', kwargs={
         'slug': ini.slug
     }), follow=True)
     self.assertContains(response, ini.name)
Example #30
0
 def test_manager_page(self):
     admin_usr = get_test_user()
     ini = get_initiative()
     admin_membership = ini.add_member(admin_usr, is_admin=True)
     self.assertTrue(admin_membership.is_admin)
     self.assertTrue(self.login())
     response = self.client.get(reverse('initiatives:manage',
                                        kwargs={'slug': ini.slug}),
                                follow=True)
     self.assertContains(response, ini.name)
Example #31
0
 def test_memberships(self):
     ini = get_initiative()
     usr = get_test_user()
     member = models.InitiativeMembership.objects.create(
         initiative=ini,
         user=usr,
     )
     self.assertIsNotNone(member)
     self.assertEqual(False, member.is_admin)
     self.assertEqual(member.user.pk, usr.pk)
     self.assertEqual(member.initiative.pk, ini.pk)
Example #32
0
 def test_request_membership_without_auth(self):
     ini = get_initiative()
     usr = get_test_user()
     response = self.client.post(reverse('initiatives:request_membership',
                                         kwargs={
                                             'slug': ini.slug,
                                         }),
                                 follow=True,
                                 data={'hi': 'hello'})
     self.assertTrue(200 == response.status_code)
     self.assertTemplateNotUsed('initiatives/detail.html')
Example #33
0
 def test_memberships(self):
     ini = get_initiative()
     usr = get_test_user()
     member = models.InitiativeMembership.objects.create(
         initiative=ini,
         user=usr,
     )
     self.assertIsNotNone(member)
     self.assertEqual(False, member.is_admin)
     self.assertEqual(member.user.pk, usr.pk)
     self.assertEqual(member.initiative.pk, ini.pk)
Example #34
0
 def test_create_layer(self):
     """
     Tests the layer creation helper method
     """
     owner = utils.get_test_user()
     initial_count = Layer.objects.all().count()
     layer = utils.create_layer("Test title", "A descriptiion", owner)
     final_count = Layer.objects.all().count()
     self.assertEqual(final_count, initial_count + 1)
     self.assertIsInstance(layer, Layer)
     self.assertEqual(layer.owner_id, owner.id)
     self.assertEqual(layer.title, "Test title")
Example #35
0
 def test_create_layer(self):
     """
     Tests the layer creation helper method
     """
     owner = utils.get_test_user()
     initial_count = Layer.objects.all().count()
     layer = utils.create_layer("Test title", "A descriptiion", owner)
     final_count = Layer.objects.all().count()
     self.assertEqual(final_count, initial_count + 1)
     self.assertIsInstance(layer, Layer)
     self.assertEqual(layer.owner_id, owner.id)
     self.assertEqual(layer.title, "Test title")
Example #36
0
 def test_organization_detail_view_post_remove_featured_mapstory(self):
     o = get_initiative()
     u = get_test_user()
     layer = create_layer('Test Layer', 'Abstract', u)
     membership = models.InitiativeMembership.objects.create(
         initiative=o, user=u)
     o.add_layer(layer, membership)
     r = self.client.post(reverse("initiatives:detail", kwargs={"slug": o.slug}), data={
         "remove_featured_mapstory": "q",
         "layer_pk": layer.pk,
         "mapstory_pk": layer.pk,
     })
     self.assertEqual(404, r.status_code)
Example #37
0
 def test_organization_detail_view_post(self):
     o = get_test_organization()
     u = get_test_user()
     layer = create_layer('Test Layer', 'Abstract', u)
     membership = models.OrganizationMembership.objects.create(
         organization=o, user=u)
     o.add_layer(layer, membership)
     r = self.client.post(reverse("organizations:detail", kwargs={"slug": o.slug}), data={
         "add_featured_layer": "quesito",
         "layer_pk": layer.pk,
         "mapstory_pk": layer.pk,
     })
     self.assertEqual(200, r.status_code)
Example #38
0
 def test_manager_post(self):
     o = get_test_organization()
     u = get_test_user()
     o.add_member(u, is_admin=True)
     self.assertTrue(
         self.client.login(username=u.username,
                           password='******'))
     response = self.client.post(reverse("organizations:manage",
                                         kwargs={'slug': o.slug}),
                                 follow=True,
                                 data={'post': 'post_testing'})
     self.assertTrue(200 == response.status_code)
     self.assertTemplateUsed(response, "organizations/manager.html")
Example #39
0
 def test_add_featured_layer(self):
     o = get_initiative()
     u = get_test_user()
     layer = create_layer('Test Layer', 'Abstract', u)
     membership = models.InitiativeMembership.objects.create(
         initiative=o, user=u)
     o.add_layer(layer, membership)
     r = self.client.post(reverse("initiatives:detail", kwargs={"slug": o.slug}), data={
         "add_featured_layer": "quesito",
         "layer_pk": layer.pk,
         "mapstory_pk": layer.pk,
     })
     self.assertEqual(200, r.status_code)
Example #40
0
 def test_manager_post(self):
     o = get_test_organization()
     u = get_test_user()
     o.add_member(u, is_admin=True)
     self.assertTrue(self.client.login(
         username=u.username, password='******'))
     response = self.client.post(
         reverse("organizations:manage", kwargs={'slug': o.slug}),
         follow=True,
         data={
             'post': 'post_testing'
         }
     )
     self.assertTrue(200 == response.status_code)
     self.assertTemplateUsed(response, "organizations/manager.html")
Example #41
0
 def test_organization_detail_view_post(self):
     o = get_initiative()
     u = get_test_user()
     layer = create_layer('Test Layer', 'Abstract', u)
     membership = models.InitiativeMembership.objects.create(initiative=o,
                                                             user=u)
     o.add_layer(layer, membership)
     r = self.client.post(reverse("initiatives:detail",
                                  kwargs={"slug": o.slug}),
                          data={
                              "add_featured_layer": "quesito",
                              "layer_pk": layer.pk,
                              "mapstory_pk": layer.pk,
                          })
     self.assertEqual(200, r.status_code)
Example #42
0
    def test_join_this_initiative(self):
        usr = get_test_user()
        ini = get_initiative()
        count = models.JoinRequest.objects.all().count()
        self.assertTrue(
            self.client.login(username=usr.username,
                              password='******'))
        response = self.client.post(reverse('initiatives:request_membership',
                                            kwargs={'slug': ini.slug}),
                                    data={'data': 'data'},
                                    follow=True)

        self.assertEqual(200, response.status_code)
        new_count = models.JoinRequest.objects.all().count()
        self.assertTrue(count + 1 == new_count)
Example #43
0
 def test_organization_detail_view_post_remove_featured_mapstory(self):
     o = get_test_organization()
     u = get_test_user()
     layer = create_layer('Test Layer', 'Abstract', u)
     membership = models.OrganizationMembership.objects.create(
         organization=o, user=u)
     o.add_layer(layer, membership)
     r = self.client.post(reverse("organizations:detail",
                                  kwargs={"slug": o.slug}),
                          data={
                              "remove_featured_mapstory": "q",
                              "layer_pk": layer.pk,
                              "mapstory_pk": layer.pk,
                          })
     self.assertEqual(404, r.status_code)
Example #44
0
 def test_request_join(self):
     ini = get_initiative()
     usr = get_test_user()
     self.assertTrue(
         self.client.login(username=usr.username,
                           password='******'))
     count = models.JoinRequest.objects.count()
     response = self.client.post(reverse('initiatives:request_membership',
                                         kwargs={
                                             'slug': ini.slug,
                                         }),
                                 follow=True,
                                 data={'hi': 'hello'})
     self.assertTrue(200 == response.status_code)
     self.assertTrue((count + 1) == models.JoinRequest.objects.count())
Example #45
0
 def test_request_join(self):
     ini = get_initiative()
     usr = get_test_user()
     self.assertTrue(
         self.client.login(username=usr.username,
                           password='******')
     )
     count = models.JoinRequest.objects.count()
     response = self.client.post(
         reverse('initiatives:request_membership', kwargs={
             'slug': ini.slug,
         }),
         follow=True,
         data={'hi': 'hello'}
     )
     self.assertTrue(200 == response.status_code)
     self.assertTrue((count + 1) == models.JoinRequest.objects.count())
Example #46
0
    def test_join_this_initiative(self):
        usr = get_test_user()
        ini = get_initiative()
        count = models.JoinRequest.objects.all().count()
        self.assertTrue(
            self.client.login(username=usr.username,
                              password='******')
        )
        response = self.client.post(
            reverse('initiatives:request_membership',
                    kwargs={'slug': ini.slug}),
            data={'data': 'data'},
            follow=True
        )

        self.assertEqual(200, response.status_code)
        new_count = models.JoinRequest.objects.all().count()
        self.assertTrue(count + 1 == new_count)
Example #47
0
    def test_accept_request_to_join_and_decline(self):
        o = get_test_organization()
        u = get_test_user()
        j = models.JoinRequest.objects.create(organization=o, user=u)
        admin = User.objects.create_user(username='******',
                                         email='*****@*****.**',
                                         password='******')
        admin_membership = models.OrganizationMembership.objects.create(
            organization=o, user=admin, is_admin=True)
        j.approve(admin_membership)

        other_user = User.objects.create_user(
            username='******',
            email='*****@*****.**',
            password='******')
        self.assertIsNotNone(
            models.OrganizationMembership.objects.get(organization=o, user=u))
        j2 = models.JoinRequest.objects.create(organization=o, user=other_user)
        j2.decline(admin_membership)
Example #48
0
 def test_manager_post_form(self):
     ini = get_initiative()
     usr = get_test_user()
     admin_membership = ini.add_member(usr, is_admin=True)
     self.assertTrue(
         self.client.login(username=usr.username,
                           password='******'))
     response = self.client.post(reverse('initiatives:manage',
                                         kwargs={'slug': ini.slug}),
                                 follow=True,
                                 data={
                                     'name': 'test',
                                     'slogan': 'test',
                                     'city': 'test',
                                     'country': 'test',
                                     'image': None,
                                     'about': 'test',
                                 })
     self.assertEqual(200, response.status_code)
Example #49
0
 def test_manager_post_form(self):
     ini = get_initiative()
     usr = get_test_user()
     ini.add_member(usr, is_admin=True)
     self.assertTrue(
         self.client.login(username=usr.username,
                           password='******')
     )
     response = self.client.post(
         reverse('initiatives:manage', kwargs={'slug': ini.slug}),
         follow=True,
         data={
             'name': 'test',
             'slogan': 'test',
             'city': 'test',
             'country': 'test',
             'image': None,
             'about': 'test',
         }
     )
     self.assertEqual(200, response.status_code)
Example #50
0
    def test_deny_membership(self):
        ini = get_initiative()
        usr = get_test_user()
        join = models.JoinRequest.objects.create(
            initiative=ini,
            user=usr,
        )
        self.assertIsNotNone(join)
        self.assertEqual(join.initiative.pk, ini.pk)
        self.assertEqual(join.user.pk, usr.pk)
        self.assertEqual(True, join.is_open)
        self.assertIsNone(join.approved_by)

        admin_usr = get_user(
            "some_admin", "*****@*****.**", "adminadmin")
        admin_membership = models.InitiativeMembership.objects.create(
            user=admin_usr,
            initiative=ini,
            is_admin=True
        )
        new_membership = join.approve(admin_membership)
        self.assertIsNotNone(new_membership)
        self.assertFalse(join.is_open)
        self.assertEqual(join.approved_by, admin_membership)
        self.assertFalse(new_membership.is_admin)
        self.assertEqual(new_membership.user.pk, usr.pk)
        self.assertTrue(self.client.login(
            username='******', password="******"))
        response = self.client.post(
            reverse('initiatives:approve_membership', kwargs={
                'slug': ini.slug
            }),
            follow=True,
            data={
                'request_pk': join.pk,
                'approval': 'decline'
            }
        )
        self.assertEqual(200, response.status_code)
Example #51
0
    def test_accept_request_to_join_and_decline(self):
        o = get_test_organization()
        u = get_test_user()
        j = models.JoinRequest.objects.create(organization=o, user=u)
        admin = User.objects.create_user(
            username='******',
            email='*****@*****.**',
            password='******'
        )
        admin_membership = models.OrganizationMembership.objects.create(
            organization=o, user=admin, is_admin=True)
        j.approve(admin_membership)

        other_user = User.objects.create_user(
            username='******',
            email='*****@*****.**',
            password='******'
        )
        self.assertIsNotNone(
            models.OrganizationMembership.objects.get(organization=o, user=u))
        j2 = models.JoinRequest.objects.create(organization=o, user=other_user)
        j2.decline(admin_membership)
Example #52
0
    def test_join_request(self):
        ini = get_initiative()
        usr = get_test_user()
        join = models.JoinRequest.objects.create(
            initiative=ini,
            user=usr,
        )
        self.assertIsNotNone(join)
        self.assertEqual(join.initiative.pk, ini.pk)
        self.assertEqual(join.user.pk, usr.pk)
        self.assertEqual(True, join.is_open)
        self.assertIsNone(join.approved_by)

        admin_usr = get_user("some_admin", "*****@*****.**",
                             "adminadmin")
        admin_membership = models.InitiativeMembership.objects.create(
            user=admin_usr, initiative=ini, is_admin=True)
        new_membership = join.approve(admin_membership)
        self.assertIsNotNone(new_membership)
        self.assertFalse(join.is_open)
        self.assertEqual(join.approved_by, admin_membership)
        self.assertFalse(new_membership.is_admin)
        self.assertEqual(new_membership.user.pk, usr.pk)
Example #53
0
    def test_add_mapstory_with_membership(self):
        user = get_test_user()
        self.assertTrue(
            self.client.login(username=user.username,
                              password="******"))
        o = get_test_organization()
        self.assertIsNotNone(o.add_member(user, is_admin=True))
        mapstory = create_mapstory(user, "Testing Mapstory")
        self.assertIsNotNone(mapstory)

        initial_count = models.OrganizationMapStory.objects.filter(
            organization=o).count()
        response = self.client.post(reverse("organizations:add_mapstory",
                                            kwargs={
                                                'slug': o.slug,
                                                'mapstory_pk': mapstory.pk
                                            }), {'data': 'data'},
                                    follow=True)
        self.assertEqual(200, response.status_code)
        # Should have added 1 mapstory to the organization
        final_count = models.OrganizationMapStory.objects.filter(
            organization=o).count()
        self.assertEqual(initial_count + 1, final_count)
Example #54
0
    def test_add_mapstory_with_membership(self):
        user = get_test_user()
        self.assertTrue(self.client.login(
            username=user.username, password="******"))
        o = get_initiative()
        self.assertIsNotNone(o.add_member(user, is_admin=True))
        mapstory = create_mapstory(user, "Testing Mapstory")
        self.assertIsNotNone(mapstory)

        initial_count = models.InitiativeMapStory.objects.filter(
            initiative=o).count()
        response = self.client.post(
            reverse("initiatives:add_mapstory", kwargs={
                'slug': o.slug,
                'mapstory_pk': mapstory.pk
            }),
            {'data': 'data'},
            follow=True
        )
        self.assertEqual(200, response.status_code)
        # Should have added 1 mapstory to the initiative
        final_count = models.InitiativeMapStory.objects.filter(
            initiative=o).count()
        self.assertEqual(initial_count + 1, final_count)
Example #55
0
from django.contrib.auth import get_user_model
from django.core.urlresolvers import reverse
from django.test import Client, TestCase

from mapstory.tests.AdminClient import AdminClient
from mapstory.tests.utils import create_layer, create_mapstory, get_test_user

from . import models

User = get_user_model()
testUser = get_test_user()


def get_test_organization():
    """Creates and returns a test Organization model"""
    org = models.Organization()
    org.name = 'Test'
    org.slogan = 'Slogan here'
    org.about = "Yeah!"
    org.save()
    return org


class TestOrganizations(TestCase):

    """Organizations' Tests."""

    def test_uses_template(self):
        c = Client()
        models.Organization()
        response = c.get(reverse('organizations:list'))
Example #56
0
 def setUp(self):
     super(TeamTests, self).setUp()
     self.username = '******'
     self.password = '******'
     self.user = get_test_user()
Example #57
0
from django.test import TestCase, Client
from django.core.urlresolvers import reverse
from django.contrib.auth import get_user_model, authenticate, get_user

from geonode.layers.models import Layer

from mapstory.tests.AdminClient import AdminClient
from mapstory.tests.utils import get_test_user, create_mapstory, create_layer, create_user
from . import models

User = get_user_model()
testUser = get_test_user()


def get_test_organization():
    """Creates and returns a test Organization model"""
    org = models.Organization()
    org.title = 'Test'
    org.slogan = 'Slogan here'
    org.about = "Yeah!"
    org.save()
    return org


class TestOrganizations(TestCase):
    """Organizations' Tests."""
    def test_uses_template(self):
        c = Client()
        models.Organization()
        response = c.get(reverse('organizations:list'))
        self.assertTemplateUsed(
Example #58
0
 def setUp(self):
     super(TeamTests, self).setUp()
     self.username = '******'
     self.password = '******'
     self.user = get_test_user()