Exemplo n.º 1
0
    def test_api_create_content(self):

        # create empy path for data
        delete_data_path(self.tmp_path)
        create_empty_data_path(self.tmp_path)

        # load info without history
        valid_info = self.borgia_info_content

        data = {'files': self.files, 'info': json.dumps(valid_info)}
        with self.client:
            self.login()
            result = self.client.post('/api/create',
                                      data=data,
                                      content_type='multipart/form-data')
            print result.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.assertEquals(stored_info["title"], valid_info["title"])

            # 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())
Exemplo n.º 2
0
    def test_api_update_content(self):

        # create empy path for data
        delete_data_path(self.tmp_path)
        create_empty_data_path(self.tmp_path)

        # load info without history
        valid_info = self.borgia_info_content

        data = {'files': self.files, 'info': json.dumps(valid_info)}
        with self.client:
            self.login()
            result = self.client.post('/api/create',
                                      data=data,
                                      content_type='multipart/form-data')
            print result.data
            self.assertEqual(result.status_code, 201)

            # make some changes
            new_info = self.borgia_info_content.copy()
            new_info["fab_time"] = 200
            new_data = {
                'info': json.dumps(new_info),
                'slug': json.dumps(new_info["slug"])
            }

            # push changes to API
            result = self.client.post('/api/update',
                                      data=new_data,
                                      content_type='multipart/form-data')

            new_content = result.json["updated_content"]

            self.assertEqual(result.status_code, 201)
            self.assertEquals(new_content["fab_time"], 200)
Exemplo n.º 3
0
    def test_create_slug_once_and_for_all(self):

        tmp = "/tmp"
        slug = "game-bla-bla-bla-fr"

        # clean
        delete_data_path(os.path.join(tmp, slug))

        info = self.borgia_info_content.copy()
        info["title"] = "bla bla bla"
        info.pop('slug', None)  # remove slug

        self.assertRaises(KeyError, lambda: info["slug"])

        game_path = create_content(info, None, tmp)

        game_info = read_content(game_path)
        self.assertEqual(game_info["slug"], "game-bla-bla-bla-fr")

        new_game_info = info.copy()
        new_game_info["title"] = "bla bla bla 2"

        updated_content = update_content_info(game_path, new_game_info)
        self.assertEqual(slug, updated_content["slug"])
        self.assertEqual(game_info["slug"], updated_content["slug"])
Exemplo n.º 4
0
    def setUp(self):
        delete_data_path(
            os.path.join(self.tmp_path, self.borgia_info_content["slug"]))

        # create a game
        info = self.borgia_info_content
        new_game_path = create_content(info, None, self.tmp_path)
Exemplo n.º 5
0
    def test_save_history_with_user(self):
        """Make sure the reference to user is correctly saved in history"""

        # create empy path for data
        delete_data_path(self.tmp_path)
        create_empty_data_path(self.tmp_path)

        # load info without history
        valid_info = self.borgia_info_content

        data = {'files': self.files, 'info': json.dumps(valid_info)}

        with self.client:
            self.login()

            # create the game through API
            result = self.client.post('/api/create',
                                      data=data,
                                      content_type='multipart/form-data')
            self.assertEqual(result.status_code, 201)
            game_path = result.json["path"]

            # get the game content
            game_info = read_content(game_path)

            # check history event content
            self.assertEqual(len(game_info["history"]), 1)
            event = game_info["history"][0]
            self.assertEqual(event["type"], "create")
            self.assertEqual(event["user"], self.user_email)

            # make some changes to the data
            new_info = valid_info.copy()
            new_info["title"] = "bla bla bla"

            # post the update
            new_data = {
                'info': json.dumps(new_info),
                'slug': json.dumps(new_info["slug"])
            }
            result = self.client.post('/api/update',
                                      data=new_data,
                                      content_type='multipart/form-data')

            self.assertEqual(result.status_code, 201)

            # read updated game
            game_path = result.json["path"]
            new_game_info = read_content(game_path)
            new_game_info["title"] = "bla bla bla"

            # check history event content
            self.assertEqual(len(new_game_info["history"]), 2)
            event = new_game_info["history"][1]
            self.assertEqual(event["type"], "update")
            self.assertEqual(event["user"], self.user_email)
Exemplo n.º 6
0
    def create_app(self):
        # pass in test configuration
        test_dir = os.path.join(os.getcwd(),"server/tests")
        config_path = os.path.join(test_dir,"config.test.yml")

        # create empy path for data
        delete_data_path(TEST_DATA_DIR)
        create_empty_data_path(TEST_DATA_DIR)

        return create_app(self, config_path=config_path)
Exemplo n.º 7
0
    def test_prevent_wrong_state_name(self):
        """Make sure you can only add valid state names."""
        info = self.borgia_info_content
        delete_data_path(os.path.join(self.tmp_path, info["slug"]))

        # create a game
        new_game_path = create_content(info, None, self.tmp_path)

        self.assertRaises(
            LudoboxError,
            lambda: update_content_state(new_game_path, "lalala"))
Exemplo n.º 8
0
    def test_add_game_forbidden(self):
        """Make sure only logged in user can add content"""

        valid_info = self.borgia_info_content

        delete_data_path(self.app.config["DATA_DIR"])
        create_empty_data_path(self.app.config["DATA_DIR"])

        data = {'files': self.files, 'info': json.dumps(valid_info)}

        with self.app.test_client() as c:

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

            print result.data
            self.assertEqual(result.status_code, 403)
Exemplo n.º 9
0
 def setUp(self):
     self.game_path = os.path.join(self.tmp_path, "test-game")
     delete_data_path('/tmp/game-borgia-le-jeu-malsain-fr')