Esempio n. 1
0
    def bucketlists():
        if request.method == "POST":
            name = str(request.data.get('name', ''))
            if name:
                bucketlist = Bucketlist(name=name)
                bucketlist.save()
                response = jsonify({
                    'id': bucketlist.id,
                    'name': bucketlist.name,
                    'date_created': bucketlist.date_created,
                    'date_modified': bucketlist.date_modified
                })
                response.status_code = 201
                return response
        else:
            # GET
            bucketlists = Bucketlist.get_all()
            results = []

            for bucketlist in bucketlists:
                obj = {
                    'id': bucketlist.id,
                    'name': bucketlist.name,
                    'date_created': bucketlist.date_created,
                    'date_modified': bucketlist.date_modified
                }
                results.append(obj)
            response = jsonify(results)
            response.status_code = 200
            return response
Esempio n. 2
0
class ModelTestCase(TestCase):
    def SetUp(self):
        self.bucketlist_name = "Write World class Code"
        self.bucketlist = Bucketlist(name=self.bucketlist_name)

    def test_model_can_crate_a_bucketlist(self):
        old_count = Bucketlist.objects.count()
        self.bucketlist.save()
        new_count = Bucketlist.objects.count()
        self.assertNotEqual(old_count, new_count)
Esempio n. 3
0
class ModelTestCase(TestCase):
    def setUp(self):
        user = User.objects.create(username="******")
        self.name = "Write world class code"
        self.bucketlist = Bucketlist(name=self.name, owner=user)

    def test_model_can_create_a_bucketlist(self):
        old_count = Bucketlist.objects.count()
        self.bucketlist.save()
        new_count = Bucketlist.objects.count()
        self.assertNotEqual(old_count, new_count)
Esempio n. 4
0
class ModelTestCase(TestCase):
    """This class defines the test suite for the bucketlist model."""
    def setUp(self):
        """Define the test client and other test variables."""
        self.bucketlist_name = "Write world class code"
        self.bucketlist = Bucketlist(name=self.bucketlist_name)

    def test_model_can_create_a_bucketlist(self):
        """Test the bucketlist model can create a bucketlist."""
        old_count = Bucketlist.objects.count()
        self.bucketlist.save()
        new_count = Bucketlist.objects.count()
        self.assertNotEqual(old_count, new_count)
Esempio n. 5
0
def Spys_ru():
    ip = get_ip()
    port = get_port()
    connection_type = get_connection_type()
    anonymity = get_anonymity()
    country = get_country()

    for index, value in enumerate(ip):
        b = Bucketlist(ip=value,
                       port=port[index],
                       anonymity=anonymity[index],
                       connection_type=connection_type[index],
                       country=country[index])
        b.save()
Esempio n. 6
0
def abort_if_bucketlist_doesnt_exist(bucketlist_id):
    bucketlist = Bucketlist.get_bucketlist(bucketlist_id)
    if not bucketlist:
        abort(404, message="Bucketlist '{}' does not exist".format(
            bucketlist_id))
    elif check_user_permission(bucketlist.user):
        return bucketlist
Esempio n. 7
0
    def setUp(self):
        """
        Create objects in the database to use for testing
        """
        self.db = db
        self.db.create_all()
        self.client = self.app.test_client()

        self.user1 = User(username="******",
                          email="*****@*****.**",
                          password='******')
        self.user2 = User(username="******",
                          email="*****@*****.**",
                          password='******')
        self.bucketlist = Bucketlist(description="My Bucketlist",
                                     user=self.user1)
        self.bucketlist2 = Bucketlist(description="My Bucketlist 2",
                                      user=self.user1)

        self.bucketlist_item = BucketlistItem(description="An item",
                                              bucketlist_id=2)
        self.bucketlist_item2 = BucketlistItem(description="An item 2",
                                               bucketlist_id=2)

        self.db.session.add(self.user1)
        self.db.session.add(self.user2)
        self.db.session.add(self.bucketlist)
        self.db.session.add(self.bucketlist2)
        self.db.session.add(self.bucketlist_item)
        self.db.session.add(self.bucketlist_item2)
        self.bucketlist.items.append(self.bucketlist_item)
        self.bucketlist.items.append(self.bucketlist_item2)
        self.db.session.commit()

        response = self.client.post(url_for('auth.login'),
                                    data=json.dumps({
                                        "username": "******",
                                        "password": "******"
                                    }))
        print("response: ", response.data)
        response_data = json.loads(response.get_data(as_text=True))
        self.jwt_token = ""
        if "token" in response_data:
            self.jwt_token = response_data["token"]
