desc
stringlengths
3
26.7k
decl
stringlengths
11
7.89k
bodies
stringlengths
8
553k
'Test page with login at /admin/group/add'
def test_core_group_add(self):
response = self.client.get(reverse('core_admin_group_add')) self.assertEquals(response.status_code, 200)
'Test index page with login at /admin/group/view/<group_id>'
def test_core_group_view(self):
response = self.client.get(reverse('core_admin_group_view', args=[self.group.id])) self.assertEquals(response.status_code, 200)
'Test index page with login at /admin/group/edit/<group_id>'
def test_core_group_edit(self):
response = self.client.get(reverse('core_admin_group_edit', args=[self.group.id])) self.assertEquals(response.status_code, 200)
'Test index page with login at /admin/group/delete/<group_id>'
def test_core_group_delete(self):
response = self.client.get(reverse('core_admin_group_delete', args=[self.group.id])) self.assertEquals(response.status_code, 200)
'Test index page with login at /admin/settings/view/'
def test_core_settings_view(self):
response = self.client.get(reverse('core_settings_view')) self.assertEquals(response.status_code, 200)
'Test index page with login at /admin/settings/edit/'
def test_core_settings_edit(self):
response = self.client.get(reverse('core_settings_edit')) self.assertEquals(response.status_code, 200)
'A logout request from an already logged out user should be harmless'
def test_user_logout(self):
response = self.client.get(reverse('user_logout')) self.assertRedirects(response, reverse('user_login')) self.assertNotIn('_auth_user_id', self.client.session)
'Test login page at /login'
def test_user_login(self):
response = self.client.post(reverse('user_login'), {'username': self.username, 'password': self.password}) self.assertRedirects(response, '/') self.assertEqual(self.client.session['_auth_user_id'], self.user.pk)
'Just test that the logo view works'
def test_logo(self):
response = self.client.get(reverse('core_logo_image')) self.assertEquals(response.status_code, 200)
'Test home page at /'
def test_home(self):
response = self.client.get('/') self.assertRedirects(response, reverse('user_login'))
'Test page at /admin/perspectives/'
def test_index_perspectives_out(self):
response = self.client.get(reverse('core_admin_index_perspectives')) self.assertRedirects(response, reverse('user_login'))
'Test add perspective page at /admin/perspective/add'
def test_perspective_add_out(self):
response = self.client.get(reverse('core_admin_perspective_add')) self.assertRedirects(response, reverse('user_login'))
'Test perspective view at /admin/perspective/view/<perspective_id>'
def test_perspective_view_out(self):
response = self.client.get(reverse('core_admin_perspective_view', args=[self.perspective.id])) self.assertRedirects(response, reverse('user_login'))
'Test perspective add at /admin/perspective/edit/<perspective_id>'
def test_perspective_edit_out(self):
response = self.client.get(reverse('core_admin_perspective_edit', args=[self.perspective.id])) self.assertRedirects(response, reverse('user_login'))
'Test perspective delete at /admin/perspective/delete/<perspective_id>'
def test_perspective_delete_out(self):
response = self.client.get(reverse('core_admin_perspective_delete', args=[self.perspective.id])) self.assertRedirects(response, reverse('user_login'))
'Test index modules page at /admin/modules/'
def test_index_modules_out(self):
response = self.client.get(reverse('core_admin_index_modules')) self.assertRedirects(response, reverse('user_login'))
'Test index users page at /admin/users/'
def test_index_users_out(self):
response = self.client.get(reverse('core_admin_index_users')) self.assertRedirects(response, reverse('user_login'))
'Test user add at /admin/user/add'
def test_core_user_add_out(self):
response = self.client.get(reverse('core_admin_user_add')) self.assertRedirects(response, reverse('user_login'))
'Test user invite at /admin/user/invite'
def test_core_user_invite_out(self):
response = self.client.get(reverse('core_admin_user_invite')) self.assertRedirects(response, reverse('user_login'))
'Test index groups at /admin/groups/'
def test_index_groups_out(self):
response = self.client.get(reverse('core_admin_index_groups')) self.assertRedirects(response, reverse('user_login'))
'Test group add at /admin/group/add'
def test_core_group_add_out(self):
response = self.client.get(reverse('core_admin_group_add')) self.assertRedirects(response, reverse('user_login'))
'Test group view at /admin/group/view/<group_id>'
def test_core_group_view_out(self):
response = self.client.get(reverse('core_admin_group_view', args=[self.group.id])) self.assertRedirects(response, reverse('user_login'))
'Test group edit at /admin/group/edit/<group_id>'
def test_core_group_edit_out(self):
response = self.client.get(reverse('core_admin_group_edit', args=[self.group.id])) self.assertRedirects(response, reverse('user_login'))
'Test group delete at /admin/group/delete/<group_id>'
def test_core_group_delete_out(self):
response = self.client.get(reverse('core_admin_group_delete', args=[self.group.id])) self.assertRedirects(response, reverse('user_login'))
'Test isettings view at /admin/settings/view/'
def test_core_settings_view_out(self):
response = self.client.get(reverse('core_settings_view')) self.assertRedirects(response, reverse('user_login'))
'Test settings edit at /admin/settings/edit/'
def test_core_settings_edit_out(self):
response = self.client.get(reverse('core_settings_edit')) self.assertRedirects(response, reverse('user_login'))
'Test get_new_messages'
def test_chat_get_new_messages(self):
response = self.client.post('/chat', {'json': '{"cmd":"Get", "location":"#"}'}) self.assertEqual(response.status_code, 200)
'Test connect'
def test_chat_connect(self):
response = self.client.post('/chat', {'json': '{"cmd":"Connect", "location":"#"}'}) self.assertEqual(response.status_code, 200)
'Test disconnect'
def test_chat_disconnect(self):
response = self.client.post('/chat', {'json': '{"cmd":"Disconnect", "location":"#"}'}) self.assertEqual(response.status_code, 200)
'Test add_new_message'
def test_chat_add_new_message(self):
response = self.client.post('/chat', {'json': '{"cmd":"Message","data":{"id":"test_b5e6d0470a5f4656c3bc77f879c3dbbc","text":"test message"},"location":"#"}'}) self.assertEqual(response.status_code, 200)
'Test exit_from_conference'
def test_chat_exit_from_conference(self):
response = self.client.post('/chat', {'json': '{"cmd":"Exit","data":{"id":"test_b5e6d0470a5f4656c3bc77f879c3dbbc"},"location":"#"}'}) self.assertEqual(response.status_code, 200)
'Test add_users_in_conference'
def test_chat_add_users_in_conference(self):
response = self.client.post('/chat', {'json': '{"cmd":"Add","data":{"id":"guest_006f721c4a59a44d969b9f73fb6360a5","users":["test"]},"location":"#"}'}) self.assertEqual(response.status_code, 200)
'Test create_conference'
def test_chat_create_conference(self):
response = self.client.post('/chat', {'json': '{"cmd":"Create","data":{"title":["Admin"],"users":["admin"]},"location":"#"}'}) self.assertEqual(response.status_code, 200)
'Prepare form'
def __init__(self, *args, **kwargs):
super(PermissionForm, self).__init__(*args, **kwargs) self.fields['read_access'].help_text = '' self.fields['read_access'].required = False self.fields['read_access'].widget.attrs.update({'class': 'multicomplete', 'callback': reverse('identities_ajax_access_lookup')}) self.fields['full_access'].help...
'Prepare form'
def __init__(self, instance, *args, **kwargs):
subscriptions = instance.subscribers.all() super(SubscribeForm, self).__init__(*args, **kwargs) self.subscriptions = subscriptions self.instance = instance self.fields['subscriber'].label = '' self.fields['subscriber'].queryset = User.objects.exclude(pk__in=subscriptions) self.fields['subscr...
'Subscribe'
def save(self):
user = self.cleaned_data['subscriber'] object = self.instance if (user not in self.subscriptions): object.subscribers.add(user) self.subscriptions = object.subscribers.all() return self.subscriptions
'Validates that a user exists with the given e-mail address.'
def clean_username(self):
username = self.cleaned_data['username'] if ('@' in username): emails = ContactValue.objects.filter(value=username, field__field_type='email', contact__trash=False, contact__related_user__isnull=False) users = [email.contact.related_user.user for email in emails] else: users = User.o...
'Send e-mail'
def save(self):
user = self.cleaned_data['username'] if user: toaddr = user.get_contact().get_email() if toaddr: password = user.generate_new_password() email = EmailPassword(toaddr, user.user.username, password) email.send_email()
'Clean Name'
def clean_username(self):
data = self.cleaned_data['username'] query = Q(name=data) existing = User.objects.filter(query) if existing: raise forms.ValidationError((_('User with username %s already exists.') % data)) user_limit = getattr(settings, 'HARDTREE_SUBSCRIPTION_USER_LIMIT', 0) if (user_limi...
'Clean password again'
def clean_password_again(self):
password1 = self.cleaned_data['password'] password2 = self.cleaned_data['password_again'] if (not (password1 == password2)): raise forms.ValidationError(_('Passwords do not match')) return password2
'Form processor'
def save(self, *args, **kwargs):
profile = None if self.invitation: django_user = django_auth.User(username=self.cleaned_data['username'], password='') django_user.set_password(self.cleaned_data['password']) django_user.save() try: profile = django_user.profile except: profile = U...
'Generates response'
def __call__(self, request, *args, **kwargs):
self.site_url = ('http://' + RequestSite(request).domain) self.link = (self.site_url + self.link) response = super(ObjectFeed, self).__call__(request, *args, **kwargs) response.content = response.content.replace('http://example.com', self.site_url) return response
'Returns feed objects'
def get_object(self, request, *args, **kwargs):
return self.objects[:50]
'Returns a single object'
def items(self, obj):
return obj
'Returns object title'
def item_title(self, obj):
if isinstance(obj, Object): return obj.creator elif isinstance(obj, UpdateRecord): return obj.author
'Returns object\'s date_created'
def item_pubdate(self, obj):
return obj.date_created
'Returns object\'s body, details or full message'
def item_description(self, obj):
if isinstance(obj, Object): if obj.body: return obj.body else: return obj.details elif isinstance(obj, UpdateRecord): body = '' for object in obj.about.all(): body += ((((((('<a href="' + self.site_url) + object.get_absolute_url()) + '">') +...
'Returns object\'s full url'
def item_link(self, obj):
if isinstance(obj, Object): return (self.site_url + obj.get_absolute_url()) elif isinstance(obj, UpdateRecord): return ((self.link + '?') + str(random.random()))
'Retrieves a list of stored messages. Returns a tuple of the messages and a flag indicating whether or not all the messages originally intended to be stored in this storage were, in fact, stored and retrieved; e.g., ``(messages, all_retrieved)``.'
def _get(self, *args, **kwargs):
lock(self.key) try: data = cache.get(self.key) if (not data): data = cPickle.dumps([]) messages = cPickle.loads(data) except: pass unlock(self.key) return (messages, True)
'Update flew by - don\'t pass response to avoid Exceptions being thrown by Django middleware'
def update(self, response, *args, **kwargs):
super(CacheStorage, self).update(response, *args, **kwargs) return []
'Stores a list of messages, returning a list of any messages which could not be stored. One type of object must be able to be stored, ``Message``.'
def _store(self, messages, *args, **kwargs):
lock(self.key) try: if messages: data = cache.get(self.key) if (not data): data = cPickle.dumps(([], True)) data = cPickle.loads(data) data.append(messages) cache.set(self.key, cPickle.dumps(messages), 2592000) else: ...
'adds to the message store'
def _add(self, messages, *args, **kwargs):
lock(self.key) try: if messages: data = cache.get(self.key) if (not data): data = cPickle.dumps([]) data = cPickle.loads(data) data.append(messages) cache.set(self.key, cPickle.dumps(data), 2592000) except: pass ...
'Send email to some recipients'
def create(self, request, *args, **kwargs):
user = request.user.profile if (request.data is None): return rc.BAD_REQUEST if ('stream' in request.data): stream = getOrNone(MessageStream, request.data['stream']) if (stream and (not user.has_permission(stream, mode='x'))): return rc.FORBIDDEN message = Message() ...
'Reply to message'
def update(self, request, *args, **kwargs):
if (request.data is None): return rc.BAD_REQUEST pkfield = (kwargs.get(self.model._meta.pk.name) or request.data.get(self.model._meta.pk.name)) if (not pkfield): return rc.BAD_REQUEST user = request.user.profile try: message = self.model.objects.get(pk=pkfield) except Obj...
'Initial Setup'
def setUp(self):
if (not self.prepared): Object.objects.all().delete() try: self.group = Group.objects.get(name='test') except Group.DoesNotExist: Group.objects.all().delete() self.group = Group(name='test') self.group.save() try: self.user ...
'Test index page at /api/messaging/mlist'
def test_unauthenticated_access(self):
response = self.client.get('/api/messaging/mlist') self.assertEquals(response.status_code, 401)
'Test index page api/messaging/mlist'
def test_get_mlist(self):
response = self.client.get(path=reverse('api_messaging_mlist'), **self.authentication_headers) self.assertEquals(response.status_code, 200)
'Test index page api/messaging/streams'
def test_get_streams(self):
response = self.client.get(path=reverse('api_messaging_streams'), **self.authentication_headers) self.assertEquals(response.status_code, 200)
'Test index page api/messaging/messages'
def test_get_messages(self):
response = self.client.get(path=reverse('api_messaging_messages'), **self.authentication_headers) self.assertEquals(response.status_code, 200)
'Save message, Cap!'
def process_msg(self, msg, attrs, attachments):
from treeio.messaging.models import Message try: conf = ModuleSetting.get_for_module('treeio.messaging', 'default_contact_type')[0] default_contact_type = ContactType.objects.get(pk=long(conf.value)) except: default_contact_type = None (email_author, created) = Contact.get_or_cre...
'Run'
def run(self):
self.process_email()
'Send email'
def send_email(self):
self.process_email()
'Returns tuple (port, ssl) for current message\'s stream'
def get_smtp_port(self):
port = 25 ssl = False if (self.message.stream.outgoing_server_type == 'SMTP-SSL'): ssl = True return (port, ssl)
'Process email'
def process_email(self):
message = self.message if message.reply_to: subject = ('Re: %s' % message.reply_to.title) else: subject = message.title body = strip_tags(message.body) html = message.body for recipient in message.recipients.all(): if (recipient.id == message.author_id): co...
'Get email from the email box'
def process_email(self):
email = EmailStream(self) email.get_emails()
'Returns absolute URL of the object'
def get_absolute_url(self):
try: return reverse('messaging_stream_view', args=[self.id]) except Exception: return ''
'Returns absolute URL of the object'
def get_absolute_url(self):
try: return reverse('messaging_message_view', args=[self.id]) except Exception: return ''
'Automatically set message title'
def save(self, *args, **kwargs):
if (not self.title): self.title = self.body self.title = re.split('<[^>]+?>', self.title) self.title = ''.join(self.title) self.title = self.title[:50] super(Message, self).save(*args, **kwargs)
'Checks if the message is read by the given user'
def is_read(self, user):
if (not isinstance(user, User)): raise TypeError('The given user is not an instance of core.User') return self.read_by.filter(pk=user.id).exists()
'Returns body without HTML tags and other shit'
def get_stripped_body(self):
return do_striptags(htsafe(self.body)).replace(u'\xa0', ' ')
'Send email'
def send_email(self):
email = EmailMessage(self) if (self.stream and self.stream.outgoing_server_name): email.send_email()
'Returns email of the original message author'
def get_original_message_author_email(self):
message = self.message contact = message.author email = ContactValue.objects.filter(field__field_type='email', contact=contact) if email: email = email[0] return email
'Migrate EmailBox: merge with Stream'
def forwards(self, orm):
for stream in orm['messaging.MessageStream'].objects.all(): if stream.email_incoming: stream.incoming_server_name = stream.email_incoming.server_name stream.incoming_server_type = stream.email_incoming.server_type stream.incoming_server_username = stream.email_incoming.se...
'Test message'
def test_model_message(self):
contact_type = ContactType(name='test') contact_type.save() contact = Contact(name='test', contact_type=contact_type) contact.save() self.user = DjangoUser(username=self.username, password='') self.user.set_password(self.password) self.user.save() stream = MessageStream(name='test') ...
'Test message'
def test_model_message_stream(self):
obj = MessageStream(name='test') obj.save() self.assertEquals('test', obj.name) self.assertNotEquals(obj.id, None) obj.delete()
'Initial Setup'
def setUp(self):
if (not self.prepared): (self.group, created) = Group.objects.get_or_create(name='test') (duser, created) = DjangoUser.objects.get_or_create(username=self.username) duser.set_password(self.password) duser.save() (perspective, created) = Perspective.objects.get_or_create(name=...
'Test index page with login at /messaging/'
def test_message_index_login(self):
response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password}) self.assertRedirects(response, '/') response = self.client.get(reverse('messaging')) self.assertEquals(response.status_code, 200)
'Test index page with login at /messaging/sent/'
def test_message_index_sent(self):
response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password}) self.assertRedirects(response, '/') response = self.client.get(reverse('messaging_sent')) self.assertEquals(response.status_code, 200)
'Test index page with login at /messaging/inbox/'
def test_message_index_inbox(self):
response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password}) self.assertRedirects(response, '/') response = self.client.get(reverse('messaging_inbox')) self.assertEquals(response.status_code, 200)
'Test index page with login at /messaging/unread/'
def test_message_index_unread(self):
response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password}) self.assertRedirects(response, '/') response = self.client.get(reverse('messaging_unread')) self.assertEquals(response.status_code, 200)
'Test index page with login at /message/compose/'
def test_message_compose_login(self):
response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password}) self.assertRedirects(response, '/') response = self.client.get(reverse('messaging_message_compose')) pass
'Test index page with login at /message/view/<message_id>'
def test_message_view_login(self):
response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password}) self.assertRedirects(response, '/') response = self.client.get(reverse('messaging_message_view', args=[self.message.id])) self.assertEquals(response.status_code, 200)
'Test index page with login at /message/edit/<message_id>'
def test_message_delete_login(self):
response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password}) self.assertRedirects(response, '/') response = self.client.get(reverse('messaging_message_delete', args=[self.message.id])) self.assertEquals(response.status_code, 200)
'Test index page with login at /stream/add/'
def test_stream_add(self):
response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password}) self.assertRedirects(response, '/') response = self.client.get(reverse('messaging_stream_edit', args=[self.stream.id])) self.assertEquals(response.status_code, 200)
'Test index page with login at /stream/view/<stream_id>'
def test_stream_view(self):
response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password}) self.assertRedirects(response, '/') response = self.client.get(reverse('messaging_stream_view', args=[self.stream.id])) self.assertEquals(response.status_code, 200)
'Test index page with login at /stream/edit/<stream_id>'
def test_stream_edit(self):
response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password}) self.assertRedirects(response, '/') response = self.client.get(reverse('messaging_stream_edit', args=[self.stream.id])) self.assertEquals(response.status_code, 200)
'Test index page with login at /stream/delete/<stream_id>'
def test_stream_delete(self):
response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password}) self.assertRedirects(response, '/') response = self.client.get(reverse('messaging_stream_delete', args=[self.stream.id])) self.assertEquals(response.status_code, 200)
'Test index page with login at /messaging/settings/view/'
def test_messaging_settings_view(self):
response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password}) self.assertRedirects(response, '/') response = self.client.get(reverse('messaging_settings_view')) self.assertEquals(response.status_code, 200)
'Test index page with login at /messaging/settings/edit/'
def test_finance_settings_edit(self):
response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password}) self.assertRedirects(response, '/') response = self.client.get(reverse('messaging_settings_edit')) self.assertEquals(response.status_code, 200)
'Test index page at /messaging/'
def test_message_index_out(self):
response = self.client.get(reverse('messaging')) self.assertRedirects(response, reverse('user_login'))
'Testing /messaging/sent/'
def test_message_sent_out(self):
response = self.client.get(reverse('messaging_sent')) self.assertRedirects(response, reverse('user_login'))
'Testing /messaging/inbox/'
def test_message_inbox_out(self):
response = self.client.get(reverse('messaging_inbox')) self.assertRedirects(response, reverse('user_login'))
'Testing /messaging/unread/'
def test_message_unread_out(self):
response = self.client.get(reverse('messaging_unread')) self.assertRedirects(response, reverse('user_login'))
'Testing /message/compose/'
def test_message_compose_out(self):
response = self.client.get(reverse('messaging_message_compose')) self.assertRedirects(response, reverse('user_login'))
'Test index page with login at /message/view/<message_id>'
def test_message_view_out(self):
response = self.client.get(reverse('messaging_message_view', args=[self.message.id])) self.assertRedirects(response, reverse('user_login'))
'Test index page with login at /message/edit/<message_id>'
def test_message_delete_out(self):
response = self.client.get(reverse('messaging_message_delete', args=[self.message.id])) self.assertRedirects(response, reverse('user_login'))
'Testing /stream/add/'
def test_stream_add_out(self):
response = self.client.get(reverse('messaging_stream_edit', args=[self.stream.id])) self.assertRedirects(response, reverse('user_login'))
'Testing /stream/view/<stream_id>'
def test_stream_view_out(self):
response = self.client.get(reverse('messaging_stream_view', args=[self.stream.id])) self.assertRedirects(response, reverse('user_login'))
'Testing /stream/edit/<stream_id>'
def test_stream_edit_out(self):
response = self.client.get(reverse('messaging_stream_edit', args=[self.stream.id])) self.assertRedirects(response, reverse('user_login'))
'Testing /stream/delete/<stream_id>'
def test_stream_delete_out(self):
response = self.client.get(reverse('messaging_stream_delete', args=[self.stream.id])) self.assertRedirects(response, reverse('user_login'))