示例#1
0
    def setUp(self):

        assert settings.DEBUG == True

        django.utils.translation.activate("en") # to test for error messages, just in case...

        reset_zodb_structure()
        create_game_instance(game_instance_id=TEST_GAME_INSTANCE_ID,
                             creator_login="******",
                             skip_randomizations=True)  # handy to test stuffs

        try:

            test_http_host = "localhost:80"

            self.client = Client()
            self.factory = RequestMock(HTTP_HOST=test_http_host)

            self.request = self.factory.get(HOME_URL)
            assert self.request.user
            assert self.request.datamanager.user.datamanager.request # double linking
            assert self.request.session
            assert self.request._messages is not None
            assert self.request.datamanager

            # we mimic messages middleware
            from django.contrib.messages.storage import default_storage
            self.request._messages = default_storage(self.request)

            self.dm = self.request.datamanager
            assert self.dm.is_initialized
            assert self.dm.connection

            self.dm.clear_all_event_stats()
            self.dm.check_database_coherency() # important
            assert self.dm.get_event_count("BASE_CHECK_DB_COHERENCY_PUBLIC_CALLED") == 1 # no bypassing because of wrong override

            self.dm.set_game_state(True)
            self.dm.set_activated_game_views(self.dm.get_activable_views().keys()) # QUICK ACCESS FIXTURE

            self.dm.clear_all_event_stats()

            #self.default_player = self.dm.get_character_usernames()[0]
            #self._set_user(self.TEST_LOGIN)

            self.initial_msg_sent_length = len(self.dm.get_all_dispatched_messages())
            self.initial_msg_queue_length = len(self.dm.get_all_queued_messages())

            # comment this to have eclipse's autocompletion to work for datamanager anyway
            self.dm = AutoCheckingDM(self.dm) # protection against uncommitted, pending changes

            # NO NEED TO COMMIT - transaction watcher should do it all #

        except Exception, e:
            print(">>>>>>>>>", repr(e))
            self.tearDown(check=False) # cleanup of connection
            raise
示例#2
0
    arguments = [arg.lower() for arg in sys.argv]

    if any(help_key in arguments for help_key in ("help", "-h", "--help")):
        print "Usage: python %s [reset_django|reset_zodb|pack_file|runserver]" % sys.argv[0]
        print "- reset_zodb: reset ZODB databases (game data) to their initial state"
        print "- reset_django: reset django databases (authentication sessions) to their initial state"
        print "- pack_file: cleans and compresses ZODB file, in case it gets too heavy (test server must not be running)"
        print "- runserver: run local django dev server, against persistent databases"
        sys.exit(1)

    elif "reset_zodb" in arguments:
        if os.path.exists(settings.ZODB_FILE):
            os.remove(settings.ZODB_FILE)
        import pychronia_game.models # initializes everything
        from pychronia_game.datamanager.datamanager_administrator import reset_zodb_structure, create_game_instance
        reset_zodb_structure()

        if "use_fixture" in arguments:
            skip_initializations = True
            skip_randomizations = True
            yaml_fixture = os.path.join(settings.GAME_FILES_ROOT, "script_fixtures", "_PROD_DUMP.yaml")
        else:
            skip_initializations = False
            skip_randomizations = False
            yaml_fixture = None
        create_game_instance(game_instance_id="DEMO",
                             creator_login="******",
                             skip_initializations=skip_initializations,
                             yaml_fixture=yaml_fixture,
                             skip_randomizations=skip_randomizations)
示例#3
0
    def setUp(self):

        assert settings.DEBUG == True

        django.utils.translation.activate(
            "en")  # to test for error messages, just in case...

        reset_zodb_structure()

        yaml_fixture = None
        skip_initializations = False
        if BaseGameTestCase.SHARED_DM_INITIAL_DATA_TREE:
            print(
                "[UNIT-TESTS] Using SHARED_DM_INITIAL_DATA_TREE to speed up the DM creation"
            )
            yaml_fixture = copy.deepcopy(
                BaseGameTestCase.SHARED_DM_INITIAL_DATA_TREE)
            skip_initializations = True

        # FIXME - very heavy with loading + checking, we should do it only once and copy/paste dm.data tree.
        create_game_instance(
            game_instance_id=TEST_GAME_INSTANCE_ID,
            creator_login="******",
            skip_randomizations=True,  # handy to test stuffs
            skip_initializations=skip_initializations,
            skip_coherence_check=True,
            yaml_fixture=yaml_fixture)

        if not BaseGameTestCase.SHARED_DM_INITIAL_DATA_TREE:
            # we cache the FIRST datamanager data, for reuse
            initial_dm = retrieve_game_instance(
                game_instance_id=TEST_GAME_INSTANCE_ID)
            BaseGameTestCase.SHARED_DM_INITIAL_DATA_TREE = copy.deepcopy(
                initial_dm.data)

        try:

            test_http_host = "localhost:80"

            self.client = DJANGO_TEST_CLIENT

            self.request_factory = RequestMock(HTTP_HOST=test_http_host,
                                               session=self.client.session)

            request = self.request_factory.get(HOME_URL)
            # this request is empty, not gone through middlewares!
            assert request.datamanager
            assert request.session
            assert request.session is not self.client.session, \
                (request.session, self.client.session) # generated on demand
            assert request.user.is_anonymous
            self.request = request

            self.dm = self.request.datamanager

            assert self.dm.is_initialized
            assert self.dm.connection

            self.dm.clear_all_event_stats()
            if not skip_initializations:
                self.dm.check_database_coherence(
                )  # thus, only done for the first testcase
                assert self.dm.get_event_count(
                    "BASE_CHECK_DB_COHERENCE_PUBLIC_CALLED"
                ) == 1  # no bypassing because of wrong override

            self.dm.set_game_state(True)
            self.dm.set_activated_game_views(
                list(self.dm.get_activable_views().keys())
            )  # QUICK ACCESS FIXTURE

            self.dm.clear_all_event_stats()

            #self.default_player = self.dm.get_character_usernames()[0]
            #self._set_user(self.TEST_LOGIN)

            self.initial_msg_sent_length = len(
                self.dm.get_all_dispatched_messages())
            self.initial_msg_queue_length = len(
                self.dm.get_all_queued_messages())

            # comment this to have eclipse's autocompletion to work for datamanager anyway
            self.dm = AutoCheckingDM(
                self.dm)  # protection against uncommitted, pending changes
            assert object.__getattribute__(
                self.dm, "_real_dm") == self.request.datamanager  # WRAPPED

            # NO NEED TO COMMIT - transaction watcher should do it all #

        except Exception as e:
            print(">>>>>>>>>", repr(e))
            self.tearDown(check=False)  # cleanup of connection
            raise
