Exemple #1
0
def test_unwatch(app, mockapi):
    app.watch('123')
    app.unwatch('123', delete=False)
    game = App.by_steamid('123')
    assert not game.enabled

    app.unwatch('123', delete=True)
    assert App.by_steamid('123') is None
Exemple #2
0
def test_watch_enable(app, mockapi):
    app.watch('123')
    game = App.by_steamid('123')
    assert game.enabled  # precondition

    app.unwatch('123', delete=False)
    game = App.by_steamid('123')
    assert not game.enabled

    app.watch('123')
    game = App.by_steamid('123')
    assert game.enabled  # precondition
Exemple #3
0
    def ls(self, include_disabled=False):  # pylint: disable=invalid-name
        '''List games that re currently being watched.

        :param bool include_disabled:
            *optional*
            if set to *True*, include *disabled* games in the list.
            Else (=default), list only enabled apps.
        :return:
            *iterable* eith waztched :class:`App` instances
        :rtype: iterable
        '''
        if include_disabled:
            return App.select().order_by(App.enabled.desc(), App.name)

        return App.select().where(App.enabled == True).order_by(App.name)
Exemple #4
0
    def ls(self, include_disabled=False):  # pylint: disable=invalid-name
        '''List games that re currently being watched.

        :param bool include_disabled:
            *optional*
            if set to *True*, include *disabled* games in the list.
            Else (=default), list only enabled apps.
        :return:
            *iterable* eith waztched :class:`App` instances
        :rtype: iterable
        '''
        if include_disabled:
            return App.select().order_by(App.enabled.desc(), App.name)

        return App.select().where(App.enabled == True).order_by(App.name)
Exemple #5
0
    def report_all(self, limit=None):
        ''':meth:`report` details for all enabled Games.

        This is similar to :meth:`report` but for all enabled games.

        Returns a list of games with packages and snapshots:

        .. code:: python

            [
                (<game-0>, [
                    (<package-0>, [<snapshot-0>, <snapshot-1>, ...]),
                    (<package-1>, [<snapshot-0>, <snapshot-1>, ...]),
                ]),
                (<game-1>, [
                    (<package-0>, [<snapshot-0>, <snapshot-1>, ...]),
                    (<package-1>, [<snapshot-0>, <snapshot-1>, ...]),
                ]),
                ...
            ]

        :param int limit:
            *optional*
            Limit the number of results.
        :rtype: list
        '''
        apps = App.select().where(App.enabled == True).order_by(App.name)
        results = []
        for app in apps:
            results.append((app, self.report(app, limit=limit)))

        return results
Exemple #6
0
    def report_all(self, limit=None):
        ''':meth:`report` details for all enabled Games.

        This is similar to :meth:`report` but for all enabled games.

        Returns a list of games with packages and snapshots:

        .. code:: python

            [
                (<game-0>, [
                    (<package-0>, [<snapshot-0>, <snapshot-1>, ...]),
                    (<package-1>, [<snapshot-0>, <snapshot-1>, ...]),
                ]),
                (<game-1>, [
                    (<package-0>, [<snapshot-0>, <snapshot-1>, ...]),
                    (<package-1>, [<snapshot-0>, <snapshot-1>, ...]),
                ]),
                ...
            ]

        :param int limit:
            *optional*
            Limit the number of results.
        :rtype: list
        '''
        apps = App.select().where(App.enabled == True).order_by(App.name)
        results = []
        for app in apps:
            results.append((app, self.report(app, limit=limit)))

        return results
