def test_move_thread(self): """its possible to move thread""" self.override_acl({'can_move_threads': 0}) response = self.client.post(self.thread.get_absolute_url(), data={'thread_action': 'move'}) self.assertEqual(response.status_code, 200) self.override_acl({'can_move_threads': 1}) response = self.client.post(self.thread.get_absolute_url(), data={'thread_action': 'move'}) self.assertEqual(response.status_code, 200) self.assertIn("Move thread to forum:", response.content) new_forum = Forum(name="New Forum", slug="new-forum", role="forum") new_forum.insert_at(self.forum.parent, save=True) self.override_acl({'can_move_threads': 1}) self.override_acl({'can_move_threads': 1}, new_forum) response = self.client.post(self.thread.get_absolute_url(), data={ 'thread_action': 'move', 'new_forum': unicode(new_forum.id), 'submit': '1' }) self.assertEqual(response.status_code, 302) self.assertEqual(self.reload_thread().forum, new_forum) # we made forum "empty", assert that board index renders response = self.client.get(reverse('misago:index')) self.assertEqual(response.status_code, 200)
class CategoryViewsTests(AuthenticatedUserTestCase): def setUp(self): super(CategoryViewsTests, self).setUp() categories_qs = Forum.objects.all_forums().filter(role='category') master_category = categories_qs[:1][0] self.category = Forum(role='category', name='Test category', slug='test-category') self.category.insert_at(master_category, save=True) def test_cant_see_category(self): """can't see category""" override_acl(self.user, {'visible_forums': []}) response = self.client.get(self.category.get_absolute_url()) self.assertEqual(response.status_code, 404) def test_cant_browse_category(self): """can't see category""" override_acl( self.user, { 'visible_forums': [self.category.parent_id, self.category.pk], 'forums': { self.category.parent_id: { 'can_see': 1, 'can_browse': 1 }, self.category.pk: { 'can_see': 1, 'can_browse': 0 }, } }) response = self.client.get(self.category.get_absolute_url()) self.assertEqual(response.status_code, 403) def test_can_browse_category(self): """can see category contents""" override_acl( self.user, { 'visible_forums': [self.category.parent_id, self.category.pk], 'forums': { self.category.parent_id: { 'can_see': 1, 'can_browse': 1 }, self.category.pk: { 'can_see': 1, 'can_browse': 1 }, } }) response = self.client.get(self.category.get_absolute_url()) self.assertEqual(response.status_code, 200)
def test_all_forums(self): """all_forums returns queryset with forums tree""" root = Forum.objects.root_category() test_forum_a = Forum(name='Test', role='category') test_forum_a.insert_at(root, position='last-child', save=True) test_forum_b = Forum(name='Test 2', role='category') test_forum_b.insert_at(root, position='last-child', save=True) all_forums_from_db = [f for f in Forum.objects.all_forums(True)] self.assertIn(test_forum_a, all_forums_from_db) self.assertIn(test_forum_b, all_forums_from_db)
def submit_form(self, form, target): new_forum = Forum( name=form.cleaned_data['name'], slug=slugify(form.cleaned_data['name']), redirect=form.cleaned_data['redirect'], style=form.cleaned_data['style'], type='redirect', ) new_forum.set_description(form.cleaned_data['description']) new_forum.insert_at(form.cleaned_data['parent'], position='last-child', save=True) Forum.objects.populate_tree(True) if form.cleaned_data['perms']: new_forum.copy_permissions(form.cleaned_data['perms']) self.request.monitor['acl_version'] = int(self.request.monitor['acl_version']) + 1 return new_forum, Message(_('New Redirect has been created.'), 'success')
class CategoryViewsTests(AuthenticatedUserTestCase): def setUp(self): super(CategoryViewsTests, self).setUp() categories_qs = Forum.objects.all_forums().filter(role='category') master_category = categories_qs[:1][0] self.category = Forum(role='category', name='Test category', slug='test-category') self.category.insert_at(master_category, save=True) def test_cant_see_category(self): """can't see category""" override_acl(self.user, {'visible_forums': []}) response = self.client.get(self.category.get_absolute_url()) self.assertEqual(response.status_code, 404) def test_cant_browse_category(self): """can't see category""" override_acl(self.user, { 'visible_forums': [self.category.parent_id, self.category.pk], 'forums': { self.category.parent_id: {'can_see': 1, 'can_browse': 1}, self.category.pk: {'can_see': 1, 'can_browse': 0}, } }) response = self.client.get(self.category.get_absolute_url()) self.assertEqual(response.status_code, 403) def test_can_browse_category(self): """can see category contents""" override_acl(self.user, { 'visible_forums': [self.category.parent_id, self.category.pk], 'forums': { self.category.parent_id: {'can_see': 1, 'can_browse': 1}, self.category.pk: {'can_see': 1, 'can_browse': 1}, } }) response = self.client.get(self.category.get_absolute_url()) self.assertEqual(response.status_code, 200)
def submit_form(self, form, target): new_forum = Forum( name=form.cleaned_data['name'], slug=slugify(form.cleaned_data['name']), type='forum', attrs=form.cleaned_data['attrs'], show_details=form.cleaned_data['show_details'], style=form.cleaned_data['style'], closed=form.cleaned_data['closed'], prune_start=form.cleaned_data['prune_start'], prune_last=form.cleaned_data['prune_last'], ) new_forum.set_description(form.cleaned_data['description']) new_forum.insert_at(form.cleaned_data['parent'], position='last-child', save=True) Forum.objects.populate_tree(True) if form.cleaned_data['perms']: new_forum.copy_permissions(form.cleaned_data['perms']) self.request.monitor['acl_version'] = int(self.request.monitor['acl_version']) + 1 return new_forum, Message(_('New Forum has been created.'), 'success')
def load_fixtures(): Forum(token='annoucements', name='annoucements', slug='annoucements', type='forum').insert_at(None, save=True) Forum(token='private', name='private', slug='private', type='forum').insert_at(None, save=True) Forum(token='reports', name='reports', slug='reports', type='forum').insert_at(None, save=True) root = Forum(token='root', name='root', slug='root') root.insert_at(None, save=True) cat = Forum(type='category', name='First Category', slug='first-category') cat.insert_at(root, save=True) forum = Forum(type='forum', name='First Forum', slug='first-forum', threads=1, posts=1) forum.insert_at(cat, save=True) Forum(type='redirect', name='Project Homepage', slug='project-homepage', redirect='http://misago-project.org').insert_at(cat, position='last-child', save=True) Forum.objects.populate_tree(True) now = timezone.now() thread = Thread.objects.create( forum=forum, name='Welcome to Misago!', slug=slugify('Welcome to Misago!'), start=now, last=now, ) post = Post.objects.create( forum=forum, thread=thread, user_name='MisagoProject', ip='127.0.0.1', agent='', post='Welcome to Misago!', post_preparsed='Welcome to Misago!', date=now, ) thread.start_post = post thread.start_poster_name = 'MisagoProject' thread.start_poster_slug = 'misagoproject' thread.last_post = post thread.last_poster_name = 'MisagoProject' thread.last_poster_slug = 'misagoproject' thread.save(force_update=True) forum.last_thread = thread forum.last_thread_name = thread.name forum.last_thread_slug = thread.slug forum.last_thread_date = thread.last forum.last_poster = thread.last_poster forum.last_poster_name = thread.last_poster_name forum.last_poster_slug = thread.last_poster_slug forum.save(force_update=True) load_monitor_fixture({ 'threads': 1, 'posts': 1, })
def test_move_threads(self): """moderation allows for moving threads""" new_forum = Forum(name="New Forum", slug="new-forum", role="forum") new_forum.insert_at(self.forum, save=True) test_acl = { 'can_see': 1, 'can_browse': 1, 'can_see_all_threads': 1, 'can_move_threads': 1 } self.override_acl(test_acl) response = self.client.get(self.link) self.assertEqual(response.status_code, 200) self.assertIn("Move threads", response.content) threads = [testutils.post_thread(self.forum) for t in xrange(10)] # see move threads form self.override_acl(test_acl) response = self.client.post(self.link, data={ 'action': 'move', 'thread': [t.pk for t in threads[:5]] }) self.assertEqual(response.status_code, 200) for thread in threads[:5]: self.assertIn(thread.title, response.content) # submit form with non-existing forum self.override_acl(test_acl) response = self.client.post(self.link, data={ 'action': 'move', 'thread': [t.pk for t in threads[:5]], 'submit': '', 'new_forum': new_forum.pk + 1234 }) self.assertEqual(response.status_code, 200) self.assertIn("Select valid forum.", response.content) # attempt move to category self.override_acl(test_acl) category = Forum.objects.all_forums().filter(role="category")[:1][0] response = self.client.post(self.link, data={ 'action': 'move', 'thread': [t.pk for t in threads[:5]], 'submit': '', 'new_forum': category.pk }) self.assertEqual(response.status_code, 200) self.assertIn("You can't move threads to category.", response.content) # attempt move to redirect self.override_acl(test_acl) redirect = Forum.objects.all_forums().filter(role="redirect")[:1][0] response = self.client.post(self.link, data={ 'action': 'move', 'thread': [t.pk for t in threads[:5]], 'submit': '', 'new_forum': redirect.pk }) self.assertEqual(response.status_code, 200) self.assertIn("You can't move threads to redirect.", response.content) # move to new_forum self.override_acl(test_acl) self.override_acl(test_acl, new_forum) response = self.client.post(self.link, data={ 'action': 'move', 'thread': [t.pk for t in threads[:5]], 'submit': '', 'new_forum': new_forum.pk }) self.assertEqual(response.status_code, 302) self.override_acl(test_acl) response = self.client.get(self.link) self.assertEqual(response.status_code, 200) self.assertIn("5 threads were moved to "New Forum".", response.content) for thread in new_forum.thread_set.all(): self.assertIn(thread, threads[:5]) for thread in self.forum.thread_set.all(): self.assertIn(thread, threads[5:])