Example #1
0
class TestSortedAssetList(unittest.TestCase):
    """
    Tests the SortedAssetList class.
    """
    def setUp(self):
        super(TestSortedAssetList, self).setUp()  # lint-amnesty, pylint: disable=super-with-arguments
        asset_list = [dict(list(zip(AssetStoreTestData.asset_fields, asset))) for asset in AssetStoreTestData.all_asset_data]  # lint-amnesty, pylint: disable=line-too-long
        self.sorted_asset_list_by_filename = SortedAssetList(
            iterable=asset_list)
        self.sorted_asset_list_by_last_edit = SortedAssetList(
            iterable=asset_list, key=lambda x: x['edited_on'])
        self.course_key = CourseLocator('org', 'course', 'run')

    def test_exception_on_bad_sort(self):
        asset_key = self.course_key.make_asset_key('asset', 'pic1.jpg')
        with pytest.raises(IncorrectlySortedList):
            __ = self.sorted_asset_list_by_last_edit.find(asset_key)

    def test_find(self):
        asset_key = self.course_key.make_asset_key('asset', 'asset.txt')
        assert self.sorted_asset_list_by_filename.find(asset_key) == 0
        asset_key_last = self.course_key.make_asset_key(
            'asset', 'weather_patterns.bmp')
        assert self.sorted_asset_list_by_filename.find(asset_key_last) == (
            len(AssetStoreTestData.all_asset_data) - 1)
Example #2
0
class TestSortedAssetList(unittest.TestCase):
    """
    Tests the SortedAssetList class.
    """
    shard = 1

    def setUp(self):
        super(TestSortedAssetList, self).setUp()
        asset_list = [
            dict(zip(AssetStoreTestData.asset_fields, asset))
            for asset in AssetStoreTestData.all_asset_data
        ]
        self.sorted_asset_list_by_filename = SortedAssetList(
            iterable=asset_list)
        self.sorted_asset_list_by_last_edit = SortedAssetList(
            iterable=asset_list, key=lambda x: x['edited_on'])
        self.course_key = CourseLocator('org', 'course', 'run')

    def test_exception_on_bad_sort(self):
        asset_key = self.course_key.make_asset_key('asset', 'pic1.jpg')
        with self.assertRaises(IncorrectlySortedList):
            __ = self.sorted_asset_list_by_last_edit.find(asset_key)

    def test_find(self):
        asset_key = self.course_key.make_asset_key('asset', 'asset.txt')
        self.assertEquals(self.sorted_asset_list_by_filename.find(asset_key),
                          0)
        asset_key_last = self.course_key.make_asset_key(
            'asset', 'weather_patterns.bmp')
        self.assertEquals(
            self.sorted_asset_list_by_filename.find(asset_key_last),
            len(AssetStoreTestData.all_asset_data) - 1)
Example #3
0
class TestSortedAssetList(unittest.TestCase):
    """
    Tests the SortedAssetList class.
    """
    shard = 1

    def setUp(self):
        super(TestSortedAssetList, self).setUp()
        asset_list = [dict(zip(AssetStoreTestData.asset_fields, asset)) for asset in AssetStoreTestData.all_asset_data]
        self.sorted_asset_list_by_filename = SortedAssetList(iterable=asset_list)
        self.sorted_asset_list_by_last_edit = SortedAssetList(iterable=asset_list, key=lambda x: x['edited_on'])
        self.course_key = CourseLocator('org', 'course', 'run')

    def test_exception_on_bad_sort(self):
        asset_key = self.course_key.make_asset_key('asset', 'pic1.jpg')
        with self.assertRaises(IncorrectlySortedList):
            __ = self.sorted_asset_list_by_last_edit.find(asset_key)

    def test_find(self):
        asset_key = self.course_key.make_asset_key('asset', 'asset.txt')
        self.assertEquals(self.sorted_asset_list_by_filename.find(asset_key), 0)
        asset_key_last = self.course_key.make_asset_key('asset', 'weather_patterns.bmp')
        self.assertEquals(
            self.sorted_asset_list_by_filename.find(asset_key_last), len(AssetStoreTestData.all_asset_data) - 1
        )