示例#4
0
    def setUp(self):

        assert settings.DEBUG == True

        django.utils.translation.activate("en") # to test for error messages, just in case...

        reset_zodb_structure()

        yaml_fixture = None
        skip_initializations = False
        if BaseGameTestCase.SHARED_DM_INITIAL_DATA_TREE:
            print ("[UNIT-TESTS] Using SHARED_DM_INITIAL_DATA_TREE to speed up the DM creation")
            yaml_fixture = copy.deepcopy(BaseGameTestCase.SHARED_DM_INITIAL_DATA_TREE)
            skip_initializations = True

        # FIXME - very heavy with loading + checking, we should do it only once and copy/paste dm.data tree.
        create_game_instance(game_instance_id=TEST_GAME_INSTANCE_ID,
                             creator_login="******",
                             skip_randomizations=True,  # handy to test stuffs
                             skip_initializations=skip_initializations,
                             skip_coherence_check=True,
                             yaml_fixture=yaml_fixture)

        if not BaseGameTestCase.SHARED_DM_INITIAL_DATA_TREE:
            # we cache the FIRST datamanager data, for reuse
            initial_dm = retrieve_game_instance(game_instance_id=TEST_GAME_INSTANCE_ID)
            BaseGameTestCase.SHARED_DM_INITIAL_DATA_TREE = copy.deepcopy(initial_dm.data)

        try:

            test_http_host = "localhost:80"

            self.client = Client()
            self.factory = RequestMock(HTTP_HOST=test_http_host)

            self.request = self.factory.get(HOME_URL)
            assert self.request.user
            assert self.request.datamanager.user.datamanager.request # double linking
            assert self.request.session
            assert self.request._messages is not None
            assert self.request.datamanager

            # we mimic messages middleware
            from django.contrib.messages.storage import default_storage
            self.request._messages = default_storage(self.request)

            self.dm = self.request.datamanager
            assert self.dm.is_initialized
            assert self.dm.connection

            self.dm.clear_all_event_stats()
            if not skip_initializations:
                self.dm.check_database_coherence()  # thus, only done for the first testcase
                assert self.dm.get_event_count("BASE_CHECK_DB_COHERENCE_PUBLIC_CALLED") == 1 # no bypassing because of wrong override

            self.dm.set_game_state(True)
            self.dm.set_activated_game_views(self.dm.get_activable_views().keys()) # QUICK ACCESS FIXTURE

            self.dm.clear_all_event_stats()

            #self.default_player = self.dm.get_character_usernames()[0]
            #self._set_user(self.TEST_LOGIN)

            self.initial_msg_sent_length = len(self.dm.get_all_dispatched_messages())
            self.initial_msg_queue_length = len(self.dm.get_all_queued_messages())

            # comment this to have eclipse's autocompletion to work for datamanager anyway
            self.dm = AutoCheckingDM(self.dm) # protection against uncommitted, pending changes

            # NO NEED TO COMMIT - transaction watcher should do it all #

        except Exception, e:
            print(">>>>>>>>>", repr(e))
            self.tearDown(check=False) # cleanup of connection
            raise
示例#5
0
        )
        print(
            "- pack_file: cleans and compresses ZODB file, in case it gets too heavy (test server must not be running)"
        )
        print(
            "- runserver: run local django dev server, against persistent databases"
        )
        sys.exit(1)

    elif "reset_zodb" in arguments:
        if os.path.exists(settings.ZODB_FILE):
            os.remove(settings.ZODB_FILE)
        import pychronia_game.models  # initializes everything
        from pychronia_game.datamanager.datamanager_administrator import reset_zodb_structure, create_game_instance

        reset_zodb_structure()

        if "use_fixture" in arguments:
            skip_initializations = True
            skip_randomizations = True
            yaml_fixture = os.path.join(settings.GAME_FILES_ROOT,
                                        "script_fixtures", "_PROD_DUMP.yaml")
        else:
            skip_initializations = False
            skip_randomizations = False
            yaml_fixture = None
        create_game_instance(game_instance_id="DEMO",
                             creator_login="******",
                             skip_initializations=skip_initializations,
                             yaml_fixture=yaml_fixture,
                             skip_randomizations=skip_randomizations)