示例#1
0
    def setUp(self):
        self.db_name = 'scsr-api-test2'

        self.app_factory = ScsrAPP(MONGODB_SETTINGS={
            'DB': self.db_name,
            'HOST': MONGODB_HOST
        },
                                   TESTING=True,
                                   WTF_CSRF_ENABLED=False,
                                   SECRET_KEY='mySecret!').APP
        self.app = self.app_factory.test_client()
示例#2
0
    def setUpClass(cls):
        print("#" * 130)
        print(" " * 40 + "Testing SCSR Model")
        print("#" * 130)
        self.db_name = 'scsr-api-test2'

        self.app_factory = ScsrAPP(MONGODB_SETTINGS={
            'DB': self.db_name,
            'HOST': MONGODB_HOST
        },
                                   TESTING=True,
                                   WTF_CSRF_ENABLED=False,
                                   SECRET_KEY='mySecret!').APP
        self.app = self.app_factory.test_client()
    def setUpClass(cls):
        print("*"*130)
        print(" "*40+"Testing Aesthetic Function Model")
        print("*"*130)
        cls.db_name = 'scsr-api-test2'
        
        cls.app_factory = ScsrAPP(
            MONGODB_SETTINGS = {'DB': cls.db_name,
                'HOST': MONGODB_HOST},
            TESTING = True,
            WTF_CSRF_ENABLED = False,
            SECRET_KEY = 'mySecret!').APP
        cls.app = cls.app_factory.test_client()
        #initialize the database with the countries and languages
        from install_system import start_countries,start_language, start_games, start_genre, start_elements_ontology, start_elements_pigd
        start_countries()
        start_language()
        start_genre()
        start_games()
        start_elements_ontology()
        start_elements_pigd()
        #load the elements

        cls.init_indexes()

        cls.init_elements()

        cls.init_interactivity_operated_indexes()

        cls.init_ludic_operated_indexes()

        cls.init_interactivity_behavior_operand_comparators()

        cls.init_ludic_behavior_operand_comparators()
示例#4
0
class ModelTest(unittest.TestCase):

    the_test = "Models View (Endpoints)"

    def setUp(self):
        print("#" * 130)
        print(" " * 40 + "Testing " + self.the_test)
        print("#" * 130)
        self.db_name = 'scsr-api-test2'

        self.app_factory = ScsrAPP(MONGODB_SETTINGS={
            'DB': self.db_name,
            'HOST': MONGODB_HOST
        },
                                   TESTING=True,
                                   WTF_CSRF_ENABLED=False,
                                   SECRET_KEY='mySecret!').APP
        self.app = self.app_factory.test_client()

    def tearDown(self):
        db = _get_db()
        db.client.drop_database(db)

    #Test to add_games in the system.
    # The add_games endpoint is an administrative endpoint, so, it needs an administrative ID in order to fulfill its tasks
    def test_elements(self):
        self.tearDown()
        self.the_test = "Element Models"
        self.setUp()
        from scsr.models.test_elements import ElementModelTest

    def test_behaviors(self):
        self.tearDown()
        self.the_test = "Behavior Models"
        self.setUp()
        from scsr.models.test_behaviors import BehaviorModelTest

    def test_persuasive_function(self):
        self.tearDown()
        self.the_test = "Persuasive Functions"
        self.setUp()
        from scsr.models.test_persuasive_function import PersuasiveFunctionModelTest

    def test_aesthetic_function(self):
        self.tearDown()
        self.the_test = "Aesthetic Functions"
        self.setUp()
        from scsr.models.test_aesthetic_function import AestheticFunctionModelTest

    def test_orchestration_function(self):
        self.tearDown()
        self.the_test = "Orchestration Functions"
        self.setUp()
        from scsr.models.test_orchestration_function import OrchestrationFunctionModelTest

    def test_reification_function(self):
        self.tearDown()
        self.the_test = "Reification Functions"
        self.setUp()
        from scsr.models.test_reification_function import ReificationFunctionModelTest
