-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'update-deleted-users' into develop
- Loading branch information
Showing
3 changed files
with
150 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ | |
from social_django.models import UserSocialAuth | ||
|
||
from ..models import User, MappingTeam | ||
from ...changeset.tests.modelfactories import ChangesetFactory | ||
from ...changeset.models import Changeset | ||
|
||
|
||
class TestCurrentUserDetailAPIView(APITestCase): | ||
|
@@ -102,6 +104,7 @@ def test_receive_oauth_token(self): | |
self.assertIn('oauth_token_secret', response.data.keys()) | ||
|
||
|
||
|
||
class TestMappingTeamListCreateAPIView(APITestCase): | ||
def setUp(self): | ||
self.url = reverse('users:mapping-team') | ||
|
@@ -379,3 +382,105 @@ def test_with_other_user(self): | |
|
||
self.assertEqual(MappingTeam.objects.filter(trusted=False).count(), 1) | ||
self.assertEqual(MappingTeam.objects.filter(trusted=True).count(), 0) | ||
self.staff_user = User.objects.create_user( | ||
username='staff', | ||
password='password', | ||
email='[email protected]', | ||
is_staff=True | ||
) | ||
UserSocialAuth.objects.create( | ||
user=self.staff_user, | ||
provider='openstreetmap', | ||
uid='123456', | ||
) | ||
|
||
|
||
|
||
class TestUpdateDeletedUsersView(APITestCase): | ||
def setUp(self): | ||
self.url = reverse('users:update-deleted-users') | ||
ChangesetFactory.create_batch(50, uid="1769", user="test_user") | ||
ChangesetFactory.create_batch(50, uid="1234", user="old_user") | ||
self.user = User.objects.create_user( | ||
username='test', | ||
password='password', | ||
email='[email protected]' | ||
) | ||
UserSocialAuth.objects.create( | ||
user=self.user, | ||
provider='openstreetmap', | ||
uid='123123', | ||
) | ||
self.staff_user = User.objects.create_user( | ||
username='staff', | ||
password='password', | ||
email='[email protected]', | ||
is_staff=True | ||
) | ||
UserSocialAuth.objects.create( | ||
user=self.staff_user, | ||
provider='openstreetmap', | ||
uid='123456', | ||
) | ||
|
||
def test_unauthenticated(self): | ||
request = self.client.post(self.url, data={'uids': [1769, 1234]}) | ||
self.assertEqual(request.status_code, 401) | ||
|
||
def test_non_staff_user(self): | ||
self.client.login(username=self.user.username, password='password') | ||
request = self.client.post(self.url, data={'uids': [1769, 1234]}) | ||
self.assertEqual(request.status_code, 403) | ||
|
||
def test_bad_request(self): | ||
self.client.login(username=self.staff_user.username, password='password') | ||
request = self.client.post(self.url) | ||
self.assertEqual(request.status_code, 400) | ||
request = self.client.post(self.url, data={'uid': [1769, 1234]}) | ||
self.assertEqual(request.status_code, 400) | ||
|
||
def test_view(self): | ||
user = User.objects.create_user( | ||
username='test_user', | ||
password='password', | ||
email='[email protected]' | ||
) | ||
UserSocialAuth.objects.create( | ||
user=user, | ||
provider='openstreetmap', | ||
uid='1769', | ||
) | ||
user_2 = User.objects.create_user( | ||
username='old_user', | ||
password='password', | ||
email='[email protected]' | ||
) | ||
UserSocialAuth.objects.create( | ||
user=user_2, | ||
provider='openstreetmap', | ||
uid='1234', | ||
) | ||
self.client.login(username=self.staff_user.username, password='password') | ||
request = self.client.post(self.url, data={'uids': [1769, 1234]}) | ||
self.assertEqual(request.status_code, 200) | ||
self.assertEqual(Changeset.objects.filter(uid='1769').count(), 50) | ||
self.assertEqual(Changeset.objects.filter(user='user_1769').count(), 50) | ||
self.assertEqual(Changeset.objects.filter(user='test_user').count(), 0) | ||
self.assertEqual(Changeset.objects.filter(uid='1234').count(), 50) | ||
self.assertEqual(Changeset.objects.filter(user='user_1234').count(), 50) | ||
self.assertEqual(Changeset.objects.filter(user='old_user').count(), 0) | ||
self.assertEqual(User.objects.filter(username='old_user').count(), 0) | ||
self.assertEqual(User.objects.filter(username='test_user').count(), 0) | ||
self.assertEqual(User.objects.filter(username='user_1234').count(), 1) | ||
self.assertEqual(User.objects.filter(username='user_1769').count(), 1) | ||
|
||
def test_view_as_strings(self): | ||
self.client.login(username=self.staff_user.username, password='password') | ||
request = self.client.post(self.url, data={'uids': ['1769', '1234']}) | ||
self.assertEqual(request.status_code, 200) | ||
self.assertEqual(Changeset.objects.filter(uid='1769').count(), 50) | ||
self.assertEqual(Changeset.objects.filter(user='user_1769').count(), 50) | ||
self.assertEqual(Changeset.objects.filter(user='test_user').count(), 0) | ||
self.assertEqual(Changeset.objects.filter(uid='1234').count(), 50) | ||
self.assertEqual(Changeset.objects.filter(user='user_1234').count(), 50) | ||
self.assertEqual(Changeset.objects.filter(user='old_user').count(), 0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters