コード例 #1
0
    def test_limit_bucketlist(self):
        """
        Tests that if a limit is passed as a parameter pagination occurs
        """
        email = "*****@*****.**"
        _pword = "test"
        arg_type = 'limit'
        arg_value = 3
        user = User.query.filter_by(email=email).first()
        # Populate bucketlist
        for i in range(10):
            bucketlist = BucketList(name='bucketlist_name{}'.format(i),
                                    user_id=user.id)
            bucketlist.save_bucketlist()

        bucketlist_no = BucketList.query.filter_by().count()
        self.assertGreaterEqual(bucketlist_no, 10)
        response = self.get_argument_bucketlist(email, _pword, arg_type,
                                                arg_value)
        result = json.loads(response.data.decode('utf-8'))
        self.assertEqual(len(result['data']), arg_value)
        self.assertEqual(result['page'], 1)
        self.assertEqual(result['per_page'], arg_value)
        self.assertEqual(result['total_data'], bucketlist_no)
        self.assertEqual(result['pages'], ceil(bucketlist_no / arg_value))
        self.assertEqual(result['prev_page'],
                         '/api/v1/bucketlist?limit={}'.format(arg_value))
        self.assertEqual(
            result['next_page'],
            '/api/v1/bucketlist?limit={}&page={}'.format(arg_value, 1 + 1))
コード例 #2
0
ファイル: base_case.py プロジェクト: malmike/BucketListAPI
 def add_test_bucketlists():
     """
     Method adds bucketlists to the database for testing
     """
     user = User.query.filter_by(email='*****@*****.**').first()
     bucketlist = BucketList(user_id=user.id, name='test bucketlist')
     bucketlist2 = BucketList(user_id=user.id, name='test bucketlist2')
     db.session.add(bucketlist)
     db.session.add(bucketlist2)
     db.session.commit()
コード例 #3
0
 def test_add_bucketlist(self):
     """
     Method checks that add bucketlist method actually adds a bucketlist
     to the database
     """
     user = User.query.filter_by(email="*****@*****.**").first()
     bucketlist = BucketList(name='test_bucketlist3', user_id=user.id)
     check = bucketlist.add_bucketlist()
     self.assertTrue(check, "Bucketlist should be added")
     self.assertTrue(
         bucketlist.id,
         "BucketList doesnot contain id so has not been added to the db"
     )
コード例 #4
0
 def test_no_repeat_bucketlist_names(self):
     """
     Method checks that add bucketlist method does not add bucketlist
     with repeated names
     """
     user = User.query.filter_by(email="*****@*****.**").first()
     bucketlist = BucketList(name='test_bucketlist', user_id=user.id)
     check = bucketlist.add_bucketlist()
     self.assertFalse(check, "Bucketlist should not be added")
     self.assertFalse(
         bucketlist.id,
         "BucketList contains id so has been added to the db"
     )
コード例 #5
0
    def post(self):
        """
        Handles adding of new bucketlists
        """
        post_data = request.get_json()
        name = strip_white_space(post_data.get('name'))

        if not name:
            return abort(400, "Bucket list name must be provided")

        bucketlist = BucketList(name=name, user_id=g.current_user.id)

        try:
            check = bucketlist.save_bucketlist()
            if check:
                response = {'status': 'success', 'message': 'Bucketlist Added'}
                return response, 201
            else:
                response = {'status': 'fail', 'message': 'Bucketlist Exists'}
                return response, 409
        except Exception as e:
            return abort(500,
                         message='Error creating your account:{}'.format(
                             e.message))