示例#1
0
def test_check_quota_Zero2():
    m = Mock(spec=ArcticLibraryBinding)
    m.quota = None
    m.get_library_metadata.return_value = 0
    ArcticLibraryBinding.check_quota(m)
    m.get_library_metadata.assert_called_once_with('QUOTA')
    assert m.quota == 0
示例#2
0
def test_check_quota_Zero2():
    self = create_autospec(ArcticLibraryBinding)
    self.quota = None
    self.get_library_metadata.return_value = 0
    ArcticLibraryBinding.check_quota(self)
    self.get_library_metadata.assert_called_once_with('QUOTA')
    assert self.quota == 0
示例#3
0
def test_check_quota_Zero2():
    m = Mock(spec=ArcticLibraryBinding)
    m.quota = None
    m.get_library_metadata.return_value = 0
    ArcticLibraryBinding.check_quota(m)
    m.get_library_metadata.assert_called_once_with('QUOTA')
    assert m.quota == 0
示例#4
0
def test_check_quota_Zero2():
    self = create_autospec(ArcticLibraryBinding)
    self.quota = None
    self.get_library_metadata.return_value = 0
    ArcticLibraryBinding.check_quota(self)
    self.get_library_metadata.assert_called_once_with('QUOTA')
    assert self.quota == 0
示例#5
0
def test_check_quota_exceeded():
    self = create_autospec(ArcticLibraryBinding)
    self.arctic = create_autospec(Arctic)
    self.quota = 1024 * 1024 * 1024
    self.quota_countdown = 0
    self.arctic.__getitem__.return_value = Mock(
        stats=Mock(return_value={"totals": {"size": 1024 * 1024 * 1024, "count": 100}})
    )
    with pytest.raises(QuotaExceededException) as e:
        ArcticLibraryBinding.check_quota(self)
    assert "Quota Exceeded: 1.000 / 1 GB used" in str(e)
示例#6
0
def test_check_quota_info():
    self = create_autospec(ArcticLibraryBinding)
    self.arctic = create_autospec(Arctic)
    self.quota = 1024 * 1024 * 1024
    self.quota_countdown = 0
    self.arctic.__getitem__.return_value = Mock(
        stats=Mock(return_value={"totals": {"size": 1 * 1024 * 1024, "count": 100}})
    )
    with patch("arctic.arctic.logger.info") as info:
        ArcticLibraryBinding.check_quota(self)
    self.arctic.__getitem__.assert_called_once_with(self.get_name.return_value)
    info.assert_called_once_with("Mongo Quota: 0.001 / 1 GB used")
    assert self.quota_countdown == 51153
示例#7
0
def test_check_quota_exceeded():
    self = create_autospec(ArcticLibraryBinding)
    self.arctic = create_autospec(Arctic)
    self.get_library_metadata.return_value = 1024 * 1024 * 1024
    self.quota_countdown = 0
    self.arctic.__getitem__.return_value = Mock(stats=Mock(return_value={'totals':
                                                                             {'size': 1024 * 1024 * 1024,
                                                                              'count': 100,
                                                                              }
                                                                             }))
    with pytest.raises(QuotaExceededException) as e:
        ArcticLibraryBinding.check_quota(self)
    assert "Quota Exceeded: 1.000 / 1 GB used" in str(e)
示例#8
0
def test_check_quota_exceeded():
    self = create_autospec(ArcticLibraryBinding)
    self.arctic = create_autospec(Arctic)
    self.quota = 1024 * 1024 * 1024
    self.quota_countdown = 0
    self.arctic.__getitem__.return_value = Mock(stats=Mock(
        return_value={'totals': {
            'size': 1024 * 1024 * 1024,
            'count': 100,
        }}))
    with pytest.raises(QuotaExceededException) as e:
        ArcticLibraryBinding.check_quota(self)
    assert "Quota Exceeded: 1.000 / 1 GB used" in str(e)
示例#9
0
def test_check_quota_exceeded():
    self = create_autospec(ArcticLibraryBinding,
                           database_name='arctic_db',
                           library='lib')
    self.arctic = create_autospec(Arctic)
    self.get_library_metadata.return_value = 1024 * 1024 * 1024
    self.quota_countdown = 0
    self.arctic.__getitem__.return_value = Mock(stats=Mock(
        return_value={'totals': {
            'size': 1024 * 1024 * 1024,
            'count': 100,
        }}))
    with pytest.raises(QuotaExceededException) as e:
        ArcticLibraryBinding.check_quota(self)
    assert "Quota Exceeded: arctic_db.lib 1.000 / 1 GB used" in str(e.value)
