Repository: AVEgame/AVE

Issue:
Check that running AVE version is high enough to play library games
I think I already did this, but needs testing.

Discussion:

Patch:
diff --git a/ave/ave.py b/ave/ave.py
index 52fb295..cb4a94d 100644
--- a/ave/ave.py
+++ b/ave/ave.py
@@ -135,16 +135,12 @@ class AVE:
             A list of the title, author and local url for each game.
         """
         try:
-            the_json = load_library_json()
+            library = load_library_json()
         except AVENoInternet:
             self.no_internet()
             raise AVEToMenu
-        menu_items = []
-        for key, value in the_json.items():
-            if 'user/' in key:
-                menu_items.append([value['title'], value['author'],
-                                   key])
-        return menu_items
+        return [(game["title"], game["author"], i)
+                for i, game in enumerate(library)]
 
     def show_download_menu(self):
         """Show a menu of games from the online library."""
diff --git a/ave/parsing/game_loader.py b/ave/parsing/game_loader.py
index 1ddf398..ce94d9f 100644
--- a/ave/parsing/game_loader.py
+++ b/ave/parsing/game_loader.py
@@ -4,6 +4,7 @@ import re
 import json
 import urllib.request
 from ..game import Game
+from .. import config
 from ..exceptions import AVENoInternet
 from .string_functions import clean
 from .file_parsing import parse_room, parse_item
@@ -16,9 +17,14 @@ def load_library_json():
     global library_json
     try:
         if library_json is None:
+            library_json = []
             with urllib.request.urlopen(
-                    "http://avegame.co.uk/gamelist.json") as f:
-                library_json = json.load(f)
+                    "https://avegame.co.uk/gamelist.json") as f:
+                for game in json.load(f):
+                    game["ave_version"] = tuple(game["ave_version"])
+                    if game["user"]:
+                        if game["ave_version"] <= config.version_tuple:
+                            library_json.append(game)
     except:  # noqa: E722
         raise AVENoInternet
     return library_json
@@ -79,13 +85,14 @@ def load_game_from_file(file, filename=None):
                 version=version, ave_version=ave_version)
 
 
-def load_game_from_library(url):
+def load_game_from_library(n):
     """Load the metadata of a game from the online library."""
-    info = load_library_json()[url]
-    return Game(url="http://avegame.co.uk/download/" + url,
+    info = load_library_json()[n]
+    print(info)
+    return Game(url="https://avegame.co.uk/download/user/" + info["filename"],
                 title=info["title"], description=info["desc"],
                 author=info["author"], active=info["active"],
-                number=info["n"])
+                number=info["number"])
 
 
 def load_full_game_from_file(file):


Test patch:
diff --git a/test/test_games.py b/test/test_games.py
index 21b63bb..dad232b 100644
--- a/test/test_games.py
+++ b/test/test_games.py
@@ -1,7 +1,7 @@
 import pytest
 import os
 from ave import config, AVE, exceptions
-from ave import load_game_from_file, load_game_from_library
+from ave import load_game_from_file
 from ave.test import check_game
 
 config.debug = True
@@ -54,15 +54,3 @@ def test_games_for_errors(filename):
     else:
         # Assert that the worst error is a Warning or lower
         assert len(errors) == 0
-
-
-def xtest_game_library():
-    ave = AVE()
-    ave.get_download_menu()
-
-
-def xtest_load_game_from_library():
-    ave = AVE()
-    game = load_game_from_library(ave.get_download_menu()[0][2])
-    game.load()
-    assert game["start"].id != "fail"
diff --git a/test/test_library.py b/test/test_library.py
new file mode 100644
index 0000000..99d1c9c
--- /dev/null
+++ b/test/test_library.py
@@ -0,0 +1,14 @@
+from ave import AVE
+from ave import load_game_from_library
+
+
+def test_game_library():
+    ave = AVE()
+    ave.get_download_menu()
+
+
+def test_load_game_from_library():
+    ave = AVE()
+    game = load_game_from_library(ave.get_download_menu()[0][2])
+    game.load()
+    assert game["start"].id != "fail"