Example #1
0
@author: niko
@author: timo

Based on course exercises code by:

@author: ivan
@author: mika oja
'''

import unittest
import flask
import json
from battleship import database
from battleship import resources

ENGINE = database.Engine('db/battleship_test.db')

MASONJSON = "application/vnd.mason+json"
JSON = "application/json"
BATTLESHIP_PLAYER_PROFILE = "/profiles/player-profile/"

resources.app.config["TESTING"] = True
resources.app.config["SERVER_NAME"] = "localhost:5000"
resources.app.config.update({"Engine": ENGINE})


class PlayersResourceTestCase(unittest.TestCase):
    '''
    Tests for methods that access the Players resource.
    '''
    create_player_request = {"nickname": "Jack Sparrow"}
Example #2
0
JSON = "application/json"
BATTLESHIP_GAME_PROFILE = "/profiles/game-profile/"
BATTLESHIP_PLAYER_PROFILE = "/profiles/player-profile/"
BATTLESHIP_SHIP_PROFILE = "/profiles/ship-profile/"
BATTLESHIP_SHOT_PROFILE = "/profiles/shot-profile/"
ERROR_PROFILE = "/profiles/error-profile/"

APIARY_PROJECT = "https://battleship.docs.apiary.io"
APIARY_PROFILES_URL = APIARY_PROJECT + "/#reference/profiles/"
APIARY_RELS_URL = APIARY_PROJECT + "/#reference/link-relations/"

LINK_RELATIONS_URL = "/battleship/link-relations/"

app = Flask(__name__, static_folder="static", static_url_path="/.")
app.debug = True
app.config.update({"Engine": database.Engine()})
api = Api(app)


class MasonObject(dict):
    '''
    Parent class for resources. Adds attributes.
    '''
    def add_error(self, title, details):
        self["@error"] = {
            "@message": title,
            "@messages": [details],
        }

    def add_namespace(self, ns, uri):
        if "@namespaces" not in self: