def test_create_Bucket(self): bucket = bucketlist.Bucket("Movies to watch") bucket.profile_id = self.testprofile.id saved = bucket.save() self.assertTrue(saved) buckets = bucketlist.Bucket.get_buckets() self.assertTrue(len(buckets) > 0) self.assertIn(bucket, buckets)
def test_query_bucket_by_id(self): bucket = bucketlist.Bucket("Bucketd") bucket.profile_id = self.testprofile.id bucket.save() bucket1 = bucketlist.Bucket.get_bucket(id=bucket.id) self.assertTrue(bucket == bucket1) # query non-existing bucket bucket2 = bucketlist.Bucket.get_bucket(id=500) self.assertFalse(bucket2)
def test_query_bucket_by_name(self): bucket = bucketlist.Bucket("New Experinces") bucket.profile_id = self.testprofile.id bucket.save() bucket1 = bucketlist.Bucket.get_bucket(name=bucket.name, profile_id=self.testprofile.id) self.assertTrue(bucket == bucket1) # query non-existing bucket bucket1 = bucketlist.Bucket.get_bucket(name="Doesnot", profile_id=self.testprofile.id) self.assertFalse(bucket1)
def test_update_bucket(self): test_bucket = bucketlist.Bucket("typo in nammme") test_bucket.profile_id = self.testprofile.id test_bucket.save() bucket_to_update = bucketlist.Bucket.get_bucket( "typo in nammme", profile_id=self.testprofile.id) bucket_to_update.name = "Finally we edit it" bucket_to_update.save() query = bucketlist.Bucket.get_bucket("Finally we edit it", profile_id=self.testprofile.id) self.assertTrue(query.name == "Finally we edit it")
def add_bucket(self, name): """Create a bucket. Args: name(str): Name of the bucket Returns: True if succesfull, False if bucket was not saved and None if error occured. """ new_bucket = bucketlist.Bucket(name) new_bucket.created_by = self.owner.username new_bucket.profile_id = self.id new_bucket.asset_id = self.next_bucket_id if new_bucket.save() and self.save(): self.bucket_lists[new_bucket.asset_id] = new_bucket self.next_bucket_id += 1 return self.save() else: return None
def test_delete_non_existing_bucket(self): bucket = bucketlist.Bucket("New Experinces") self.assertFalse(bucket.delete())
def test_save_duplicate_buckets(self): bucket = bucketlist.Bucket("New Experinces") bucket.save() bucket = bucketlist.Bucket("New Experinces") self.assertTrue(bucket.save())
def setUp(self): self.app = new_app('testing') self.app_context = self.app.app_context() self.app_context.push() database.drop_all() database.create_all() self.registerdata = { "username": "******", "email": "*****@*****.**", "password": "******" } self.new_user = user.User( username="******", password="******", email="*****@*****.**") self.data = { "email": "*****@*****.**", "password": "******" } self.new_user.save() self.new_mentor = user.User("Turing", "Inigma1#UKT", "*****@*****.**") self.new_mentor.save() self.new_follower = user.User("Knuth", "Log2#XUKT", "*****@*****.**") self.testprofile = profile.Profile("@mentor", self.new_mentor) self.testprofile.save() self.new_bucket = bucketlist.Bucket("Travelling") self.new_bucket.profile_id = self.testprofile.id self.new_bucket.asset_id = 0 self.new_bucket.save() self.new_item = bucketlist.Item("Drink alchol") self.new_item.profile_id = self.testprofile.id self.new_item.asset_id = 0 self.new_item.bucket_id = self.new_bucket.id self.new_item.save() self.new_item1 = bucketlist.Item("Go to Mombasa") self.new_item1.profile_id = self.testprofile.id self.new_item1.asset_id = 1 self.new_item1.bucket_id = self.new_bucket.id self.new_item1.save() # mock bucket self.new_bucket.items[self.new_item.asset_id] = self.new_item self.new_bucket.items[self.new_item1.asset_id] = self.new_item1 self.new_bucket.save() # mock profile self.new_profile = profile.Profile("@crimson_profile", self.new_user) self.new_profile.save() self.new_profile.add_bucket("Travelling") self.new_profile.add_item(name="Drink alchol", buc_name="Travelling") self.new_profile.add_item(name="Go to Mombasa", buc_id=0) self.new_profile.mentors[self.new_mentor.username] = self.new_mentor self.new_profile.save() self.client = self.app.test_client() self.login_url = "/api/v1.0/login" self.register_url = "/api/v1.0/register"