def test_sync_down_since(self): paul = Person.create(self.firestore, name="paul") sol = Person.create(self.firestore, name="sol") dog1 = Dog.create(self.firestore, name="woofer", owner=paul) dog2 = Dog.create(self.firestore, name="tiny", owner=paul) dog3 = Dog.create(self.firestore, name="fly", owner=paul) dogs_ref = self.firestore.db.collection("dog") syncer = FirestoreSyncer(self.couchdb, self.firestore) syncer.add_query(dogs_ref.where("owner_id", "==", paul.key)) dogs = Dog.all(self.couchdb) dogs_list = list(dogs) self.assertEqual(len(dogs_list), 0) changed = syncer.sync_down() self.assertEqual(len(changed), 3) dogs = Dog.all(self.couchdb) dogs_list = list(dogs) self.assertEqual(len(dogs_list), 3) dog3.update({"name": "jelly"}) changed = syncer.sync_down() print(changed) self.assertEqual(len(changed), 1) updated = self.couchdb.get(dog3.key) self.assertEqual(updated.name, "jelly")
def test_sync_up(self): paul = Person.create(self.firestore, name="paul") sol = Person.create(self.firestore, name="sol") dog1 = Dog.create(self.firestore, name="woofer", owner=paul) dog2 = Dog.create(self.firestore, name="tiny", owner=paul) dog3 = Dog.create(self.firestore, name="fly", owner=paul) dogs_ref = self.firestore.db.collection("dog") syncer = FirestoreSyncer(self.couchdb, self.firestore) syncer.add_query(dogs_ref.where("owner_id", "==", paul.key)) dogs = Dog.all(self.couchdb) dogs_list = list(dogs) self.assertEqual(len(dogs_list), 0) syncer.sync_down() dogs = Dog.all(self.couchdb) dogs_list = list(dogs) self.assertEqual(len(dogs_list), 3) dog4 = Dog.create(self.couchdb, name="di", owner_id=paul.key) dog5 = Dog.create(self.couchdb, name="stevie", owner_id=paul.key) syncer.sync_up() dogs = list(paul.dogs) self.assertEqual(len(dogs), 5)
def test_sync_up(self): paul = Person.create(self.firestore, name="paul") sol = Person.create(self.firestore, name="sol") dog1 = Dog.create(self.firestore, name="woofer", owner=paul) dog2 = Dog.create(self.firestore, name="tiny", owner=paul) dog3 = Dog.create(self.firestore, name="fly", owner=paul) dogs_ref = self.firestore.db.collection("dog") syncer = FirestoreSyncer(self.couchdb, self.firestore) syncer.add_query(dogs_ref.where("owner_id", "==", paul.key)) dogs = Dog.all(self.couchdb) dogs_list = list(dogs) self.assertEqual(len(dogs_list), 0) syncer.sync_down() dogs = Dog.all(self.couchdb) dogs_list = list(dogs) self.assertEqual(len(dogs_list), 3) dog4 = Dog.create(self.couchdb, name="di", owner_id=paul.key) dog5 = Dog.create(self.couchdb, name="stevie", owner_id=paul.key) syncer.sync_up() dogs = list(paul.dogs) self.assertEqual(len(dogs), 5)
def test_sync_down_since(self): paul = Person.create(self.firestore, name="paul") sol = Person.create(self.firestore, name="sol") dog1 = Dog.create(self.firestore, name="woofer", owner=paul) dog2 = Dog.create(self.firestore, name="tiny", owner=paul) dog3 = Dog.create(self.firestore, name="fly", owner=paul) dogs_ref = self.firestore.db.collection("dog") syncer = FirestoreSyncer(self.couchdb, self.firestore) syncer.add_query(dogs_ref.where("owner_id", "==", paul.key)) dogs = Dog.all(self.couchdb) dogs_list = list(dogs) self.assertEqual(len(dogs_list), 0) changed = syncer.sync_down() self.assertEqual(len(changed), 3) dogs = Dog.all(self.couchdb) dogs_list = list(dogs) self.assertEqual(len(dogs_list), 3) dog3.update({"name":"jelly"}) changed = syncer.sync_down() print(changed) self.assertEqual(len(changed), 1) updated = self.couchdb.get(dog3.key) self.assertEqual(updated.name, "jelly")
def test_uniqueness_delete(self): self.clear_db() paul = Person(name="paul") self.db.put(paul) dog1 = Dog.create(self.db, name="rufus", owner_id=paul.key, kennel_club_membership="123456") dog1.delete(self.db) dog2 = Dog.create(self.db, name="another", owner_id=paul.key, kennel_club_membership="123456")
def test_uniqueness_delete(self): paul = Person(name="paul") self.db.put(paul) dog1 = Dog.create(self.db, name="rufus", owner_id=paul.key, kennel_club_membership="123456") dog1.delete(self.db) dog2 = Dog.create(self.db, name="another", owner_id=paul.key, kennel_club_membership="123456")
def test_make_an_object_and_refresh(self): dog = Dog.create(self.db, name="woofer") dog2 = Dog.get(self.db, dog.key) self.assertIsNotNone(dog2) time.sleep(1) self.db.refresh() dog3 = Dog.create(self.db, name="another") dog4 = Dog.get(self.db, dog3.key) self.assertIsNotNone(dog4)
def test_uniqueness(self): self.clear_db() paul = Person(name="paul") self.db.put(paul) dog1 = Dog.create(self.db, name="rufus", owner_id=paul.key, kennel_club_membership="123456") dog2 = Dog.create(self.db, name="fly", owner_id=paul.key) # raises if setting one value self.assertRaises(FamUniqueError, dog2.update, {"kennel_club_membership": "123456"}) self.assertIsNone(dog2.kennel_club_membership) # raises if creating a new one self.assertRaises(FamUniqueError, Dog.create, self.db, name="steve", owner_id=paul.key, kennel_club_membership="123456")
def test_uniqueness(self): paul = Person(name="paul") self.db.put(paul) dog1 = Dog.create(self.db, name="rufus", owner_id=paul.key, kennel_club_membership="123456") dog2 = Dog.create(self.db, name="fly", owner_id=paul.key) # raises if setting one value self.assertRaises(FamUniqueError, dog2.update, {"kennel_club_membership": "123456"}) self.assertIsNone(dog2.kennel_club_membership) # raises if creating a new one self.assertRaises(FamUniqueError, Dog.create, self.db, name="steve", owner_id=paul.key, kennel_club_membership="123456")
def test_query_generator(self): paul = Person.create(self.firestore, name="paul") dog1 = Dog.create(self.firestore, name="woofer", owner=paul) dog2 = Dog.create(self.firestore, name="tiny", owner=paul) dog3 = Dog.create(self.firestore, name="fly", owner=paul) dogs_ref = self.firestore.db.collection("dog") q = dogs_ref.where(u"owner_id", u"==", paul.key) dogs = self.firestore.query_items(q, batch_size=1) dogs_list = list(dogs) self.assertTrue(isinstance(dogs_list[0], Dog)) self.assertEqual(len(dogs_list), 3)
def test_query_generator(self): paul = Person.create(self.firestore, name="paul") dog1 = Dog.create(self.firestore, name="woofer", owner=paul) dog2 = Dog.create(self.firestore, name="tiny", owner=paul) dog3 = Dog.create(self.firestore, name="fly", owner=paul) dogs_ref = self.firestore.db.collection("dog") q = dogs_ref.where(u"owner_id", u"==", paul.key) dogs = self.firestore.query_items(q, batch_size=1) dogs_list = list(dogs) self.assertTrue(isinstance(dogs_list[0], Dog)) self.assertEqual(len(dogs_list), 3)
def test_get_unique(self): self.clear_db() paul = Person(name="paul") self.db.put(paul) dog1 = Dog.create(self.db, name="rufus", owner_id=paul.key, kennel_club_membership="123456") dog2 = Dog.get_unique_instance(self.db, "kennel_club_membership", "123456") self.assertIsNotNone(dog2) self.assertTrue(dog2.kennel_club_membership == "123456")
def test_get_unique(self): paul = Person(name="paul") self.db.put(paul) dog1 = Dog.create(self.db, name="rufus", owner_id=paul.key, kennel_club_membership="123456") dog2 = Dog.get_unique_instance(self.db, "kennel_club_membership", "123456") self.assertIsNotNone(dog2) self.assertTrue(dog2.kennel_club_membership == "123456")
def test_updates_from_dict(self): self.clear_db() paul = Person.create(self.db, name="paul") dog1 = Dog.create(self.db, name="rufus", owner_id=paul.key, kennel_club_membership="123456") attrs = { "name":"joe", "kennel_club_membership": "9876543" } dog1.update(attrs) dog2 = Dog.get(self.db, dog1.key) self.assertTrue(dog2.kennel_club_membership == "9876543")
def test_updates_from_dict(self): paul = Person.create(self.db, name="paul") dog1 = Dog.create(self.db, name="rufus", owner_id=paul.key, kennel_club_membership="123456") attrs = {"name": "joe", "kennel_club_membership": "9876543"} dog1.update(attrs) dog2 = Dog.get(self.db, dog1.key) self.assertTrue(dog2.kennel_club_membership == "9876543")
def test_sync_down_single(self): paul = Person.create(self.firestore, name="paul") sol = Person.create(self.firestore, name="sol") dog1 = Dog.create(self.firestore, name="woofer", owner=paul) syncer = FirestoreSyncer(self.couchdb, self.firestore) dog1_ref = self.firestore.db.collection("dog").document(dog1.key) syncer.add_doc_ref(dog1_ref) dogs = Dog.all(self.couchdb) dogs_list = list(dogs) self.assertEqual(len(dogs_list), 0) syncer.sync_down() dogs = Dog.all(self.couchdb) dogs_list = list(dogs) self.assertEqual(len(dogs_list), 1)
def test_sync_down_single(self): paul = Person.create(self.firestore, name="paul") sol = Person.create(self.firestore, name="sol") dog1 = Dog.create(self.firestore, name="woofer", owner=paul) syncer = FirestoreSyncer(self.couchdb, self.firestore) dog1_ref = self.firestore.db.collection("dog").document(dog1.key) syncer.add_doc_ref(dog1_ref) dogs = Dog.all(self.couchdb) dogs_list = list(dogs) self.assertEqual(len(dogs_list), 0) syncer.sync_down() dogs = Dog.all(self.couchdb) dogs_list = list(dogs) self.assertEqual(len(dogs_list), 1)
def test_data_base_id(self): dog = Dog.create(self.db, name="woofer") dog_id = dog.key self.assertTrue(dog.key is not None) doc_ref = self.db.db.collection("dog").document(dog_id) doc = doc_ref.get() as_dict = doc.to_dict() # self.assertTrue("_id" not in as_dict) self.assertTrue("type" not in as_dict) self.assertTrue("namespace" not in as_dict) got_dog = Dog.get(self.db, dog_id) self.assertTrue(got_dog.key == dog_id) self.assertTrue(got_dog.namespace == dog.namespace) self.assertTrue(got_dog.type == "dog")
def test_data_base_id(self): dog = Dog.create(self.db, name="woofer") dog_id = dog.key self.assertTrue(dog.key is not None) doc_ref = self.db.db.collection("dog").document(dog_id) doc = doc_ref.get() as_dict = doc.to_dict() # self.assertTrue("_id" not in as_dict) self.assertTrue("type" not in as_dict) self.assertTrue("namespace" not in as_dict) got_dog = Dog.get(self.db, dog_id) self.assertTrue(got_dog.key == dog_id) self.assertTrue(got_dog.namespace == dog.namespace) self.assertTrue(got_dog.type == "dog")