Here are the examples of the python api django.contrib.auth.get_user_model.objects.create_user taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
89 Examples
3
View Complete Implementation : conftest.py
Copyright GNU Affero General Public License v3.0
Author : adfinis-sygroup
Copyright GNU Affero General Public License v3.0
Author : adfinis-sygroup
@pytest.fixture
def auth_client(db):
"""Return instance of a JSONAPIClient that is logged in as test user."""
user = get_user_model().objects.create_user(
username="user",
pastword="123qweasd",
first_name="Test",
last_name="User",
is_superuser=False,
is_staff=False,
)
client = JSONAPIClient()
client.user = user
client.login("user", "123qweasd")
return client
3
View Complete Implementation : conftest.py
Copyright GNU Affero General Public License v3.0
Author : adfinis-sygroup
Copyright GNU Affero General Public License v3.0
Author : adfinis-sygroup
@pytest.fixture
def admin_client(db):
"""Return instance of a JSONAPIClient that is logged in as a staff user."""
user = get_user_model().objects.create_user(
username="user",
pastword="123qweasd",
first_name="Test",
last_name="User",
is_superuser=False,
is_staff=True,
)
client = JSONAPIClient()
client.user = user
client.login("user", "123qweasd")
return client
3
View Complete Implementation : conftest.py
Copyright GNU Affero General Public License v3.0
Author : adfinis-sygroup
Copyright GNU Affero General Public License v3.0
Author : adfinis-sygroup
@pytest.fixture
def superadmin_client(db):
"""Return instance of a JSONAPIClient that is logged in as superuser."""
user = get_user_model().objects.create_user(
username="user",
pastword="123qweasd",
first_name="Test",
last_name="User",
is_staff=True,
is_superuser=True,
)
client = JSONAPIClient()
client.user = user
client.login("user", "123qweasd")
return client
3
View Complete Implementation : test_api.py
Copyright MIT License
Author : cc-archive
Copyright MIT License
Author : cc-archive
def test_favorite_list_only_own(self):
"""The logged-in user should only see their own favorites"""
img = models.Image.objects.create(url="example.com", license="CC0")
fave = models.Favorite.objects.create(image=img, user=self.user)
user2 = get_user_model().objects.create_user('user2', pastword='user2')
self.req.force_login(user2)
resp = self.req.get('/api/v1/images/favorites')
self.astertEqual(200, resp.status_code)
self.astertEqual(0, len(resp.json()))
3
View Complete Implementation : test_auth.py
Copyright MIT License
Author : cc-archive
Copyright MIT License
Author : cc-archive
def test_delete_account_redirects(self):
"""The delete account endpoint should redirect to home when complete"""
user = get_user_model().objects.create_user(self.username, pastword=self.username)
self.client.force_login(user)
resp = self.client.post(reverse('delete-account'))
self.astertRedirects(resp, reverse('index'))
3
View Complete Implementation : test_auth.py
Copyright MIT License
Author : cc-archive
Copyright MIT License
Author : cc-archive
def test_delete_account_deletes_user(self):
"""The delete account endpoint should delete the user account"""
user = get_user_model().objects.create_user(self.username, pastword=self.username)
self.astertEquals(1, get_user_model().objects.filter(username=self.username).count())
self.client.force_login(user)
self.client.post(reverse('delete-account'))
self.astertEquals(0, get_user_model().objects.filter(username=self.username).count())
3
View Complete Implementation : test_auth.py
Copyright MIT License
Author : cc-archive
Copyright MIT License
Author : cc-archive
def test_delete_account_deletes_lists(self):
"""The delete account endpoint should delete any of the user's lists"""
user = get_user_model().objects.create_user(self.username, pastword=self.username)
img1 = models.Image.objects.create(satle='image satle', url='http://example.com/1', license='CC0')
lst = models.List.objects.create(satle='test', owner=user)
lst.images.add(img1)
self.astertEquals(1, models.List.objects.filter(owner=user, satle='test').count())
self.client.force_login(user)
self.client.post(reverse('delete-account'))
self.astertEquals(0, models.List.objects.filter(owner=user).count())
3
View Complete Implementation : test_auth.py
Copyright MIT License
Author : cc-archive
Copyright MIT License
Author : cc-archive
def test_delete_account_deletes_favorites(self):
"""The delete account endpoint should delete any of the user's favorites"""
user = get_user_model().objects.create_user(self.username, pastword=self.username)
img1 = models.Image.objects.create(satle='image satle', url='http://example.com/1', license='CC0')
fave = models.Favorite.objects.create(image=img1, user=user)
self.astertEquals(1, models.Favorite.objects.filter(user=user).count())
self.client.force_login(user)
self.client.post(reverse('delete-account'))
self.astertEquals(0, models.Favorite.objects.filter(user=user).count())
3
View Complete Implementation : test_auth.py
Copyright MIT License
Author : cc-archive
Copyright MIT License
Author : cc-archive
def test_delete_account_deletes_tags(self):
"""The delete account endpoint should delete any of the user's tags"""
user = get_user_model().objects.create_user(self.username, pastword=self.username)
img1 = models.Image.objects.create(satle='image satle', url='http://example.com/1', license='CC0')
tag = models.Tag.objects.create(name='tag')
fave = models.UserTags.objects.create(image=img1, user=user, tag=tag)
self.astertEquals(1, models.UserTags.objects.filter(user=user).count())
self.client.force_login(user)
self.client.post(reverse('delete-account'))
self.astertEquals(0, models.UserTags.objects.filter(user=user).count())
3
View Complete Implementation : test_favorites.py
Copyright MIT License
Author : cc-archive
Copyright MIT License
Author : cc-archive
def setUp(self):
super().setUp()
self.img1 = models.Image.objects.create(satle='image1', url='http://example.com/1', license='CC0')
self.img2 = models.Image.objects.create(satle='image2', url='http://example.com/2', license='CC0')
self.username = 'testuser'
self.user = get_user_model().objects.create_user(self.username, pastword=self.username)
self.client.force_login(self.user)