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_batch_put_delayed(self): with FirestoreBatchContext(self.db) as bdb: dog = Dog(name="woofer") bdb.put(dog) got = Dog.get(self.db, dog.key) self.assertIsNone(got) got = Dog.get(self.db, dog.key) self.assertIsNotNone(got) self.assertEqual(len(bdb.results), 1)
def test_delete_dog_refs(self): paul = Person(name="paul") paul.save(self.db) dog = Dog(name="rufus", owner_id=paul.key) dog.save(self.db) key = dog.key dog2 = Dog(name="fly", owner_id=paul.key) dog2.save(self.db) reviveddog1 = Dog.get(self.db, key) self.assertTrue(reviveddog1 is not None) paul.delete(self.db) reviveddog2 = Dog.get(self.db, key) self.assertTrue(reviveddog2 is not None)
def test_delete_dog_refs(self): paul = Person(name="paul") paul.save(self.db) dog = Dog(name="rufus", owner_id=paul.key) dog.save(self.db) key = dog.key dog2 = Dog(name="fly", owner_id=paul.key) dog2.save(self.db) reviveddog1 = Dog.get(self.db, key) self.assertTrue(reviveddog1 is not None) paul.delete(self.db) reviveddog2 = Dog.get(self.db, key) self.assertTrue(reviveddog2 is not None)
def test_delete_dog_refs(self): paul = Person(name="paul") self.db.put(paul) dog = Dog(name="rufus", owner_id=paul.key) self.db.put(dog) key = dog.key dog2 = Dog(name="fly", owner_id=paul.key) self.db.put(dog2) reviveddog1 = Dog.get(self.db, key) self.assertTrue(reviveddog1 is not None) self.db.delete(paul) reviveddog2 = Dog.get(self.db, key) self.assertTrue(reviveddog2 is not None)
def test_batch_update(self): with FirestoreBatchContext(self.db) as bdb: dog = Dog(name="woofer") bdb.put(dog) dog.update({"name": "steve"}) got = Dog.get(self.db, dog.key) self.assertIsNotNone(got) self.assertEqual(got.name, "steve") self.assertEqual(len(bdb.results), 2)
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_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_delete_dog_to_refs(self): paul = Person(name="paul") paul.save(self.db) dog = Dog(name="rufus", owner_id=paul.key) dog.save(self.db) key = dog.key dog2 = Dog(name="fly", owner_id=paul.key) dog2.save(self.db) self.assertTrue(dog2.owner is not None) key = paul.key dog.delete(self.db) revivedpaul = self.db.get(key) self.assertTrue(revivedpaul is None) refresheddog2 = Dog.get(self.db, dog2.key) self.assertTrue(refresheddog2.owner is None)
def test_delete_dog_to_refs(self): paul = Person(name="paul") paul.save(self.db) dog = Dog(name="rufus", owner_id=paul.key) dog.save(self.db) key = dog.key dog2 = Dog(name="fly", owner_id=paul.key) dog2.save(self.db) self.assertTrue(dog2.owner is not None) key = paul.key dog.delete(self.db) revivedpaul = self.db.get(key) self.assertTrue(revivedpaul is None) refresheddog2 = Dog.get(self.db, dog2.key) self.assertTrue(refresheddog2.owner is None)
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")