diff --git a/src/postorius/tests/fixtures/vcr_cassettes/test_list_members_add_owner.yaml b/src/postorius/tests/fixtures/vcr_cassettes/test_list_members_add_owner.yaml index 68685b9..1cc54b2 100644 --- a/src/postorius/tests/fixtures/vcr_cassettes/test_list_members_add_owner.yaml +++ b/src/postorius/tests/fixtures/vcr_cassettes/test_list_members_add_owner.yaml @@ -74,11 +74,26 @@ method: !!python/unicode 'POST' uri: http://localhost:9001/3.0/domains response: - body: {string: !!python/unicode ''} + body: {string: !!python/unicode 'Duplicate email host: example.com'} headers: - content-length: ['0'] - location: ['http://localhost:9001/3.0/domains/example.com'] - status: {code: 201, message: Created} + content-length: ['33'] + content-type: [application/json; charset=utf-8] + status: {code: 400, message: Bad Request} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode 'GET' + uri: http://localhost:9001/3.0/domains/example.com + response: + body: {string: !!python/unicode '{"base_url": "http://example.com", "description": + null, "http_etag": "\"e736411818ff1815ca83575e0958c38c5188f0a4\"", "mail_host": + "example.com", "self_link": "http://localhost:9001/3.0/domains/example.com", + "url_host": "example.com"}'} + headers: + content-length: ['233'] + content-type: [application/json; charset=utf-8] + status: {code: 200, message: OK} - request: body: null headers: diff --git a/src/postorius/tests/fixtures/vcr_cassettes/test_list_members_add_owner_by_owner.yaml b/src/postorius/tests/fixtures/vcr_cassettes/test_list_members_add_owner_by_owner.yaml new file mode 100644 index 0000000..8dbe3c0 --- /dev/null +++ b/src/postorius/tests/fixtures/vcr_cassettes/test_list_members_add_owner_by_owner.yaml @@ -0,0 +1,502 @@ +interactions: +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode 'GET' + uri: http://localhost:9001/3.0/lists/foo@example.com + response: + body: {string: !!python/unicode '{"display_name": "Foo", "fqdn_listname": "foo@example.com", + "http_etag": "\"698a819bbb6b902096a8c5543cc7fac2328960d5\"", "list_id": "foo.example.com", + "list_name": "foo", "mail_host": "example.com", "member_count": 0, "self_link": + "http://localhost:9001/3.0/lists/foo.example.com", "volume": 1}'} + headers: + content-length: ['294'] + content-type: [application/json; charset=utf-8] + status: {code: 200, message: OK} +- request: + body: subscriber=su%40example.com&role=owner&list_id=foo.example.com + headers: + accept-encoding: ['gzip, deflate'] + !!python/unicode 'content-type': [!!python/unicode 'application/x-www-form-urlencoded'] + method: !!python/unicode 'POST' + uri: http://localhost:9001/3.0/members + response: + body: {string: !!python/unicode ''} + headers: + content-length: ['0'] + location: ['http://localhost:9001/3.0/members/2'] + status: {code: 201, message: Created} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode 'GET' + uri: http://localhost:9001/3.0/lists/foo.example.com/roster/owner + response: + body: {string: !!python/unicode '{"entries": [{"address": "http://localhost:9001/3.0/addresses/su@example.com", + "delivery_mode": "regular", "email": "su@example.com", "http_etag": "\"50eebd88044b56c4a2073d93c0bf5c5da54f9b3c\"", + "list_id": "foo.example.com", "member_id": 2, "role": "owner", "self_link": + "http://localhost:9001/3.0/members/2", "user": "http://localhost:9001/3.0/users/2"}], + "http_etag": "\"902cfc083f243f174e2457cc0b5ef0e669c1cae3\"", "start": 0, "total_size": + 1}'} + headers: + content-length: ['446'] + content-type: [application/json; charset=utf-8] + status: {code: 200, message: OK} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode 'GET' + uri: http://localhost:9001/3.0/lists/foo@example.com + response: + body: {string: !!python/unicode '{"display_name": "Foo", "fqdn_listname": "foo@example.com", + "http_etag": "\"698a819bbb6b902096a8c5543cc7fac2328960d5\"", "list_id": "foo.example.com", + "list_name": "foo", "mail_host": "example.com", "member_count": 0, "self_link": + "http://localhost:9001/3.0/lists/foo.example.com", "volume": 1}'} + headers: + content-length: ['294'] + content-type: [application/json; charset=utf-8] + status: {code: 200, message: OK} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode 'GET' + uri: http://localhost:9001/3.0/users/su@example.com + response: + body: {string: !!python/unicode '{"created_on": "2005-08-01T07:49:23", "http_etag": + "\"b36f8ca1d91d583901c768dc116815282d469c66\"", "is_server_owner": false, + "self_link": "http://localhost:9001/3.0/users/2", "user_id": 2}'} + headers: + content-length: ['188'] + content-type: [application/json; charset=utf-8] + status: {code: 200, message: OK} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode 'GET' + uri: http://localhost:9001/3.0/users/2/addresses + response: + body: {string: !!python/unicode '{"entries": [{"email": "su@example.com", "http_etag": + "\"a8988d233ad4b9e8641ad5d75553912565efec83\"", "original_email": "su@example.com", + "registered_on": "2005-08-01T07:49:23", "self_link": "http://localhost:9001/3.0/addresses/su@example.com", + "user": "http://localhost:9001/3.0/users/2"}], "http_etag": "\"7cc723891821fbf8b0974c2ec407cca11fbb6726\"", + "start": 0, "total_size": 1}'} + headers: + content-length: ['381'] + content-type: [application/json; charset=utf-8] + status: {code: 200, message: OK} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode 'GET' + uri: http://localhost:9001/3.0/addresses/su@example.com + response: + body: {string: !!python/unicode '{"email": "su@example.com", "http_etag": "\"a8988d233ad4b9e8641ad5d75553912565efec83\"", + "original_email": "su@example.com", "registered_on": "2005-08-01T07:49:23", + "self_link": "http://localhost:9001/3.0/addresses/su@example.com", "user": + "http://localhost:9001/3.0/users/2"}'} + headers: + content-length: ['276'] + content-type: [application/json; charset=utf-8] + status: {code: 200, message: OK} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode 'GET' + uri: http://localhost:9001/3.0/lists/foo.example.com/roster/owner + response: + body: {string: !!python/unicode '{"entries": [{"address": "http://localhost:9001/3.0/addresses/su@example.com", + "delivery_mode": "regular", "email": "su@example.com", "http_etag": "\"50eebd88044b56c4a2073d93c0bf5c5da54f9b3c\"", + "list_id": "foo.example.com", "member_id": 2, "role": "owner", "self_link": + "http://localhost:9001/3.0/members/2", "user": "http://localhost:9001/3.0/users/2"}], + "http_etag": "\"902cfc083f243f174e2457cc0b5ef0e669c1cae3\"", "start": 0, "total_size": + 1}'} + headers: + content-length: ['446'] + content-type: [application/json; charset=utf-8] + status: {code: 200, message: OK} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode 'GET' + uri: http://localhost:9001/3.0/lists/foo.example.com/roster/moderator + response: + body: {string: !!python/unicode '{"http_etag": "\"32223434a0f3af4cdc4673d1fbc5bac1f6d98fd3\"", + "start": 0, "total_size": 0}'} + headers: + content-length: ['90'] + content-type: [application/json; charset=utf-8] + status: {code: 200, message: OK} +- request: + body: subscriber=newowner%40example.com&role=owner&list_id=foo.example.com + headers: + accept-encoding: ['gzip, deflate'] + !!python/unicode 'content-type': [!!python/unicode 'application/x-www-form-urlencoded'] + method: !!python/unicode 'POST' + uri: http://localhost:9001/3.0/members + response: + body: {string: !!python/unicode ''} + headers: + content-length: ['0'] + location: ['http://localhost:9001/3.0/members/3'] + status: {code: 201, message: Created} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode 'GET' + uri: http://localhost:9001/3.0/lists/foo@example.com/roster/member?count=1&page=1 + response: + body: {string: !!python/unicode '{"http_etag": "\"32223434a0f3af4cdc4673d1fbc5bac1f6d98fd3\"", + "start": 0, "total_size": 0}'} + headers: + content-length: ['90'] + content-type: [application/json; charset=utf-8] + status: {code: 200, message: OK} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode 'GET' + uri: http://localhost:9001/3.0/lists/foo@example.com/roster/member?count=25&page=1 + response: + body: {string: !!python/unicode '{"http_etag": "\"32223434a0f3af4cdc4673d1fbc5bac1f6d98fd3\"", + "start": 0, "total_size": 0}'} + headers: + content-length: ['90'] + content-type: [application/json; charset=utf-8] + status: {code: 200, message: OK} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode 'GET' + uri: http://localhost:9001/3.0/lists/foo.example.com/roster/owner + response: + body: {string: !!python/unicode '{"entries": [{"address": "http://localhost:9001/3.0/addresses/newowner@example.com", + "delivery_mode": "regular", "email": "newowner@example.com", "http_etag": + "\"0a19a1b74530e9a6e79d0164fd3504f7b06cd5bd\"", "list_id": "foo.example.com", + "member_id": 3, "role": "owner", "self_link": "http://localhost:9001/3.0/members/3", + "user": "http://localhost:9001/3.0/users/1"}, {"address": "http://localhost:9001/3.0/addresses/su@example.com", + "delivery_mode": "regular", "email": "su@example.com", "http_etag": "\"50eebd88044b56c4a2073d93c0bf5c5da54f9b3c\"", + "list_id": "foo.example.com", "member_id": 2, "role": "owner", "self_link": + "http://localhost:9001/3.0/members/2", "user": "http://localhost:9001/3.0/users/2"}], + "http_etag": "\"c0fdf1ee97951fabb09248a5b663efb29ead01cf\"", "start": 0, "total_size": + 2}'} + headers: + content-length: ['801'] + content-type: [application/json; charset=utf-8] + status: {code: 200, message: OK} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode 'GET' + uri: http://localhost:9001/3.0/lists/foo.example.com/roster/moderator + response: + body: {string: !!python/unicode '{"http_etag": "\"32223434a0f3af4cdc4673d1fbc5bac1f6d98fd3\"", + "start": 0, "total_size": 0}'} + headers: + content-length: ['90'] + content-type: [application/json; charset=utf-8] + status: {code: 200, message: OK} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode 'GET' + uri: http://localhost:9001/3.0/lists/foo.example.com/roster/owner + response: + body: {string: !!python/unicode '{"entries": [{"address": "http://localhost:9001/3.0/addresses/newowner@example.com", + "delivery_mode": "regular", "email": "newowner@example.com", "http_etag": + "\"0a19a1b74530e9a6e79d0164fd3504f7b06cd5bd\"", "list_id": "foo.example.com", + "member_id": 3, "role": "owner", "self_link": "http://localhost:9001/3.0/members/3", + "user": "http://localhost:9001/3.0/users/1"}, {"address": "http://localhost:9001/3.0/addresses/su@example.com", + "delivery_mode": "regular", "email": "su@example.com", "http_etag": "\"50eebd88044b56c4a2073d93c0bf5c5da54f9b3c\"", + "list_id": "foo.example.com", "member_id": 2, "role": "owner", "self_link": + "http://localhost:9001/3.0/members/2", "user": "http://localhost:9001/3.0/users/2"}], + "http_etag": "\"c0fdf1ee97951fabb09248a5b663efb29ead01cf\"", "start": 0, "total_size": + 2}'} + headers: + content-length: ['801'] + content-type: [application/json; charset=utf-8] + status: {code: 200, message: OK} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode 'GET' + uri: http://localhost:9001/3.0/lists/foo@example.com + response: + body: {string: !!python/unicode '{"display_name": "Foo", "fqdn_listname": "foo@example.com", + "http_etag": "\"698a819bbb6b902096a8c5543cc7fac2328960d5\"", "list_id": "foo.example.com", + "list_name": "foo", "mail_host": "example.com", "member_count": 0, "self_link": + "http://localhost:9001/3.0/lists/foo.example.com", "volume": 1}'} + headers: + content-length: ['294'] + content-type: [application/json; charset=utf-8] + status: {code: 200, message: OK} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode 'GET' + uri: http://localhost:9001/3.0/users/su@example.com + response: + body: {string: !!python/unicode '{"created_on": "2005-08-01T07:49:23", "http_etag": + "\"b36f8ca1d91d583901c768dc116815282d469c66\"", "is_server_owner": false, + "self_link": "http://localhost:9001/3.0/users/2", "user_id": 2}'} + headers: + content-length: ['188'] + content-type: [application/json; charset=utf-8] + status: {code: 200, message: OK} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode 'GET' + uri: http://localhost:9001/3.0/users/2/addresses + response: + body: {string: !!python/unicode '{"entries": [{"email": "su@example.com", "http_etag": + "\"a8988d233ad4b9e8641ad5d75553912565efec83\"", "original_email": "su@example.com", + "registered_on": "2005-08-01T07:49:23", "self_link": "http://localhost:9001/3.0/addresses/su@example.com", + "user": "http://localhost:9001/3.0/users/2"}], "http_etag": "\"7cc723891821fbf8b0974c2ec407cca11fbb6726\"", + "start": 0, "total_size": 1}'} + headers: + content-length: ['381'] + content-type: [application/json; charset=utf-8] + status: {code: 200, message: OK} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode 'GET' + uri: http://localhost:9001/3.0/addresses/su@example.com + response: + body: {string: !!python/unicode '{"email": "su@example.com", "http_etag": "\"a8988d233ad4b9e8641ad5d75553912565efec83\"", + "original_email": "su@example.com", "registered_on": "2005-08-01T07:49:23", + "self_link": "http://localhost:9001/3.0/addresses/su@example.com", "user": + "http://localhost:9001/3.0/users/2"}'} + headers: + content-length: ['276'] + content-type: [application/json; charset=utf-8] + status: {code: 200, message: OK} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode 'GET' + uri: http://localhost:9001/3.0/lists/foo.example.com/roster/owner + response: + body: {string: !!python/unicode '{"entries": [{"address": "http://localhost:9001/3.0/addresses/newowner@example.com", + "delivery_mode": "regular", "email": "newowner@example.com", "http_etag": + "\"0a19a1b74530e9a6e79d0164fd3504f7b06cd5bd\"", "list_id": "foo.example.com", + "member_id": 3, "role": "owner", "self_link": "http://localhost:9001/3.0/members/3", + "user": "http://localhost:9001/3.0/users/1"}, {"address": "http://localhost:9001/3.0/addresses/su@example.com", + "delivery_mode": "regular", "email": "su@example.com", "http_etag": "\"50eebd88044b56c4a2073d93c0bf5c5da54f9b3c\"", + "list_id": "foo.example.com", "member_id": 2, "role": "owner", "self_link": + "http://localhost:9001/3.0/members/2", "user": "http://localhost:9001/3.0/users/2"}], + "http_etag": "\"c0fdf1ee97951fabb09248a5b663efb29ead01cf\"", "start": 0, "total_size": + 2}'} + headers: + content-length: ['801'] + content-type: [application/json; charset=utf-8] + status: {code: 200, message: OK} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode 'GET' + uri: http://localhost:9001/3.0/lists/foo@example.com + response: + body: {string: !!python/unicode '{"display_name": "Foo", "fqdn_listname": "foo@example.com", + "http_etag": "\"698a819bbb6b902096a8c5543cc7fac2328960d5\"", "list_id": "foo.example.com", + "list_name": "foo", "mail_host": "example.com", "member_count": 0, "self_link": + "http://localhost:9001/3.0/lists/foo.example.com", "volume": 1}'} + headers: + content-length: ['294'] + content-type: [application/json; charset=utf-8] + status: {code: 200, message: OK} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode 'GET' + uri: http://localhost:9001/3.0/lists/foo.example.com/roster/owner + response: + body: {string: !!python/unicode '{"entries": [{"address": "http://localhost:9001/3.0/addresses/newowner@example.com", + "delivery_mode": "regular", "email": "newowner@example.com", "http_etag": + "\"0a19a1b74530e9a6e79d0164fd3504f7b06cd5bd\"", "list_id": "foo.example.com", + "member_id": 3, "role": "owner", "self_link": "http://localhost:9001/3.0/members/3", + "user": "http://localhost:9001/3.0/users/1"}, {"address": "http://localhost:9001/3.0/addresses/su@example.com", + "delivery_mode": "regular", "email": "su@example.com", "http_etag": "\"50eebd88044b56c4a2073d93c0bf5c5da54f9b3c\"", + "list_id": "foo.example.com", "member_id": 2, "role": "owner", "self_link": + "http://localhost:9001/3.0/members/2", "user": "http://localhost:9001/3.0/users/2"}], + "http_etag": "\"c0fdf1ee97951fabb09248a5b663efb29ead01cf\"", "start": 0, "total_size": + 2}'} + headers: + content-length: ['801'] + content-type: [application/json; charset=utf-8] + status: {code: 200, message: OK} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode 'DELETE' + uri: http://localhost:9001/3.0/lists/foo@example.com/owner/newowner@example.com + response: + body: {string: !!python/unicode ''} + headers: + content-length: ['0'] + status: {code: 204, message: No Content} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode 'GET' + uri: http://localhost:9001/3.0/lists/foo.example.com/roster/owner + response: + body: {string: !!python/unicode '{"entries": [{"address": "http://localhost:9001/3.0/addresses/su@example.com", + "delivery_mode": "regular", "email": "su@example.com", "http_etag": "\"50eebd88044b56c4a2073d93c0bf5c5da54f9b3c\"", + "list_id": "foo.example.com", "member_id": 2, "role": "owner", "self_link": + "http://localhost:9001/3.0/members/2", "user": "http://localhost:9001/3.0/users/2"}], + "http_etag": "\"902cfc083f243f174e2457cc0b5ef0e669c1cae3\"", "start": 0, "total_size": + 1}'} + headers: + content-length: ['446'] + content-type: [application/json; charset=utf-8] + status: {code: 200, message: OK} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode 'GET' + uri: http://localhost:9001/3.0/lists/foo@example.com + response: + body: {string: !!python/unicode '{"display_name": "Foo", "fqdn_listname": "foo@example.com", + "http_etag": "\"698a819bbb6b902096a8c5543cc7fac2328960d5\"", "list_id": "foo.example.com", + "list_name": "foo", "mail_host": "example.com", "member_count": 0, "self_link": + "http://localhost:9001/3.0/lists/foo.example.com", "volume": 1}'} + headers: + content-length: ['294'] + content-type: [application/json; charset=utf-8] + status: {code: 200, message: OK} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode 'GET' + uri: http://localhost:9001/3.0/users/su@example.com + response: + body: {string: !!python/unicode '{"created_on": "2005-08-01T07:49:23", "http_etag": + "\"b36f8ca1d91d583901c768dc116815282d469c66\"", "is_server_owner": false, + "self_link": "http://localhost:9001/3.0/users/2", "user_id": 2}'} + headers: + content-length: ['188'] + content-type: [application/json; charset=utf-8] + status: {code: 200, message: OK} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode 'GET' + uri: http://localhost:9001/3.0/users/2/addresses + response: + body: {string: !!python/unicode '{"entries": [{"email": "su@example.com", "http_etag": + "\"a8988d233ad4b9e8641ad5d75553912565efec83\"", "original_email": "su@example.com", + "registered_on": "2005-08-01T07:49:23", "self_link": "http://localhost:9001/3.0/addresses/su@example.com", + "user": "http://localhost:9001/3.0/users/2"}], "http_etag": "\"7cc723891821fbf8b0974c2ec407cca11fbb6726\"", + "start": 0, "total_size": 1}'} + headers: + content-length: ['381'] + content-type: [application/json; charset=utf-8] + status: {code: 200, message: OK} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode 'GET' + uri: http://localhost:9001/3.0/addresses/su@example.com + response: + body: {string: !!python/unicode '{"email": "su@example.com", "http_etag": "\"a8988d233ad4b9e8641ad5d75553912565efec83\"", + "original_email": "su@example.com", "registered_on": "2005-08-01T07:49:23", + "self_link": "http://localhost:9001/3.0/addresses/su@example.com", "user": + "http://localhost:9001/3.0/users/2"}'} + headers: + content-length: ['276'] + content-type: [application/json; charset=utf-8] + status: {code: 200, message: OK} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode 'GET' + uri: http://localhost:9001/3.0/lists/foo.example.com/roster/owner + response: + body: {string: !!python/unicode '{"entries": [{"address": "http://localhost:9001/3.0/addresses/su@example.com", + "delivery_mode": "regular", "email": "su@example.com", "http_etag": "\"50eebd88044b56c4a2073d93c0bf5c5da54f9b3c\"", + "list_id": "foo.example.com", "member_id": 2, "role": "owner", "self_link": + "http://localhost:9001/3.0/members/2", "user": "http://localhost:9001/3.0/users/2"}], + "http_etag": "\"902cfc083f243f174e2457cc0b5ef0e669c1cae3\"", "start": 0, "total_size": + 1}'} + headers: + content-length: ['446'] + content-type: [application/json; charset=utf-8] + status: {code: 200, message: OK} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode 'GET' + uri: http://localhost:9001/3.0/lists/foo@example.com + response: + body: {string: !!python/unicode '{"display_name": "Foo", "fqdn_listname": "foo@example.com", + "http_etag": "\"698a819bbb6b902096a8c5543cc7fac2328960d5\"", "list_id": "foo.example.com", + "list_name": "foo", "mail_host": "example.com", "member_count": 0, "self_link": + "http://localhost:9001/3.0/lists/foo.example.com", "volume": 1}'} + headers: + content-length: ['294'] + content-type: [application/json; charset=utf-8] + status: {code: 200, message: OK} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode 'GET' + uri: http://localhost:9001/3.0/lists/foo.example.com/roster/owner + response: + body: {string: !!python/unicode '{"entries": [{"address": "http://localhost:9001/3.0/addresses/su@example.com", + "delivery_mode": "regular", "email": "su@example.com", "http_etag": "\"50eebd88044b56c4a2073d93c0bf5c5da54f9b3c\"", + "list_id": "foo.example.com", "member_id": 2, "role": "owner", "self_link": + "http://localhost:9001/3.0/members/2", "user": "http://localhost:9001/3.0/users/2"}], + "http_etag": "\"902cfc083f243f174e2457cc0b5ef0e669c1cae3\"", "start": 0, "total_size": + 1}'} + headers: + content-length: ['446'] + content-type: [application/json; charset=utf-8] + status: {code: 200, message: OK} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode 'GET' + uri: http://localhost:9001/3.0/lists/foo.example.com/roster/owner + response: + body: {string: !!python/unicode '{"entries": [{"address": "http://localhost:9001/3.0/addresses/su@example.com", + "delivery_mode": "regular", "email": "su@example.com", "http_etag": "\"50eebd88044b56c4a2073d93c0bf5c5da54f9b3c\"", + "list_id": "foo.example.com", "member_id": 2, "role": "owner", "self_link": + "http://localhost:9001/3.0/members/2", "user": "http://localhost:9001/3.0/users/2"}], + "http_etag": "\"902cfc083f243f174e2457cc0b5ef0e669c1cae3\"", "start": 0, "total_size": + 1}'} + headers: + content-length: ['446'] + content-type: [application/json; charset=utf-8] + status: {code: 200, message: OK} +version: 1 diff --git a/src/postorius/tests/fixtures/vcr_cassettes/test_list_members_add_owner_new_owner_added.yaml b/src/postorius/tests/fixtures/vcr_cassettes/test_list_members_add_owner_new_owner_added.yaml index 0c62831..1cfbbf7 100644 --- a/src/postorius/tests/fixtures/vcr_cassettes/test_list_members_add_owner_new_owner_added.yaml +++ b/src/postorius/tests/fixtures/vcr_cassettes/test_list_members_add_owner_new_owner_added.yaml @@ -63,145 +63,6 @@ body: {string: !!python/unicode ''} headers: content-length: ['0'] - location: ['http://localhost:9001/3.0/members/109'] - status: {code: 201, message: Created} -- request: - body: null - headers: - accept-encoding: ['gzip, deflate'] - method: !!python/unicode 'GET' - uri: http://localhost:9001/3.0/lists/foo@example.com/roster/member?count=1&page=1 - response: - body: {string: !!python/unicode '{"http_etag": "\"32223434a0f3af4cdc4673d1fbc5bac1f6d98fd3\"", - "start": 0, "total_size": 0}'} - headers: - content-length: ['90'] - content-type: [application/json; charset=utf-8] - status: {code: 200, message: OK} -- request: - body: null - headers: - accept-encoding: ['gzip, deflate'] - method: !!python/unicode 'GET' - uri: http://localhost:9001/3.0/lists/foo@example.com/roster/member?count=25&page=1 - response: - body: {string: !!python/unicode '{"http_etag": "\"32223434a0f3af4cdc4673d1fbc5bac1f6d98fd3\"", - "start": 0, "total_size": 0}'} - headers: - content-length: ['90'] - content-type: [application/json; charset=utf-8] - status: {code: 200, message: OK} -- request: - body: null - headers: - accept-encoding: ['gzip, deflate'] - method: !!python/unicode 'GET' - uri: http://localhost:9001/3.0/lists/foo.example.com/roster/owner - response: - body: {string: !!python/unicode '{"entries": [{"address": "http://localhost:9001/3.0/addresses/newowner@example.com", - "delivery_mode": "regular", "email": "newowner@example.com", "http_etag": - "\"3d5a7162cfea3a3714cffd29d27ebde67d79a761\"", "list_id": "foo.example.com", - "member_id": 109, "role": "owner", "self_link": "http://localhost:9001/3.0/members/109", - "user": "http://localhost:9001/3.0/users/127"}], "http_etag": "\"58b1525f8309e885c67d43ddb5be942764bc9d6d\"", - "start": 0, "total_size": 1}'} - headers: - content-length: ['464'] - content-type: [application/json; charset=utf-8] - status: {code: 200, message: OK} -- request: - body: null - headers: - accept-encoding: ['gzip, deflate'] - method: !!python/unicode 'GET' - uri: http://localhost:9001/3.0/lists/foo.example.com/roster/moderator - response: - body: {string: !!python/unicode '{"http_etag": "\"32223434a0f3af4cdc4673d1fbc5bac1f6d98fd3\"", - "start": 0, "total_size": 0}'} - headers: - content-length: ['90'] - content-type: [application/json; charset=utf-8] - status: {code: 200, message: OK} -- request: - body: null - headers: - accept-encoding: ['gzip, deflate'] - method: !!python/unicode 'GET' - uri: http://localhost:9001/3.0/lists/foo.example.com/roster/owner - response: - body: {string: !!python/unicode '{"entries": [{"address": "http://localhost:9001/3.0/addresses/newowner@example.com", - "delivery_mode": "regular", "email": "newowner@example.com", "http_etag": - "\"3d5a7162cfea3a3714cffd29d27ebde67d79a761\"", "list_id": "foo.example.com", - "member_id": 109, "role": "owner", "self_link": "http://localhost:9001/3.0/members/109", - "user": "http://localhost:9001/3.0/users/127"}], "http_etag": "\"58b1525f8309e885c67d43ddb5be942764bc9d6d\"", - "start": 0, "total_size": 1}'} - headers: - content-length: ['464'] - content-type: [application/json; charset=utf-8] - status: {code: 200, message: OK} -- request: - body: null - headers: - accept-encoding: ['gzip, deflate'] - method: !!python/unicode 'GET' - uri: http://localhost:9001/3.0/lists/foo@example.com - response: - body: {string: !!python/unicode '{"display_name": "Foo", "fqdn_listname": "foo@example.com", - "http_etag": "\"698a819bbb6b902096a8c5543cc7fac2328960d5\"", "list_id": "foo.example.com", - "list_name": "foo", "mail_host": "example.com", "member_count": 0, "self_link": - "http://localhost:9001/3.0/lists/foo.example.com", "volume": 1}'} - headers: - content-length: ['294'] - content-type: [application/json; charset=utf-8] - status: {code: 200, message: OK} -- request: - body: null - headers: - accept-encoding: ['gzip, deflate'] - method: !!python/unicode 'GET' - uri: http://localhost:9001/3.0/users/su@example.com - response: - body: {string: !!python/unicode '404 Not Found'} - headers: - content-length: ['13'] - content-type: [application/json; charset=utf-8] - status: {code: 404, message: Not Found} -- request: - body: null - headers: - accept-encoding: ['gzip, deflate'] - method: !!python/unicode 'GET' - uri: http://localhost:9001/3.0/lists/foo.example.com/roster/owner - response: - body: {string: !!python/unicode '{"http_etag": "\"32223434a0f3af4cdc4673d1fbc5bac1f6d98fd3\"", - "start": 0, "total_size": 0}'} - headers: - content-length: ['90'] - content-type: [application/json; charset=utf-8] - status: {code: 200, message: OK} -- request: - body: null - headers: - accept-encoding: ['gzip, deflate'] - method: !!python/unicode 'GET' - uri: http://localhost:9001/3.0/lists/foo.example.com/roster/moderator - response: - body: {string: !!python/unicode '{"http_etag": "\"32223434a0f3af4cdc4673d1fbc5bac1f6d98fd3\"", - "start": 0, "total_size": 0}'} - headers: - content-length: ['90'] - content-type: [application/json; charset=utf-8] - status: {code: 200, message: OK} -- request: - body: subscriber=newowner%40example.com&role=owner&list_id=foo.example.com - headers: - accept-encoding: ['gzip, deflate'] - !!python/unicode 'content-type': [!!python/unicode 'application/x-www-form-urlencoded'] - method: !!python/unicode 'POST' - uri: http://localhost:9001/3.0/members - response: - body: {string: !!python/unicode ''} - headers: - content-length: ['0'] location: ['http://localhost:9001/3.0/members/1'] status: {code: 201, message: Created} - request: @@ -277,4 +138,60 @@ content-length: ['458'] content-type: [application/json; charset=utf-8] status: {code: 200, message: OK} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode 'GET' + uri: http://localhost:9001/3.0/lists/foo@example.com + response: + body: {string: !!python/unicode '{"display_name": "Foo", "fqdn_listname": "foo@example.com", + "http_etag": "\"698a819bbb6b902096a8c5543cc7fac2328960d5\"", "list_id": "foo.example.com", + "list_name": "foo", "mail_host": "example.com", "member_count": 0, "self_link": + "http://localhost:9001/3.0/lists/foo.example.com", "volume": 1}'} + headers: + content-length: ['294'] + content-type: [application/json; charset=utf-8] + status: {code: 200, message: OK} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode 'GET' + uri: http://localhost:9001/3.0/lists/foo.example.com/roster/owner + response: + body: {string: !!python/unicode '{"entries": [{"address": "http://localhost:9001/3.0/addresses/newowner@example.com", + "delivery_mode": "regular", "email": "newowner@example.com", "http_etag": + "\"1e656e8469afe5acc1725ce34ba2d64c95d401bb\"", "list_id": "foo.example.com", + "member_id": 1, "role": "owner", "self_link": "http://localhost:9001/3.0/members/1", + "user": "http://localhost:9001/3.0/users/1"}], "http_etag": "\"6d8e08bc7a0c4c26e574f282f7c140254cc57531\"", + "start": 0, "total_size": 1}'} + headers: + content-length: ['458'] + content-type: [application/json; charset=utf-8] + status: {code: 200, message: OK} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode 'DELETE' + uri: http://localhost:9001/3.0/lists/foo@example.com/owner/newowner@example.com + response: + body: {string: !!python/unicode ''} + headers: + content-length: ['0'] + status: {code: 204, message: No Content} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode 'GET' + uri: http://localhost:9001/3.0/lists/foo.example.com/roster/owner + response: + body: {string: !!python/unicode '{"http_etag": "\"32223434a0f3af4cdc4673d1fbc5bac1f6d98fd3\"", + "start": 0, "total_size": 0}'} + headers: + content-length: ['90'] + content-type: [application/json; charset=utf-8] + status: {code: 200, message: OK} version: 1 diff --git a/src/postorius/tests/mailman_api_tests/test_list_members.py b/src/postorius/tests/mailman_api_tests/test_list_members.py index 4afa51c..f114825 100644 --- a/src/postorius/tests/mailman_api_tests/test_list_members.py +++ b/src/postorius/tests/mailman_api_tests/test_list_members.py @@ -17,14 +17,18 @@ import logging from django.conf import settings +from django.contrib import messages from django.contrib.auth.models import User from django.core.urlresolvers import reverse +from django.utils.timezone import now from django.test import Client, TestCase from django.test.utils import override_settings from six.moves.urllib_error import HTTPError from six.moves.urllib_parse import quote +from postorius.models import MailmanUser, Mailman404Error from postorius.tests import MM_VCR, API_CREDENTIALS +from postorius.tests.utils import get_flash_messages from postorius.utils import get_client @@ -111,7 +115,7 @@ @override_settings(**API_CREDENTIALS) -class AddOwnerTest(TestCase): +class AddRemoveOwnerTest(TestCase): """Tests for the list members page. Tests creation of list owners. @@ -120,14 +124,14 @@ @MM_VCR.use_cassette('test_list_members_add_owner.yaml') def setUp(self): self.client = Client() + self.mm_client = get_client() try: - self.domain = get_client().create_domain('example.com') + self.domain = self.mm_client.create_domain('example.com') except HTTPError: - self.domain = get_client().get_domain('example.com') + self.domain = self.mm_client.get_domain('example.com') self.foo_list = self.domain.create_list('foo') self.su = User.objects.create_superuser( 'su', 'su@example.com', 'pwd') - # login and post new owner data to url self.client.login(username='su', password='pwd') @MM_VCR.use_cassette('test_list_members_add_owner.yaml') @@ -136,11 +140,45 @@ self.su.delete() @MM_VCR.use_cassette('test_list_members_add_owner_new_owner_added.yaml') - def test_new_owner_added(self): + def test_add_remove_owner(self): self.client.post( reverse('list_members', args=('foo@example.com', )), {'owner_email': 'newowner@example.com'}) - self.assertTrue(u'newowner@example.com' in self.foo_list.owners) + self.assertTrue('newowner@example.com' in self.foo_list.owners) + self.client.post( + reverse('remove_role', args=('foo@example.com', 'owner', + 'newowner@example.com'))) + self.assertFalse('newowner@example.com' in self.foo_list.owners) + + @MM_VCR.use_cassette('test_list_members_add_owner_by_owner.yaml') + def test_remove_owner_as_owner(self): + self.mm_client.get_list('foo@example.com').add_owner('su@example.com') + self.assertTrue('su@example.com' in self.foo_list.owners) + # Make the logged in user a simple list owner + self.su.is_superuser = False + self.su.save() + # It must still be allowed to create and remove owners + self.client.post( + reverse('list_members', args=('foo@example.com', )), + {'owner_email': 'newowner@example.com'}) + self.assertTrue('newowner@example.com' in self.foo_list.owners) + response = self.client.post( + reverse('remove_role', args=('foo@example.com', 'owner', + 'newowner@example.com'))) + self.assertFalse('newowner@example.com' in self.foo_list.owners) + msgs = get_flash_messages(response) + self.assertEqual(len(msgs), 1) + self.assertEqual(msgs[0].level, messages.SUCCESS, msgs[0].message) + # But not to remove itself + response = self.client.post( + reverse('remove_role', args=('foo@example.com', 'owner', + 'su@example.com'))) + self.assertTrue('su@example.com' in self.foo_list.owners) + self.assertEqual(response.status_code, 302) + msgs = get_flash_messages(response) + self.assertEqual(len(msgs), 2) + self.assertEqual(msgs[1].level, messages.ERROR, msgs[1].message) + @override_settings(**API_CREDENTIALS) diff --git a/src/postorius/views/list.py b/src/postorius/views/list.py index ad5c2e0..769f9f5 100644 --- a/src/postorius/views/list.py +++ b/src/postorius/views/list.py @@ -853,7 +853,9 @@ messages.error(request, _('The user {} is not an owner'.format(address))) return redirect("list_members", the_list.list_id) - user_addresses = set([request.user.email]) | set(user.other_emails) + # the user may not have a other_emails property if it's a superuser + user_addresses = set([request.user.email]) | \ + set(getattr(request.user, 'other_emails', [])) if address in user_addresses: messages.error(request, _('You cannot remove yourself.')) return redirect("list_members", the_list.list_id)