def test_load_microblogging_for_followed_nodes(self): create_nodes_for_path("foo.1") foo2 = create_nodes_for_path("foo.2") foo1bar1 = create_nodes_for_path("foo.1/bar.1") hugo = create_user("hugo") create_vote(hugo, [foo2]) create_vote(hugo, [foo1bar1]) posts = [ create_post("posted at node", hugo, location='foo.2'), create_post("reference /foo.2", hugo, location=''), create_post("reference /foo.1/bar.1", hugo, location='foo.2') ] wrong_posts = [ create_post("posted somewhere", hugo, location='foo.1'), create_post("reference wrong /foo.1", hugo, location=''), create_post("neither", hugo, location='') ] response = self.client.get( reverse('load_microblogging_for_followed_nodes', kwargs={'name': 'hugo'})) res = json.loads(response.content)["loadMicrobloggingResponse"] response_id_list = [m["microblogID"] for m in res] for post in posts: self.assertIn(post.id, response_id_list) for post in wrong_posts: self.assertNotIn(post.id, response_id_list) self.assertEqual(len(res), 3)
def test_load_microblogging_for_followed_nodes(self): create_nodes_for_path("foo.1") foo2 = create_nodes_for_path("foo.2") foo1bar1 = create_nodes_for_path("foo.1/bar.1") hugo = create_user("hugo") create_vote(hugo, [foo2]) create_vote(hugo, [foo1bar1]) posts = [create_post("posted at node", hugo, location='foo.2'), create_post("reference /foo.2", hugo, location=''), create_post("reference /foo.1/bar.1", hugo, location='foo.2')] wrong_posts = [create_post("posted somewhere", hugo, location='foo.1'), create_post("reference wrong /foo.1", hugo, location=''), create_post("neither", hugo, location='')] response = self.client.get( reverse('load_microblogging_for_followed_nodes', kwargs={'name': 'hugo'})) res = json.loads(response.content)["loadMicrobloggingResponse"] response_id_list = [m["microblogID"] for m in res] for post in posts: self.assertIn(post.id, response_id_list) for post in wrong_posts: self.assertNotIn(post.id, response_id_list) self.assertEqual(len(res), 3)
def test_mail_notify_derivate(self): hugo = create_user("hugo") hugo.email = "*****@*****.**" hugo.profile.wants_mail_notification = True hugo.save() max = create_user("max") max.email = "*****@*****.**" max.profile.wants_mail_notification = True max.save() berta = create_user("berta") berta.email = "*****@*****.**" berta.profile.wants_mail_notification = False berta.save() post = create_post('System Message', hugo) node = create_nodes_for_path('/foo.1', [hugo]) create_vote(hugo, [node]) create_vote(max, [node]) create_vote(berta, [node]) derivate = create_nodes_for_path('/foo.2', [hugo]) node.add_derivate(derivate) notify_derivate(node, post) self.assertEqual(len(mail.outbox), 1) m = mail.outbox[0] self.assertEqual(m.to, []) self.assertEqual(m.bcc, ['*****@*****.**', '*****@*****.**']) self.assertIn('System Message', m.body) self.assertGreater(len(m.subject), 0)
def test_load_microblogging_all_loads_all_microblogging(self): hugo = create_user("hugo") herbert = create_user("herbert") create_nodes_for_path("foo.1") posts = [create_post("text", hugo, location=''), create_post("text3", hugo, location='foo.1'), create_post("text2", herbert, location='foo.1')] response = self.client.get(reverse('load_microblogging_all')) res = json.loads(response.content)["loadMicrobloggingResponse"] ids = [m["microblogID"] for m in res] for p in posts: self.assertIn(p.id, ids) self.assertEqual(len(res), 3)
def setUp(self): self.hugo = create_user('hugo') self.herbert = create_user('herbert') self.foo1 = create_nodes_for_path('foo.1') self.foo1bar1 = create_nodes_for_path('foo.1/bar.1') self.schema_skeleton = { 'author': self.hugo.id, 'location': self.foo1.id, 'type': "userpost", 'template_text': "some text", 'mentions': [], 'references': [], 'answer_to': None }
def test_delete_posts_referring_to_removes_referring_posts1(self): hugo = create_user('hugo') node = create_nodes_for_path("path.1") create_post("foo", hugo, '/path.1') self.assertEqual(Post.objects.count(), 1) delete_posts_referring_to(node) self.assertEqual(Post.objects.count(), 0)
def test_store_microblogging(self): hugo = create_user('hugo', password='******') foo1 = create_nodes_for_path('foo.1') self.assertTrue(self.client.login(username="******", password="******")) response = self.client.post( reverse('store_microblogging', kwargs={'path': 'foo.1'}), json.dumps({ 'microblogText': 'test stuff on http://testserver/foo.1/ and reference /foo.1 and also @hugo' }), content_type="application/json") res = json.loads(response.content) self.assertIn("storeMicrobloggingResponse", res) self.assertEqual(hugo.microblogging_posts.count(), 1) p = hugo.microblogging_posts.all()[0] self.assertEqual(p.location, foo1) self.assertEqual(p.author, hugo) self.assertEqual(p.post_type, Post.USER_POST) self.assertIn(hugo, p.mentions.all()) self.assertIn(foo1, p.node_references.all()) self.assertEqual( p.text_template, "test stuff on {n0}/ and reference {n0} and also {u0}") self.assertTrue(p.text_cache != "")
def test_load_microblogging_all_loads_all_microblogging(self): hugo = create_user("hugo") herbert = create_user("herbert") create_nodes_for_path("foo.1") posts = [ create_post("text", hugo, location=''), create_post("text3", hugo, location='foo.1'), create_post("text2", herbert, location='foo.1') ] response = self.client.get(reverse('load_microblogging_all')) res = json.loads(response.content)["loadMicrobloggingResponse"] ids = [m["microblogID"] for m in res] for p in posts: self.assertIn(p.id, ids) self.assertEqual(len(res), 3)
def test_load_microblogging_for_node(self): hugo = create_user("hugo") create_nodes_for_path("foo.1") wrong_post = create_post("text", hugo, location='') posts = [create_post("is only posted there", hugo, location='foo.1'), create_post("references /foo.1 and is posted there", hugo, location='foo.1'), create_post("references /foo.1 but is not posted there", hugo, location='')] response = self.client.get(reverse('load_microblogging_for_node', kwargs={'path': 'foo.1'})) res = json.loads(response.content)["loadMicrobloggingResponse"] self.assertNotIn(wrong_post.id, [m["microblogID"] for m in res]) for post in posts: self.assertIn(post.id, [m["microblogID"] for m in res]) self.assertEqual(len(res), 3)
def test_post_new_derivate_for_node_message(self): hugo = create_user('Hugo') node_a = create_nodes_for_path('/bla.1/blubb.1', [hugo]) node_b = create_nodes_for_path('/bla.2/pling.1', [hugo]) post = post_new_derivate_for_node_message(hugo, '/bla.1/blubb.1', '/bla.2/pling.1') self.assertEqual(post.author, get_system_user()) self.assertEqual(post.location, node_a) self.assertEqual(post.post_type, Post.NODE_REFINED) self.assertIn(hugo, post.mentions.all()) self.assertIn(node_a, post.node_references.all()) self.assertIn(node_b, post.node_references.all()) self.assertEqual(post.node_references.count(), 2) self.assertEqual( post.text_cache, u'<span style="color: gray;">Hinweis:</span> ' + u'<a href="/user/Hugo">@Hugo</a> hat <a href="/bla.1/blubb.1">' u'blubb_long<span class="nodeIndex">1</span></a> zu ' + u'<a href="/bla.2/pling.1">pling_long' u'<span class="nodeIndex">1</span></a> weiterentwickelt.')
def test_load_microblogging_for_node(self): hugo = create_user("hugo") create_nodes_for_path("foo.1") wrong_post = create_post("text", hugo, location='') posts = [ create_post("is only posted there", hugo, location='foo.1'), create_post("references /foo.1 and is posted there", hugo, location='foo.1'), create_post("references /foo.1 but is not posted there", hugo, location='') ] response = self.client.get( reverse('load_microblogging_for_node', kwargs={'path': 'foo.1'})) res = json.loads(response.content)["loadMicrobloggingResponse"] self.assertNotIn(wrong_post.id, [m["microblogID"] for m in res]) for post in posts: self.assertIn(post.id, [m["microblogID"] for m in res]) self.assertEqual(len(res), 3)
def test_create_post_adds_many_to_many_relations(self): hugo = create_user('hugo') herbert = create_user('herbert') foo = create_nodes_for_path('foo.1') bar = create_nodes_for_path('bar.1') schema = { 'author': hugo.id, 'location': foo.id, 'type': "userpost", 'template_text': "reference to {u0} and {u1} and {n0} and {n1}", 'mentions': [hugo, herbert], 'references': [foo, bar], 'answer_to': None } p = create_post_from_schema(schema) p_db = Post.objects.get(id=p.id) self.assertEqual(p.author, p_db.author) self.assertEqual(p.post_type, p_db.post_type) self.assertListEqual(list(p.mentions.all()), list(p_db.mentions.all())) self.assertListEqual(list(p.node_references.all()), list(p_db.node_references.all()))
def test_store_microblogging(self): hugo = create_user('hugo', password='******') foo1 = create_nodes_for_path('foo.1') self.assertTrue(self.client.login(username="******", password="******")) response = self.client.post( reverse('store_microblogging', kwargs={'path': 'foo.1'}), {'microblogText': 'test stuff on http://testserver/foo.1/ and reference /foo.1 and also @hugo'}) res = json.loads(response.content) self.assertIn("storeMicrobloggingResponse", res) self.assertEqual(hugo.microblogging_posts.count(), 1) p = hugo.microblogging_posts.all()[0] self.assertEqual(p.location, foo1) self.assertEqual(p.author, hugo) self.assertEqual(p.post_type, Post.USER_POST) self.assertIn(hugo, p.mentions.all()) self.assertIn(foo1, p.node_references.all()) self.assertEqual(p.text_template, "test stuff on {n0}/ and reference {n0} and also {u0}") self.assertTrue(p.text_cache != "")
def test_post_new_generic_argument_for_node_message(self): hugo = create_user('Hugo') node = create_nodes_for_path('/bla.1/blubb.1', [hugo]) argument = create_argument(node, Argument.PRO, 'Argumentutinio', 'Arrgumente!', [hugo]) post = post_new_argument_for_node_message(hugo, '/bla.1/blubb.1', Argument.PRO, '/bla.1/blubb.1.pro.1') self.assertEqual(post.author, get_system_user()) self.assertEqual(post.location, node) self.assertEqual(post.post_type, Post.ARGUMENT_CREATED) self.assertIn(hugo, post.mentions.all()) self.assertIn(node, post.node_references.all()) self.assertIn(argument.pk, [a.pk for a in post.node_references.all()]) self.assertEqual(post.node_references.count(), 2) self.assertEqual( post.text_cache, u'<span style="color: gray;">Hinweis:</span> ' + u'<a href="/user/Hugo">@Hugo</a> hat dem Vorschlag ' u'<a href="/bla.1/blubb.1">blubb_long' u'<span class="nodeIndex">1</span></a> das Argument ' + u'<a href="/bla.1/blubb.1.pro.1">Argumentutinio' u'<span class="nodeIndex">1</span></a> hinzugefügt.')
def setUp(self): self.hugo = create_user('hugo') self.herbert = create_user('herbert') self.foo1 = create_nodes_for_path('foo.1') self.schema_skeleton = { 'author': 0, 'location': 0, 'type': "userpost", 'template_text': "some text", 'mentions': [], 'references': [], 'answer_to': -1 } self.wrong_schema = { 'author': self.hugo, 'location': 'foo.1', 'type': 5, 'template_text': None, 'mentions': {}, 'references': {}, 'answer_to': 'my_mom' }
def setUp(self): self.hugo = create_user('hugo') self.herbert = create_user('herbert') self.root = get_root_node() self.foo1 = create_nodes_for_path('foo.1') self.foo2 = create_nodes_for_path('foo.2')