Ejemplo n.º 1
0
 def test_parseMicroblogging_mention_case_insensitive(self):
     mbs = parse_microblogging("hey @HERBert cool name", self.hugo, "")
     expected = {
         'template_text': "hey {u0} cool name",
         'mentions': [self.herbert.id],
     }
     self.assert_schema_equal(mbs, expected)
Ejemplo n.º 2
0
 def test_parseMicroblogging_invalid_reference(self):
     mbs = parse_microblogging("someone should write /cool.1", self.hugo, "")
     expected = {
         'template_text': "someone should write /cool.1",
         'references': [],
     }
     self.assert_schema_equal(mbs, expected)
Ejemplo n.º 3
0
 def test_parseMicroblogging_single_node_reference(self):
     mbs = parse_microblogging("the proposal /foo.1 is cool", self.hugo, "")
     expected = {
         'template_text': "the proposal {n0} is cool",
         'references': [self.foo1],
     }
     self.assert_schema_equal(mbs, expected)
Ejemplo n.º 4
0
 def test_parseMicroblogging_mention_case_insensitive(self):
     mbs = parse_microblogging("hey @HERBert cool name", self.hugo, "")
     expected = {
         'template_text': "hey {u0} cool name",
         'mentions': [self.herbert.id],
     }
     self.assert_schema_equal(mbs, expected)
Ejemplo n.º 5
0
 def test_parseMicroblogging_single_node_reference(self):
     mbs = parse_microblogging("the proposal /foo.1 is cool", self.hugo, "")
     expected = {
         'template_text': "the proposal {n0} is cool",
         'references': [self.foo1],
     }
     self.assert_schema_equal(mbs, expected)
Ejemplo n.º 6
0
 def test_parseMicroblogging_invalid_mention(self):
     mbs = parse_microblogging("does anyone know @ninja", self.hugo, "")
     expected = {
         'template_text': "does anyone know @ninja",
         'mentions': [],
     }
     self.assert_schema_equal(mbs, expected)
Ejemplo n.º 7
0
 def test_parseMicroblogging_multiple_mention(self):
     mbs = parse_microblogging("@herbert is like @hugo but more @herbert",
                               self.hugo, "")
     expected = {
         'template_text': "{u1} is like {u0} but more {u1}",
         'mentions': [self.hugo.id, self.herbert.id],
     }
     self.assert_schema_equal(mbs, expected)
Ejemplo n.º 8
0
 def test_parseMicroblogging_multiple_mention(self):
     mbs = parse_microblogging("@herbert is like @hugo but more @herbert",
                               self.hugo, "")
     expected = {
         'template_text': "{u1} is like {u0} but more {u1}",
         'mentions': [self.hugo.id, self.herbert.id],
     }
     self.assert_schema_equal(mbs, expected)
Ejemplo n.º 9
0
 def test_parseMicroblogging_invalid_reference(self):
     mbs = parse_microblogging("someone should write /cool.1", self.hugo,
                               "")
     expected = {
         'template_text': "someone should write /cool.1",
         'references': [],
     }
     self.assert_schema_equal(mbs, expected)
Ejemplo n.º 10
0
 def test_parseMicroblogging_invalid_mention(self):
     mbs = parse_microblogging("does anyone know @ninja",
                               self.hugo, "")
     expected = {
         'template_text': "does anyone know @ninja",
         'mentions': [],
     }
     self.assert_schema_equal(mbs, expected)
Ejemplo n.º 11
0
 def test_parseMicroblogging_multiple_node_references(self):
     mbs = parse_microblogging("/foo.1 was improved to /foo.2 and is now "
                               "better than /foo.1 because /foo.1 sucks",
                               self.hugo, "")
     expected = {
         'template_text': "{n0} was improved to {n1} and is now better than "
                          "{n0} because {n0} sucks",
         'references': [self.foo1, self.foo2],
     }
     self.assert_schema_equal(mbs, expected)
Ejemplo n.º 12
0
 def test_parseMicroblogging_multiple_node_references(self):
     mbs = parse_microblogging(
         "/foo.1 was improved to /foo.2 and is now "
         "better than /foo.1 because /foo.1 sucks", self.hugo, "")
     expected = {
         'template_text':
         "{n0} was improved to {n1} and is now better than "
         "{n0} because {n0} sucks",
         'references': [self.foo1, self.foo2],
     }
     self.assert_schema_equal(mbs, expected)
Ejemplo n.º 13
0
 def test_parseMicroblogging(self):
     mbs = parse_microblogging("text", self.hugo, "")
     expected = {
         'author': self.hugo.id,
         'location': self.root.id,
         'type': "userpost",
         'template_text': "text",
         'mentions': [],
         'references': [],
         'answer_to': None
     }
     self.assert_schema_equal(mbs, expected)
Ejemplo n.º 14
0
 def test_parseMicroblogging(self):
     mbs = parse_microblogging("text", self.hugo, "")
     expected = {
         'author': self.hugo.id,
         'location': self.root.id,
         'type': "userpost",
         'template_text': "text",
         'mentions': [],
         'references': [],
         'answer_to': None
     }
     self.assert_schema_equal(mbs, expected)
    def forwards(self, orm):
        for post in orm['microblogging.Post'].objects.all():
            text = self.replace_node_references(post.text)
            text = strip_tags(text)

            schema = parse_microblogging(text, post.author, '/', get_root_node())
            post.text_template = schema['template_text']
            post.location_id, post.node_references =\
                self.get_location_and_references(list(post.node_references.all()), schema['references'])
            if post.node_references.count() < len(schema['references']):
                print("Missing reference! Adding location to node references.")
                post.node_references.add(post.location)
            if post.node_references.count() < len(schema['references']):
                print("Missing reference! Using references from the Text.")
                post.node_references = [orm['node_storage.Node'].objects.get(id=r.id) for r in schema['references']]
            self.post_render(post)
            post.save()
    def forwards(self, orm):
        for post in orm["microblogging.Post"].objects.all():
            text = self.replace_node_references(post.text)
            text = strip_tags(text)

            schema = parse_microblogging(text, post.author, "/", get_root_node())
            post.text_template = schema["template_text"]
            post.location_id, post.node_references = self.get_location_and_references(
                list(post.node_references.all()), schema["references"]
            )
            if post.node_references.count() < len(schema["references"]):
                print("Missing reference! Adding location to node references.")
                post.node_references.add(post.location)
            if post.node_references.count() < len(schema["references"]):
                print("Missing reference! Using references from the Text.")
                post.node_references = [orm["node_storage.Node"].objects.get(id=r.id) for r in schema["references"]]
            self.post_render(post)
            post.save()
Ejemplo n.º 17
0
 def test_parseMicroblogging_correct_location(self):
     mbs = parse_microblogging("text", self.hugo, "foo.2")
     self.assertEqual(mbs['location'], self.foo2.id)
Ejemplo n.º 18
0
 def test_parseMicroblogging_correct_location(self):
     mbs = parse_microblogging("text", self.hugo, "foo.2")
     self.assertEqual(mbs['location'], self.foo2.id)