Repository: nextcloud/appstore

Issue:
use settings.AUTH_USER_MODEL
use settings.AUTH_USER_MODEL to refer to the auth usr model.

See https://docs.djangoproject.com/en/1.9/topics/auth/customizing/#referencing-the-user-model



Discussion:

Resolving patch:
diff --git a/nextcloudappstore/core/models.py b/nextcloudappstore/core/models.py
--- a/nextcloudappstore/core/models.py
+++ b/nextcloudappstore/core/models.py
@@ -1,3 +1,4 @@
+from django.conf import settings  # type: ignore
 from django.contrib.auth.models import User  # type: ignore
 from django.db import models  # type: ignore
 from django.utils.translation import ugettext_lazy as _  # type: ignore
@@ -32,14 +33,15 @@ class App(TranslatableModel):
                                    verbose_name=_('Created at'))
     last_modified = models.DateTimeField(auto_now=True, editable=False,
                                          verbose_name=_('Updated at'))
-    owner = models.ForeignKey('auth.User', verbose_name=_('App owner'),
+    owner = models.ForeignKey(settings.AUTH_USER_MODEL,
+                              verbose_name=_('App owner'),
                               on_delete=models.CASCADE,
                               related_name='owned_apps')
-    co_maintainers = models.ManyToManyField('auth.User',
+    co_maintainers = models.ManyToManyField(settings.AUTH_USER_MODEL,
                                             verbose_name=_('Co-Maintainers'),
                                             related_name='co_maintained_apps',
                                             blank=True)
-    recommendations = models.ManyToManyField('auth.User',
+    recommendations = models.ManyToManyField(settings.AUTH_USER_MODEL,
                                              verbose_name=_('Recommendations'),
                                              related_name='recommended_apps',
                                              blank=True)


Test patch:
diff --git a/nextcloudappstore/core/api/v1/tests/api.py b/nextcloudappstore/core/api/v1/tests/api.py
--- a/nextcloudappstore/core/api/v1/tests/api.py
+++ b/nextcloudappstore/core/api/v1/tests/api.py
@@ -1,6 +1,6 @@
 import base64
 
-from django.contrib.auth.models import User
+from django.contrib.auth import get_user_model
 from django.test import TestCase
 from rest_framework import HTTP_HEADER_ENCODING
 from rest_framework.test import APIClient
@@ -8,8 +8,9 @@
 
 class ApiTest(TestCase):
     def setUp(self):
-        self.user = User.objects.create_user(username='test', password='test',
-                                             email='test@test.com')
+        self.user = get_user_model().objects.create_user(username='test',
+                                                         password='test',
+                                                         email='test@test.com')
         self.api_client = APIClient()
 
     def _login(self, user='test', password='test'):
diff --git a/nextcloudappstore/core/api/v1/tests/test_app.py b/nextcloudappstore/core/api/v1/tests/test_app.py
--- a/nextcloudappstore/core/api/v1/tests/test_app.py
+++ b/nextcloudappstore/core/api/v1/tests/test_app.py
@@ -1,4 +1,4 @@
-from django.contrib.auth.models import User
+from django.contrib.auth import get_user_model
 from django.core.urlresolvers import reverse
 from nextcloudappstore.core.api.v1.tests.api import ApiTest
 from nextcloudappstore.core.models import App, AppRelease
@@ -26,8 +26,9 @@ def test_delete_unauthenticated(self):
         self.assertEqual(401, response.status_code)
 
     def test_delete_unauthorized(self):
-        owner = User.objects.create_user(username='owner', password='owner',
-                                         email='owner@owner.com')
+        owner = get_user_model().objects.create_user(username='owner',
+                                                     password='owner',
+                                                     email='owner@owner.com')
         App.objects.create(id='news', owner=owner)
         url = reverse('api-v1:app-delete', kwargs={'pk': 'news'})
         self._login()
@@ -35,8 +36,9 @@ def test_delete_unauthorized(self):
         self.assertEqual(403, response.status_code)
 
     def test_delete_co_maintainer(self):
-        owner = User.objects.create_user(username='owner', password='owner',
-                                         email='owner@owner.com')
+        owner = get_user_model().objects.create_user(username='owner',
+                                                     password='owner',
+                                                     email='owner@owner.com')
         app = App.objects.create(id='news', owner=owner)
         app.co_maintainers.add(self.user)
         app.save()
diff --git a/nextcloudappstore/core/api/v1/tests/test_app_release.py b/nextcloudappstore/core/api/v1/tests/test_app_release.py
--- a/nextcloudappstore/core/api/v1/tests/test_app_release.py
+++ b/nextcloudappstore/core/api/v1/tests/test_app_release.py
@@ -1,7 +1,7 @@
 from unittest.mock import patch
 
 from nextcloudappstore.core.api.v1.release.provider import AppReleaseProvider
-from django.contrib.auth.models import User
+from django.contrib.auth import get_user_model
 from django.core.urlresolvers import reverse
 from nextcloudappstore.core.api.v1.tests.api import ApiTest
 from nextcloudappstore.core.models import App, AppRelease
@@ -33,16 +33,18 @@ def test_delete_unauthenticated(self):
         self.assertEqual(401, response.status_code)
 
     def test_delete_unauthorized(self):
-        owner = User.objects.create_user(username='owner', password='owner',
-                                         email='owner@owner.com')
+        owner = get_user_model().objects.create_user(username='owner',
+                                                     password='owner',
+                                                     email='owner@owner.com')
         self.create_release(owner)
         self._login()
         response = self.api_client.delete(self.delete_url)
         self.assertEqual(403, response.status_code)
 
     def test_delete_co_maintainer(self):
-        owner = User.objects.create_user(username='owner', password='owner',
-                                         email='owner@owner.com')
+        owner = get_user_model().objects.create_user(username='owner',
+                                                     password='owner',
+                                                     email='owner@owner.com')
         self.create_release(owner=owner, co_maintainers=[self.user])
         self._login()
         response = self.api_client.delete(self.delete_url)
@@ -64,8 +66,9 @@ def test_create_unauthenticated(self):
 
     @patch.object(AppReleaseProvider, 'get_release_info')
     def test_create_unauthorized(self, get_release_info):
-        owner = User.objects.create_user(username='owner', password='owner',
-                                         email='owner@owner.com')
+        owner = get_user_model().objects.create_user(username='owner',
+                                                     password='owner',
+                                                     email='owner@owner.com')
         self.create_release(owner)
         self._login()
 
@@ -77,8 +80,9 @@ def test_create_unauthorized(self, get_release_info):
 
     @patch.object(AppReleaseProvider, 'get_release_info')
     def test_create_co_maintainer(self, get_release_info):
-        owner = User.objects.create_user(username='owner', password='owner',
-                                         email='owner@owner.com')
+        owner = get_user_model().objects.create_user(username='owner',
+                                                     password='owner',
+                                                     email='owner@owner.com')
         self.create_release(owner=owner, co_maintainers=[self.user])
         self._login()
 
diff --git a/nextcloudappstore/core/api/v1/tests/test_release_importer.py b/nextcloudappstore/core/api/v1/tests/test_release_importer.py
--- a/nextcloudappstore/core/api/v1/tests/test_release_importer.py
+++ b/nextcloudappstore/core/api/v1/tests/test_release_importer.py
@@ -1,4 +1,4 @@
-from django.contrib.auth.models import User
+from django.contrib.auth import get_user_model
 from django.test import TestCase
 from nextcloudappstore.core.api.v1.release import ReleaseConfig
 from nextcloudappstore.core.api.v1.release.importer import ReleaseImporter
@@ -15,8 +15,9 @@ def setUp(self):
         self.config = ReleaseConfig()
         self.min = read_relative_file(__file__, 'data/infoxmls/minimal.xml')
         self.full = read_relative_file(__file__, 'data/infoxmls/full.xml')
-        self.user = User.objects.create_user(username='test', password='test',
-                                             email='test@test.com')
+        self.user = get_user_model().objects.create_user(username='test',
+                                                         password='test',
+                                                         email='test@test.com')
         self.app = App.objects.create(pk='news', owner=self.user)
         Screenshot.objects.create(url='https://google.com', ordering=1,
                                   app=self.app)