示例#10
0
def test_check_quota_info():
    self = create_autospec(ArcticLibraryBinding)
    self.arctic = create_autospec(Arctic)
    self.get_library_metadata.return_value = 1024 * 1024 * 1024
    self.quota_countdown = 0
    self.arctic.__getitem__.return_value = Mock(stats=Mock(return_value={'totals':
                                                                             {'size': 1 * 1024 * 1024,
                                                                              'count': 100,
                                                                              }
                                                                             }))
    with patch('arctic.arctic.logger.info') as info:
        ArcticLibraryBinding.check_quota(self)
    self.arctic.__getitem__.assert_called_once_with(self.get_name.return_value)
    info.assert_called_once_with('Mongo Quota: 0.001 / 1 GB used')
    assert self.quota_countdown == 51153
示例#11
0
def test_check_quota():
    self = create_autospec(ArcticLibraryBinding)
    self.arctic = create_autospec(Arctic)
    self.get_library_metadata.return_value = 1024 * 1024 * 1024
    self.quota_countdown = 0
    self.arctic.__getitem__.return_value = Mock(stats=Mock(return_value={'totals':
                                                                             {'size': 900 * 1024 * 1024,
                                                                              'count': 100,
                                                                              }
                                                                             }))
    with patch('arctic.arctic.logger.warning') as warn:
        ArcticLibraryBinding.check_quota(self)
    self.arctic.__getitem__.assert_called_once_with(self.get_name.return_value)
    warn.assert_called_once_with('Mongo Quota: 0.879 / 1 GB used')
    assert self.quota_countdown == 6
示例#12
0
def test_check_quota_90_percent():
    self = create_autospec(ArcticLibraryBinding, database_name='arctic_db',
                           library='lib')
    self.arctic = create_autospec(Arctic)
    self.get_library_metadata.return_value = 1024 * 1024 * 1024
    self.quota_countdown = 0
    self.arctic.__getitem__.return_value = Mock(stats=Mock(return_value={'totals':
                                                                             {'size': 0.91 * 1024 * 1024 * 1024,
                                                                              'count': 1000000,
                                                                              }
                                                                             }))
    with patch('arctic.arctic.logger.warning') as warn:
        ArcticLibraryBinding.check_quota(self)
    self.arctic.__getitem__.assert_called_once_with(self.get_name.return_value)
    warn.assert_called_once_with('Mongo Quota: arctic_db.lib 0.910 / 1 GB used')
示例#13
0
def test_check_quota_info():
    self = create_autospec(ArcticLibraryBinding)
    self.arctic = create_autospec(Arctic)
    self.quota = 1024 * 1024 * 1024
    self.quota_countdown = 0
    self.arctic.__getitem__.return_value = Mock(stats=Mock(
        return_value={'totals': {
            'size': 1 * 1024 * 1024,
            'count': 100,
        }}))
    with patch('arctic.arctic.logger.info') as info:
        ArcticLibraryBinding.check_quota(self)
    self.arctic.__getitem__.assert_called_once_with(self.get_name.return_value)
    info.assert_called_once_with('Mongo Quota: 0.001 / 1 GB used')
    assert self.quota_countdown == 51153
示例#14
0
def test_check_quota():
    self = create_autospec(ArcticLibraryBinding)
    self.arctic = create_autospec(Arctic)
    self.quota = 1024 * 1024 * 1024
    self.quota_countdown = 0
    self.arctic.__getitem__.return_value = Mock(stats=Mock(return_value={'totals':
                                                                             {'size': 900 * 1024 * 1024,
                                                                              'count': 100,
                                                                              }
                                                                             }))
    with patch('arctic.arctic.logger.warn') as warn:
        ArcticLibraryBinding.check_quota(self)
    self.arctic.__getitem__.assert_called_once_with(self.get_name.return_value)
    warn.assert_called_once_with('Mongo Quota: 0.879 / 1 GB used')
    assert self.quota_countdown == 6
示例#15
0
def test_check_quota_90_percent():
    self = create_autospec(ArcticLibraryBinding, database_name='arctic_db',
                           library='lib')
    self.arctic = create_autospec(Arctic)
    self.get_library_metadata.return_value = 1024 * 1024 * 1024
    self.quota_countdown = 0
    self.arctic.__getitem__.return_value = Mock(stats=Mock(return_value={'totals':
                                                                             {'size': 0.91 * 1024 * 1024 * 1024,
                                                                              'count': 1000000,
                                                                              }
                                                                             }))
    with patch('arctic.arctic.logger.warning') as warn:
        ArcticLibraryBinding.check_quota(self)
    self.arctic.__getitem__.assert_called_once_with(self.get_name.return_value)
    warn.assert_called_once_with('Mongo Quota: arctic_db.lib 0.910 / 1 GB used')
