示例#1
0
    def setUp(self):
        """Set up test variables."""
        self.initializer = Initializer()

        self.same_email = {
            "username": "******",
            "email": "*****@*****.**",
            "password": "******"
        }

        self.bad_mail = {
            "username": "******",
            "email": "testexample",
            "password": "******"
        }

        self.weak_pass = {
            "username": "******",
            "email": "*****@*****.**",
            "password": "******"
        }

        self.invalid_username = {
            "username": 31411,
            "email": "*****@*****.**",
            "password": "******"
        }
示例#2
0
 def setUp(self):
     """Set up test variables."""
     self.initializer = Initializer()
示例#3
0
class BucketlistTestCase(unittest.TestCase):
    """Test case for the authentication blueprint."""
    def setUp(self):
        """Set up test variables."""
        self.initializer = Initializer()

    def test_post_item(self):
        login = self.initializer.login()

        self.assertEqual(login.status_code, 200)
        data = json.loads(login.data.decode())
        output = {
            "Token": data['auth_token'],
        }
        buc_data = {"name": "bucket 1"}
        input_data = {"name": "bucket 1 item", "done": True}
        bucketlists = self.initializer.get_app().test_client().post(
            '/bucketlists/',
            headers=output,
            data=json.dumps(buc_data),
            content_type='application/json')
        self.assertEqual(bucketlists.status_code, 200)

        bucketlists = self.initializer.get_app().test_client().post(
            '/bucketlists/1/items/',
            headers=output,
            data=json.dumps(input_data),
            content_type='application/json')
        self.assertEqual(bucketlists.status_code, 200)
        bucketlists = self.initializer.get_app().test_client().get(
            '/bucketlists/1', headers=output)
        self.assertEqual(bucketlists.status_code, 200)
        self.assertIn('bucket 1 item', bucketlists.get_data(as_text=True))

    def test_post_item_directly(self):
        login = self.initializer.login()

        self.assertEqual(login.status_code, 200)
        data = json.loads(login.data.decode())
        output = {
            "Token": data['auth_token'],
        }
        input_data = {"name": "bucket 1", "done": False}

        bucketlists = self.initializer.get_app().test_client().post(
            '/bucketlists/1/items/',
            headers=output,
            data=json.dumps(input_data),
            content_type='application/json')
        self.assertEqual(bucketlists.status_code, 404)

    def test_update_item(self):
        login = self.initializer.login()

        self.assertEqual(login.status_code, 200)
        data = json.loads(login.data.decode())
        output = {
            "Token": data['auth_token'],
        }

        bucket_data = {"name": "bucket 1"}
        input_data = {"name": "bucket 1", "done": False}

        update_data = {"name": "bucket 2", "done": True}

        bucketlists = self.initializer.get_app().test_client().post(
            '/bucketlists/',
            headers=output,
            data=json.dumps(bucket_data),
            content_type='application/json')
        self.assertEqual(bucketlists.status_code, 200)

        bucketlists = self.initializer.get_app().test_client().post(
            '/bucketlists/1/items/',
            headers=output,
            data=json.dumps(input_data),
            content_type='application/json')
        self.assertEqual(bucketlists.status_code, 200)
        bucketlists = self.initializer.get_app().test_client().put(
            '/bucketlists/1/items/1',
            headers=output,
            data=json.dumps(update_data),
            content_type='application/json')
        self.assertEqual(bucketlists.status_code, 200)
        self.assertIn('bucket 2', bucketlists.get_data(as_text=True))

    def test_delete_item(self):
        login = self.initializer.login()

        self.assertEqual(login.status_code, 200)
        data = json.loads(login.data.decode())
        output = {
            "Token": data['auth_token'],
        }
        bucket_data = {"name": "bucket 1"}
        input_data = {"name": "bucket 1", "done": True}
        bucketlists = self.initializer.get_app().test_client().post(
            '/bucketlists/',
            headers=output,
            data=json.dumps(bucket_data),
            content_type='application/json')
        self.assertEqual(bucketlists.status_code, 200)
        bucketlists = self.initializer.get_app().test_client().post(
            '/bucketlists/1/items/',
            headers=output,
            data=json.dumps(input_data),
            content_type='application/json')
        self.assertEqual(bucketlists.status_code, 200)
        bucketlists = self.initializer.get_app().test_client().delete(
            '/bucketlists/1/items/1', headers=output)
        self.assertEqual(bucketlists.status_code, 200)
        self.assertIn('Bucketlistitem successfully deleted',
                      bucketlists.get_data(as_text=True))
示例#4
0
 def setUp(self):
     self.initializer = Initializer()
