#482 Fix tests with bodhi-client 6+
Merged by onosek. Opened by adamwill.
adamwill/fedpkg bodhi6-oidc-metadata-mock  into  master

Download 482.patch

bodhi-client was ported to use OIDC Client for authentication.
We need to mock out its OIDC provider metadata discovery because
it does an unavoidable network request, and we also need to make
sure HOME is defined in os.environ because the new OIDC code
expects to read it (in BodhiClient._build_oidc_client()).

Signed-off-by: Adam Williamson awilliam@redhat.com

After today's discussion with @churchyard I am working on it right now. Some tests need to add this env variable, because tox doesn't contain it.

This is a pull request that adds it...

Oh, my bad. I missed it. I thought it is an opened issue :)

With this the tests pass on py36 (bodhi-client 5) and py39 and py310 (bodhi-client 6) for me.

I had a different solution:

#setup
        if self.bodhi_version >= 6:
            # bodhi-client version 6 uses a storage location derived from environment
            # variable "HOME". In the tox test environment this variable is missing.
            # Therefore it is set manually for relevant test cases.
            self.tempdir = mkdtemp()
            os.environ["HOME"] = self.tempdir
#teardown
        if self.bodhi_version >= 6:
            # no need to unset os.environ["HOME"] - it is unset already
            rmdir(self.tempdir)

added for some test classes (that test bodhi operations) in test_cli.py

Since we're already using a mock patcher for EDITOR, it doesn't seem to make any sense to do HOME a different way. Using a tempdir rather than just /tmp might be an improvement though, that was a bit of laziness on my part. I'm not sure if anything actually gets written there.

I also don't see any point conditionalizing it on the version, because setting it doesn't cause any problems for older versions, so why not just do it always.

I wanted to be just safe (with conditionalizing). It is possibly not necessary. I think only directory .config was written there.

Ok, let's use your code because it uses an already existing approach.

Let me check it a little more and I will merge it. Miro asked me to build it in --target=f37-python.

rebased onto dd6fab58a845a0d96a8979a3f8cbbeff2c7ec18c

In mock build tests I realized I need to do the patch in more places, and also that we have two different ways of getting the Bodhi version, so I cleaned that up and switched to using mkdtemp. This builds in koji for me. I can do the f37-python build, don't worry about it.

rebased onto 987c00d628f4a5cfb3146cbc51c4a91bf75b93a1

...and fixed something flake8 complained about. now it passes tox and a mock build, should be good to go. I'm running an f37-python build too.

Thanks, for resolving these two ways of getting versions. That was something I had in progress too :).
mkdtemp() has a requirement - the user himself has to take care of created directories. Currently, tests don't clean them.

I tried to remove oidcmeta_patcher occurrences and tests pass too.

They fail in Koji. I think when run via tox or fedpkg's CI, the network works, so the failures don't happen. They only happen in Koji or Mock where networking is disabled. But it is always good practice to not have any unnecessary network access in a test suite, anyhow.

Try removing those occurrences and building in Koji or Mock and you should see the failures.

I'll think about the tempdir thing. Maybe we should just go back to using /tmp...:D

They fail in Koji. I think when run via tox or fedpkg's CI, the network works, so the failures don't happen. They only happen in Koji or Mock where networking is disabled. But it is always good practice to not have any unnecessary network access in a test suite, anyhow.

Try removing those occurrences and building in Koji or Mock and you should see the failures.

Yes, that is something I would find out later during building. And it would take some time to dig the correct metadata out from OIDCClient. Appreciated.

I'll think about the tempdir thing. Maybe we should just go back to using /tmp...:D

Agree, currently, it should not break anything.

rebased onto aa4529c331df32572d4ac8f73054c7d34e97db3a

OK, switched back to /tmp.

Commit b36e303b fixes this pull-request

Pull-Request has been merged by onosek

Metadata