Exemple #7
0
    def watch(self, appid, threshold=None):
        '''Start watching for changes on the steam game with the given
        ``appid``.

        - If this ``appid`` is new, it is added to the database.
        - If the item is already in the database but is *disabled*, it is
          *enabled*.
        - If the item is already being watched, nothing happens.

        Emits ``SIGNAL_APP_ADDED`` when the game is added/enabled.

        :param str appid:
            The steam app id of the game to watch.
        :param int threshold:
            *optional*
            Price threshold (**not working**).
        '''
        should_update = False
        known = App.by_steamid(appid)

        if known and known.enabled:
            LOG.warning(('Attempted to add {a!r} to the watchlist'
                         ' but it is already being watched.').format(a=appid))
            app = known
        elif known:  # is disabled
            app = known
            app.enable()
            app.save()
            should_update = True

        else:  # not previously known
            data = storeapi.appdetails(appid)
            app = App.from_apidata(appid, data, threshold=threshold)
            app.save()
            should_update = True

        if should_update:
            LOG.info('{a.name!r} was added to the watchlist.'.format(a=app))
            self._signal(SIGNAL_APP_ADDED, app=app)
            self.fetch(app)

        return app
Exemple #8
0
    def watch(self, appid, threshold=None):
        '''Start watching for changes on the steam game with the given
        ``appid``.

        - If this ``appid`` is new, it is added to the database.
        - If the item is already in the database but is *disabled*, it is
          *enabled*.
        - If the item is already being watched, nothing happens.

        Emits ``SIGNAL_APP_ADDED`` when the game is added/enabled.

        :param str appid:
            The steam app id of the game to watch.
        :param int threshold:
            *optional*
            Price threshold (**not working**).
        '''
        should_update = False
        known = App.by_steamid(appid)

        if known and known.enabled:
            LOG.warning(('Attempted to add {a!r} to the watchlist'
                         ' but it is already being watched.').format(a=appid))
            app = known
        elif known:  # is disabled
            app = known
            app.enable()
            app.save()
            should_update = True

        else:  # not previously known
            data = storeapi.appdetails(appid)
            app = App.from_apidata(appid, data, threshold=threshold)
            app.save()
            should_update = True

        if should_update:
            LOG.info('{a.name!r} was added to the watchlist.'.format(a=app))
            self._signal(SIGNAL_APP_ADDED, app=app)
            self.fetch(app)

        return app
Exemple #9
0
def test_app_create():
    app = App.create(steamid='1',
                     kind='game',
                     enabled=False,
                     name='The Name',
                     threshold=1000)
    assert app.id is not None
    assert app.steamid == '1'
    assert app.kind == 'game'
    assert not app.enabled
    assert app.name == 'The Name'
    assert app.threshold == 1000
Exemple #10
0
def test_app_package_link():
    app = App.create(steamid='6', kind='game')
    pkg0 = Package.create(steamid='6')
    pkg1 = Package.create(steamid='7')

    pkg0.link(app)
    pkg1.link(app)

    assert pkg0 in app.packages
    assert pkg1 in app.packages
    assert app in pkg0.apps
    assert app in pkg1.apps
Exemple #11
0
 def do_fetch(app, options):
     '''Execute the ``fetch`` command.'''
     if options.games:
         for steamid in options.games:
             game = App.by_steamid(steamid)
             if not game:
                 LOG.warning(
                     'Game with id {s!r} is not watched'.format(s=steamid))
             else:
                 app.fetch(game)
     else:
         app.fetch_all()
Exemple #12
0
def test_app_package_link():
    app = App.create(steamid='6', kind='game')
    pkg0 = Package.create(steamid='6')
    pkg1 = Package.create(steamid='7')

    pkg0.link(app)
    pkg1.link(app)

    assert pkg0 in app.packages
    assert pkg1 in app.packages
    assert app in pkg0.apps
    assert app in pkg1.apps
Exemple #13
0
def test_app_from_apidata():
    apidata = {
        'type': 'game',
        'name': 'The Name',
    }
    app = App.from_apidata('2', apidata, threshold=1000)
    assert app.id is not None
    assert app.steamid == '2'
    assert app.kind == 'game'
    assert app.enabled
    assert app.name == 'The Name'
    assert app.threshold == 1000
Exemple #14
0
def test_app_from_apidata():
    apidata = {
        'type': 'game',
        'name': 'The Name',
    }
    app = App.from_apidata('2', apidata, threshold=1000)
    assert app.id is not None
    assert app.steamid == '2'
    assert app.kind == 'game'
    assert app.enabled
    assert app.name == 'The Name'
    assert app.threshold == 1000
