|
1 | 1 | # SPDX-License-Identifier: Apache-2.0 |
2 | 2 |
|
3 | | -import uuid |
4 | | - |
5 | 3 | import pretend |
6 | 4 | import pytest |
7 | 5 |
|
8 | 6 | from pyramid.httpexceptions import HTTPBadRequest |
9 | 7 |
|
| 8 | +from tests.common.db.accounts import UserUniqueLoginFactory |
10 | 9 | from tests.common.db.ip_addresses import IpAddressFactory |
11 | 10 | from warehouse.admin.views import ip_addresses as ip_views |
12 | 11 |
|
@@ -45,21 +44,32 @@ def test_with_invalid_page(self): |
45 | 44 |
|
46 | 45 | class TestIpAddressDetail: |
47 | 46 | def test_no_ip_address(self, db_request): |
48 | | - db_request.matchdict["ip_address_id"] = None |
| 47 | + db_request.matchdict["ip_address"] = None |
49 | 48 |
|
50 | 49 | with pytest.raises(HTTPBadRequest): |
51 | 50 | ip_views.ip_address_detail(db_request) |
52 | 51 |
|
53 | 52 | def test_ip_address_not_found(self, db_request): |
54 | | - db_request.matchdict["ip_address_id"] = uuid.uuid4() |
| 53 | + db_request.matchdict["ip_address"] = "69.69.69.69" |
55 | 54 |
|
56 | 55 | with pytest.raises(HTTPBadRequest): |
57 | 56 | ip_views.ip_address_detail(db_request) |
58 | 57 |
|
59 | | - def test_ip_address_found(self, db_request): |
| 58 | + def test_ip_address_found_no_unique_logins(self, db_request): |
60 | 59 | ip_address = IpAddressFactory() |
61 | | - db_request.matchdict["ip_address_id"] = ip_address.id |
| 60 | + db_request.matchdict["ip_address"] = str(ip_address.ip_address) |
| 61 | + |
| 62 | + result = ip_views.ip_address_detail(db_request) |
| 63 | + |
| 64 | + assert result == {"ip_address": ip_address, "unique_logins": []} |
| 65 | + |
| 66 | + def test_ip_address_found_with_unique_logins(self, db_request): |
| 67 | + ip_address = IpAddressFactory() |
| 68 | + unique_login = UserUniqueLoginFactory.create( |
| 69 | + ip_address=str(ip_address.ip_address) |
| 70 | + ) |
| 71 | + db_request.matchdict["ip_address"] = str(ip_address.ip_address) |
62 | 72 |
|
63 | 73 | result = ip_views.ip_address_detail(db_request) |
64 | 74 |
|
65 | | - assert result == {"ip_address": ip_address} |
| 75 | + assert result == {"ip_address": ip_address, "unique_logins": [unique_login]} |
0 commit comments