def test_update_user_no_password(self): body = models.UserData(data=models.User( type="users", attributes=models.UserAttributes(user_name="name", password=""))) response = self.client.open('/api/v1/user/{user_id}'.format(user_id=1), method='PATCH', data=json.dumps(body), content_type='application/json') self.assert200(response, 'Response body is : ' + response.data.decode('utf-8'))
def __create_user(record: database.User): return models.User(id=str(record.id), type="users", attributes=models.UserAttributes( user_name=record.user_name, last_name=record.last_name, first_name=record.first_name, email=record.email, permissions=[ models.UserAttributesPermissions(p.label.name) for p in record.permissions ]))
def test_restore_not_authenticated(self): """Test case for restore log out """ body = models.User(attributes=models.UserAttributes(user_name="user")) response = self.client.open('/api/v1/restore', method='POST', data=json.dumps(body), content_type='application/json') self.assert401(response, 'Response body is : ' + response.data.decode('utf-8'))
def test_add_duplicate_user(self): """Test case for add_user add a new user """ body = models.UserData(data=models.User( type="users", attributes=models.UserAttributes(user_name="user"))) response = self.client.open('/api/v1/user', method='POST', data=json.dumps(body), content_type='application/json') self.assert409(response, 'Response body is : ' + response.data.decode('utf-8'))
def test_update_duplicate_user(self): with database.session_scope() as session: user = util.create_user({"user.user_name": "user2"}) session.add(user) body = models.UserData(data=models.User( type="users", attributes=models.UserAttributes(user_name="user"))) response = self.client.open('/api/v1/user/{user_id}'.format(user_id=2), method='PATCH', data=json.dumps(body), content_type='application/json') self.assert409(response, 'Response body is : ' + response.data.decode('utf-8'))
def test_update_user(self): body = models.UserData( data=models.User(type="users", attributes=models.UserAttributes( user_name="new_name", email="*****@*****.**", password="******", old_password="******", permissions=[ models.UserAttributesPermissions("read"), models.UserAttributesPermissions("write") ]))) response = self.client.open('/api/v1/user/{user_id}'.format(user_id=1), method='PATCH', data=json.dumps(body), content_type='application/json') self.assert200(response, 'Response body is : ' + response.data.decode('utf-8'))
def test_add_user(self): """Test case for add_user add a new user """ body = models.UserData( data=models.User(type="users", attributes=models.UserAttributes( user_name="name", password="******", permissions=[ models.UserAttributesPermissions("read"), models.UserAttributesPermissions("write") ]))) response = self.client.open('/api/v1/user', method='POST', data=json.dumps(body), content_type='application/json') self.assert201(response, 'Response body is : ' + response.data.decode('utf-8'))