Skip to content

Fix test get_user_apps/1

Ilja requested to merge ilja/pleroma:fix_test_get_user_apps into develop

I had a test who failed, mix test test/pleroma/web/o_auth/app_test.exs:54[1]. A user has a list of applications and this test adds them and then sees if the list it gets back is the same as the apps it added.

The problem is that the test checks a list of apps against a list it fetched from the database, but the query doesn't return an ordered list[2]. Often the test passes, but that's no guarantee.

You just want to know if the apps you added are actually there. The order of the list doesn't matter, so I changed the test accordingly.

[1]

$ mix test test/pleroma/web/o_auth/app_test.exs:54
RUM enabled: false
Compiling 12 files (.ex)
Compiling lib/pleroma/web/router.ex (it's taking more than 10s)
Compiling 8 files (.ex)
Generated pleroma app

18:24:38.617 [info]  Migrations already up
Excluding tags: [:test]
Including tags: [line: "54"]



  1) test get_user_apps/1 (Pleroma.Web.OAuth.AppTest)
     test/pleroma/web/o_auth/app_test.exs:45
     Assertion with == failed
     code:  assert App.get_user_apps(user) == apps
     left:  [
              %Pleroma.Web.OAuth.App{__meta__: #Ecto.Schema.Metadata<:loaded, "apps">, client_id: "e3dbea12-d36c-4e2f-8e69-8e501e10e76e", client_name: "Some client 2", client_secret: "aaa;/&bbb", id: 48303, inserted_at: ~N[2022-02-22 17:25:01], oauth_authorizations: #Ecto.Association.NotLoaded<association :oauth_authorizations is not loaded>, oauth_tokens: #Ecto.Association.NotLoaded<association :oauth_tokens is not loaded>, redirect_uris: "https://example.com/callback", scopes: ["read", "write", "follow", "push", "admin"], trusted: false, updated_at: ~N[2022-02-22 17:25:01], user: #Ecto.Association.NotLoaded<association :user is not loaded>, user_id: "AGk2qYl6zHBVZhBxvE", website: "https://example.com"},
              %Pleroma.Web.OAuth.App{__meta__: #Ecto.Schema.Metadata<:loaded, "apps">, client_id: "853996f8-97d0-4c6e-93a0-60576743eb29", client_name: "Some client 1", client_secret: "aaa;/&bbb", id: 48302, inserted_at: ~N[2022-02-22 17:25:01], oauth_authorizations: #Ecto.Association.NotLoaded<association :oauth_authorizations is not loaded>, oauth_tokens: #Ecto.Association.NotLoaded<association :oauth_tokens is not loaded>, redirect_uris: "https://example.com/callback", scopes: ["read", "write", "follow", "push", "admin"], trusted: false, updated_at: ~N[2022-02-22 17:25:01], user: #Ecto.Association.NotLoaded<association :user is not loaded>, user_id: "AGk2qYl6zHBVZhBxvE", website: "https://example.com"},
              %Pleroma.Web.OAuth.App{
                __meta__: #Ecto.Schema.Metadata<:loaded, "apps">,
                client_id: "726f2c4b-585e-46a0-ae80-9afdc5b08708",
                client_name: "Some client 0",
                client_secret: "aaa;/&bbb",
                id: 48301,
                inserted_at: ~N[2022-02-22 17:25:01],
                oauth_authorizations: #Ecto.Association.NotLoaded<association :oauth_authorizations is not loaded>,
                oauth_tokens: #Ecto.Association.NotLoaded<association :oauth_tokens is not loaded>,
                redirect_uris: "https://example.com/callback",
                scopes: ["read", "write", "follow", "push", "admin"],
                trusted: false,
                updated_at: ~N[2022-02-22 17:25:01],
                user: #Ecto.Association.NotLoaded<association :user is not loaded>,
                user_id: "AGk2qYl6zHBVZhBxvE",
                website: "https://example.com"
              }
            ]
     right: [
              %Pleroma.Web.OAuth.App{
                __meta__: #Ecto.Schema.Metadata<:loaded, "apps">,
                client_id: "726f2c4b-585e-46a0-ae80-9afdc5b08708",
                client_name: "Some client 0",
                client_secret: "aaa;/&bbb",
                id: 48301,
                inserted_at: ~N[2022-02-22 17:25:01],
                oauth_authorizations: #Ecto.Association.NotLoaded<association :oauth_authorizations is not loaded>,
                oauth_tokens: #Ecto.Association.NotLoaded<association :oauth_tokens is not loaded>,
                redirect_uris: "https://example.com/callback",
                scopes: ["read", "write", "follow", "push", "admin"],
                trusted: false,
                updated_at: ~N[2022-02-22 17:25:01],
                user: #Ecto.Association.NotLoaded<association :user is not loaded>,
                user_id: "AGk2qYl6zHBVZhBxvE",
                website: "https://example.com"
              },
              %Pleroma.Web.OAuth.App{__meta__: #Ecto.Schema.Metadata<:loaded, "apps">, client_id: "853996f8-97d0-4c6e-93a0-60576743eb29", client_name: "Some client 1", client_secret: "aaa;/&bbb", id: 48302, inserted_at: ~N[2022-02-22 17:25:01], oauth_authorizations: #Ecto.Association.NotLoaded<association :oauth_authorizations is not loaded>, oauth_tokens: #Ecto.Association.NotLoaded<association :oauth_tokens is not loaded>, redirect_uris: "https://example.com/callback", scopes: ["read", "write", "follow", "push", "admin"], trusted: false, updated_at: ~N[2022-02-22 17:25:01], user: #Ecto.Association.NotLoaded<association :user is not loaded>, user_id: "AGk2qYl6zHBVZhBxvE", website: "https://example.com"},
              %Pleroma.Web.OAuth.App{__meta__: #Ecto.Schema.Metadata<:loaded, "apps">, client_id: "e3dbea12-d36c-4e2f-8e69-8e501e10e76e", client_name: "Some client 2", client_secret: "aaa;/&bbb", id: 48303, inserted_at: ~N[2022-02-22 17:25:01], oauth_authorizations: #Ecto.Association.NotLoaded<association :oauth_authorizations is not loaded>, oauth_tokens: #Ecto.Association.NotLoaded<association :oauth_tokens is not loaded>, redirect_uris: "https://example.com/callback", scopes: ["read", "write", "follow", "push", "admin"], trusted: false, updated_at: ~N[2022-02-22 17:25:01], user: #Ecto.Association.NotLoaded<association :user is not loaded>, user_id: "AGk2qYl6zHBVZhBxvE", website: "https://example.com"}
            ]
     stacktrace:
       test/pleroma/web/o_auth/app_test.exs:54: (test)



Finished in 0.2 seconds (0.2s async, 0.00s sync)
5 tests, 1 failure, 4 excluded

Randomized with seed 217002
[os_mon] cpu supervisor port (cpu_sup): Erlang has closed
[os_mon] memory supervisor port (memsup): Erlang has closed

[2] https://git.pleroma.social/pleroma/pleroma/-/blob/develop/lib/pleroma/web/o_auth/app.ex#L136

Edited by Ilja

Merge request reports