def test_create_content_already_existing(self): tmp = "/tmp" info = self.borgia_info_content new_game = create_content(info, None, tmp) self.assertRaises(LudoboxError, lambda: create_content(info, None, tmp))
def api_create_resource(): """ This function allow to post 2 things : * info : a dict containing a (valid) description of the game * files : a bunch of files of the game itself """ # make sure unauthorized boxes can not create new games if current_app.config["UPLOAD_ALLOWED"] is False: response = jsonify({'message': 'Upload not allowed'}) return response, 401 files = request.files.getlist('files') current_app.logger.debug("UPLOADED FILES:", [f.filename for f in files]) info = json.loads(request.form["info"]) # Save the game description as pure JSON file data_path = create_content(info, files, current_app.config["DATA_DIR"]) slugified_name = get_resource_slug(info) return jsonify({"path": data_path, "slug": slugified_name}), 201
def test_create_slug_once_and_for_all(self): tmp = "/tmp" slug = "game-bla-bla-bla-fr" # clean delete_data_path(os.path.join(tmp, slug)) info = self.borgia_info_content.copy() info["title"] = "bla bla bla" info.pop('slug', None) # remove slug self.assertRaises(KeyError, lambda: info["slug"]) game_path = create_content(info, None, tmp) game_info = read_content(game_path) self.assertEqual(game_info["slug"], "game-bla-bla-bla-fr") new_game_info = info.copy() new_game_info["title"] = "bla bla bla 2" updated_content = update_content_info(game_path, new_game_info) self.assertEqual(slug, updated_content["slug"]) self.assertEqual(game_info["slug"], updated_content["slug"])
def setUp(self): delete_data_path( os.path.join(self.tmp_path, self.borgia_info_content["slug"])) # create a game info = self.borgia_info_content new_game_path = create_content(info, None, self.tmp_path)
def test_create_content_invalid(self): """Make sure an error is raised before writing invalid data""" info = self.borgia_info_content info_wrong = info.copy() info_wrong["description"] = 72 self.assertRaises( ValidationError, lambda: create_content(info_wrong, None, self.tmp_path))
def test_prevent_wrong_state_name(self): """Make sure you can only add valid state names.""" info = self.borgia_info_content delete_data_path(os.path.join(self.tmp_path, info["slug"])) # create a game new_game_path = create_content(info, None, self.tmp_path) self.assertRaises( LudoboxError, lambda: update_content_state(new_game_path, "lalala"))
def test_update_content_info(self): tmp = "/tmp" info = self.borgia_info_content game_path = create_content(info, None, tmp) game_info = read_content(game_path) new_game_info = game_info.copy() new_game_info["title"] = "bla bla bla" updated_content = update_content_info(game_path, new_game_info) self.assertEqual(len(updated_content["history"]), 2) event = updated_content["history"][1] self.assertEqual(event["type"], "update")
def test_create_content_without_attachements(self): """ Make sure that content is written properly""" tmp = "/tmp" info = self.borgia_info_content new_game = create_content(info, None, tmp) # dir and files are written properly self.assertTrue(os.path.isdir(new_game)) json_path = os.path.join(new_game, "info.json") self.assertTrue(os.path.exists(json_path)) new_game_info = read_content(new_game) # basic check for simlarity self.assertTrue(info["title"], new_game_info["title"]) # make sure history has been written self.assertIn("history", new_game_info.keys()) self.assertTrue(len(new_game_info["history"]), 1) event = new_game_info["history"][0] self.assertTrue(event["type"], "create")