示例#16
0
def test_database_library_specifier(library, expected_library, expected_database):
    mongo = MagicMock()
    with patch('arctic.arctic.ArcticLibraryBinding._auth'):
        ml = ArcticLibraryBinding(mongo, library)

    assert ml.library == expected_library
    mongo._conn.__getitem__.assert_called_with(expected_database)
示例#17
0
def test_ArcticLibraryBinding_db():
    arctic = create_autospec(Arctic)
    arctic._conn = create_autospec(MongoClient)
    alb = ArcticLibraryBinding(arctic, "sentinel.library")
    with patch.object(alb, '_auth') as _auth:
        # connection is cached during __init__
        alb._db
        assert _auth.call_count == 0

        # Change the arctic connection
        arctic._conn = create_autospec(MongoClient)
        alb._db
        assert _auth.call_count == 1

        # connection is still cached
        alb._db
        assert _auth.call_count == 1
示例#18
0
def test_set_quota():
    m = Mock(spec=ArcticLibraryBinding)
    ArcticLibraryBinding.set_quota(m, 10000)
    m.set_library_metadata.assert_called_once_with('QUOTA', 10000)
    assert m.quota_countdown == 0
    assert m.quota == 10000
示例#19
0
def test_get_quota():
    m = Mock(spec=ArcticLibraryBinding)
    m.get_library_metadata.return_value = 42
    assert ArcticLibraryBinding.get_quota(m) == 42
    m.get_library_metadata.assert_called_once_with('QUOTA')
示例#20
0
def test_check_quota_countdown():
    self = create_autospec(ArcticLibraryBinding)
    self.quota = 10
    self.quota_countdown = 10
    ArcticLibraryBinding.check_quota(self)
    assert self.quota_countdown == 9
示例#21
0
def test_check_quota_countdown():
    self = create_autospec(ArcticLibraryBinding)
    self.quota = 10
    self.quota_countdown = 10
    ArcticLibraryBinding.check_quota(self)
    assert self.quota_countdown == 9
示例#22
0
def test_check_quota_Zero():
    self = create_autospec(ArcticLibraryBinding)
    self.quota = 0
    ArcticLibraryBinding.check_quota(self)
示例#23
0
def test_set_quota():
    self = create_autospec(ArcticLibraryBinding)
    ArcticLibraryBinding.set_quota(self, 10000)
    self.set_library_metadata.assert_called_once_with('QUOTA', 10000)
    assert self.quota_countdown == 0
    assert self.quota == 10000
示例#24
0
def test_get_quota():
    self = create_autospec(ArcticLibraryBinding)
    self.get_library_metadata.return_value = 42
    assert ArcticLibraryBinding.get_quota(self) == 42
    self.get_library_metadata.assert_called_once_with('QUOTA')
示例#25
0
def test_get_quota():
    self = create_autospec(ArcticLibraryBinding)
    self.get_library_metadata.return_value = 42
    assert ArcticLibraryBinding.get_quota(self) == 42
    self.get_library_metadata.assert_called_once_with('QUOTA')
示例#26
0
def test_check_quota_countdown():
    self = create_autospec(ArcticLibraryBinding)
    self.get_library_metadata.return_value = 10
    self.quota_countdown = 10
    ArcticLibraryBinding.check_quota(self)
    assert self.quota_countdown == 9
示例#27
0
def test_check_quota_countdown():
    self = create_autospec(ArcticLibraryBinding)
    self.get_library_metadata.return_value = 10
    self.quota_countdown = 10
    ArcticLibraryBinding.check_quota(self)
    assert self.quota_countdown == 9
示例#28
0
def test_get_quota():
    m = Mock(spec=ArcticLibraryBinding)
    m.get_library_metadata.return_value = 42
    assert ArcticLibraryBinding.get_quota(m) == 42
    m.get_library_metadata.assert_called_once_with('QUOTA')
示例#29
0
def test_set_quota():
    m = Mock(spec=ArcticLibraryBinding)
    ArcticLibraryBinding.set_quota(m, 10000)
    m.set_library_metadata.assert_called_once_with('QUOTA', 10000)
    assert m.quota_countdown == 0
    assert m.quota == 10000
示例#30
0
def test_lib_repr():
    mongo = MagicMock()
    with patch('arctic.arctic.ArcticLibraryBinding._auth'):
        ml = ArcticLibraryBinding(mongo, 'asdf')
        assert str(ml) == repr(ml)
示例#31
0
def test_set_quota():
    self = create_autospec(ArcticLibraryBinding)
    ArcticLibraryBinding.set_quota(self, 10000)
    self.set_library_metadata.assert_called_once_with('QUOTA', 10000)
    assert self.quota_countdown == 0
    assert self.quota == 10000
示例#32
0
def test_check_quota_Zero():
    self = create_autospec(ArcticLibraryBinding)
    self.quota = 0
    ArcticLibraryBinding.check_quota(self)