diff --git a/osidb/signals.py b/osidb/signals.py index b6bffedcf..78024a43f 100644 --- a/osidb/signals.py +++ b/osidb/signals.py @@ -79,8 +79,10 @@ def auto_create_profile(sender, instance, created, **kwargs): if created: Profile.objects.create( user=instance, - bz_user_id=get_bz_user_id(instance.email), - jira_user_id=get_jira_user_id(instance.email), + # TODO I am disabling the external system queries for now to safe the extra API calls + # and dependencies but the full removal requires User-Profile rework and major release + # bz_user_id=get_bz_user_id(instance.email), + # jira_user_id=get_jira_user_id(instance.email), ).save() diff --git a/osidb/tests/cassettes/test_users/TestUsers.test_profile_creation.yaml b/osidb/tests/cassettes/test_users/TestUsers.test_profile_creation.yaml deleted file mode 100644 index e3b680c60..000000000 --- a/osidb/tests/cassettes/test_users/TestUsers.test_profile_creation.yaml +++ /dev/null @@ -1,360 +0,0 @@ -interactions: -- request: - body: null - headers: - Accept: - - '*/*' - Accept-Encoding: - - gzip, deflate - Connection: - - keep-alive - Content-Type: - - application/json - User-Agent: - - python-bugzilla/3.2.0 - method: GET - uri: https://example.com/rest/version - response: - body: - string: '{"version":"5.0.4.rh69"}' - headers: - Access-Control-Allow-Headers: - - origin, content-type, accept, x-requested-with - Access-Control-Allow-Origin: - - '*' - Cache-Control: - - private, must-revalidate - Connection: - - keep-alive - Content-Security-Policy: - - frame-ancestors 'self' bugzilla.redhat.com - Content-Type: - - application/json; charset=UTF-8 - Date: - - Wed, 13 Apr 2022 09:28:44 GMT - ETag: - - abwKR1TjVJZeK1gHfdLsWA - Strict-Transport-Security: - - max-age=63072000; includeSubDomains - Vary: - - Accept-Encoding,User-Agent - X-content-type-options: - - nosniff - X-xss-protection: - - 1; mode=block - content-length: - - '24' - x-rh-edge-cache-status: - - Miss from child, Miss from parent - x-rh-edge-reference-id: - - 0.1cc31302.1649842124.2b5214c - x-rh-edge-request-id: - - 2b5214c - status: - code: 200 - message: OK -- request: - body: null - headers: - Accept: - - '*/*' - Accept-Encoding: - - gzip, deflate - Connection: - - keep-alive - Content-Type: - - application/json - User-Agent: - - python-bugzilla/3.2.0 - method: GET - uri: https://example.com/rest/user?match=atorresj%40redhat.com - response: - body: - string: '{"users":[{"email":"atorresj@redhat.com","can_login":true,"saved_searches":[],"real_name":"Adrian - Torres","id":467417,"name":"atorresj@redhat.com","saved_reports":[]}]}' - headers: - Access-Control-Allow-Headers: - - origin, content-type, accept, x-requested-with - Access-Control-Allow-Origin: - - '*' - Cache-Control: - - private, must-revalidate - Connection: - - keep-alive - Content-Security-Policy: - - frame-ancestors 'self' bugzilla.redhat.com - Content-Type: - - application/json; charset=UTF-8 - Date: - - Wed, 13 Apr 2022 09:28:45 GMT - ETag: - - MBzZOYGA05NZgr51QOJ5Ng - Strict-Transport-Security: - - max-age=63072000; includeSubDomains - Vary: - - Accept-Encoding,User-Agent - X-content-type-options: - - nosniff - X-xss-protection: - - 1; mode=block - content-length: - - '168' - x-rh-edge-cache-status: - - Miss from child, Miss from parent - x-rh-edge-reference-id: - - 0.1cc31302.1649842125.2b52307 - x-rh-edge-request-id: - - 2b52307 - status: - code: 200 - message: OK -- request: - body: null - headers: - Accept: - - application/json,*.*;q=0.9 - Accept-Encoding: - - gzip, deflate - Cache-Control: - - no-cache - Connection: - - keep-alive - Content-Type: - - application/json - User-Agent: - - python-requests/2.26.0 - X-Atlassian-Token: - - no-check - method: GET - uri: https://example.com/rest/api/2/user/search?includeActive=True&includeInactive=False&maxResults=50&username=atorresj%40redhat.com - response: - body: - string: '[{"self":"https://example.com/rest/api/2/user?username=atorresj@redhat.com","key":"JIRAUSER173566","name":"atorresj@redhat.com","emailAddress":"atorresj@redhat.com","avatarUrls":{"48x48":"https://example.com/secure/useravatar?ownerId=JIRAUSER173566&avatarId=35078","24x24":"https://example.com/secure/useravatar?size=small&ownerId=JIRAUSER173566&avatarId=35078","16x16":"https://example.com/secure/useravatar?size=xsmall&ownerId=JIRAUSER173566&avatarId=35078","32x32":"https://example.com/secure/useravatar?size=medium&ownerId=JIRAUSER173566&avatarId=35078"},"displayName":"Adrian - Torres Justo","active":true,"deleted":false,"timeZone":"Europe/Brussels","locale":"en_US"}]' - headers: - Cache-Control: - - max-age=0, no-cache, no-store - Connection: - - keep-alive - Content-Security-Policy: - - sandbox - Content-Type: - - application/json;charset=UTF-8 - Date: - - Wed, 13 Apr 2022 09:28:45 GMT - Expires: - - Wed, 13 Apr 2022 09:28:45 GMT - Pragma: - - no-cache - Vary: - - User-Agent - - Accept-Encoding - content-length: - - '702' - referrer-policy: - - strict-origin-when-cross-origin - strict-transport-security: - - max-age=31536000 - x-anodeid: - - rh1-jira-prod-0 - x-arequestid: - - 568x3413708x2 - x-asessionid: - - 1h6tx3h - x-content-type-options: - - nosniff - x-frame-options: - - SAMEORIGIN - x-rh-edge-cache-status: - - Miss from child, Miss from parent - x-rh-edge-reference-id: - - 0.6ff06e68.1649842125.127c739d - x-rh-edge-request-id: - - 127c739d - x-seraph-loginreason: - - OK - x-xss-protection: - - 1; mode=block - status: - code: 200 - message: OK -- request: - body: null - headers: - Accept: - - '*/*' - Accept-Encoding: - - gzip, deflate - Connection: - - keep-alive - Content-Type: - - application/json - User-Agent: - - python-bugzilla/3.2.0 - method: GET - uri: https://example.com/rest/version - response: - body: - string: '{"version":"5.0.4.rh69"}' - headers: - Access-Control-Allow-Headers: - - origin, content-type, accept, x-requested-with - Access-Control-Allow-Origin: - - '*' - Cache-Control: - - private, must-revalidate - Connection: - - keep-alive - Content-Security-Policy: - - frame-ancestors 'self' bugzilla.redhat.com - Content-Type: - - application/json; charset=UTF-8 - Date: - - Wed, 13 Apr 2022 09:28:46 GMT - ETag: - - abwKR1TjVJZeK1gHfdLsWA - Strict-Transport-Security: - - max-age=63072000; includeSubDomains - Vary: - - Accept-Encoding,User-Agent - X-content-type-options: - - nosniff - X-xss-protection: - - 1; mode=block - content-length: - - '24' - x-rh-edge-cache-status: - - Miss from child, Miss from parent - x-rh-edge-reference-id: - - 0.1cc31302.1649842126.2b526c3 - x-rh-edge-request-id: - - 2b526c3 - status: - code: 200 - message: OK -- request: - body: null - headers: - Accept: - - '*/*' - Accept-Encoding: - - gzip, deflate - Connection: - - keep-alive - Content-Type: - - application/json - User-Agent: - - python-bugzilla/3.2.0 - method: GET - uri: https://example.com/rest/user?names=atorresj%40redhat.com - response: - body: - string: '{"users":[{"saved_reports":[],"email":"atorresj@redhat.com","can_login":true,"name":"atorresj@redhat.com","saved_searches":[],"id":467417,"real_name":"Adrian - Torres"}]}' - headers: - Access-Control-Allow-Headers: - - origin, content-type, accept, x-requested-with - Access-Control-Allow-Origin: - - '*' - Cache-Control: - - private, must-revalidate - Connection: - - keep-alive - Content-Security-Policy: - - frame-ancestors 'self' bugzilla.redhat.com - Content-Type: - - application/json; charset=UTF-8 - Date: - - Wed, 13 Apr 2022 09:28:46 GMT - ETag: - - MBzZOYGA05NZgr51QOJ5Ng - Strict-Transport-Security: - - max-age=63072000; includeSubDomains - Vary: - - Accept-Encoding,User-Agent - X-content-type-options: - - nosniff - X-xss-protection: - - 1; mode=block - content-length: - - '168' - x-rh-edge-cache-status: - - Miss from child, Miss from parent - x-rh-edge-reference-id: - - 0.1cc31302.1649842126.2b52843 - x-rh-edge-request-id: - - 2b52843 - status: - code: 200 - message: OK -- request: - body: null - headers: - Accept: - - application/json,*.*;q=0.9 - Accept-Encoding: - - gzip, deflate - Cache-Control: - - no-cache - Connection: - - keep-alive - Content-Type: - - application/json - User-Agent: - - python-requests/2.26.0 - X-Atlassian-Token: - - no-check - method: GET - uri: https://example.com/rest/api/2/user?username=atorresj%40redhat.com - response: - body: - string: '{"self":"https://example.com/rest/api/2/user?username=atorresj@redhat.com","key":"JIRAUSER173566","name":"atorresj@redhat.com","emailAddress":"atorresj@redhat.com","avatarUrls":{"48x48":"https://example.com/secure/useravatar?ownerId=JIRAUSER173566&avatarId=35078","24x24":"https://example.com/secure/useravatar?size=small&ownerId=JIRAUSER173566&avatarId=35078","16x16":"https://example.com/secure/useravatar?size=xsmall&ownerId=JIRAUSER173566&avatarId=35078","32x32":"https://example.com/secure/useravatar?size=medium&ownerId=JIRAUSER173566&avatarId=35078"},"displayName":"Adrian - Torres Justo","active":true,"deleted":false,"timeZone":"Europe/Brussels","locale":"en_US","groups":{"size":10,"items":[]},"applicationRoles":{"size":1,"items":[]},"expand":"groups,applicationRoles"}' - headers: - Cache-Control: - - max-age=0, no-cache, no-store - Connection: - - keep-alive - Content-Security-Policy: - - sandbox - Content-Type: - - application/json;charset=UTF-8 - Date: - - Wed, 13 Apr 2022 09:28:46 GMT - Expires: - - Wed, 13 Apr 2022 09:28:46 GMT - Pragma: - - no-cache - Vary: - - User-Agent - - Accept-Encoding - content-length: - - '808' - referrer-policy: - - strict-origin-when-cross-origin - strict-transport-security: - - max-age=31536000 - x-anodeid: - - rh1-jira-prod-2 - x-arequestid: - - 568x3171448x3 - x-asessionid: - - mev8p2 - x-content-type-options: - - nosniff - x-frame-options: - - SAMEORIGIN - x-rh-edge-cache-status: - - Miss from child, Miss from parent - x-rh-edge-reference-id: - - 0.6ff06e68.1649842126.127c81f2 - x-rh-edge-request-id: - - 127c81f2 - x-seraph-loginreason: - - OK - x-xss-protection: - - 1; mode=block - status: - code: 200 - message: OK -version: 1 diff --git a/osidb/tests/cassettes/test_users/TestUsers.test_profile_creation_no_account.yaml b/osidb/tests/cassettes/test_users/TestUsers.test_profile_creation_no_account.yaml deleted file mode 100644 index 4997b57d3..000000000 --- a/osidb/tests/cassettes/test_users/TestUsers.test_profile_creation_no_account.yaml +++ /dev/null @@ -1,179 +0,0 @@ -interactions: -- request: - body: null - headers: - Accept: - - '*/*' - Accept-Encoding: - - gzip, deflate - Connection: - - keep-alive - Content-Type: - - application/json - User-Agent: - - python-bugzilla/3.2.0 - method: GET - uri: https://example.com/rest/version - response: - body: - string: '{"version":"5.0.4.rh69"}' - headers: - Access-Control-Allow-Headers: - - origin, content-type, accept, x-requested-with - Access-Control-Allow-Origin: - - '*' - Cache-Control: - - private, must-revalidate - Connection: - - keep-alive - Content-Security-Policy: - - frame-ancestors 'self' bugzilla.redhat.com - Content-Type: - - application/json; charset=UTF-8 - Date: - - Fri, 15 Apr 2022 14:32:58 GMT - ETag: - - abwKR1TjVJZeK1gHfdLsWA - Strict-Transport-Security: - - max-age=63072000; includeSubDomains - Vary: - - Accept-Encoding,User-Agent - X-content-type-options: - - nosniff - X-xss-protection: - - 1; mode=block - content-length: - - '24' - x-rh-edge-cache-status: - - Miss from child, Miss from parent - x-rh-edge-reference-id: - - 0.1cc31302.1650033178.3aa9283 - x-rh-edge-request-id: - - 3aa9283 - status: - code: 200 - message: OK -- request: - body: null - headers: - Accept: - - '*/*' - Accept-Encoding: - - gzip, deflate - Connection: - - keep-alive - Content-Type: - - application/json - User-Agent: - - python-bugzilla/3.2.0 - method: GET - uri: https://example.com/rest/user?match=foobarbaz%40example.com - response: - body: - string: '{"users":[]}' - headers: - Access-Control-Allow-Headers: - - origin, content-type, accept, x-requested-with - Access-Control-Allow-Origin: - - '*' - Cache-Control: - - private, must-revalidate - Connection: - - keep-alive - Content-Security-Policy: - - frame-ancestors 'self' bugzilla.redhat.com - Content-Type: - - application/json; charset=UTF-8 - Date: - - Fri, 15 Apr 2022 14:32:59 GMT - ETag: - - lcSD3PP7LvrIt7WBKfsHPw - Strict-Transport-Security: - - max-age=63072000; includeSubDomains - Vary: - - Accept-Encoding,User-Agent - X-content-type-options: - - nosniff - X-xss-protection: - - 1; mode=block - content-length: - - '12' - x-rh-edge-cache-status: - - Miss from child, Miss from parent - x-rh-edge-reference-id: - - 0.1cc31302.1650033179.3aa93e5 - x-rh-edge-request-id: - - 3aa93e5 - status: - code: 200 - message: OK -- request: - body: null - headers: - Accept: - - application/json,*.*;q=0.9 - Accept-Encoding: - - gzip, deflate - Cache-Control: - - no-cache - Connection: - - keep-alive - Content-Type: - - application/json - User-Agent: - - python-requests/2.26.0 - X-Atlassian-Token: - - no-check - method: GET - uri: https://example.com/rest/api/2/user/search?includeActive=True&includeInactive=False&maxResults=50&username=foobarbaz%40example.com - response: - body: - string: '[]' - headers: - Cache-Control: - - max-age=0, no-cache, no-store - Connection: - - keep-alive - Content-Security-Policy: - - sandbox - Content-Type: - - application/json;charset=UTF-8 - Date: - - Fri, 15 Apr 2022 14:32:59 GMT - Expires: - - Fri, 15 Apr 2022 14:32:59 GMT - Pragma: - - no-cache - Vary: - - User-Agent - - Accept-Encoding - content-length: - - '2' - referrer-policy: - - strict-origin-when-cross-origin - strict-transport-security: - - max-age=31536000 - x-anodeid: - - rh1-jira-prod-1 - x-arequestid: - - 872x6090654x2 - x-asessionid: - - h2u1h - x-content-type-options: - - nosniff - x-frame-options: - - SAMEORIGIN - x-rh-edge-cache-status: - - Miss from child, Miss from parent - x-rh-edge-reference-id: - - 0.6df06e68.1650033179.19cef04f - x-rh-edge-request-id: - - 19cef04f - x-seraph-loginreason: - - OK - x-xss-protection: - - 1; mode=block - status: - code: 200 - message: OK -version: 1 diff --git a/osidb/tests/test_users.py b/osidb/tests/test_users.py index 2cdd65edf..d2669aa45 100644 --- a/osidb/tests/test_users.py +++ b/osidb/tests/test_users.py @@ -1,47 +1,12 @@ import pytest -from bugzilla import Bugzilla from django.contrib.auth.models import User -from jira import JIRA - -from osidb.helpers import get_env pytestmark = pytest.mark.unit class TestUsers: @pytest.mark.enable_signals - @pytest.mark.vcr def test_profile_creation_no_account(self, test_user_dict_no_account): new_user = User.objects.create(**test_user_dict_no_account) assert new_user.profile - assert not new_user.profile.bz_user_id - assert not new_user.profile.jira_user_id - - @pytest.mark.enable_signals - @pytest.mark.vcr - def test_profile_creation(self, bugzilla_token, jira_token, test_user_dict): - new_user = User.objects.create(**test_user_dict) - - assert new_user.profile - assert new_user.profile.bz_user_id == "atorresj@redhat.com" - assert new_user.profile.jira_user_id == "atorresj@redhat.com" - # test that profile serialization works - assert str(new_user.profile) == "foo" - - # verify that the user info can be fetched from bugzilla / jira - bz_url = get_env("BZIMPORT_BZ_URL", "https://bugzilla.redhat.com") - jira_url = get_env("JIRA_URL", "https://issues.redhat.com") - bz_api = Bugzilla(bz_url, api_key=bugzilla_token, force_rest=True) - jira_api = JIRA( - options={ - "server": jira_url, - # avoid auto-updating the lib - "check_update": False, - }, - token_auth=jira_token, - get_server_info=False, - ) - - assert bz_api.getuser(new_user.profile.bz_user_id) - assert jira_api.user(new_user.profile.jira_user_id)