예제 #1
0
 def test_platform_model_creation_2(self):
     g = Platform.Platform(2, "test platform 2")
     db.session.add(g)
     db.session.commit()
     e = Platform.Platform(3, "test platform 3")
     db.session.add(e)
     db.session.commit()
     result = Platform.Platform.query.all()
     assert (len(result) == 2)
예제 #2
0
 def test_platform_model_creation_3(self):
     g = Platform.Platform(2, "test platform 3")
     db.session.add(g)
     db.session.commit()
     e = Platform.Platform(2, "duplicate")
     try:
         db.session.add(e)
         db.session.commit()
         assert (False)
     except Exception as e:
         db.session.rollback()
예제 #3
0
    def test_game_platforms(self):
        p1 = Platform(name="Commodore 64", short="C64")
        p2 = Platform(name="Game Boy", short="GB")
        self.session.add(p1)
        self.session.add(p2)

        g = Game(name="A Random Game")
        g.platforms.append(p1)
        g.platforms.append(p2)
        self.session.add(g)

        self.assertTrue(len(g.platforms) >= 2)
예제 #4
0
    def test_platform_insert(self):
        platform_repr = {"name": "Playstation 4", "short": "PS4"}
        p = Platform(**platform_repr)
        self.session.add(p)

        r = self.session.query(Platform).filter(Platform.short == "PS4").first()
        self.assertEqual(r.name, "Playstation 4")
예제 #5
0
파일: rong360.py 프로젝트: Moxikai/rong360
    def saveBasicInfoToSQLite(self, **kwargs):

        platform = Platform(id=kwargs['id'],
                            name=kwargs['name'],
                            gradeFromThird=kwargs['gradeFromThird'],
                            profitAverage=kwargs['profitAverage'],
                            dateSale=kwargs['dateSale'],
                            registeredCapital=kwargs['registeredCapital'],
                            area=kwargs['area'],
                            url=kwargs['area'],
                            startMoney=kwargs['startMoney'],
                            managementFee=kwargs['managementFee'],
                            cashTakingFee=kwargs['cashTakingFee'],
                            backGround=kwargs['backGround'],
                            provisionOfRisk=kwargs['provisionOfRisk'],
                            foundCustodian=kwargs['foundCustodian'],
                            safeguardWay=kwargs['safeguardWay'],
                            assignmentOfDebt=kwargs['assignmentOfDebt'],
                            automaticBidding=kwargs['automaticBidding'],
                            cashTime=kwargs['cashTime'],
                            abstract=kwargs['abstract'])
        if not session.query(Platform).filter(
                Platform.id == kwargs['id']).first():
            session.add(platform)
            session.commit()
            print '平台-----%s-----基本信息保存成功!' % (kwargs['name'])
        else:
            print '平台-----%s-----基本信息已存在,无需重复保存!' % kwargs['name']
예제 #6
0
 def post(self):
     """Create a new campaign."""
     campaign_dict = self.get_request_json()
     validate_campaign_dict(campaign_dict)
     # get a list of platforms
     platforms_list = campaign_dict["platforms"]
     del campaign_dict["platforms"]
     # construct and store a new campaign
     campaign = Campaign(**campaign_dict)
     campaign.put()
     campaign_id = campaign.key.id()
     # construct and store platforms for campaign
     platforms = []
     for platform_name in platforms_list:
         platform = Platform(name=platform_name,
                             counter=0,
                             campaign=campaign.key,
                             id="%d-%s" % (campaign_id, platform_name))
         platforms.append(platform)
     ndb.put_multi_async(platforms)
     # prepare response representation of the created campaign
     output = campaign_to_dict(campaign, platforms=platforms)
     # set the appropriate response headers
     self.response.location = self.uri_for("campaign-detail",
                                           campaign_id=campaign_id)
     self.response.status_int = 201
     return output
