def test_user_generic_invite_link(client: Client): auth = authenticate_user1(client) house_1 = get_house1_id(client, auth) invite_link = client.get("/house/{}/user/invite".format(house_1), headers={"Authorization": auth}) json_invite = invite_link.get_json() assert json_invite["status"] == "success" assert len(json_invite["data"]) > 5 auth2 = authenticate_user2(client) joined = client.get(json_invite["data"], headers={"Authorization": auth2}) assert joined.get_json()["status"] == "success"
def test_delete_volume(client: Client): res = client.put("/volumes/test", json={"password": "******"}) href = get_href(res.get_json(), "self") res = client.delete(href) data = res.get_json() assert res.status_code == 200 assert data["name"] == "test" assert not data["mounted"] assert len(data["_links"]) == 1
def test_get_files(client: Client): res = client.put("/volumes/test", json={"password": "******"}) href = get_href(res.get_json(), "files") res = client.get(href) data = res.get_json() assert res.status_code == 200 assert any( x["name"] == "bar.txt" and x["type"] == "file" and x["size"] == 11 for x in data["contents"]) assert any(x["name"] == "foo" and x["type"] == "directory" for x in data["contents"])
def test_get_volumes(client: Client): res = client.get("/volumes") data = res.get_json() assert res.status_code == 200 assert len(data["volumes"]) == len(manager.get_volumes()) assert data["volumes"][0]["name"] == "test"
def test_get_all_users(self, admin_client: Client, get_users_mock) -> None: rv: Response = admin_client.get("/admin/users", ) assert rv.status_code == 200 users = rv.get_json()["users"] assert len(users) == 1 assert get_users_mock["users"][0].username == users[0]["username"] assert get_users_mock["filter"] == UsersFilter.All
def test_get_volume(client: Client): res = client.get("/volumes/test") data = res.get_json() assert res.status_code == 200 assert data["name"] == "test" assert not data["mounted"] assert len(data["_links"]) == 1
def test_put_volume(client: Client): res = client.put("/volumes/test", json={"password": "******"}) data = res.get_json() assert res.status_code == 200 assert data["name"] == "test" assert data["mounted"] assert len(data["_links"]) == 2
def test_identical_base_quote_currencies( self, authorized_client: Client) -> None: rv: Response = authorized_client.post( "/account/quotes", json=dict(action="buy", amount=1_000_000, currency_pair="Coin1_Coin1"), )
def test_user_get_task_by_id(client: Client): auth = authenticate_user1(client) resp = client.get("/house/user", headers={"Authorization": auth}) json_resp = resp.get_json() house_1 = json_resp["data"][0]["house_id"] get_tasks_resp = client.get("/house/{}/task/all".format(house_1), headers={ "Authorization": auth }).get_json() task_resp = client.get( "/task/{}".format(get_tasks_resp["data"][0]["task_id"]), headers={ "Authorization": auth }, ).get_json() assert task_resp["data"]["name"] == TASK1_NAME assert task_resp["data"]["frequency"] == TASK1_FREQUENCY
def test_user_reset_password(client: Client): with mail.record_messages() as outbox: client.get("/auth/password_reset/{}".format(TEST_USER1_EMAIL)) assert outbox[0].subject == "Reset your password." body_text: str = outbox[0].body body_text = body_text.replace( "Follow this link to reset your password: /auth/password_reset/reset_form/", "", ) email_verify_resp = client.post( "/auth/password_reset/reset/{}".format(body_text), data={ "password": TEST_USER1_PASSWORD, "password2": TEST_USER1_PASSWORD }, ) assert re.match(b"Your password has been reset.", email_verify_resp.data)
def test_drive_train_step(flask_app: Flask, client: Client): translate = 1 rotate = 0 data = {"translate": translate, "rotate": rotate} response = client.put("/drive_train/step", json=data) assert response.status_code == 200 responese_data = response.json assert 1 == responese_data["left_motor_speed"] assert 1 == responese_data["right_motor_speed"]
def test_user_update_house(client: Client): auth = authenticate_user1(client) house_1 = get_house1_id(client, auth) update_resp = client.post( "/house/update", json={ "house_id": house_1, "name": TEST_HOUSE_NEW_NAME }, headers={"Authorization": auth}, ) assert update_resp.get_json()["status"] == "success" auth2 = authenticate_user2(client) house_resp = client.get("/house/{}/get".format(house_1), headers={"Authorization": auth2}) json_house = house_resp.get_json() assert json_house["status"] == "success" assert json_house["data"]["name"] == TEST_HOUSE_NEW_NAME
def test_user_create_house(client: Client): auth = authenticate_user1(client) resp = client.post( "/house/add", json=dict(name=TEST_HOUSE_NAME, description=TEST_HOUSE_DESCRIPTION), headers={"Authorization": auth}, ) json_resp = resp.get_json() assert json_resp["status"] == "success"
def test_login_user(client: Client): resp = client.post( "/auth/login", json=dict(identifier=TEST_USER1_USERNAME, password=TEST_USER1_PASSWORD), ) json = resp.get_json() assert json["status"] == "success" assert len(json["data"]["access_token"]) > 5
def test_illegal_amount(self, authorized_client: Client) -> None: rv: Response = authorized_client.post( "/account/quotes", json=dict( action="buy", amount="what?!", currency_pair="Coin1_USD", ), ) assert rv.status_code == 400
def test_wrong_action(self, authorized_client: Client) -> None: rv: Response = authorized_client.post( "/account/quotes", json=dict( action="steal", amount=100, currency_pair="Coin1_USD", ), ) assert rv.status_code == 400
def test_register_user(client: Client): with mail.record_messages() as outbox: resp = client.post( "/auth/register", json=dict( username=TEST_USER1_USERNAME, email=TEST_USER1_EMAIL, password=TEST_USER1_OLD_PASSWORD, ), ) json = resp.get_json() assert outbox[0].subject == "Verify your email." body_text: str = outbox[0].body body_text = body_text.replace( "Follow this link to verify your email: ", "") email_verify_resp = client.get(body_text) assert email_verify_resp.data == b"Successfully verified your email." assert json["msg"] == "Created a new user." assert json["status"] == "success"
def test_login_user_custom_expiry(client: Client): token = client.post( "/auth/login", json={ "identifier": TEST_USER1_EMAIL, "password": TEST_USER1_PASSWORD, "custom_expiry": 1000, }, ).get_json() decoded = jwt.decode(token["data"]["access_token"], verify=False) assert (decoded["exp"] - 1000) == decoded["iat"]
def test_get_payment_command_json(self, authorized_client: Client, mock_get_payment_command_json) -> None: rv: Response = authorized_client.get( "/offchain/query/payment_command/22", ) assert rv.status_code == 200 assert rv.get_data() is not None payment_command = rv.get_json()["payment_command"] assert payment_command is not None assert (payment_command["my_actor_address"] == "tdm1pzmhcxpnyns7m035ctdqmexxad8ptgazxhllvyscesqdgp")
def create_new_job(client: Client, data, auth_header, must_succeed=True): """ Helper function for valid new job creation. """ response = client.post('/api/v1/jobs', headers=auth_header, data=data) if must_succeed: assert response.status_code == 200, f"status code was {response.status_code} with {response.data}" assert response.content_type == 'application/json' return response.json return response
def test_user_get_tasks(client: Client): auth = authenticate_user1(client) house_1 = get_house1_id(client, auth) get_tasks_resp = client.get("/house/{}/task/all".format(house_1), headers={ "Authorization": auth }).get_json() assert get_tasks_resp["status"] == "success" assert len(get_tasks_resp["data"]) == 1 assert get_tasks_resp["data"][0]["name"] == TASK1_NAME assert get_tasks_resp["data"][0]["description"] == TASK1_DESCRIPTION assert get_tasks_resp["data"][0]["frequency"] == TASK1_FREQUENCY
def test_register_user_3(client: Client): resp = client.post( "/auth/register", json=dict( username=TEST_USER3_USERNAME, email=TEST_USER3_EMAIL, password=TEST_USER3_PASSWORD, ), ) json = resp.get_json() assert json["msg"] == "Created a new user." assert json["status"] == "success"
def test_simple_greet(client: Client): """ Test the ``/simple_greet`` endpoint. This is a sanity check to make sure we aren't breaking the usual working of Blueprints. :param client: Client to the flask app. """ common_test(client) response = client.get("/simple_greet") assert response.status_code == 200 assert response.data == b"Hello, World!"
def test_custom_greet_parameterized(client: Client, greeting: str, name: str): """ Test the ``/custom_greet_parameterized`` endpoint. Test to check if EasyAPI passes both the ``greeting`` and ``name`` url parameter correctly to the endpoint even when the order in url parameters is changed. :param client: Client to the flask app. :param greeting: Greeting to greet the person with. :param name: Name of the person to greet. """ common_test(client) response_greeting_name = client.get( f"/custom_greet_parameterized?greeting={greeting}&name={name}") assert response_greeting_name.status_code == 200 assert response_greeting_name.data == f"{greeting}, {name}!".encode() # Change the order of name and greeting in url parameters. response_name_greeting = client.get( f"/custom_greet_parameterized?name={name}&greeting={greeting}") assert response_name_greeting.status_code == 200 assert response_name_greeting.data == f"{greeting}, {name}!".encode() assert response_greeting_name.data == response_name_greeting.data
def put_json(client: Client, url: str, json_body: Union[dict, list], **kwargs) -> Response: """ Send a PUT request to this URL. :param client: Flask test client. :param url: Relative server URL (starts with /). :param json_body: Python structure corresponding to the JSON to be sent. :return: Received response. """ return client.put(url, data=json.dumps(json_body), content_type="application/json", **kwargs)
def test_non_unique_username(self, admin_client: Client, create_new_user_mock) -> None: rv: Response = admin_client.post( "/admin/users", json=dict( username=NON_UNIQUE_USERNAME, is_admin=True, password="******", first_name="Test", last_name="Test oğlu", ), ) assert rv.status_code == 409
def test_200_usd(self, authorized_client: Client, mock_create_order) -> None: rv: Response = authorized_client.post( "/account/quotes", json=dict( action="buy", amount=10000, currency_pair="Coin1_USD", ), ) assert rv.status_code == 200 data = rv.get_json() assert data["price"] == 12345 assert data["rfq"]["action"] == "buy"
def test_greet_parameterized(client: Client, name: str): """ Test the ``/greet_parameterized`` endpoint. Test to check if EasyAPI passes the ``name`` url parameter passed to the endpoint. :param client: Client to the flask app. :param name: Name of the person to greet. """ common_test(client) response = client.get(f"/greet_parameterized?name={name}") assert response.status_code == 200 assert response.data == f"Hello, {name}!".encode()
def test_user_update_task(client: Client): auth = authenticate_user1(client) house_1 = get_house1_id(client, auth) get_tasks_resp = client.get("/house/{}/task/all".format(house_1), headers={ "Authorization": auth }).get_json() task_update_resp = client.post( "/task/{}/update".format(get_tasks_resp["data"][0]["task_id"]), headers={ "Authorization": auth }, json={ "name": TASK1_UPDATED_NAME }, ).get_json() assert task_update_resp["status"] == "success" task_resp = client.get( "/task/{}".format(get_tasks_resp["data"][0]["task_id"]), headers={ "Authorization": auth }, ).get_json() assert task_resp["data"]["name"] == TASK1_UPDATED_NAME
def test_user_add_task(client: Client): auth = authenticate_user2(client) house_1 = get_house1_id(client, auth) add_task_resp = client.post( "/house/{}/task/add".format(house_1), json={ "name": TASK1_NAME, "description": TASK1_DESCRIPTION, "frequency": TASK1_FREQUENCY, }, headers={ "Authorization": auth }, ).get_json() assert add_task_resp["status"] == "success"