def test_56_add_comment_with_image_too_big(john_doe_api_client, default_hearing, get_comments_url_and_data): section = default_hearing.sections.first() url, data = get_comments_url_and_data(default_hearing, section) comment_data = get_comment_data(section=section.pk, images=[image_test_json()]) # 10 bytes max with override_settings(MAX_IMAGE_SIZE=10): response = john_doe_api_client.post(url, data=comment_data, format='json') data = get_data_from_response(response, status_code=400) assert data['images'][0]['image'][0] == 'Image size should be smaller than 10 bytes.'
def test_56_add_comment_with_invalid_content_as_images(john_doe_api_client, default_hearing, get_comments_url_and_data): section = default_hearing.sections.first() url, data = get_comments_url_and_data(default_hearing, section) invalid_image = image_test_json() invalid_image.update({"image": "not a b64 image"}) comment_data = get_comment_data(section=section.pk, images=[invalid_image]) response = john_doe_api_client.post(url, data=comment_data, format='json') data = get_data_from_response(response, status_code=400) assert data['images'][0]['image'][0] == 'Invalid content. Expected "data:image"' invalid_image.update({"image": "data:image/jpg;base64,not a b64 image"}) comment_data = get_comment_data(section=section.pk, images=[invalid_image]) response = john_doe_api_client.post(url, data=comment_data, format='json') data = get_data_from_response(response, status_code=400) error = data['images'][0]['image'][0] assert error == 'Upload a valid image. The file you uploaded was either not an image or a corrupted image.'
def test_56_add_comment_with_images_to_section(john_doe_api_client, default_hearing, get_comments_url_and_data): section = default_hearing.sections.first() url, data = get_comments_url_and_data(default_hearing, section) old_comment_list = get_data_from_response(john_doe_api_client.get(url)) # If pagination is used the actual data is in "results" if 'results' in old_comment_list: old_comment_list = old_comment_list['results'] # set section explicitly comment_data = get_comment_data(section=section.pk, images=[image_test_json()]) response = john_doe_api_client.post(url, data=comment_data, format='json') data = get_data_from_response(response, status_code=201) assert 'images' in data assert data['images'][0]['url'].startswith( 'http://testserver/media/images/') # Check that the comment is available in the comment endpoint now new_comment_list = get_data_from_response(john_doe_api_client.get(url)) # If pagination is used the actual data is in "results" if 'results' in new_comment_list: new_comment_list = new_comment_list['results'] # Replace the images with the list of URL returned by the creation response_data = deepcopy(comment_data) response_data['images'][0].pop('image') response_data['images'][0].update({ 'url': data['images'][0]['url'], 'height': 635, 'width': 952, }) assert len(new_comment_list) == len(old_comment_list) + 1 new_comment = [c for c in new_comment_list if c["id"] == data["id"]][0] new_comment['images'][0].pop('id') assert_common_keys_equal(new_comment, response_data) assert new_comment["is_registered"] == True assert new_comment["author_name"] is None
def test_56_add_comment_with_images_to_section(john_doe_api_client, default_hearing, get_comments_url_and_data): section = default_hearing.sections.first() url, data = get_comments_url_and_data(default_hearing, section) old_comment_list = get_data_from_response(john_doe_api_client.get(url)) # If pagination is used the actual data is in "results" if 'results' in old_comment_list: old_comment_list = old_comment_list['results'] # set section explicitly comment_data = get_comment_data(section=section.pk, images=[image_test_json()]) response = john_doe_api_client.post(url, data=comment_data, format='json') data = get_data_from_response(response, status_code=201) assert 'images' in data assert data['images'][0]['url'].startswith('http://testserver/media/images/') # Check that the comment is available in the comment endpoint now new_comment_list = get_data_from_response(john_doe_api_client.get(url)) # If pagination is used the actual data is in "results" if 'results' in new_comment_list: new_comment_list = new_comment_list['results'] # Replace the images with the list of URL returned by the creation response_data = deepcopy(comment_data) response_data['images'][0].pop('image') response_data['images'][0].update({ 'url': data['images'][0]['url'], 'height': 635, 'width': 952, }) assert len(new_comment_list) == len(old_comment_list) + 1 new_comment = [c for c in new_comment_list if c["id"] == data["id"]][0] new_comment['images'][0].pop('id') assert_common_keys_equal(new_comment, response_data) assert new_comment["is_registered"] == True assert new_comment["author_name"] is None
def valid_hearing_json(contact_person, default_label): return { "abstract": "", "title": "My first hearing", "id": "nD6aC5herQM3X1yi9aNQf6rGm6ZogAlC", "borough": "Punavuori", "n_comments": 0, "published": True, "labels": [{ "id": default_label.id, "label": default_label.label }], "open_at": "2016-09-29T11:39:12Z", "close_at": "2016-09-29T11:39:12Z", "created_at": "2016-10-04T10:30:38.066436Z", "servicemap_url": "", "sections": [ { "type": "closure-info", "commenting": 'none', "published": True, "title": "Section 3", "abstract": "", "content": "<p>Enter the introductioververn text for the hearing here.</p>", "created_at": "2016-10-04T12:12:06.798574Z", "created_by": None, "images": [], "n_comments": 0, "plugin_identifier": "", "plugin_data": "", "type_name_singular": "sulkeutumistiedote", "type_name_plural": "sulkeutumistiedotteet", }, { "commenting": 'none', "published": True, "title": "Section 1", "abstract": "", "content": "<p>Enter the introduction text for the hearing here.ve</p>", "created_at": "2016-10-04T11:33:37.430091Z", "created_by": None, "images": [ image_test_json(), ], "n_comments": 0, "plugin_identifier": "", "plugin_data": "", "type_name_singular": "pääosio", "type_name_plural": "pääosiot", "type": "main" }, { "id": "3adn7MGkOJ8e4NlhsElxKggbfdmrSmVE", "type": "part", "commenting": 'none', "published": True, "title": "Section 2", "abstract": "", "content": "<p>Enter the introduction text for the hearing here.eve</p>", "created_at": "2016-10-04T12:09:16.818364Z", "created_by": None, "images": [ image_test_json(), ], "n_comments": 0, "plugin_identifier": "", "plugin_data": "", "type_name_singular": "osa-alue", "type_name_plural": "osa-alueet" }, ], "closed": True, "organization": None, "geojson": None, "main_image": None, "contact_persons": [{ "id": contact_person.id, "name": contact_person.name, "title": contact_person.title, "phone": contact_person.phone, "email": contact_person.email, "organization": contact_person.organization.id, }], }
def valid_hearing_json(contact_person, default_label): return { "abstract": "", "title": "My first hearing", "id": "nD6aC5herQM3X1yi9aNQf6rGm6ZogAlC", "borough": "Punavuori", "n_comments": 0, "published": True, "labels": [{"id": default_label.id, "label": default_label.label}], "open_at": "2016-09-29T11:39:12Z", "close_at": "2016-09-29T11:39:12Z", "created_at": "2016-10-04T10:30:38.066436Z", "servicemap_url": "", "sections": [ { "type": "closure-info", "commenting": 'none', "published": True, "title": "Section 3", "abstract": "", "content": "<p>Enter the introductioververn text for the hearing here.</p>", "created_at": "2016-10-04T12:12:06.798574Z", "created_by": None, "images": [], "n_comments": 0, "plugin_identifier": "", "plugin_data": "", "type_name_singular": "sulkeutumistiedote", "type_name_plural": "sulkeutumistiedotteet", }, { "commenting": 'none', "published": True, "title": "Section 1", "abstract": "", "content": "<p>Enter the introduction text for the hearing here.ve</p>", "created_at": "2016-10-04T11:33:37.430091Z", "created_by": None, "images": [ image_test_json(), ], "n_comments": 0, "plugin_identifier": "", "plugin_data": "", "type_name_singular": "pääosio", "type_name_plural": "pääosiot", "type": "main" }, { "id": "3adn7MGkOJ8e4NlhsElxKggbfdmrSmVE", "type": "part", "commenting": 'none', "published": True, "title": "Section 2", "abstract": "", "content": "<p>Enter the introduction text for the hearing here.eve</p>", "created_at": "2016-10-04T12:09:16.818364Z", "created_by": None, "images": [ image_test_json(), ], "n_comments": 0, "plugin_identifier": "", "plugin_data": "", "type_name_singular": "osa-alue", "type_name_plural": "osa-alueet" }, ], "closed": True, "organization": None, "geojson": None, "main_image": None, "contact_persons": [{ "id": contact_person.id, "name": contact_person.name, "title": contact_person.title, "phone": contact_person.phone, "email": contact_person.email, "organization": contact_person.organization.id, }], }