Esempio n. 1
0
    def add_item(self, name, description="TO DO", buc_id=None, buc_name=None):
        """Create an item.

        Args:
            name(str): Name of the item
            description(str): Give description of item, saved along the item
            buc_name(str):Name for the bucket item will be added to this bucket
            buc_id(int): asset_id for bucket item will be added here

        Returns:
            True if succesfull, False if item was not saved and None if the
            bucket does not exist.
        """
        bucket = None
        if buc_name:
            bucket = self.get_bucket(name=buc_name)
        elif buc_id or buc_id == 0:
            bucket = self.get_bucket(bucket_id=buc_id)

        if bucket:
            new_item = bucketlist.Item(name, description)
            new_item.profile_id = self.id
            new_item.asset_id = self.next_item_id
            if bucket.save() and new_item.save() and self.save():
                bucket.items[new_item.asset_id] = new_item
                self.next_item_id += 1
                return self.save()
            else:
                return False
        return None
    def test_query_by_id(self):
        item = bucketlist.Item("I will go to Mombasa")
        item.profile_id = self.testprofile.id
        item.save()

        query = bucketlist.Item.get_item(id=item.id)
        self.assertTrue(item == query)

        # query non-existin id
        item = bucketlist.Item.get_item(id=1400)
        self.assertFalse(item)
 def test_create_Item(self):
     item = bucketlist.Item("swimming accross the sea",
                            description=""" I Will go swimming
                            across the red sea
                            one day, i say one day i will
                            """)
     item.profile_id = self.testprofile.id
     item.save()
     query = bucketlist.Item.get_item(name="swimming accross the sea",
                                      profile_id=self.testprofile.id)
     self.assertTrue(query)
     self.assertEqual(item, query)
    def test_query_by_name(self):
        item = bucketlist.Item(name="new item in list")
        item.profile_id = self.testprofile.id
        item.save()

        query = bucketlist.Item.get_item(name="new item in list",
                                         profile_id=self.testprofile.id)
        self.assertTrue(query)

        # query non-exsting name
        query = bucketlist.Item.get_item(name="item does not exist",
                                         profile_id=self.testprofile.id)
        self.assertFalse(query)
    def test_update_item(self):
        item = bucketlist.Item("I will go to school")
        item.profile_id = self.testprofile.id
        item.save()

        query = bucketlist.Item.get_item(name="I will go to school",
                                         profile_id=self.testprofile.id)
        query.name = "I will not go to school"
        query.description = "Get some basic education"
        query.save()

        query = bucketlist.Item.get_item(name="I will not go to school",
                                         profile_id=self.testprofile.id)
        self.assertTrue(query)
        self.assertTrue(query.description == "Get some basic education")
        query = bucketlist.Item.get_item(name="I will go to school",
                                         profile_id=self.testprofile.id)
        self.assertFalse(query)
 def test_delete_non_existing_Item(self):
     item = bucketlist.Item(name="new item in list")
     self.assertFalse(item.delete())
    def test_save_duplicate_items(self):
        item = bucketlist.Item(name="new item in list")
        item.save()

        item = bucketlist.Item(name="new item in list")
        self.assertTrue(item.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"