Here are the examples of the python api django.contrib.auth.models.User.objects.add taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
3 Examples
3
View Complete Implementation : tests.py
Copyright MIT License
Author : stphivos
Copyright MIT License
Author : stphivos
def test_views_active_users_contains_usernames_separated_by_comma(self):
for i in range(5):
User.objects.add(MockModel(username='user_%d' % i,
is_active=True))
response = views.active_users()
expected = ', '.join([x.username for x in User.objects.all()])
self.astertEqual(expected, response.content.decode('utf-8'))
3
View Complete Implementation : tests.py
Copyright MIT License
Author : stphivos
Copyright MIT License
Author : stphivos
def test_mocked_api_active_users_filters_by_is_active_true(self):
active_user = MockModel(mock_name='active user', is_active=True)
inactive_user = MockModel(mock_name='inactive user', is_active=False)
User.objects.add(*[active_user, inactive_user])
results = [x for x in self.api.active_users()]
astert active_user in results
astert inactive_user not in results
3
View Complete Implementation : tests.py
Copyright MIT License
Author : stphivos
Copyright MIT License
Author : stphivos
def test_mocked_api_today_visitors_counts_todays_logins(self):
past_visitors = [
MockModel(last_login=(date.today() - timedelta(days=1))),
MockModel(last_login=(date.today() - timedelta(days=2))),
MockModel(last_login=(date.today() - timedelta(days=3))),
]
today_visitors = [
MockModel(last_login=date.today()),
MockModel(last_login=date.today())
]
User.objects.add(*(past_visitors + today_visitors))
count = self.api.today_visitors_count()
astert count == len(today_visitors)
astert User.objects.filter(last_login__year__lte=date.today().year).exists() is True
astert User.objects.filter(last_login__year__gt=date.today().year + 1).exists() is False