예제 #7
0
def addPlatform():
    checkIfUserLoggedIn()
    if request.method == 'POST':
        # This could be a lot cleaner
        input_date = request.form['releasedate'].split('-')
        year = int(input_date[0])
        month = int(input_date[1])
        day = int(input_date[2])
        release_date = datetime.date(year, month, day)
        # create the new Platform object
        newPlatform = Platform(
            name=request.form['name'],
            user_id=login_session['user_id'],
            manufacturer=request.form['manufacturer'],
            medium=request.form['medium'],
            internet_enabled=request.form['internet_enabled'],
            controller_ports=request.form['controller_ports'],
            release_date=release_date)
        flash('Creating new platform')

        # Add it to the session
        session.add(newPlatform)

        # and commit it to add it to the database
        session.commit()
        return redirect(url_for('showPlatforms'))
    else:
        return render_template('addplatform.html')
예제 #8
0
    def put(self, campaign_id):
        """Update the existing campaign."""
        campaign_id = int(campaign_id)
        future = Campaign.get_by_id_async(campaign_id)
        campaign_dict = self.get_request_json()
        validate_campaign_dict(campaign_dict, all_required=False)

        campaign = future.get_result()

        platforms = []
        # get a list of existing campaign platforms
        existing_platforms_list = {
            platform.name: platform
            for platform in Platform.query(
                Platform.campaign == campaign.key).fetch(3)
        }

        # special processing for platforms field
        platforms_to_store = []
        if "platforms" in campaign_dict:
            # get a list of platforms from the request
            platforms_list = campaign_dict["platforms"]
            del campaign_dict["platforms"]
            # construct platforms for campaign
            for platform_name in platforms_list:
                if platform_name not in existing_platforms_list:
                    platform = Platform(name=platform_name,
                                        counter=0,
                                        campaign=campaign.key,
                                        id="%d-%s" %
                                        (campaign_id, platform_name))
                    platforms_to_store.append(platform)
                else:
                    platform = existing_platforms_list[platform_name]
                platforms.append(platform)
        else:
            # no changes to platforms field, just copy
            for platform in existing_platforms_list.values():
                platforms.append(platform)

        # update the rest of the fields
        for field_name in campaign_dict:
            setattr(campaign, field_name, campaign_dict[field_name])
        campaign.update_date = datetime.now()

        @ndb.transactional_async(xg=True)
        def _update():
            """Do the update in transaction"""
            ndb.put_multi_async(platforms_to_store)
            campaign.put_async()

        future = _update()

        output = campaign_to_dict(campaign, platforms=platforms)
        # explicitly do the json conversion here, while we may be waiting for the _update to finish
        output = json.dumps(output, default=json_serial, sort_keys=True)
        future.get_result()
        return output
예제 #9
0
def populate_platforms():
    event_plugins = [
        plugin for plugin in loadedPlugins
        if isinstance(loadedPlugins[plugin], plugins.EventPlugin)
    ]

    for plugin in event_plugins:
        if not Platform.query.filter_by(name=plugin).first():
            print(f"Adding new platform: {plugin}")
            new_platform = Platform(name=plugin)
            db.session.add(new_platform)
            db.session.commit()
예제 #10
0
 def test_game_platform_model_creation_1(self):
     c = Company.Company(*TestModels.test_company)
     db.session.add(c)
     db.session.commit()
     new_game = Game.Game(*TestModels.test_game)
     db.session.add(new_game)
     db.session.commit()
     new_platform = Platform.Platform(1, "test platform")
     db.session.add(new_platform)
     db.session.commit()
     new_game_platform = Game_Platform.Game_Platform(1, 1)
     db.session.add(new_game_platform)
     db.session.commit()
예제 #11
0
 def test_game_platform_model_creation_2(self):
     c = Company.Company(*TestModels.test_company)
     db.session.add(c)
     db.session.commit()
     new_platform = Platform.Platform(1, "test platform")
     db.session.add(new_platform)
     db.session.commit()
     new_game_platform = Game_Platform.Game_Platform(1, 1)
     try:
         db.session.add(new_game_platform)
         db.session.commit()
         assert (False)
     except Exception as e:
         db.session.rollback()
