예제 #1
0
def get_failed():
	fails = _session\
		.query(sql.Post)\
		.join(sql.URL)\
		.filter(sql.URL.failed == True)\
		.all()
	return sql.encode_safe(fails)
예제 #2
0
    def test_full_encode(self):
        """ The entire nested relation should serialize """
        p = sql.session().query(sql.Post).join(sql.URL).join(sql.File).first()
        self.assertTrue(p, msg='Failed to find a test Post.')
        for u in p.urls:
            self.assertTrue(u.file, msg="URL is missing a file! %s" %
                            u)  # These are lazy loaded, so check them all.
        ser = sql.encode_safe(p)

        self.assertTrue(
            ser, msg='Failed to properly encode full stack Post into Object!')
        self.assertGreater(len(ser['urls']),
                           0,
                           msg='Lost Post URLs in encode!')
        for u in ser['urls']:
            self.assertIn('file', u, msg='Lost file in URL encode! %s' % u)
예제 #3
0
 def test_post_json_encode(self):
     """ Posts should serialize """
     posts = self.ps.search_fields(['type'], 'Submission')
     self.assertGreater(len(posts),
                        0,
                        msg="Didn't find enough Posts to test!")
     ser = sql.encode_safe(posts, stringify=True,
                           indent=4)  # Encode Post results to JSON string.
     arr = json.loads(ser)  # Decode the JSON string os Posts.
     self.assertGreater(len(arr), 0, msg='Failed to decode array of posts.')
     for p in arr:
         for f in self.ps.get_searchable_fields():
             self.assertIn(f,
                           p,
                           msg='Field was missing from decoded Post: %s' %
                           f)