Exemple #15
0
 def do_fetch(app, options):
     '''Execute the ``fetch`` command.'''
     if options.games:
         for steamid in options.games:
             game = App.by_steamid(steamid)
             if not game:
                 LOG.warning(
                     'Game with id {s!r} is not watched'.format(s=steamid))
             else:
                 app.fetch(game)
     else:
         app.fetch_all()
Exemple #16
0
def test_app_integrity():
    App.create(steamid='3', kind='game')
    with pytest.raises(IntegrityError):
        App.create(steamid='3', kind='game')

    with pytest.raises(IntegrityError):
        App.create(steamid='4')  # missing 'kind'
Exemple #17
0
def test_app_integrity():
    App.create(steamid='3', kind='game')
    with pytest.raises(IntegrityError):
        App.create(steamid='3', kind='game')

    with pytest.raises(IntegrityError):
        App.create(steamid='4')  # missing 'kind'
Exemple #18
0
def test_app_create():
    app = App.create(
        steamid='1',
        kind='game',
        enabled=False,
        name='The Name',
        threshold=1000
    )
    assert app.id is not None
    assert app.steamid == '1'
    assert app.kind == 'game'
    assert not app.enabled
    assert app.name == 'The Name'
    assert app.threshold == 1000
Exemple #19
0
    def do_report(app, options):
        '''Execute the ``report`` command.'''
        if options.games:
            reports = []
            for steamid in options.games:
                game = App.by_steamid(steamid)
                if not game:
                    LOG.warning(
                        'Game with id {s!r} is not watched'.format(s=steamid))
                else:
                    reports.append(
                        (game, app.report(game, limit=options.limit)), )
        else:
            reports = app.report_all(limit=options.limit)

        renderers = {'tree': TreeRenderer, 'tab': TabularRenderer}
        renderer_cls = renderers[options.format or options.report_format]
        renderer = renderer_cls(sys.stdout, options)
        renderer.render_report(reports)
Exemple #20
0
    def do_report(app, options):
        '''Execute the ``report`` command.'''
        if options.games:
            reports = []
            for steamid in options.games:
                game = App.by_steamid(steamid)
                if not game:
                    LOG.warning(
                        'Game with id {s!r} is not watched'.format(s=steamid))
                else:
                    reports.append(
                        (game, app.report(game, limit=options.limit)),
                    )
        else:
            reports = app.report_all(limit=options.limit)

        renderers = {
            'tree': TreeRenderer,
            'tab': TabularRenderer
        }
        renderer_cls = renderers[options.format or options.report_format]
        renderer = renderer_cls(sys.stdout, options)
        renderer.render_report(reports)
Exemple #21
0
def test_app_package_create():
    app = App.create(steamid='5', kind='game')
    pkg = Package.create(steamid='5')
    app_pkg = AppPackage.create(app=app, package=pkg)
    assert app_pkg.app.id == app.id
    assert app_pkg.package.id == pkg.id
Exemple #22
0
    def unwatch(self, appid, delete=False):
        '''Stop watching the game with the given ``appid``.

        - If the game is currently bein watched, it will be *disabled*,
          unless the optional parameter ``delete`` is set to *True*
          (which will completely remove the game and all measures.)
        - If the game is currently not being watched, nothing happens.

        Emits ``SIGNAL_APP_REMOVED`` when the application is deleted/disabled.

        :param str appid:
            The steam app id of the game to watch.
        :param bool delete:
            *optional*
            if *True*, the game is deleted from the database.
            If *False* (=default), it is disabled.
        '''
        app = App.by_steamid(appid)
        if app is None:
            LOG.warning(('Attempted to remove {a!r} from the watchlist'
                         ' but it was not watched.').format(a=appid))
            return

        if delete:
            LOG.debug('Delete {a!r}.'.format(a=app))
            # packages linked to this app can be deleted
            # only if they are not linked to another app
            delete_pkgs = []
            unlink_pkgs = []
            LOG.debug('Find deletable packages.')
            for pkg in app.packages:
                no_delete = False
                for linked_app in pkg.apps:
                    if linked_app.id != app.id:
                        LOG.debug(('{p!r} will not be deleted, it is also'
                                   ' linked to {a!r}.'
                                  ).format(p=pkg, a=linked_app))
                        no_delete = True
                if no_delete:
                    unlink_pkgs.append(pkg)
                else:
                    delete_pkgs.append(pkg)

            for unlinkable_pkg in unlink_pkgs:
                app.unlink(unlinkable_pkg)

            for deletable_pkg in delete_pkgs:
                LOG.debug('Delete {p!r}.'.format(p=deletable_pkg))
                # delete associated snapshots
                for snapshot in deletable_pkg.snapshots:
                    LOG.debug('Delete {s!r}.'.format(s=snapshot))
                    snapshot.delete_instance()
                # delete the package itself
                deletable_pkg.delete_instance()

            # finally, delete the app
            app.delete_instance()
            LOG.info('Deleted {a.name!r}.'.format(a=app))
        else:
            app.disable()
            app.save()
            LOG.info('Disabled {a.name!r}'.format(a=app))

        self._signal(SIGNAL_APP_REMOVED, app=app)
