Пример #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
Пример #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)
Пример #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)
Пример #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)
Пример #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()
Пример #6
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()
Пример #7
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")
Пример #8
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')