Esempio n. 8
0
    def setUp(self):
        self.app = create_app('testing')
        self.app_context = self.app.app_context()
        self.app_context.push()

        db.create_all()

        user = User(
            username="******",
            email="*****@*****.**",
            password_hash="chiditheboss"
        )
        user.hash_password("chiditheboss")
        db.session.add(user)
        db.session.commit()
        g.user = user

        bucketlist = Bucketlist(name="Awesome Bucketlist", created_by=g.user.id)
        bucketlist.save()

        self.client = self.app.test_client()
    def test_bucketlist_creation(self):
        """Test the method to create a new bucket list.

        If the user is unauthenticated a 403 FORBIDDEN response should be
        returned. With authentication a 201 CREATED response should be
        returned. The Bucketlist table should contain a bucketlist called
        `BL Name - With auth`
        """
        no_auth_data = {"name": "BL Name - No auth"}
        with_auth_data = {"name": "BL Name - With auth"}
        before_auth = self.client.post(self.bucketlists, no_auth_data)
        self.client.force_authenticate(self.user)
        mybl = Bucketlist(name="Save Bucketlist", created_by=self.user)
        Bucketlist.save(mybl)
        bl = Bucketlist.objects.filter(name="Save Bucketlist")
        after_auth = self.client.post(self.bucketlists, with_auth_data)

        self.assertEqual(bl.count(), 1)
        self.assertEqual(before_auth.status_code, 403)
        self.assertEqual(after_auth.status_code, 201)
        self.assertEqual(after_auth.data["name"], "BL Name - With auth")
Esempio n. 10
0
    def test_bucketlist_creation(self):
        """Test the method to create a new bucket list.

        If the user is unauthenticated a 403 FORBIDDEN response should be
        returned. With authentication a 201 CREATED response should be
        returned. The Bucketlist table should contain a bucketlist called
        `BL Name - With auth`
        """
        no_auth_data = {'name': 'BL Name - No auth'}
        with_auth_data = {'name': 'BL Name - With auth'}
        before_auth = self.client.post(self.bucketlists, no_auth_data)
        self.client.force_authenticate(self.user)
        mybl = Bucketlist(name='Save Bucketlist', created_by=self.user)
        Bucketlist.save(mybl)
        bl = Bucketlist.objects.filter(name='Save Bucketlist')
        after_auth = self.client.post(self.bucketlists, with_auth_data)

        self.assertEqual(bl.count(), 1)
        self.assertEqual(before_auth.status_code, 403)
        self.assertEqual(after_auth.status_code, 201)
        self.assertEqual(after_auth.data['name'], 'BL Name - With auth')
Esempio n. 11
0
def initdb():
    db.create_all()
    user1 = User(username="******",
                 email="*****@*****.**",
                 password="******")
    user2 = User(username="******", email="*****@*****.**", password="******")
    bucketlist = Bucketlist(description="My Bucketlist", user=user1)
    bucketlist_item = BucketlistItem(description="An item",
                                     bucketlist=bucketlist)
    db.session.add(user1)
    db.session.add(user2)
    db.session.add(bucketlist)
    db.session.add(bucketlist_item)
    db.session.commit()
    print("Initialized the database")
Esempio n. 12
0
 def setUp(self):
     """Define the test client and other test variables."""
     self.bucketlist_name = "Write world class code"
     self.bucketlist = Bucketlist(name=self.bucketlist_name)
Esempio n. 13
0
 def setUp(self):
     user = User.objects.create(username="******")
     self.name = "Write world class code"
     self.bucketlist = Bucketlist(name=self.name, owner=user)
Esempio n. 14
0
 def make_bucketlist(self, data):
     data['user'] = current_identity
     return Bucketlist(**data)
Esempio n. 15
0
 def SetUp(self):
     self.bucketlist_name = "Write World class Code"
     self.bucketlist = Bucketlist(name=self.bucketlist_name)