Exemple #23
0
 def fetch_all(self):
     ''':meth:`fetch` updates for all enabled games.'''
     apps = App.select().where(App.enabled == True)
     for app in apps:
         self.fetch(app)
Exemple #24
0
    def unwatch(self, appid, delete=False):
        '''Stop watching the game with the given ``appid``.

        - If the game is currently bein watched, it will be *disabled*,
          unless the optional parameter ``delete`` is set to *True*
          (which will completely remove the game and all measures.)
        - If the game is currently not being watched, nothing happens.

        Emits ``SIGNAL_APP_REMOVED`` when the application is deleted/disabled.

        :param str appid:
            The steam app id of the game to watch.
        :param bool delete:
            *optional*
            if *True*, the game is deleted from the database.
            If *False* (=default), it is disabled.
        '''
        app = App.by_steamid(appid)
        if app is None:
            LOG.warning(('Attempted to remove {a!r} from the watchlist'
                         ' but it was not watched.').format(a=appid))
            return

        if delete:
            LOG.debug('Delete {a!r}.'.format(a=app))
            # packages linked to this app can be deleted
            # only if they are not linked to another app
            delete_pkgs = []
            unlink_pkgs = []
            LOG.debug('Find deletable packages.')
            for pkg in app.packages:
                no_delete = False
                for linked_app in pkg.apps:
                    if linked_app.id != app.id:
                        LOG.debug(('{p!r} will not be deleted, it is also'
                                   ' linked to {a!r}.').format(p=pkg,
                                                               a=linked_app))
                        no_delete = True
                if no_delete:
                    unlink_pkgs.append(pkg)
                else:
                    delete_pkgs.append(pkg)

            for unlinkable_pkg in unlink_pkgs:
                app.unlink(unlinkable_pkg)

            for deletable_pkg in delete_pkgs:
                LOG.debug('Delete {p!r}.'.format(p=deletable_pkg))
                # delete associated snapshots
                for snapshot in deletable_pkg.snapshots:
                    LOG.debug('Delete {s!r}.'.format(s=snapshot))
                    snapshot.delete_instance()
                # delete the package itself
                deletable_pkg.delete_instance()

            # finally, delete the app
            app.delete_instance()
            LOG.info('Deleted {a.name!r}.'.format(a=app))
        else:
            app.disable()
            app.save()
            LOG.info('Disabled {a.name!r}'.format(a=app))

        self._signal(SIGNAL_APP_REMOVED, app=app)
Exemple #25
0
 def fetch_all(self):
     ''':meth:`fetch` updates for all enabled games.'''
     apps = App.select().where(App.enabled == True)
     for app in apps:
         self.fetch(app)
Exemple #26
0
def test_app_package_create():
    app = App.create(steamid='5', kind='game')
    pkg = Package.create(steamid='5')
    app_pkg = AppPackage.create(app=app, package=pkg)
    assert app_pkg.app.id == app.id
    assert app_pkg.package.id == pkg.id