def test_add_user_inactive(self): add_inactive_user() with self.client: resp_login = log_in(self.client) token = json.loads(resp_login.data.decode())["auth_token"] response = add_users(self.client, token) data = json.loads(response.data.decode()) self.assertEqual(response.status_code, 401) self.assertEqual(data["status"], "fail") self.assertEqual(data["message"], "Provide a valid auth token")
def test_add_user_invalid_json(self): """Ensure error is thrown if the JSON object is empty""" add_admin() with self.client: resp_login = log_in(self.client) token = json.loads(resp_login.data.decode())["auth_token"] response = add_users(self.client, token, {}) data = json.loads(response.data.decode()) self.assertEqual(response.status_code, 400) self.assertEqual(data["status"], "fail") self.assertEqual(data["message"], "Invalid payload")
def test_add_user_not_admin(self): add_user() with self.client: resp_login = log_in(self.client) token = json.loads(resp_login.data.decode())["auth_token"] response = add_users(self.client, token) data = json.loads(response.data.decode()) self.assertEqual(response.status_code, 401) self.assertEqual(data["status"], "fail") self.assertEqual(data["message"], "You do not have permission to do that")
def test_add_user(self): """Ensure a new user can be added to the database""" add_admin() with self.client: resp_login = log_in(self.client) token = json.loads(resp_login.data.decode())["auth_token"] response = add_users(self.client, token) data = json.loads(response.data.decode()) self.assertEqual(response.status_code, 201) self.assertEqual(data["status"], "success") self.assertEqual(data["message"], "[email protected] was added!")
def test_add_user_duplicate_email(self): """Ensure error is thrown if the email already exists""" add_admin() with self.client: resp_login = log_in(self.client) token = json.loads(resp_login.data.decode())["auth_token"] response = add_users(self.client, token, { "username": "******", "email": "*****@*****.**", "password": "******" }) data = json.loads(response.data.decode()) self.assertEqual(response.status_code, 400) self.assertEqual(data["status"], "fail") self.assertEqual(data["message"], "Sorry. That email already exists")
def test_add_user_empty_email(self): """ Ensure error is thrown if the JSON object does not have a email key """ add_admin() with self.client: resp_login = log_in(self.client) token = json.loads(resp_login.data.decode())["auth_token"] response = add_users(self.client, token, { "username": "******", "password": "******" }) data = json.loads(response.data.decode()) self.assertEqual(response.status_code, 400) self.assertEqual(data["status"], "fail") self.assertEqual(data["message"], "Invalid payload")