It’s kind of complicated question and possible something wrong with my own code but I almost gave up.
tldr: in dev version of phoenix app python microservice can fetch the row from postgres table, while in test – it can’t
In the Elixir app I have the test where i calling the :create method:
test "successfully add new review source", %{
...
conn = Accounts.sign_in_user(conn, user)
conn = post conn, review_source_path(conn, :create, review_source: %{
...
})
the :create method:
def create(conn, %{"review_source" => review_source_params}) do
...
changeset = ReviewSource.changeset(%ReviewSource{}, review_source_params)
case Repo.insert(changeset) do
{:ok, review_source} ->
#test = Repo.get!(ReviewSource, review_source.id) this return not nil, so the object existing in database
url = "mocroservice_url/#{review_source.id}"
response = HTTPoison.patch!(url, "{}")
So in the HTTPoison.patch! line the microservice being called but it can’t get the object with such id:
20:39:50 web.1 | Review_SourcesDoesNotExist: <class '__main__.Review_Sources'> instance matching query does not exist:
20:39:50 web.1 | SQL: SELECT "t1"."id", "t1"."type", "t1"."url", "t1"."review_widget_id", "t1"."inserted_at", "t1"."updated_at" FROM "review_sources" AS "t1" WHERE ("t1"."id" = %s) LIMIT 1 OFFSET 0
In both elixir app and flask microservice while testing the databases name are identical – projname_test. The object id also identical but i also tried selecting all row from database in microservice route handler and it’s empty. It works correclty in dev when databases set to projname_dev, the dev version also works when databases set to projname_test.
So is there something i should know about database condition when testing?