Bladeren bron

Fix PagureHooksPagureHooktests failure when system wide config exist

When a pagure configuration file exist, for example, under
`/etc/pagure/pagure.cfg` and the `APP_URL` key in that file is
different from `http://localhost.localdomain/` then this test-case
will fail (intermediately?).

The root cause seem to be that `pagure_hook.py` keep a local
version of the configuration from the time when the file was loaded,
long time before the test-case create its configuration file.

```
pagure_config = pagure.config.reload_config()
```

The test case generate the configuration in `tests.setUp()`.

A the timing looks like this:

```
$ pytest tests/ -k test_generate_revision_change_log_full_url_fork
Using configuration file `/etc/pagure/pagure.cfg`
<reload_config from env: /etc/pagure/pagure.cfg>
<reload_config from env: /etc/pagure/pagure.cfg>
<reload_config from env: /etc/pagure/pagure.cfg>
<pagure_hook>
<reload_config from env: /etc/pagure/pagure.cfg>
<pagure_hook>

tests/test_pagure_hooks_pagure_hook.py
<reload_config from env: /etc/pagure/pagure.cfg>
<reload_config from env: /etc/pagure/pagure.cfg>
<Create config file in /tmp/pagure-tests-path-9yeilfhy/config>
<reload_config from env: /tmp/pagure-tests-path-9yeilfhy/config>
Detailed log of new commits:
[...]
```

That looks a bit inefficient, notice how the local version of
`pagure_config` inside `pagure_hook` is loaded from
`/etc/pagure/pagure.cfg` even before the test case have been chosen.

I can think of 3 ways to fix the issue.

1) Replace `"http://localhost.localdomain/"` with `mock.ANY`.
2) Pull the value of `pagure_config["APP_URL"]` from `pagure_hook`
   and use that in the test.
3) Fix the value of `pagure_config["APP_URL"]` using `mock.patch`.

Here version 3.

Signed-off-by: Dominik Wombacher <dominik@wombacher.cc>
Klaus Koder 7 maanden geleden
bovenliggende
commit
9b74b3cfa2
1 gewijzigde bestanden met toevoegingen van 12 en 0 verwijderingen
  1. 12 0
      tests/test_pagure_hooks_pagure_hook.py

+ 12 - 0
tests/test_pagure_hooks_pagure_hook.py

@@ -93,6 +93,10 @@ class PagureHooksPagureHooktests(tests.SimplePagureTest):
         # Add a README to the git repo - First commit
         tests.add_readme_git_repo(self.folder)
 
+    @mock.patch.dict(
+        "pagure.hooks.pagure_hook.pagure_config",
+        {"APP_URL": "http://localhost.localdomain/"},
+    )
     @mock.patch("pagure.hooks.pagure_hook.fixes_relation")
     def test_generate_revision_change_log_short_url(self, fixes_relation):
         """Test generate_revision_change_log when the comment contains
@@ -125,6 +129,10 @@ class PagureHooksPagureHooktests(tests.SimplePagureTest):
             "http://localhost.localdomain/",
         )
 
+    @mock.patch.dict(
+        "pagure.hooks.pagure_hook.pagure_config",
+        {"APP_URL": "http://localhost.localdomain/"},
+    )
     @mock.patch("pagure.hooks.pagure_hook.fixes_relation")
     def test_generate_revision_change_log_full_url(self, fixes_relation):
         """Test generate_revision_change_log when the comment contains
@@ -161,6 +169,10 @@ class PagureHooksPagureHooktests(tests.SimplePagureTest):
             "http://localhost.localdomain/",
         )
 
+    @mock.patch.dict(
+        "pagure.hooks.pagure_hook.pagure_config",
+        {"APP_URL": "http://localhost.localdomain/"},
+    )
     @mock.patch("pagure.hooks.pagure_hook.fixes_relation")
     def test_generate_revision_change_log_full_url_fork(self, fixes_relation):
         """Test generate_revision_change_log when the comment contains