示例#5
0
    def setUpClass(cls):
        print("*" * 130)
        print(" " * 40 + "Testing Element Model")
        print("*" * 130)
        cls.db_name = 'scsr-api-test2'

        cls.app_factory = ScsrAPP(MONGODB_SETTINGS={
            'DB': cls.db_name,
            'HOST': MONGODB_HOST
        },
                                  TESTING=True,
                                  WTF_CSRF_ENABLED=False,
                                  SECRET_KEY='mySecret!').APP
        cls.app = cls.app_factory.test_client()
        #initialize the database with the countries and languages
        from install_system import start_countries, start_language, start_games, start_genre
        start_countries()
        start_language()
        start_genre()
        start_games()
        ''' start_elements_ontology()
示例#6
0
    def setUpClass(cls):
        print("*" * 130)
        print(" " * 40 + "Testing Behavior Model")
        print("*" * 130)
        cls.db_name = 'scsr-api-test2'

        cls.app_factory = ScsrAPP(MONGODB_SETTINGS={
            'DB': cls.db_name,
            'HOST': MONGODB_HOST
        },
                                  TESTING=True,
                                  WTF_CSRF_ENABLED=False,
                                  SECRET_KEY='mySecret!').APP
        cls.app = cls.app_factory.test_client()
        #initialize the database with the countries and languages
        from install_system import start_countries, start_language, start_games, start_genre, start_elements_ontology, start_elements_pigd
        start_countries()
        start_language()
        start_genre()
        start_games()
        start_elements_ontology()
        start_elements_pigd()
        cls.els1 = [1, 3, 5, 7, 9]
        cls.els2 = [2, 3, 4, 7, 8, 10, 12, 11]
        cls.els1_add = [6, 13, 18]
        cls.els1_rem1 = [3]
        cls.els1_rem2 = [5, 9]
        cls.els1_add2 = [20, 24, 32, 42]
        cls.int = list(set(cls.els1) & set(cls.els2))
        cls.uni = list(set(cls.els1) | set(cls.els2))
        cls.xor = list(set(cls.els1) ^ set(cls.els2))
        cls.diff1 = list(set(cls.els1) - set(cls.els2))
        cls.diff2 = list(set(cls.els2) - set(cls.els1))
        cls.newels1 = list(
            set(set(cls.els1) | set(cls.els1_add)) - set(cls.els1_rem1))
        cls.newels2 = list(
            set(cls.newels1) - set(cls.els1_rem2) | set(cls.els1_add2))
        cls.init_elements()
示例#7
0
class ScsrModelTest(unittest.TestCase):
    def setUpClass(cls):
        print("#" * 130)
        print(" " * 40 + "Testing SCSR Model")
        print("#" * 130)
        self.db_name = 'scsr-api-test2'

        self.app_factory = ScsrAPP(MONGODB_SETTINGS={
            'DB': self.db_name,
            'HOST': MONGODB_HOST
        },
                                   TESTING=True,
                                   WTF_CSRF_ENABLED=False,
                                   SECRET_KEY='mySecret!').APP
        self.app = self.app_factory.test_client()

    def tearDownClass(cls):
        db = _get_db()
        db.client.drop_database(db)

    #Test to add_games in the system.
    # The add_games endpoint is an administrative endpoint, so, it needs an administrative ID in order to fulfill its tasks
    def test_add_games(self):
        pass
示例#8
0
class AppTest(unittest.TestCase):
    def setUp(self):
        self.db_name = 'scsr-api-test2'

        self.app_factory = ScsrAPP(MONGODB_SETTINGS={
            'DB': self.db_name,
            'HOST': MONGODB_HOST
        },
                                   TESTING=True,
                                   WTF_CSRF_ENABLED=False,
                                   SECRET_KEY='mySecret!').APP
        self.app = self.app_factory.test_client()

    def tearDown(self):
        db = _get_db()
        db.client.drop_database(db)

    def app_dict(self):
        return json.dumps(dict(app_id="Scsr_Client", app_secret="scsr_secret"))

    def test_create_app(self):
        #basic registration
        rv = self.app.post('/apps/',
                           data=self.app_dict(),
                           content_type='application/json')
        assert rv.status_code == 200

        #missing app_secret
        dado = json.dumps(dict(app_id="Scsr_Client"))
        rv = self.app.post('/apps/',
                           data=dado,
                           content_type='application/json')
        assert "MISSING_APP_ID_OR_APP_SECRET" in str(rv.data)

        #repeat registration
        rv = self.app.post('/apps/',
                           data=self.app_dict(),
                           content_type='application/json')
        assert "APP_ID_ALREADY_EXISTS" in str(rv.data)

    def test_token_generation(self):
        dado = json.dumps(dict(app_id="Scsr_Client"))

        rv = self.app.post('/apps/',
                           data=self.app_dict(),
                           content_type='application/json')
        assert rv.status_code == 200

        #generate access token
        rv = self.app.post('/apps/access_token/',
                           data=self.app_dict(),
                           content_type='application/json')
        token = json.loads(rv.data.decode('utf-8')).get('token')
        assert token is not None

        rv = self.app.post('/apps/access_token/',
                           data=dado,
                           content_type='application/json')
        assert "MISSING_APP_ID_OR_APP_SECRET" in str(rv.data)

        #incorrect app_secret
        dado2 = json.dumps(
            dict(app_id="Scsr_Client", app_secret="secreto errado"))
        rv = self.app.post('/apps/access_token/',
                           data=dado2,
                           content_type='application/json')
        assert "INCORRECT_CREDENTIALS" in str(rv.data)

        #Test working token
        rv = self.app.get('/games/',
                          headers={
                              'X-APP-ID': 'Scsr_Client',
                              'X-APP-TOKEN': token
                          },
                          content_type='application/json')
        assert rv.status_code == 200

        #test bad_token
        rv = self.app.get('/games/',
                          headers={
                              'X-APP-ID': 'Scsr_Client',
                              'X-APP-TOKEN': token + "lll"
                          },
                          content_type='application/json')
        assert rv.status_code == 403

        #test expired token
        now = datetime.utcnow().replace(second=0, microsecond=0)
        expires = now + timedelta(days=-31)
        access = Access.objects.first()  # pylint: disable=no-member
        access.expires = expires
        access.save()
        rv = self.app.get('/games/',
                          headers={
                              'X-APP-ID': 'Scsr_Client',
                              'X-APP-TOKEN': token
                          },
                          content_type='application/json')
        assert "TOKEN_EXPIRED" in str(rv.data)
示例#9
0
import os, sys

sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))

from flask_script import Manager, Server
from application import ScsrAPP

app = ScsrAPP()
manager = Manager(app.APP)

# Turn on the debugger by default and reloader
manager.add_command(
    "runserver",
    Server(use_debugger=True,
           use_reloader=True,
           host=os.getenv('IP', '0.0.0.0'),
           port=int(os.getenv('PORT', 5000))))

if __name__ == "__main__":
    manager.run()