Пример #1
0
 def test_context_and_deserialisation(self):
     store_file = mktemp()
     for name, value in self.TEST_DATA:
         if isinstance(value, tuple):
             value = list(value)
         with JsonStore(store_file) as store:
             store[name] = value
         with JsonStore(store_file) as store:
             self.assertEqual(getattr(store, name), value)
Пример #2
0
    def test_new_store(self):
        store_file = mktemp()
        JsonStore(store_file, auto_commit=True)
        with open(self._store_file) as handle:
            self.assertEqual(handle.read(), '{}')
        os.remove(store_file)

        JsonStore(store_file, auto_commit=False)
        with open(self._store_file) as handle:
            self.assertEqual(handle.read(), '{}')
        os.remove(store_file)
Пример #3
0
 def test_no_auto_commit(self):
     store_file = mktemp()
     store = JsonStore(store_file, indent=None, auto_commit=False)
     store.value1 = 1
     store['value2'] = 2
     with open(store_file) as handle:
         self.assertEqual({}, json.load(handle))
Пример #4
0
    def __init__(self):
        self._driver = Scraper.get_reusable_driver()
        self._store = JsonStore('store.json')

        if not 'not_notified' in self._store:
            self._store['not_notified'] = []

        if not 'notified' in self._store:
            self._store['notified'] = []
Пример #5
0
 def test_auto_commit(self):
     store_file = mktemp()
     store = JsonStore(store_file, indent=None, auto_commit=True)
     store.value1 = 1
     with open(store_file) as handle:
         self.assertEqual({"value1": 1}, json.load(handle))
     store["value2"] = 2
     with open(store_file) as handle:
         self.assertEqual({"value1": 1, "value2": 2}, json.load(handle))
Пример #6
0
 def setUp(self):
     self._store_file = mktemp()
     self.store = JsonStore(self._store_file, indent=None, auto_commit=True)
Пример #7
0
 def __init__(self):
     self.store = JsonStore('forms.json')
Пример #8
0
 def test_empty_store(self):
     store_file = mktemp()
     with open(store_file, "wb") as f:
         f.write(b"")
     self.assertTrue(JsonStore(f.name))
Пример #9
0
def add(server_id, key, value):
    store = JsonStore(str(server_id) + ".json")
    store[key] = value
Пример #10
0
def remove(server_id, key):
    store = JsonStore(str(server_id) + ".json")
    del store[key]
    store._save()
Пример #11
0
def remove_from_dict(server_id, list_key, key):
    store = JsonStore(str(server_id) + ".json")
    del store["{}.{}".format(list_key, key)]
    store._save()
Пример #12
0
def add_to_dict(server_id, list_key, key, value):
    store = JsonStore(str(server_id) + ".json")
    store["{}.{}".format(list_key, key)] = value
Пример #13
0
def initialize_dict(server_id, list_key):
    store = JsonStore(str(server_id) + ".json")
    exec("store.{} = {}").format(list_key, {})
Пример #14
0
def get(server_id, key):
    store = JsonStore(str(server_id) + ".json")
    return store[key]
Пример #15
0
 def __init__(self):
     self._lock = threading.Lock()
     self.store = JsonStore(config.config_path, indent=2, auto_commit=True)
     self.init_store()