Пример #1
0
    def answer_invitation_email(self, community, password):
        invitation_url = re.compile(
            r'%s\.eldmyra\.se(.*?)"' % community).search(
                mail.outbox[0].html_message).groups(0)[0].replace(
                    '&', '&')
        invitation_url, params = split_url_and_params(invitation_url)

        new_client = Client()
        new_client.community = 'test'
        response = new_client.post(
            invitation_url, {
                'first_name': params['email'].replace('@', '_').replace(
                    '.', '_'),
                'last_name': 'User',
                'birthday': '1980-04-17',
                'gender': 'M',
                'password': password,
                'confirm_password': password,
                'email': params['email'],
                'email': params['email'],
                'code': params['code'],
                'user_contract': 'checked'
            })
        self.assertEquals(response.status_code, 302)
        self.assertEquals(
            response['Location'],
            'http://community.%s.eldmyra.se/' % new_client.community)
        new_client.user = User.objects.get(email=params['email'])
        del mail.outbox[0]
        return new_client
Пример #2
0
 def create_community(self, name, email):
     old_user_count = User.objects.all().count()
     old_group_count = Group.objects.all().count()
     client = Client()
     client.community = 'eldmyra'
     response = client.post('/create_community/', {'name':name, 'domain':name+'.eldmyra.se', 'email':email, 'confirm_email':email, 'community_type':'Friends', 'user_contract':'checked'})
     self.assertEquals(response.status_code, 200)
     #self.assertContains(response.contents, '%s.eldmyra.se' % name)
     self.assertEquals(len(mail.outbox), 1)
     self.assertEquals(old_group_count+1, Group.objects.all().count())
     self.assertEquals(old_user_count+1, User.objects.all().count())
     del mail.outbox[0]
Пример #3
0
    def answer_invitation_email(self, community, password):
        invitation_url = re.compile(r'%s\.eldmyra\.se(.*?)"' % community).search(mail.outbox[0].html_message).groups(0)[0].replace('&', '&')
        invitation_url, params = split_url_and_params(invitation_url)

        new_client = Client()
        new_client.community = 'test'
        response = new_client.post(invitation_url, {'first_name':params['email'].replace('@', '_').replace('.', '_'), 'last_name':'User', 'birthday':'1980-04-17', 'gender':'M', 'password':password, 'confirm_password':password, 'email':params['email'], 'email':params['email'], 'code':params['code'], 'user_contract':'checked'})
        self.assertEquals(response.status_code, 302)
        self.assertEquals(response['Location'], 'http://community.%s.eldmyra.se/' % new_client.community)
        new_client.user = User.objects.get(email=params['email'])
        del mail.outbox[0]
        return new_client
Пример #4
0
 def create_community(self, name, email):
     old_user_count = User.objects.all().count()
     old_group_count = Group.objects.all().count()
     client = Client()
     client.community = 'eldmyra'
     response = client.post(
         '/create_community/', {
             'name': name,
             'domain': name + '.eldmyra.se',
             'email': email,
             'confirm_email': email,
             'community_type': 'Friends',
             'user_contract': 'checked'
         })
     self.assertEquals(response.status_code, 200)
     #self.assertContains(response.contents, '%s.eldmyra.se' % name)
     self.assertEquals(len(mail.outbox), 1)
     self.assertEquals(old_group_count + 1, Group.objects.all().count())
     self.assertEquals(old_user_count + 1, User.objects.all().count())
     del mail.outbox[0]
