def test_default(self, init):
    r = ReadOnlyStorage()
    r._store = MagicMock()
    r._store.status = MagicMock(return_value={
      'channels': 1,
      'messages': 2,
      'cancer': 3,
    })
    r.cancer = MagicMock(return_value=[
      {
        'messages': 1,
        'cancer': 2
      },
      {
        'messages': 3,
        'cancer': 4
      },
    ])

    expected = {
      'total': {
        'channels': 1,
        'messages': 2,
        'cancer': 3,
      },
      'live': {
        'channels': 2,
        'messages': 4,
        'cancer': 6,
      }
    }

    result = r.status()

    self.assertEqual(result, expected)
    def test_default(self, init):
        r = ReadOnlyStorage()
        r._store = MagicMock()
        r._store.status = MagicMock(return_value={
            'channels': 1,
            'messages': 2,
            'cancer': 3,
        })
        r.cancer = MagicMock(return_value=[
            {
                'messages': 1,
                'cancer': 2
            },
            {
                'messages': 3,
                'cancer': 4
            },
        ])

        expected = {
            'total': {
                'channels': 1,
                'messages': 2,
                'cancer': 3,
            },
            'live': {
                'channels': 2,
                'messages': 4,
                'cancer': 6,
            }
        }

        result = r.status()

        self.assertEqual(result, expected)
  def test_request(self, init):
    r = ReadOnlyStorage()
    r.socket = MagicMock()
    r.socket.recv_pyobj = MagicMock(return_value="data")
    r.poller = MagicMock()

    result = r.cancer()

    self.assertEqual(result, "data")
    def test_request(self, init):
        r = ReadOnlyStorage()
        r.socket = MagicMock()
        r.socket.recv_pyobj = MagicMock(return_value="data")
        r.poller = MagicMock()

        result = r.cancer()

        self.assertEqual(result, "data")
  def test_fail(self, connect, disconnect, init):
    r = ReadOnlyStorage()
    r.socket = MagicMock()
    r.poller = MagicMock()
    r.poller.poll = MagicMock(return_value=False)

    result = r.cancer()

    self.assertEqual(result, [])
    self.assertEqual(connect.call_count, 1)
    self.assertEqual(disconnect.call_count, 1)
    def test_fail(self, connect, disconnect, init):
        r = ReadOnlyStorage()
        r.socket = MagicMock()
        r.poller = MagicMock()
        r.poller.poll = MagicMock(return_value=False)

        result = r.cancer()

        self.assertEqual(result, [])
        self.assertEqual(connect.call_count, 1)
        self.assertEqual(disconnect.call_count, 1)
Esempio n. 7
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. 8
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)