from smashbox.utilities import *
from smashbox.utilities.hash_files import *
from smashbox.protocol import chunk_file_upload,file_upload, file_download

@add_worker
def main(step):

    d = make_workdir()
    reset_owncloud_account()

    URL = oc_webdav_url()

    MB=1000*1000

    filename=create_hashfile(d,size=int(5.5*MB))

    # careful with the chunk size...
    r=chunk_file_upload(filename,URL,chunk_size=1*MB,android_client_bug_900=True)
    file_download(os.path.basename(filename),URL,d)
    analyse_hashfiles(d)

    # upload again matching the existing etag
    r=chunk_file_upload(filename,URL,chunk_size=1*MB,android_client_bug_900=True,header_if_match=r.headers['ETag'])
    analyse_hashfiles(d)

    # upload again with a non-matching etag
    r = chunk_file_upload(filename,URL,header_if_match='!@# does not exist 123')
    fatal_check(r.rc == 412) # precondition failed

@@ -236,30 +236,707 @@
     
-URL = oc_webdav_url()%0A
+# we make client look like an Android client%0A    config.pycurl_USERAGENT = %22Android-ownCloud%22%0A%0A    # this test ust be run against the mobile endpoint of cernbox which may be convinently set in the config%0A    # for vanilla owncloud server mobile endpoint is the same as generic webdav endpoint%0A    webdav_endpoint = config.get('oc_mobile_webdav_endpoint',None)%0A%0A    URL = oc_webdav_url(webdav_endpoint=webdav_endpoint)%0A%0A    if webdav_endpoint is None:%0A        logger.warning('oc_mobile_webdav_endpoint was not defined, using standard endpoint, URL: %25s',URL)%0A%0A    # Note: specifying a different chunk size will result in corrupted file!%0A    # This is a hack until the android-client is properly fixed!
 %0A   
@@ -941,18 +941,18 @@
    MB=10
-00
+24
 *1000%0A%0A 
@@ -1561,8 +1561,99 @@
  failed%0A
+%0A    # TODO: %0A    #  - make sure that without user agent header the upload fails%0A    #  - %0A

fix chunk-size, set USERAGENT and optional custom oc_mobile_webdav_endpoint