Пример #5
0
    def test_all(self):
        # create the first community the manual way
        self.community = Group.objects.create(name='test')
        MetaGroup.objects.create(group=self.community,
                                 created_by=self.superuser,
                                 domain='test.eldmyra.se')

        self.superuser_client = Client()

        self.superuser_client.community = 'test'
        login(self.superuser_client, self.superuser.email, 'superuserpassword')

        # "eldmyra" community is special as it is used by the external page
        Group.objects.create(name='eldmyra')

        # create users
        self.admin_client = self.create_user(inviter=self.superuser_client,
                                             email='*****@*****.**',
                                             password='******',
                                             community='test')
        self.user_client = self.create_user(inviter=self.superuser_client,
                                            email='*****@*****.**',
                                            password='******',
                                            community='test')
        self.user_client2 = self.create_user(inviter=self.superuser_client,
                                             email='*****@*****.**',
                                             password='******',
                                             community='test')
        self.user_client3 = self.create_user(inviter=self.superuser_client,
                                             email='*****@*****.**',
                                             password='******',
                                             community='test')
        self.assertEqual(
            SubscriptionResult.objects.all().count(),
            6)  # 6 = SubscriptionResults from the joining: 0+1+2+3
        SubscriptionResult.objects.all().delete()

        # check that the user cannot invite people
        self.invite(self.user_client, email='*****@*****.**', fail=True)

        # login tests
        client = Client()
        client.community = 'test'
        login(
            client, 'fake@email', 'superuserpassword', expected_code=200
        )  # Try to log in with a username that does not exist but a password that does
        login(
            client, self.superuser.email, 'blabla', expected_code=200
        )  # Try to log in with the an existing user but a password that does not exist
        login(client, 'fake@email', password='******', expected_code=200
              )  # Try to log in with neither password or username existing
        login(
            client,
            self.superuser.email,
            password='******',
            expected_code=200
        )  # Try to log in with an existing user using another existing users password

        # check that test.eldmyra.se shows normally
        self.assertContains(self.user_client.get('/'),
                            'site-media/login_background.jpg')

        # create another community with a new user: test2
        self.create_community('test2', '*****@*****.**')

        # TODO: create another community with an existing user: test3

        # TODO: create users for test2

        # set all the users to view the inside community
        self.user_client.community = 'community.test'
        self.superuser_client.community = 'community.test'
        self.admin_client.community = 'community.test'

        # check that community.test.eldmyra.se leads to the portal
        self.assertContains(self.user_client.get('/'), 'Portal')

        # create objects
        objects = self.create_objects(self.user_client)
        # check that the creator user did not get SubscriptionResults
        self.assertEqual(
            SubscriptionResult.objects.filter(
                user=self.user_client.user).count(), 0)
        # check that all the non-creators got SubscriptionResults
        self.assertEqual(
            SubscriptionResult.objects.all().count(),
            len(new_notification_classes) *
            (Group.objects.get(name='test').user_set.count() -
             1))  # notifications = things to watch * (members - the creator)
        # check that the admin got SubscriptionResults for each created object
        for key in objects:
            if key not in [Bug]:  # ignore list
                url = '/notifications/new/%s/' % get_content_type(key).id
                s = u'%s' % objects[key]
                content = smart_unicode(self.admin_client.get(url).content)
                self.assert_(
                    s in content,
                    u'new object list for %s broken: %s not in %s' %
                    (str(key), s, content))
        # TODO: check that members of other communities didn't get notifications
        # TODO: notifications
        # TODO: check that a user from another community cannot view the objects
        # TODO: check that an admin from another community cannot view the objects
        self.check_access('view', self.user_client,
                          objects)  # check that the user can view them all
        self.check_access('view', self.admin_client,
                          objects)  # check that the admin can view them all
        self.check_access(
            'view', self.superuser_client,
            objects)  # check that the superuser can view them all
        self.check_access(
            'delete', self.superuser_client,
            objects)  # check that the superuser can delete them all
        self.delete_all_objects()

        # check that a user can reply to thread he did not create
        objects = self.create_objects(self.user_client)
        self.assertEqual(Message.objects.all().count(), 2)
        self.create_object(self.user_client2, objects, Message,
                           objects[Thread].get_absolute_url(), {
                               'body': 'body',
                               'parent_message_id': objects[Message].id
                           })
        self.assertEqual(Message.objects.all().count(), 3)
        self.delete_all_objects()

        objects = self.create_objects(self.user_client)
        self.check_access(
            'delete', self.user_client,
            objects)  # check that the user can delete the objects
        self.delete_all_objects()

        objects = self.create_objects(self.user_client)
        self.check_access(
            'delete', self.admin_client, objects, fail=all_classes
        )  # check that another user cannot delete the objects
        self.delete_all_objects()

        administration_content_types = [
            ('thread', [Thread, Message]),
            ('file', [File]),
            ('image_set', [ImageSet, Image]),
            ('event', [Event]),
            #'homepage', [?]),
        ]

        for domain in administration_content_types:
            objects = self.create_objects(self.user_client)
            old_number_of_objects = 0
            old_number_of_objects = sum([
                cls.objects.filter(deleted=False).count() for cls in domain[1]
            ])
            self.superuser_client.post(
                '/administration/', {
                    'new_%s' % domain[0]: 'checked',
                    'new_user_id': self.admin_client.user.id
                })  # add domain admin rights to admin
            self.check_access(
                'delete',
                self.admin_client,
                objects,
                fail=set(all_classes) - set(domain[1])
            )  # check that the admin can delete things in the domain but not anything else
            new_number_of_objects = sum([
                cls.objects.filter(deleted=False).count() for cls in domain[1]
            ])
            if not old_number_of_objects > new_number_of_objects:
                print domain
            self.assert_(old_number_of_objects > new_number_of_objects)
            self.delete_all_objects()

        # TODO: check that an admin from community X cannot view or delete objects in community Y

        # user settings
        # change presentation and set user image
        # remove user image
        # change password
        # homepage administration
        # bookmarks
        # notifications (check that they don't leak across community borders!)

        # create a second community
        # invite an existing user to the community

        # log out
        self.assertEqual(
            self.superuser_client.get('/logout/').status_code, 302)