示例#5
0
class BucketlistTestCase(unittest.TestCase):
    def setUp(self):
        self.initializer = Initializer()

    def test_post_bucketlist_successfully(self):
        login = self.initializer.login()

        self.assertEqual(login.status_code, 200)
        data = json.loads(login.data.decode())
        input_data = {
            "name": "bucket 1",
        }
        output = {"Token": data['auth_token'], "q": "bucketlist1"}
        bucketlists = self.initializer.get_app().test_client().post(
            '/bucketlists/',
            headers=output,
            data=json.dumps(input_data),
            content_type='application/json')
        self.assertEqual(bucketlists.status_code, 200)
        self.assertIn('bucket 1', bucketlists.get_data(as_text=True))

    def test_get_bucketlist(self):
        """
        Test user successful login.
        """
        login = self.initializer.login()

        self.assertEqual(login.status_code, 200)
        data = json.loads(login.data.decode())
        output = {"Token": data['auth_token']}
        bucketlists = self.initializer.get_app().test_client().get(
            '/bucketlists/', headers=output)
        self.assertEqual(bucketlists.status_code, 200)

    def test_get_bucketlist_with_search(self):
        """
        Test user successful login.
        """
        login = self.initializer.login()

        self.assertEqual(login.status_code, 200)
        data = json.loads(login.data.decode())
        output = {"Token": data['auth_token']}
        search_out = {"Token": data['auth_token'], "q": "buc"}
        get_data = {"name": "bucketlist 1"}
        bucketlists = self.initializer.get_app().test_client().post(
            '/bucketlists/',
            headers=output,
            data=json.dumps(get_data),
            content_type='application/json')
        self.assertEqual(bucketlists.status_code, 200)
        bucketlists = self.initializer.get_app().test_client().get(
            '/bucketlists/', headers=search_out)
        self.assertEqual(bucketlists.status_code, 200)
        self.assertIn('bucketlist', bucketlists.get_data(as_text=True))

    def test_unauthorized_get_bucketlist(self):
        output = None
        bucketlists = self.initializer.get_app().test_client().get(
            '/bucketlists/', headers=output)
        self.assertEqual(bucketlists.status_code, 401)
        self.assertIn('unauthorized action',
                      bucketlists.get_data(as_text=True))

    def test_post_bucketlist_without_data(self):
        login = self.initializer.login()

        self.assertEqual(login.status_code, 200)
        data = json.loads(login.data.decode())
        data_input = None
        output = {"Token": data['auth_token']}
        bucketlists = self.initializer.get_app().test_client().post(
            '/bucketlists/',
            headers=output,
            data=json.dumps(data_input),
            content_type='application/json')
        self.assertEqual(bucketlists.status_code, 400)
        self.assertIn('not found', bucketlists.get_data(as_text=True))

    def test_unauthorized_post_bucketlist(self):
        data_input = {"name": "bucketlist 1"}
        bucketlists = self.initializer.get_app().test_client().post(
            '/bucketlists/',
            data=json.dumps(data_input),
            content_type='application/json')
        self.assertEqual(bucketlists.status_code, 401)
        self.assertIn('unauthorized action',
                      bucketlists.get_data(as_text=True))
示例#6
0
class RegisterTestCase(unittest.TestCase):
    """Test case for the authentication blueprint."""

    def setUp(self):
        """Set up test variables."""
        self.initializer = Initializer()

        self.same_email = {
            "username": "******",
            "email": "*****@*****.**",
            "password": "******"
        }

        self.bad_mail = {
            "username": "******",
            "email": "testexample",
            "password": "******"
        }

        self.weak_pass = {
            "username": "******",
            "email": "*****@*****.**",
            "password": "******"
        }

        self.invalid_username = {
            "username": 31411,
            "email": "*****@*****.**",
            "password": "******"
        }

    def test_registration(self):
        """
        Test user successful registration.
        """
        result = self.initializer.register()
        self.assertEqual(result.status_code, 201)

    def test_for_valid_username(self):
        result = self.initializer.get_app().test_client().post(
            '/auth/register',
            data=json.dumps(
                self.invalid_username),
            content_type='application/json')
        self.assertEqual(result.status_code, 201)

    def test_already_registered_username(self):
        """
        Test that a user cannot be registered twice with the same email.
        """
        initial = self.initializer.register()
        self.assertEqual(initial.status_code, 201)
        result = self.initializer.register()
        self.assertEqual(result.status_code, 202)

    def test_already_registered_email(self):
        """
        Test that a user cannot be registered twice with the same username.
        """
        initial = self.initializer.register()
        self.assertEqual(initial.status_code, 201)
        result = self.initializer.get_app().test_client().post('/auth/register',
                                                               data=json.dumps(self.same_email),
                                                               content_type='application/json')
        self.assertEqual(result.status_code, 202)

    def test_reg_pass_validation(self):
        """
        Test that a user cannot be registered with a weak password.
        """
        result = self.initializer.get_app().test_client().post('/auth/register',
                                                               data=json.dumps(self.weak_pass),
                                                               content_type='application/json')
        self.assertEqual(result.status_code, 200)

    def test_reg_email_validation(self):
        result = self.initializer.get_app().test_client().post('/auth/register',
                                                               data=json.dumps(self.bad_mail),
                                                               content_type='application/json')
        self.assertEqual(result.status_code, 200)
