コード例 #1
0
ファイル: content_models_tests.py プロジェクト: zhudy/ka-lite
 def test_update_item(self):
     item = get_random_content()[0]
     available = item.get("available")
     inverse_available = not available
     update_item({"available": inverse_available}, item.get("path"))
     item2 = get_content_item(content_id=item.get("id"))
     self.assertEqual(item2.get("available"), inverse_available)
コード例 #2
0
ファイル: content_models_tests.py プロジェクト: Aypak/ka-lite
 def test_update_item(self):
     item = get_random_content()[0]
     available = item.get("available")
     inverse_available = not available
     update_item({"available": inverse_available}, item.get("path"))
     item2 = get_content_item(content_id=item.get("id"))
     self.assertEqual(item2.get("available"), inverse_available)
コード例 #3
0
ファイル: base.py プロジェクト: arceduardvincent/ka-lite
 def create_random_content_file(self):
     """
     Helper function for testing content files.
     """
     content = get_random_content(kinds=["Video"], limit=1)[0]
     youtube_id = content["id"]
     path = content["path"]
     fake_content_file = os.path.join(settings.CONTENT_ROOT, "%s.mp4" % youtube_id)
     with open(fake_content_file, "w") as fh:
         fh.write("")
     update_item(update={"files_complete": 1, "available": True, "size_on_disk": 12}, path=content["path"])
     self.assertTrue(os.path.exists(fake_content_file), "Make sure the content file was created, youtube_id='%s'." % youtube_id)
     return (fake_content_file, content["id"], youtube_id, path)
コード例 #4
0
 def test_update_item_with_duplicated_item(self):
     """
     Tests that update_items updates *all* items with the same id.
     Content item ids are not unique (though paths are) because the db is not normalized, so items with the same
       id should be updated together.
     """
     item_id = "addition_1"  # This item is known to be duplicated.
     items = get_content_items(ids=[item_id])
     self.assertGreater(len(items), 1)
     item = items[0]
     available = item.get("available")
     inverse_available = not available
     update_item({"available": inverse_available}, item.get("path"))
     items = get_content_items(ids=[item.get("id")])
     self.assertTrue(all([item.get("available") == inverse_available for item in items]))
コード例 #5
0
 def create_random_content_file(self):
     """
     Helper function for testing content files.
     """
     content = get_random_content(kinds=["Video"], limit=1)[0]
     youtube_id = content["id"]
     path = content["path"]
     fake_content_file = os.path.join(settings.CONTENT_ROOT,
                                      "%s.mp4" % youtube_id)
     with open(fake_content_file, "w") as fh:
         fh.write("")
     update_item(update={
         "files_complete": 1,
         "available": True,
         "size_on_disk": 12
     },
                 path=content["path"])
     self.assertTrue(
         os.path.exists(fake_content_file),
         "Make sure the content file was created, youtube_id='%s'." %
         youtube_id)
     return (fake_content_file, content["id"], youtube_id, path)