def test_py_rest_server(self):
        # POST a valid user
        self.test_app = app.test_client()
        post_data = {}
        post_data['username'] = "******"
        post_data['email'] = "*****@*****.**"
        post_data['password'] = "******"
        post_data['confirm-password'] = "******"
        response = self.test_app.post('/sign-up', data=post_data)
        self.assertEquals(response.status, "302 FOUND")

        # Access DB to find the accessToken
        mongo_url = os.environ["MONGO_URL"]
        connection = Connection(mongo_url)
        db = connection.auth.users
        found_user = db.find_one()

        post_data = {}
        post_data['token'] = found_user['token']
        r = requests.post("https://localhost:8000",
                          data=json.dumps(post_data),
                          verify=False)
        self.assertEquals(r.status_code, 200)
        found = "Hello testuser12! Python is pleased to meet you!" in r.text
        self.assertEquals(found, True)
 def test_username_empty(self):
     self.test_app = app.test_client()
     post_data = {}
     post_data['username'] = ""
     post_data['email'] = "*****@*****.**"
     post_data['password'] = "******"
     post_data['confirm-password'] = "******"
     response = self.test_app.post('/sign-up', data=post_data)
     self.assertEquals(response.status, "400 BAD REQUEST")
 def test_register_successful_user_without_mfa(self):
     self.test_app = app.test_client()
     post_data = {}
     post_data['username'] = "******"
     post_data['email'] = "*****@*****.**"
     post_data['password'] = "******"
     post_data['confirm-password'] = "******"
     response = self.test_app.post('/sign-up', data=post_data)
     self.assertEquals(response.status, "302 FOUND")
 def test_password_mismatch(self):
     self.test_app = app.test_client()
     post_data = {}
     post_data['username'] = "******"
     post_data['email'] = "*****@*****.**"
     post_data['password'] = "******"
     post_data['confirm-password'] = "******"
     response = self.test_app.post('/sign-up', data=post_data)
     self.assertEquals(response.status, "400 BAD REQUEST")
 def test_email_invalid(self):
     self.test_app = app.test_client()
     post_data = {}
     post_data['username'] = "******"
     post_data['email'] = "email_without_at_symbol"
     post_data['password'] = "******"
     post_data['confirm-password'] = "******"
     response = self.test_app.post('/sign-up', data=post_data)
     self.assertEquals(response.status, "400 BAD REQUEST")
 def test_password_less_than_8_chars(self):
     self.test_app = app.test_client()
     post_data = {}
     post_data['username'] = "******"
     post_data['email'] = "*****@*****.**"
     post_data['password'] = "******"
     post_data['confirm-password'] = "******"
     response = self.test_app.post('/sign-up', data=post_data)
     self.assertEquals(response.status, "400 BAD REQUEST")
    def test_login_successful_user_with_mfa(self):
        self.test_app = app.test_client()
        # Register
        post_data = {}
        post_data['username'] = "******"
        post_data['email'] = "*****@*****.**"
        post_data['password'] = "******"
        post_data['confirm-password'] = "******"
        response = self.test_app.post('/sign-up', data=post_data)
        self.assertEquals(response.status, "302 FOUND")

        #Login
        post_data = {}
        post_data['username'] = "******"
        post_data['password'] = "******"
        response = self.test_app.post('/', data=post_data)
        self.assertEquals(response.status, "200 OK")
    def test_invalid_login(self):
        # Register
        self.test_app = app.test_client()
        post_data = {}
        post_data['username'] = "******"
        post_data['email'] = "*****@*****.**"
        post_data['password'] = "******"
        post_data['confirm-password'] = "******"
        response = self.test_app.post('/sign-up', data=post_data)
        self.assertEquals(response.status, "302 FOUND")

        #Login with bad password
        post_data = {}
        post_data['username'] = "******"
        post_data['password'] = "******"
        response = self.test_app.post('/', data=post_data)
        self.assertEquals(response.status, "401 UNAUTHORIZED")
    def test_py_rest_server_timeout(self):
        self.test_app = app.test_client()

        # Access DB to find the accessToken
        mongo_url = os.environ["MONGO_URL"]
        connection = Connection(mongo_url)
        db = connection.auth.users
        found_user = db.find_one()

        post_data = {}
        post_data['token'] = found_user['token']
        r = requests.post("https://localhost:8000",
                          data=json.dumps(post_data),
                          verify=False)
        self.assertEquals(r.status_code, 200)

        # Update expiry in the database to 10 seconds from now
        found_user['expires_at'] = datetime.utcnow() + timedelta(seconds=10)
        db.save(found_user)
        sleep(10)
        r = requests.post("https://localhost:8000",
                          data=json.dumps(post_data),
                          verify=False)
        self.assertEquals(r.status_code, 401)
 def test_site_is_up(self):
     self.test_app = app.test_client()
     response = self.test_app.get("/")
     self.assertEquals(response.status, "200 OK")
Beispiel #11
0
 def setUp(self):
     app.config['TESTING'] = True
     app.config['DEBUG'] = False
     self.app = app.test_client()