def test_add_transaction(client, transactions): response = client.post('add_transaction', json=transactions) assert response.status_code == 201 response = client.get('/get_unverified_transactions') assert response.status_code == 200 data = json.loads(response.get_data(as_text=True)) assert data['Transactions'][0] == transactions['transaction']
def test_song_creation(client): req = random_song_creation_request() instruments_as_str = [i.value for i in req.instruments] res = client.post('/songs', json={ "title": req.title, "instruments": instruments_as_str }) assert res.status_code == 200 assert res.json["title"] == req.title assert res.json["instruments"] == instruments_as_str
def new_song_from_api(client, req: Optional[SongCreationRequest] = None): _req = random_song_creation_request() if req is None else req instruments_as_str = [i.value for i in _req.instruments] res = client.post('/songs', json={ "title": _req.title, "instruments": instruments_as_str }) return Song(id=res.json["id"], title=res.json["title"], instruments=_req.instruments, created_at=res.json["created_at"], updated_at=res.json["updated_at"])
def test_register_unsuccesful_for_big_username(new_user, configed_app, client): with configed_app.test_request_context(): response = client.post( "register", data=dict( username="".join("a" for i in range(60)), email=new_user.email, password=new_user.password, confirm_password=new_user.password, ), follow_redirects=False, ) assert ( response.status_code == 200 ), "User register with big username. Status code: {response.status_code}" delete_user(new_user)
def test_register_unsuccesful_for_missing_email(new_user, configed_app, client): with configed_app.test_request_context(): response = client.post( "register", data=dict( username=new_user.username, email="", password=new_user.password, confirm_password=new_user.password, ), follow_redirects=False, ) assert ( response.status_code == 200 ), "User register with missing email. Status code: {response.status_code}" delete_user(new_user)
def test_register_succesful_for_correct_credentials(new_user, configed_app, client): with configed_app.test_request_context(): response = client.post( "register", data=dict( username=new_user.username, email=new_user.email, password=new_user.password, confirm_password=new_user.password, ), follow_redirects=False, ) assert ( response.status_code == 302 ), "User didn't register with correct credentials. Status code: {response.status_code}" delete_user(new_user)
def test_register_unsuccesful_for_different_pass_and_conf_pass( new_user, configed_app, client): with configed_app.test_request_context(): response = client.post( "register", data=dict( username=new_user.username, email=new_user.email, password=new_user.password, confirm_password=new_user.password + "a", ), follow_redirects=False, ) assert ( response.status_code == 200 ), "User register with different password and confirm password. Status code: {response.status_code}" delete_user(new_user)
def test_song_creation_empty_instruments(client): req = random_song_creation_request() res = client.post('/songs', json={"title": req.title, "instruments": []}) assert res.status_code == 400