def test_default(self, init):
    r = ReadOnlyStorage()
    r._store = MagicMock()
    r._store.leaderboards = MagicMock(return_value="data")

    result = r.leaderboards("foo")

    self.assertEqual(result, "data")
    r._store.leaderboards.assert_called_once_with("foo")
    def test_default(self, init):
        r = ReadOnlyStorage()
        r._store = MagicMock()
        r._store.leaderboards = MagicMock(return_value="data")

        result = r.leaderboards("foo")

        self.assertEqual(result, "data")
        r._store.leaderboards.assert_called_once_with("foo")
Esempio n. 3
0
class Storage(StorageInterface):

  def __init__(self):
    super().__init__()

    self.storage = None

  # defaults to ReadOnlyStorage
  def cancer(self):
    if not self.storage:
      from twitchcancer.storage.readonlystorage import ReadOnlyStorage
      self.storage = ReadOnlyStorage()

    return self.storage.cancer()

  # defaults to ReadOnlyStorage
  def leaderboards(self, horizon):
    if not self.storage:
      from twitchcancer.storage.readonlystorage import ReadOnlyStorage
      self.storage = ReadOnlyStorage()

    return self.storage.leaderboards(horizon)

  # defaults to ReadOnlyStorage
  def leaderboard(self, name):
    if not self.storage:
      from twitchcancer.storage.readonlystorage import ReadOnlyStorage
      self.storage = ReadOnlyStorage()

    return self.storage.leaderboard(name)

  # defaults to ReadOnlyStorage
  def channel(self, channel):
    if not self.storage:
      from twitchcancer.storage.readonlystorage import ReadOnlyStorage
      self.storage = ReadOnlyStorage()

    return self.storage.channel(channel)

  # defaults to ReadOnlyStorage
  def status(self):
    if not self.storage:
      from twitchcancer.storage.readonlystorage import ReadOnlyStorage
      self.storage = ReadOnlyStorage()

    return self.storage.status()

  # defaults to MemoryStorage
  def store(self, channel, cancer):
    # messages are stored in-memory only
    if not self.storage:
      from twitchcancer.storage.memorystorage import MemoryStorage
      self.storage = MemoryStorage()

    self.storage.store(channel, cancer)

  # defaults to WriteOnlyStorage
  def record(self):
    # summaries are written to the database
    if not self.storage:
      from twitchcancer.storage.writeonlystorage import WriteOnlyStorage
      self.storage = WriteOnlyStorage()

    self.storage.record()

  # defaults to ReadOnlyStorage
  def search(self, channel):
    if not self.storage:
      from twitchcancer.storage.readonlystorage import ReadOnlyStorage
      self.storage = ReadOnlyStorage()

    return self.storage.search(channel)
Esempio n. 4
0
class Storage(StorageInterface):

    def __init__(self):
        super().__init__()

        self.storage = None

    # defaults to ReadOnlyStorage
    def cancer(self):
        if not self.storage:
            from twitchcancer.storage.readonlystorage import ReadOnlyStorage
            self.storage = ReadOnlyStorage()

        return self.storage.cancer()

    # defaults to ReadOnlyStorage
    def leaderboards(self, horizon):
        if not self.storage:
            from twitchcancer.storage.readonlystorage import ReadOnlyStorage
            self.storage = ReadOnlyStorage()

        return self.storage.leaderboards(horizon)

    # defaults to ReadOnlyStorage
    def leaderboard(self, name):
        if not self.storage:
            from twitchcancer.storage.readonlystorage import ReadOnlyStorage
            self.storage = ReadOnlyStorage()

        return self.storage.leaderboard(name)

    # defaults to ReadOnlyStorage
    def channel(self, channel):
        if not self.storage:
            from twitchcancer.storage.readonlystorage import ReadOnlyStorage
            self.storage = ReadOnlyStorage()

        return self.storage.channel(channel)

    # defaults to ReadOnlyStorage
    def status(self):
        if not self.storage:
            from twitchcancer.storage.readonlystorage import ReadOnlyStorage
            self.storage = ReadOnlyStorage()

        return self.storage.status()

    # defaults to MemoryStorage
    def store(self, channel, cancer):
        # messages are stored in-memory only
        if not self.storage:
            from twitchcancer.storage.memorystorage import MemoryStorage
            self.storage = MemoryStorage()

        self.storage.store(channel, cancer)

    # defaults to WriteOnlyStorage
    def record(self):
        # summaries are written to the database
        if not self.storage:
            from twitchcancer.storage.writeonlystorage import WriteOnlyStorage
            self.storage = WriteOnlyStorage()

        self.storage.record()

    # defaults to ReadOnlyStorage
    def search(self, channel):
        if not self.storage:
            from twitchcancer.storage.readonlystorage import ReadOnlyStorage
            self.storage = ReadOnlyStorage()

        return self.storage.search(channel)