def test_foreign_key_field(): post = Post() assert isinstance(post.category, Related) assert post.category_id is None assert isinstance(post.author, Related) assert post.author_id is None
def test_get_object_id_from_related_object(self): """get_object_id() should return the value of a field specified by GRAPH_ID_FIELD. If the field isn't found on the instance, it's searched on a related object specified by RELATED_OBJECT_FIELD. """ post = Post(graph_id='111111111_22222222') post.save() post_insights = PostInsightsWithoutGraphID(post=post) self.assertEqual(post_insights.RELATED_OBJECT_FIELD, 'post') self.assertEqual(post_insights.get_graph_id(), '111111111_22222222')
def setUp(self): """Creates three ``Post`` objects with different field settings.""" # Post with Markdown field self.mp = Post(title="example Markdown post", body="**markdown**", body_markup_type='markdown') self.mp.save() # Post with reStructuredText field self.rp = Post(title="example reStructuredText post", body="*reST*", body_markup_type='restructuredtext') self.rp.save() # Post being attacked self.xss_str = "<script>alert('xss');</script>" self.xss_post = Post(title="example XSS post", body=self.xss_str, body_markup_type='markdown', comment=self.xss_str) self.xss_post.save()
def test_save_and_insert(self): author = Author(name='test author 6') author.save() post = Post(title='test title 6', content='test content 6', pub_date=datetime.now(), author_id='6') post.save() c = db.execute('select * from author where id=6;') self.assertEqual(len(c.fetchall()), 1) c = db.execute('select * from my_post where id=6;') self.assertEqual(len(c.fetchall()), 1)
def setUp(self): """Creates three ``Post`` objects with different field settings.""" # Post with Markdown field self.mp = Post(title="example Markdown post", body="**markdown**", body_markup_type='markdown') self.mp.save() # default data attribute values for textareas: self.mm_settings = mm_settings.MARKUPMIRROR_CODEMIRROR_SETTINGS.copy() default = mm_settings.MARKUPMIRROR_DEFAULT_MARKUP_TYPE self.mm_settings.update({ 'preview_url': reverse('markupmirror:preview'), 'base_url': reverse('markupmirror:base'), 'mode': markup_pool[default].codemirror_mode, 'markup_type': default, })