Пример #6
0
    def test_all(self):
        # create the first community the manual way
        self.community = Group.objects.create(name='test')
        MetaGroup.objects.create(group=self.community, created_by=self.superuser, domain='test.eldmyra.se')

        self.superuser_client = Client()

        self.superuser_client.community = 'test'
        login(self.superuser_client, self.superuser.email, 'superuserpassword')

        # "eldmyra" community is special as it is used by the external page
        Group.objects.create(name='eldmyra')

        # create users
        self.admin_client = self.create_user(inviter=self.superuser_client, email='*****@*****.**', password='******', community='test')
        self.user_client = self.create_user(inviter=self.superuser_client, email='*****@*****.**', password='******', community='test')
        self.user_client2 = self.create_user(inviter=self.superuser_client, email='*****@*****.**', password='******', community='test')
        self.user_client3 = self.create_user(inviter=self.superuser_client, email='*****@*****.**', password='******', community='test')
        self.assertEqual(SubscriptionResult.objects.all().count(), 6) # 6 = SubscriptionResults from the joining: 0+1+2+3
        SubscriptionResult.objects.all().delete()
        
        # check that the user cannot invite people
        self.invite(self.user_client, email='*****@*****.**', fail=True)

        # login tests
        client = Client()
        client.community = 'test'
        login(client, 'fake@email', 'superuserpassword', expected_code=200) # Try to log in with a username that does not exist but a password that does
        login(client, self.superuser.email, 'blabla', expected_code=200) # Try to log in with the an existing user but a password that does not exist
        login(client, 'fake@email', password='******', expected_code=200) # Try to log in with neither password or username existing
        login(client, self.superuser.email, password='******', expected_code=200) # Try to log in with an existing user using another existing users password

        # check that test.eldmyra.se shows normally
        self.assertContains(self.user_client.get('/'), 'site-media/login_background.jpg')
        
        # create another community with a new user: test2
        self.create_community('test2', '*****@*****.**')
        
        # TODO: create another community with an existing user: test3
        
        # TODO: create users for test2

        # set all the users to view the inside community
        self.user_client.community = 'community.test'
        self.superuser_client.community = 'community.test'
        self.admin_client.community = 'community.test'

        # check that community.test.eldmyra.se leads to the portal
        self.assertContains(self.user_client.get('/'), 'Portal')

        # create objects
        objects = self.create_objects(self.user_client)
        # check that the creator user did not get SubscriptionResults
        self.assertEqual(SubscriptionResult.objects.filter(user=self.user_client.user).count(), 0)
        # check that all the non-creators got SubscriptionResults
        self.assertEqual(SubscriptionResult.objects.all().count(), len(new_notification_classes)*(Group.objects.get(name='test').user_set.count()-1)) # notifications = things to watch * (members - the creator)
        # check that the admin got SubscriptionResults for each created object
        for key in objects:
            if key not in [Bug]: # ignore list
                url = '/notifications/new/%s/' % get_content_type(key).id
                s = u'%s' % objects[key]
                content = smart_unicode(self.admin_client.get(url).content)
                self.assert_(s in content, u'new object list for %s broken: %s not in %s' % (str(key), s, content))
        # TODO: check that members of other communities didn't get notifications
        # TODO: notifications
        # TODO: check that a user from another community cannot view the objects
        # TODO: check that an admin from another community cannot view the objects
        self.check_access('view', self.user_client, objects) # check that the user can view them all
        self.check_access('view', self.admin_client, objects) # check that the admin can view them all
        self.check_access('view', self.superuser_client, objects) # check that the superuser can view them all
        self.check_access('delete', self.superuser_client, objects) # check that the superuser can delete them all
        self.delete_all_objects()
        
        # check that a user can reply to thread he did not create
        objects = self.create_objects(self.user_client)
        self.assertEqual(Message.objects.all().count(), 2)
        self.create_object(self.user_client2, objects, Message, objects[Thread].get_absolute_url(), {'body':'body', 'parent_message_id':objects[Message].id})
        self.assertEqual(Message.objects.all().count(), 3)
        self.delete_all_objects()        
        
        objects = self.create_objects(self.user_client)
        self.check_access('delete', self.user_client, objects) # check that the user can delete the objects
        self.delete_all_objects()

        objects = self.create_objects(self.user_client)
        self.check_access('delete', self.admin_client, objects, fail=all_classes) # check that another user cannot delete the objects
        self.delete_all_objects()
        
        administration_content_types = [
            ('thread', [Thread, Message]),
            ('file', [File]),
            ('image_set', [ImageSet, Image]),
            ('event' , [Event]),
            #'homepage', [?]),
        ]
        
        for domain in administration_content_types:
            objects = self.create_objects(self.user_client)
            old_number_of_objects = 0
            old_number_of_objects = sum([cls.objects.filter(deleted=False).count() for cls in domain[1]])
            self.superuser_client.post('/administration/', {'new_%s' % domain[0]:'checked', 'new_user_id':self.admin_client.user.id}) # add domain admin rights to admin
            self.check_access('delete', self.admin_client, objects, fail=set(all_classes)-set(domain[1])) # check that the admin can delete things in the domain but not anything else
            new_number_of_objects = sum([cls.objects.filter(deleted=False).count() for cls in domain[1]])
            if not old_number_of_objects > new_number_of_objects:
                print domain
            self.assert_(old_number_of_objects > new_number_of_objects)
            self.delete_all_objects()
            
        # TODO: check that an admin from community X cannot view or delete objects in community Y

        # user settings
        # change presentation and set user image
        # remove user image
        # change password
        # homepage administration
        # bookmarks
        # notifications (check that they don't leak across community borders!)
        
        # create a second community
        # invite an existing user to the community

        # log out
        self.assertEqual(self.superuser_client.get('/logout/').status_code, 302)