def test_post_image_json_utf16(module_scoped_container_getter):
    multipart_form_data = build_image_multipart("Pictures/",
                                                abstract_test.utf16_json)
    json_response = abstract_test.post_multipart(abstract_test.image,
                                                 multipart_form_data, 400)
    assert json_response["error"] == "Invalid encoding in file " \
           + abstract_test.utf16_json + ", valid encodings are UTF-8 and US-ASCII"
Esempio n. 2
0
def test_post_categorize_invalid_categories_file(module_scoped_container_getter):
    multipart_form_data = abstract_test.build_base_multipart_images(abstract_test.categorize, files, "Pictures/")
    multipart_form_data.append(('categories', (str("invalid2.pdf")
                                               , open('InvalidFiles/' + "Invalid2.pdf", 'rb')
                                               , 'text/plain')))
    json_response = abstract_test.post_multipart(abstract_test.categorize, multipart_form_data, 400)
    assert json_response["error"] == "Invalid extension, allowed extensions are: ['csv', 'json']"
Esempio n. 3
0
def test_post_categorize_json(module_scoped_container_getter):
    multipart_form_data = build_categorize_multipart("Pictures/", abstract_test.example_json)
    json_response = abstract_test.post_multipart(abstract_test.categorize, multipart_form_data, 201)
    for f in files:
        if f != "sources.txt":
            assert ((json_response[f] == "an apple") or (json_response[f] == "a dog"))
    assert len(json_response) == len(files) - 1
Esempio n. 4
0
def test_post_video_csv(module_scoped_container_getter):
    multipart_form_data = build_video_multipart(file, abstract_test.example_csv, "Videos/")
    json_response = abstract_test.post_multipart(abstract_test.video, multipart_form_data, 201)

    with open('CategoryFiles/' + abstract_test.example_csv, 'r') as f:
        reader = csv.reader(f)
        categories = next(reader)

    is_valid_response(categories, json_response)
Esempio n. 5
0
def test_post_video_json(module_scoped_container_getter):
    multipart_form_data = build_video_multipart(file, abstract_test.example_json, "Videos/")
    json_response = abstract_test.post_multipart(abstract_test.video, multipart_form_data, 201)

    with open('CategoryFiles/' + abstract_test.example_json) as json_file:
        categories = json.load(json_file)['categories']

    is_valid_response(categories, json_response)

    assert len(json_response) == len(categories)
def test_post_image_invalid_image_files(module_scoped_container_getter):
    multipart_form_data = abstract_test\
        .build_base_multipart_images(abstract_test.image, os.listdir("InvalidFiles"), "InvalidFiles/")
    multipart_form_data.append(
        ('categories', (str(abstract_test.example_json),
                        open("CategoryFiles/" + abstract_test.example_json,
                             'rb'), 'text/plain')))
    json_response = abstract_test.post_multipart(abstract_test.image,
                                                 multipart_form_data, 400)
    assert json_response[
        "error"] == "Invalid extension, allowed extensions are: ['png', 'jpg', 'jpeg']"
def test_post_image_json(module_scoped_container_getter):
    multipart_form_data = build_image_multipart("Pictures/",
                                                abstract_test.example_json)
    json_response = abstract_test.post_multipart(abstract_test.image,
                                                 multipart_form_data, 201)
    with open('CategoryFiles/' + abstract_test.example_json) as json_file:
        categories = json.load(json_file)['categories']

    matches = 0
    for element in categories:
        if json_response[element] in files:
            matches += 1

    assert len(json_response) == len(categories)
    assert len(categories) == matches
def test_post_image_csv(module_scoped_container_getter):
    multipart_form_data = build_image_multipart("Pictures/",
                                                abstract_test.example_csv)
    json_response = abstract_test.post_multipart(abstract_test.image,
                                                 multipart_form_data, 201)

    with open('CategoryFiles/' + abstract_test.example_csv, 'r') as f:
        reader = csv.reader(f)
        categories = next(reader)

    matches = 0
    for element in categories:
        if json_response[element] in files:
            matches += 1

    assert len(json_response) == len(categories)
    assert len(categories) == matches
Esempio n. 9
0
def test_post_categorize_invalid_image_files(module_scoped_container_getter):
    multipart_form_data = abstract_test.build_base_multipart_images(abstract_test.categorize, os.listdir('InvalidFiles'), "InvalidFiles/")
    json_response = abstract_test.post_multipart(abstract_test.categorize, multipart_form_data, 400)
    assert json_response["error"] == "Invalid extension, allowed extensions are: ['png', 'jpg', 'jpeg']"
Esempio n. 10
0
def test_post_video_invalid_video_file(module_scoped_container_getter):
    multipart_form_data = build_video_multipart('Invalid2.pdf', abstract_test.example_json, "InvalidFiles/")
    json_response = abstract_test.post_multipart(abstract_test.video, multipart_form_data, 400)
    assert json_response["error"] == "Invalid extension, allowed extensions are: {'mp4'}"
Esempio n. 11
0
def test_post_video_json_utf16(module_scoped_container_getter):
    multipart_form_data = build_video_multipart(file, abstract_test.utf16_json, "Videos/")
    json_response = abstract_test.post_multipart(abstract_test.video, multipart_form_data, 400)

    assert json_response['error'] == 'Invalid encoding in file ' \
           + abstract_test.utf16_json + ', valid encodings are UTF-8 and US-ASCII'