def test_list_user_images(pic): ''' Test each aspect of list_user_images ''' # Return None when no images assert picture.list_user_images(pic[0]) is None picture.add_picture(*pic) result = picture.list_user_images(pic[0]) tag_path = pic[0] / picture.tags_to_path(pic[1]) compare = (pic[0], str(tag_path), picture.id_to_filename(1)) assert result == [compare]
def test_api_images(pic, client): ''' Test each aspect of the images page in the API ''' expected = {} responce = client.get('/images') assert responce.data == jsonify(expected).data # Confirm no images picture.add_picture(*pic) pic_value = picture.make_picture(1, *pic) pic_value['image_name'] = picture.id_to_filename( pic_value.pop('picture_id')) pic_value.pop('user_id') expected[pic[0]] = [pic_value] responce = client.get('/images') assert responce.data == jsonify(expected).data # Confirm normal operation
def test_api_differences(pic, client): ''' Test each aspect of the deifferences page in the API ''' expected = {} result = {} responce = client.get('/differences') assert responce.data == jsonify(expected).data # Confirm no images # Add three pictures picture.add_picture(*pic) picture.add_picture(*pic) picture.add_picture(*pic) result['files-db'] = [] result['db-files'] = [] expected[pic[0]] = result responce = client.get('/differences') assert responce.data == jsonify(expected).data # Confirm no differences tag_path = pic[0] / picture.tags_to_path(pic[1]) # Remove the second picture from the image directory (tag_path / picture.id_to_filename(2)).unlink() # Remove the third picture from the database with sql.connection(sql.PICTURE) as table: table.delete(picture_id=3) result['files-db'] = [(pic[0], str(tag_path), picture.id_to_filename(3))] result['db-files'] = [(pic[0], str(tag_path), picture.id_to_filename(2))] expected[pic[0]] = result responce = client.get('/differences') assert responce.data == jsonify(expected).data # Confirm normal operation
def test_add_picture(pic): ''' Test each aspect of add_picture ''' # Refuse pictures for non existant users assert not picture.add_picture(f'new_{pic[0]}', pic[1]) # Refuse tags contianing numbers and symbols assert not picture.add_picture(pic[0], '#a_num_32') assert not picture.add_picture(pic[0], '#a_sym_&stuf') # Refuse tag strings longer than 100 characters assert not picture.add_picture(pic[0], '#a ' * 35) # Sucessfully add two pictures assert picture.add_picture(*pic) assert picture.add_picture(*pic)
def test_reconcile_images(pic): ''' Test reconcile_images by adding three pictures Remove one from the database, and another from the image directory Make sure reconcile_images returns the correct missing images ''' # Add three pictures picture.add_picture(*pic) picture.add_picture(*pic) picture.add_picture(*pic) tag_path = pic[0] / picture.tags_to_path(pic[1]) # Remove the second picture from the image directory (tag_path / picture.id_to_filename(2)).unlink() with sql.connection(sql.PICTURE) as table: table.delete(picture_id=3) result = picture.reconcile_images(pic[0]) file_not_db = {(pic[0], str(tag_path), picture.id_to_filename(3))} db_not_file = {(pic[0], str(tag_path), picture.id_to_filename(2))} assert result['files-db'] == file_not_db assert result['db-files'] == db_not_file
def upload_picture(user_id, tags): ''' Uploads an image onto the database ''' logger.info('Uploading a picture') return picture.add_picture(user_id, tags)