def test_with_hostname(flask_client): login(flask_client) r = flask_client.post( url_for("api.new_random_alias", hostname="www.test.com"), ) assert r.status_code == 201 assert r.json["alias"].endswith("d1.test") # make sure alias starts with the suggested prefix assert r.json["alias"].startswith("test") # assert returned field res = r.json assert "id" in res assert "email" in res assert "creation_date" in res assert "creation_timestamp" in res assert "nb_forward" in res assert "nb_block" in res assert "nb_reply" in res assert "enabled" in res assert "note" in res alias_used_on: AliasUsedOn = AliasUsedOn.first() assert alias_used_on.hostname == "www.test.com" assert alias_used_on.alias_id == res["id"]
def test_full_payload(flask_client): """Create alias with: - additional mailbox - note - name - hostname (in URL) """ user = login(flask_client) # create another mailbox mb = Mailbox.create(user_id=user.id, email="*****@*****.**", verified=True) Session.commit() word = random_word() suffix = f".{word}@{EMAIL_DOMAIN}" signed_suffix = signer.sign(suffix).decode() assert AliasUsedOn.count() == 0 r = flask_client.post( "/api/v3/alias/custom/new?hostname=example.com", json={ "alias_prefix": "prefix", "signed_suffix": signed_suffix, "note": "test note", "mailbox_ids": [user.default_mailbox_id, mb.id], "name": "your name", }, ) assert r.status_code == 201 assert r.json["alias"] == f"prefix.{word}@{EMAIL_DOMAIN}" # assert returned field res = r.json assert res["note"] == "test note" assert res["name"] == "your name" new_alias: Alias = Alias.get_by(email=r.json["alias"]) assert new_alias.note == "test note" assert len(new_alias.mailboxes) == 2 alias_used_on = AliasUsedOn.first() assert alias_used_on.alias_id == new_alias.id assert alias_used_on.hostname == "example.com"