From 7728c087196cfe370bdbd4f6c7ae33251760eb06 Mon Sep 17 00:00:00 2001 From: Matej Focko Date: Fri, 24 Apr 2020 14:52:58 +0200 Subject: [PATCH] Add is_fork and username to PagureProject __str__ --- ogr/services/pagure/project.py | 5 +- ...on.test_pagure.Forks.test_fork_in_str.yaml | 53 +++++++++++++++++++ tests/integration/test_pagure.py | 5 ++ 3 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 tests/integration/test_data/test_pagure/tests.integration.test_pagure.Forks.test_fork_in_str.yaml diff --git a/ogr/services/pagure/project.py b/ogr/services/pagure/project.py index eaba0551..01dafe5d 100644 --- a/ogr/services/pagure/project.py +++ b/ogr/services/pagure/project.py @@ -65,7 +65,10 @@ def __init__( self.namespace = namespace def __str__(self) -> str: - return f'PagureProject(namespace="{self.namespace}", repo="{self.repo}")' + fork_info = "" + if self._is_fork: + fork_info = f', username="{self._username}", is_fork={self._is_fork}' + return f'PagureProject(namespace="{self.namespace}", repo="{self.repo}"{fork_info})' def __eq__(self, o: object) -> bool: if not isinstance(o, PagureProject): diff --git a/tests/integration/test_data/test_pagure/tests.integration.test_pagure.Forks.test_fork_in_str.yaml b/tests/integration/test_data/test_pagure/tests.integration.test_pagure.Forks.test_fork_in_str.yaml new file mode 100644 index 00000000..2dd81df8 --- /dev/null +++ b/tests/integration/test_data/test_pagure/tests.integration.test_pagure.Forks.test_fork_in_str.yaml @@ -0,0 +1,53 @@ +_requre: + DataTypes: 1 + key_strategy: StorageKeysInspectFull + version_storage_file: 2 +unittest.case: + tests.integration.test_pagure: + ogr.services.pagure.user: + ogr.services.pagure.service: + requests.sessions: + requre.objects: + requests.sessions: + send: + - metadata: + latency: 0.8971946239471436 + module_call_list: + - unittest.case + - tests.integration.test_pagure + - ogr.services.pagure.user + - ogr.services.pagure.service + - requests.sessions + - requre.objects + - requests.sessions + - send + output: + __store_indicator: 2 + _content: + username: mfocko + _next: null + elapsed: 0.2 + encoding: null + headers: + Connection: Keep-Alive + Content-Length: '26' + Content-Security-Policy: default-src 'self';script-src 'self' + 'nonce-YqLDC0BS8d7iY8mKO7VtBbIne' https://apps.fedoraproject.org; + style-src 'self' 'nonce-YqLDC0BS8d7iY8mKO7VtBbIne'; object-src + 'none';base-uri 'self';img-src 'self' https:; + Content-Type: application/json + Date: Fri, 01 Nov 2019 13-36-03 GMT + Keep-Alive: timeout=5, max=100 + Referrer-Policy: same-origin + Server: Apache/2.4.6 (Red Hat Enterprise Linux) OpenSSL/1.0.2k-fips + mod_wsgi/3.4 Python/2.7.5 + Set-Cookie: pagure=eyJfcGVybWFuZW50Ijp0cnVlLCJjc3JmIjp7IiBiIjoiWVRZelpEQmpZemczTldaa1pUWXhZV1ptT1dZMlkyWTFOMlV4T0dWa05EY3hZalkzTmpZek1BPT0ifX0.EYRyew.BuB19eIOGCc9z2zT-uzFxvR0LG8; + Expires=Mon, 25-May-2020 12:52:11 GMT; Secure; HttpOnly; Path=/ + Strict-Transport-Security: max-age=31536000; includeSubDomains; + preload + X-Content-Type-Options: nosniff + X-Frame-Options: ALLOW-FROM https://pagure.io/ + X-Xss-Protection: 1; mode=block + raw: !!binary "" + reason: OK + status_code: 200 diff --git a/tests/integration/test_pagure.py b/tests/integration/test_pagure.py index 8b768f2b..1347c684 100644 --- a/tests/integration/test_pagure.py +++ b/tests/integration/test_pagure.py @@ -346,6 +346,11 @@ def test_fork(self): urls = fork.get_git_urls() assert "{username}" not in urls["ssh"] + def test_fork_in_str(self): + str_representation = str(self.ogr_fork) + assert 'username="' in str_representation + assert "is_fork=True" in str_representation + def test_nonexisting_fork(self): ogr_project_non_existing_fork = self.service.get_project( namespace=None,