Commit 5f0eb5e1 authored by Michal Čihař's avatar Michal Čihař

Cleanup user setup in API tests

Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent acf5e120
...@@ -47,6 +47,13 @@ class APIBaseTest(APITestCase, RepoTestMixin): ...@@ -47,6 +47,13 @@ class APIBaseTest(APITestCase, RepoTestMixin):
'slug': 'test' 'slug': 'test'
} }
self.tearDown() self.tearDown()
self.user = User.objects.create_user(
'apitest',
'apitest@example.org',
'x',
)
group = Group.objects.get(name='Users')
self.user.groups.add(group)
def tearDown(self): def tearDown(self):
cache.delete(get_acl_cache_key(None)) cache.delete(get_acl_cache_key(None))
...@@ -65,16 +72,13 @@ class APIBaseTest(APITestCase, RepoTestMixin): ...@@ -65,16 +72,13 @@ class APIBaseTest(APITestCase, RepoTestMixin):
) )
def authenticate(self, superuser=False): def authenticate(self, superuser=False):
user, dummy = User.objects.get_or_create(username='test') if self.user.is_superuser != superuser:
group = Group.objects.get(name='Users') self.user.is_superuser = superuser
user.groups.add(group) self.user.save()
user.is_superuser = superuser cache.delete(get_acl_cache_key(self.user))
user.save()
cache.delete(get_acl_cache_key(user))
self.client.credentials( self.client.credentials(
HTTP_AUTHORIZATION='Token ' + user.auth_token.key HTTP_AUTHORIZATION='Token ' + self.user.auth_token.key
) )
return user
def do_request(self, name, kwargs, data=None, code=200, superuser=False, def do_request(self, name, kwargs, data=None, code=200, superuser=False,
get=True, request=None): get=True, request=None):
...@@ -376,9 +380,9 @@ class TranslationAPITest(APIBaseTest): ...@@ -376,9 +380,9 @@ class TranslationAPITest(APIBaseTest):
) )
def test_upload_denied(self): def test_upload_denied(self):
user = self.authenticate() self.authenticate()
# Remove all permissions # Remove all permissions
user.groups.all()[0].permissions.clear() self.user.groups.all()[0].permissions.clear()
response = self.client.put( response = self.client.put(
reverse( reverse(
'api:translation-file', 'api:translation-file',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment