'Tests a simple locking and unlocking of an asset in the toy course.'

def test_locking(self):

    def verify_asset_locked_state(locked):
        '    Helper    method    to    verify    lock    state    in    the    contentstore    '
        asset_location = StaticContent.get_location_from_path('/c4x/edX/toy/asset/sample_static.html')
        content = contentstore().find(asset_location)
        self.assertEqual(content.locked, locked)
    def post_asset_update(lock, course):
        '    Helper    method    for    posting    asset    update.    '
        content_type = 'application/txt'
        upload_date = datetime(2013, 6, 1, 10, 30, tzinfo=UTC)
        asset_location = course.id.make_asset_key('asset', 'sample_static.html')
        url = reverse_course_url('assets_handler', course.id, kwargs={'asset_key_string': unicode(asset_location)})
        resp = self.client.post(url, json.dumps(assets._get_asset_json('sample_static.html', content_type, upload_date, asset_location, None, lock)), 'application/json')
        self.assertEqual(resp.status_code, 201)
        return json.loads(resp.content)
    module_store = modulestore()
    course_items = import_course_from_xml(module_store, self.user.id, TEST_DATA_DIR, ['toy'], static_content_store=contentstore(), verbose=True)
    course = course_items[0]
    verify_asset_locked_state(False)
    resp_asset = post_asset_update(True, course)
    self.assertTrue(resp_asset['locked'])
    verify_asset_locked_state(True)
    resp_asset = post_asset_update(False, course)
    self.assertFalse(resp_asset['locked'])
    verify_asset_locked_state(False)
