def test_3_create_without_permissions(): """ Try to create a user without the permissions """ request = PyledgerRequest() request.request = 'new_user' request.user = '******' request.password = '******' request.data = pickle.dumps(('user3', 'new_password')) response = PyledgerResponse() response.ParseFromString(handle_request(request.SerializeToString())) assert response.successful == False assert response.data == b'Not enough permissions'
def test_master_session(): """ Get a master session key """ request = PyledgerRequest() request.request = 'session' request.user = '******' request.password = '******' response = PyledgerResponse() response.ParseFromString(handle_request(request.SerializeToString())) assert response.successful == True session_key = response.data.decode('utf-8') session = Session.from_key(session_key) assert session.key == session_key
def test_2_create_user(): """ Create a user from the API """ request = PyledgerRequest() request.request = 'new_user' request.user = '******' request.password = '******' request.session_key = 'test_session' request.data = pickle.dumps(('user2', 'new_password')) response = PyledgerResponse() response.ParseFromString(handle_request(request.SerializeToString())) assert response.successful == True assert response.data == b'user2' user = User.from_name('user2') assert user.get_permissions() == Permissions.USER assert user.check_password('new_password')
def test_access_contract_as_root(): request = PyledgerRequest() response = PyledgerResponse() request.request = 'call' request.contract = 'AuthDigitalCurrency' request.call = 'add_account' request.user = '******' request.password = '******' request.data = pickle.dumps({'key': 'new_account'}) byte_request = request.SerializeToString() byte_response = handle_request(byte_request) response.ParseFromString(byte_response) assert response.successful == True response_data = pickle.loads(response.data) assert response_data == 'new_account'