Esempio n. 1
0
 def test_musi(self):
     data = build_data()
     music = Music(**data)
     self.session.add(music)
     self.session.commit()
     self.assertEqual(music.mid, data.get('mid'))
     self.assertEqual(music.music_uri, data.get('music_uri'))
Esempio n. 2
0
 def test_get_multi_music(self):
     m1 = build_data()
     m1['mid'] = 1
     m2 = build_data()
     m2['mid'] = 2
     m3 = build_data()
     m3['mid'] = 3
     m4 = build_data()
     m4['mid'] = 4
     music_list = [m1, m2, m3, m4]
     data = dict([(self.cache.music_key.format(m.get('mid')), json.dumps(m))
                  for m in music_list])
     self.rds.mset(**data)
     res = self.cache.get_multi_music([1, 2, 3, 4])
     for m in music_list:
         self.assertEqual(m, res.get(m.get('mid')))
Esempio n. 3
0
 def test_musi(self):
     data = build_data()
     music = Music(**data)
     self.session.add(music)
     self.session.commit()
     self.assertEqual(music.mid, data.get('mid'))
     self.assertEqual(music.music_uri, data.get('music_uri'))
Esempio n. 4
0
 def test_cache_multi_music(self):
     m1 = build_data()
     m1['mid'] = 1
     m2 = build_data()
     m2['mid'] = 2
     m3 = build_data()
     m3['mid'] = 3
     m4 = build_data()
     m4['mid'] = 4
     music_list = [m1, m2, m3, m4]
     self.cache.cache_multi_music(music_list)
     for m in music_list:
         res = self.rds.get(self.cache.music_key.format(m.get('mid')))
         res = byte_decode(res)
         tm = json.loads(res)
         self.assertEqual(m, tm)
Esempio n. 5
0
 def test_cache_multi_music(self):
     m1 = build_data()
     m1['mid'] = 1
     m2 = build_data()
     m2['mid'] = 2
     m3 = build_data()
     m3['mid'] = 3
     m4 = build_data()
     m4['mid'] = 4
     music_list = [m1, m2, m3, m4]
     self.cache.cache_multi_music(music_list)
     for m in music_list:
         res = self.rds.get(self.cache.music_key.format(m.get('mid')))
         res = byte_decode(res)
         tm = json.loads(res)
         self.assertEqual(m, tm)
Esempio n. 6
0
 def test_get_multi_music(self):
     m1 = build_data()
     m1['mid'] = 1
     m2 = build_data()
     m2['mid'] = 2
     m3 = build_data()
     m3['mid'] = 3
     m4 = build_data()
     m4['mid'] = 4
     music_list = [m1, m2, m3, m4]
     data = dict(
         [(self.cache.music_key.format(m.get('mid')),
           json.dumps(m)) for m in music_list])
     self.rds.mset(**data)
     res = self.cache.get_multi_music([1, 2, 3, 4])
     for m in music_list:
         self.assertEqual(m, res.get(m.get('mid')))
Esempio n. 7
0
 def test_cache_music(self):
     """"""
     music = build_data()
     music['mid'] = 1
     self.cache.cache_music(music)
     res = self.rds.get(self.cache.music_key.format(music.get('mid')))
     res = byte_decode(res)
     test_music = json.loads(res)
     self.assertEqual(test_music, music)
Esempio n. 8
0
 def test_exc(self):
     """"""
     # SQLAlchemyError
     data = build_data()
     with patch.object(Session, 'commit', side_effect=SQLAlchemyError):
         response = self.fetch('/', method='POST',
                               body=urlencode(dict(data=json.dumps(data))))
         res = json.loads(response.body.decode('utf-8'))
         self.assertEqual(res.get('error_code'), 20101)
Esempio n. 9
0
 def test_ani(self):
     data = build_data(op='ani')
     ani = Animation(**data)
     self.session.add(ani)
     self.session.commit()
     self.assertEqual(ani.video_uri, data.get('video_uri'))
     self.assertEqual(ani.name, data.get('name'))
     self.assertEqual(ani.artist, data.get('artist'))
     self.assertEqual(ani.lang, data.get('lang'))
