コード例 #1
0
ファイル: test_content.py プロジェクト: tuxun/ludobox
    def test_read_game_info(self):
        """Make sure an info file is read properly"""

        info = read_game_info(self.game_path)
        with open(os.path.join(self.game_path, 'info.json'), 'r') as f:
            json_data = json.load(f)

        json_data["slug"] = "2" # add slug

        self.assertEquals(len(info.keys()), len(json_data.keys()) )
        self.assertEquals(sorted(info.keys()), sorted(json_data.keys()))

        # wrong game raises error
        self.assertRaises(ValidationError, lambda:read_game_info(self.wrong_game_path))
コード例 #2
0
    def test_basic_game_info_update(self):
        """Make sure an update is properly parsed and stored"""

        borgia_info = read_game_info(self.borgia_game_path)

        # make some basic changes
        modified_borgia_info = borgia_info
        modified_borgia_info["title"] = "Coucou"

        updated_game_info = update_game_info(self.borgia_game_path,
                                             modified_borgia_info)

        # make sure changes have been done
        self.assertEquals(modified_borgia_info["title"],
                          updated_game_info["title"])
        self.assertEquals(updated_game_info["title"], "Coucou")

        # make sure there is a new event in history
        self.assertEquals(len(updated_game_info["history"]), 1)

        event = updated_game_info["history"][0]["patch"]
        print event

        # try to apply patch again
        new = JsonPatch(event).apply(modified_borgia_info)

        # make sure the original title is back
        self.assertEquals(new["title"], "Borgia, le jeu malsain")
コード例 #3
0
    def test_api_add_game(self):

        valid_info = read_game_info(os.path.join(os.getcwd(), 'server/tests/test-data/test-game'))

        data = {
            'files': [
                (StringIO('my readme'), 'test-README.txt'),
                (StringIO('my rules'), 'test-RULES.txt'),
                (io.BytesIO(b"abcdef"), 'test.jpg')
            ],
            'info': json.dumps(valid_info)
        }

        result = self.app.post('/api/create',
                                data=data,
                                content_type='multipart/form-data'
                                )

        self.assertEqual(result.status_code, 201)
        res = json.loads(result.data)
        self.assertIn("path", res.keys())

        # load JSON info data
        with open(os.path.join(res["path"], 'info.json'), 'r' )as  f:
            stored_info = json.load(f)
        self.assertEqual(stored_info, valid_info)

        # check for files
        written_filenames = os.listdir(os.path.join(res["path"], 'files'))
        self.assertEqual(written_filenames.sort(), [f[1] for f in data["files"]].sort())
コード例 #4
0
ファイル: test_content.py プロジェクト: tuxun/ludobox
 def test_get_resource_slug(self):
     """Make sure the slug contains name of the game + language"""
     borgia_game_path = os.path.join(os.getcwd(), 'data/borgia-le-jeu-malsain-fr')
     print borgia_game_path
     borgia_info = read_game_info(borgia_game_path)
     slug = get_resource_slug(borgia_info)
     print slug
     self.assertEquals("borgia-le-jeu-malsain-fr", slug)
コード例 #5
0
ファイル: test_content.py プロジェクト: tuxun/ludobox
    def test_validate_game_data(self):
        """Make sure an info file is parsed properly"""
        info = read_game_info(self.game_path)
        self.assertEquals(validate_game_data(info), None)

        # make sure error is raised with a basic mistake
        info_wrong = info.copy()
        info_wrong["description"] = 72
        self.assertRaises(ValidationError, lambda:validate_game_data(info_wrong))
コード例 #6
0
    def test_validate_basic_event_history(self):

        borgia_info = read_game_info(self.borgia_game_path)

        # make some basic changes
        modified_borgia_info = borgia_info
        modified_borgia_info["title"] = "Coucou"

        updated_game_info = update_game_info(self.borgia_game_path,
                                             modified_borgia_info)

        validate_game_data(updated_game_info)
コード例 #7
0
ファイル: test_content.py プロジェクト: tuxun/ludobox
    def test_write_info_json(self):
        """Make sure the JSON info file is written properly"""

        # load data
        info = read_game_info(self.game_path)

        # create game path and write info file
        os.makedirs(self.tmp_path)
        write_info_json(info, self.tmp_path)

        # check if data has been written correctly
        info_path = os.path.join(self.tmp_path, 'info.json')
        self.assertTrue(os.path.exists(info_path))
        with open(info_path, "r") as f :
            data = json.load(f)
        self.assertEquals(info, data)
コード例 #8
0
import ludobox

from ludobox.content import read_game_info, get_resource_slug

data_dir = os.path.join(os.getcwd(),"data")
print "CHANGES : %s"%data_dir
print "-"*10

renames = []
for game_folder_name in os.listdir(data_dir) :
    path = os.path.join(data_dir,game_folder_name)
    # get only folders
    if os.path.isdir(path):
        info_file = os.path.join(path, "info.json")
        if os.path.exists(info_file):
            info = read_game_info(path)
            slug = get_resource_slug(info)
            if game_folder_name != slug:
                renames.append( (game_folder_name, slug) )
                print "'%s' will update to '%s'"%(game_folder_name, slug)

def confirm_choice():
    confirm = raw_input( "Rename these %s folder(s) : Yes or No [y/n] ?" %len(renames) )
    if confirm != 'y' and confirm != 'n':
        print("\n Invalid Option. Please Enter a Valid Option.")
        return confirm_choice()
    elif confirm == 'y' :
        return True
    elif confirm == 'n' :
        return False
コード例 #9
0
ファイル: test_content.py プロジェクト: tuxun/ludobox
 def test_writing_invalid_data(self):
     """Make sure an error is raised before writing invalid data"""
     info = read_game_info(self.game_path)
     info_wrong = info.copy()
     info_wrong["description"] = 72
     self.assertRaises(ValidationError, lambda:write_info_json(info_wrong, self.tmp_path))
コード例 #10
0
ファイル: test_content.py プロジェクト: tuxun/ludobox
 def test_borgia_game_data(self):
     """Make sure the borgias are okay with the model"""
     borgia_game_path = os.path.join(os.getcwd(), 'data/borgia-le-jeu-malsain-fr')
     print borgia_game_path
     borgia_info = read_game_info(borgia_game_path)
     self.assertEquals(validate_game_data(borgia_info), None)