예제 #12
0
    def test_platform_games(self):
        p1 = Platform(name="Commodore 64", short="C64")
        p2 = Platform(name="Game Boy", short="GB")
        self.session.add(p1)
        self.session.add(p2)

        g1 = Game(name="A Random Game")
        g2 = Game(name="A Random Game 2")
        g3 = Game(name="A Random Game 2: Spinoff")
        g4 = Game(name="A Random Game 3: Return of the Jedi")
        g1.platforms.append(p1)
        g2.platforms.append(p1)
        g3.platforms.append(p2)
        g4.platforms.append(p1)
        g4.platforms.append(p2)

        self.session.add(g1)
        self.session.add(g2)
        self.session.add(g3)
        self.session.add(g4)

        self.assertEqual(len(p1.games.all()), 3)
        self.assertEqual(len(p2.games.all()), 2)
예제 #13
0
    def setUp(self):
        self.pf_source_mock = MagicMock()
        self.scraper = Scraper("www.platform.url", "Test Platform", "tp", [self.pf_source_mock])

        # don't know how to mock properly yet so mocking out db
        # operations using partial mock.
        self.scraper.get_platform = MagicMock(name="get_platform")
        self.db_platform = Platform()
        self.scraper.get_platform.return_value = self.db_platform

        self.save_mock = MagicMock(name="save_batch")
        self.scraper.save_batch = self.save_mock

        self.logger_mock = Mock()
        get_logger_mock = Mock(return_value=self.logger_mock)
        self.scraper.get_logger = get_logger_mock
예제 #14
0
def addget_platform(user_id):

    body = request.get_json()

    if request.method == 'POST':
        addplatform = Platform(user_id=user_id, platform_name=body['platform_name'], platform_id=body['platform_id'])
        db.session.add(addplatform)
        db.session.commit()
        response_body = addplatform.serialize()

        return jsonify(response_body), 200
    
    if request.method == 'GET':
        getplatforms = db.session.query(Platform).filter(Platform.user_id == user_id)
        response_body = list(map(lambda x: x.serialize(), getplatforms))

        return jsonify(response_body), 200

    return "All Good!", 200
예제 #15
0
# Create demo genres and platforms
newGenre = Genre(name="Action")
session.add(newGenre)
newGenre = Genre(name="Adventure")
session.add(newGenre)
newGenre = Genre(name="RPG")
session.add(newGenre)
newGenre = Genre(name="MMO")
session.add(newGenre)
newGenre = Genre(name="Strategy")
session.add(newGenre)
newGenre = Genre(name="Shooter")
session.add(newGenre)

newPlatform = Platform(name="PC")
session.add(newPlatform)
newPlatform = Platform(name="Playstation 4")
session.add(newPlatform)
newPlatform = Platform(name="Playstation 3")
session.add(newPlatform)
newPlatform = Platform(name="Xbox 360")
session.add(newPlatform)
newPlatform = Platform(name="Xbox One")
session.add(newPlatform)
newPlatform = Platform(name="Wii U")
session.add(newPlatform)

# Create a demo item
newItem = Item(title="Destiny",
               description="An online shooter from the makers of Halo.",
예제 #16
0
 def test_platform_model_creation_1(self):
     g = Platform.Platform(1, "test platform")
     db.session.add(g)
     db.session.commit()
     result = Platform.Platform.query.all()
     assert (len(result) == 1)
예제 #17
0
Base.metadata.bind = engine

DBSession = sessionmaker(bind=engine)
# A DBSession() instance establishes all conversations with the database
# and represents a "staging zone" for all the objects loaded into the
# database session object. Any change made against the objects in the
# session won't be persisted into the database until you call
# session.commit(). If you're not happy about the changes, you can
# revert all of them back to the last commit by calling
# session.rollback()
session = DBSession()

platform1 = Platform(id=1,
                     user_id=1,
                     name='Playstation',
                     medium='CD',
                     internet_enabled=False,
                     controller_ports=2,
                     manufacturer='Sony',
                     release_date=datetime.date(1994, 12, 3))

session.add(platform1)
session.commit()

game1 = Game(user_id=1,
             title='Metal Gear Solid',
             developer='Konami Computer Entertainment Japan',
             publisher='Konami',
             platform_id=1,
             release_date=datetime.date(1996, 12, 3))

session.add(game1)