示例#7
0
class BucketlistTestCase(unittest.TestCase):
    """Test case for the authentication blueprint."""
    def setUp(self):
        """Set up test variables."""
        self.initializer = Initializer()

    def test_get_bucketlist_by_id(self):
        """
        Test user successful login.
        """
        login = self.initializer.login()

        self.assertEqual(login.status_code, 200)
        data = json.loads(login.data.decode())
        output = {
            "Token": data['auth_token'],
        }
        input_data = {"name": "bucket 1"}
        bucketlists = self.initializer.get_app().test_client().post(
            '/bucketlists/',
            headers=output,
            data=json.dumps(input_data),
            content_type='application/json')
        self.assertEqual(bucketlists.status_code, 200)
        bucketlists = self.initializer.get_app().test_client().get(
            '/bucketlists/1', headers=output)
        self.assertEqual(bucketlists.status_code, 200)
        self.assertIn('1', bucketlists.get_data(as_text=True))

    def test_unauthorized_get_bucketlist(self):
        login = self.initializer.login()

        self.assertEqual(login.status_code, 200)
        data = json.loads(login.data.decode())
        output = {
            "Token": data['auth_token'],
        }
        input_data = {"name": "bucket 1"}
        bucketlists = self.initializer.get_app().test_client().post(
            '/bucketlists/',
            headers=output,
            data=json.dumps(input_data),
            content_type='application/json')
        self.assertEqual(bucketlists.status_code, 200)
        bucketlists = self.initializer.get_app().test_client().get(
            '/bucketlists/1', headers=None)
        self.assertEqual(bucketlists.status_code, 401)
        self.assertIn('unauthorized action',
                      bucketlists.get_data(as_text=True))

    def test_update_bucketlist(self):
        login = self.initializer.login()
        self.assertEqual(login.status_code, 200)
        data = json.loads(login.data.decode())
        output = {
            "Token": data['auth_token'],
        }
        input_data = {"name": "bucket 1"}
        update_data = {"name": "bucket 2"}

        bucketlists = self.initializer.get_app().test_client().post(
            '/bucketlists/',
            headers=output,
            data=json.dumps(input_data),
            content_type='application/json')
        self.assertEqual(bucketlists.status_code, 200)
        bucketlists = self.initializer.get_app().test_client().put(
            '/bucketlists/1',
            headers=output,
            data=json.dumps(update_data),
            content_type='application/json')
        self.assertEqual(bucketlists.status_code, 200)
        self.assertIn('bucket 2', bucketlists.get_data(as_text=True))

    def test_unauthorized_update(self):
        login = self.initializer.login()
        self.assertEqual(login.status_code, 200)
        data = json.loads(login.data.decode())
        output = {
            "Token": data['auth_token'],
        }
        input_data = {"name": "bucket 1"}
        update_data = {"name": "bucket 2"}

        bucketlists = self.initializer.get_app().test_client().post(
            '/bucketlists/',
            headers=output,
            data=json.dumps(input_data),
            content_type='application/json')
        self.assertEqual(bucketlists.status_code, 200)
        bucketlists = self.initializer.get_app().test_client().put(
            '/bucketlists/1',
            data=json.dumps(update_data),
            content_type='application/json')
        self.assertEqual(bucketlists.status_code, 401)
        self.assertIn('unauthorized action',
                      bucketlists.get_data(as_text=True))

    def test_delete_bucketlist(self):
        login = self.initializer.login()

        self.assertEqual(login.status_code, 200)
        data = json.loads(login.data.decode())
        output = {
            "Token": data['auth_token'],
        }
        input_data = {"name": "bucket 1"}

        bucketlists = self.initializer.get_app().test_client().post(
            '/bucketlists/',
            headers=output,
            data=json.dumps(input_data),
            content_type='application/json')
        self.assertEqual(bucketlists.status_code, 200)
        bucketlists = self.initializer.get_app().test_client().delete(
            '/bucketlists/1', headers=output)
        self.assertEqual(bucketlists.status_code, 200)
        self.assertIn('Bucketlist successfully deleted',
                      bucketlists.get_data(as_text=True))

    def test_unauthorized_delete(self):
        login = self.initializer.login()

        self.assertEqual(login.status_code, 200)
        data = json.loads(login.data.decode())
        output = {
            "Token": data['auth_token'],
        }
        input_data = {"name": "bucket 1"}

        bucketlists = self.initializer.get_app().test_client().post(
            '/bucketlists/',
            headers=output,
            data=json.dumps(input_data),
            content_type='application/json')
        self.assertEqual(bucketlists.status_code, 200)
        bucketlists = self.initializer.get_app().test_client().delete(
            '/bucketlists/1')
        self.assertEqual(bucketlists.status_code, 401)
        self.assertIn('unauthorized action',
                      bucketlists.get_data(as_text=True))