Esempio n. 10
0
 def test_clear_music(self):
     m1 = build_data()
     m1['mid'] = 1
     m2 = build_data()
     m2['mid'] = 2
     m3 = build_data()
     m3['mid'] = 3
     m4 = build_data()
     m4['mid'] = 4
     music_list = [m1, m2, m3, m4]
     data = dict([(self.cache.music_key.format(m.get('mid')), json.dumps(m))
                  for m in music_list])
     self.rds.mset(**data)
     self.cache.clear_music(mid=m1.get('mid'))
     self.cache.clear_music(mid_list=[m.get('mid') for m in music_list])
     for m in music_list:
         self.assertIsNone(
             self.rds.get(self.cache.music_key.format(m.get('mid'))))
Esempio n. 11
0
 def test_car(self):
     data = build_data(op='car')
     car = Caricature(**data)
     self.session.add(car)
     self.session.commit()
     self.assertEqual(car.part_id, data.get('part_id'))
     self.assertEqual(car.image_id, data.get('image_id'))
     self.assertEqual(car.name, data.get('name'))
     self.assertEqual(car.artist, data.get('artist'))
Esempio n. 12
0
 def test_ani(self):
     data = build_data(op='ani')
     ani = Animation(**data)
     self.session.add(ani)
     self.session.commit()
     self.assertEqual(ani.video_uri, data.get('video_uri'))
     self.assertEqual(ani.name, data.get('name'))
     self.assertEqual(ani.artist, data.get('artist'))
     self.assertEqual(ani.lang, data.get('lang'))
Esempio n. 13
0
 def test_clear_music(self):
     m1 = build_data()
     m1['mid'] = 1
     m2 = build_data()
     m2['mid'] = 2
     m3 = build_data()
     m3['mid'] = 3
     m4 = build_data()
     m4['mid'] = 4
     music_list = [m1, m2, m3, m4]
     data = dict(
         [(self.cache.music_key.format(m.get('mid')),
           json.dumps(m)) for m in music_list])
     self.rds.mset(**data)
     self.cache.clear_music(mid=m1.get('mid'))
     self.cache.clear_music(mid_list=[m.get('mid') for m in music_list])
     for m in music_list:
         self.assertIsNone(self.rds.get(self.cache.music_key.format(m.get('mid'))))
Esempio n. 14
0
 def test_car(self):
     data = build_data(op='car')
     car = Caricature(**data)
     self.session.add(car)
     self.session.commit()
     self.assertEqual(car.part_id, data.get('part_id'))
     self.assertEqual(car.image_id, data.get('image_id'))
     self.assertEqual(car.name, data.get('name'))
     self.assertEqual(car.artist, data.get('artist'))
Esempio n. 15
0
 def test_cache_music(self):
     """"""
     music = build_data()
     music['mid'] = 1
     self.cache.cache_music(music)
     res = self.rds.get(self.cache.music_key.format(music.get('mid')))
     res = byte_decode(res)
     test_music = json.loads(res)
     self.assertEqual(test_music, music)
Esempio n. 16
0
 def test_exc(self):
     """"""
     # SQLAlchemyError
     data = build_data()
     with patch.object(Session, 'commit', side_effect=SQLAlchemyError):
         response = self.fetch('/',
                               method='POST',
                               body=urlencode(dict(data=json.dumps(data))))
         res = json.loads(response.body.decode('utf-8'))
         self.assertEqual(res.get('error_code'), 20101)
Esempio n. 17
0
 def setUp(self):
     super().setUp()
     self.data = build_data()
Esempio n. 18
0
 def setUp(self):
     super().setUp()
     self.data = build_data()
Esempio n. 19
0
 def test_get_music(self):
     music = build_data()
     music['mid'] = 1
     self.rds.set(self.cache.music_key.format(music.get('mid')), music)
     test_music = self.cache.get_music(music.get('mid'))
     self.assertEqual(music, test_music)
Esempio n. 20
0
 def test_get_music(self):
     music = build_data()
     music['mid'] = 1
     self.rds.set(self.cache.music_key.format(music.get('mid')), music)
     test_music = self.cache.get_music(music.get('mid'))
     self.assertEqual(music, test_music)