def test_resource_email(self): force_authenticate(self.request, user=UserFactory()) with mock.patch("api.v2.views.email.resource_request_email" ) as mock_email_support: response = self.view(self.request) mock_email_support.assert_called_once() self.assertEquals(response.status_code, 200)
def test_resource_request_email(self): """ Assert general expected behavior of resource_request_email """ user = UserFactory( username="******", first_name="First", last_name="Last", email="*****@*****.**" ) # Mock out a request request = mock.Mock() request.user = user request.POST = {} request.session = None with mock.patch('core.tasks.EmailMessage') as MockMessage, \ override_settings(ATMO_SUPPORT=('Support', '*****@*****.**')): resource_request_email( request, user.username, "All the resources", "Did I stutter?" ) kwargs = MockMessage.call_args[1] # Assert that Django's EmailMessage is called with the right # paramaters # Note: We are not testing the body of the email here MockMessage.assert_called_with( cc=None, to=['Support <*****@*****.**>'], subject='Atmosphere Resource Request - user0', from_email='First Last <*****@*****.**>', body=kwargs['body'] )
def test_user_insert(self): """Test that we can insert a user""" user = UserFactory() assert User.objects.count() == 1 assert user.username is not None assert self.is_valid_generated_username(user.username) assert self.is_valid_generated_email(user.username, user.email)
def setup_method(self, method): """ Setup method run after each test. Creates a user, saves its token, and creates a tournament. """ self.user = UserFactory() self.token = Token.objects.get(user_id=self.user.user_id) self.tournament = TournamentFactory()
def setup_method(self, method): """ Setup method run after each test. Creates a user, tournament, match and saves the user token. """ self.user = UserFactory() self.token = Token.objects.get(user_id=self.user.user_id) self.tournament = TournamentFactory() self.match = MatchFactory()
def setup_method(self, method): """ Setup method runs after each test. Creates a tournament, a user, a tournamentUser. """ self.user = UserFactory() self.token = Token.objects.get(user_id=self.user.user_id) self.tournament = TournamentFactory() self.tournamentUser = TournamentUserFactory()
def setUp(self): """ Setup method run after each test. Creates a user and saves its token. """ self.user = UserFactory() self.token = Token.objects.get(user_id=self.user.user_id) self.user.is_active = True self.user.username = '******' self.user.set_password('password') self.user.save()
def setup_method(self, method): """ Setup method runs after each test. Creates a tournament, a user, a tournamentUser. """ self.user = UserFactory() self.token = Token.objects.get(user_id=self.user.user_id) self.tournament = TournamentFactory() self.match = MatchFactory() self.url = reverse('match-detail', kwargs={'pk': self.match.match_id})
def test_match_insert(self): """Test that we can insert a Match""" match = MatchFactory(users=[UserFactory()]) assert Match.objects.count() == 1 assert 1 <= match.round <= 100 assert match.parent is None assert match.users is not None assert MatchUser.objects.count() == 1 for user in match.users.all(): if not UserTests.is_valid_generated_username(user.username): assert False
def setUp(self): self.tags = TagFactory.create_batch(10) self.anonymous_user = AnonymousUserFactory() self.user = UserFactory() self.staff_user = UserFactory(is_staff=True) self.tag = TagFactory.create() self.unsaved_tag = TagFactory.build() self.updated_tag_data = { 'name': 'new-tag-name', 'description': 'new tag description' } self.factory = APIRequestFactory() self.create_view = TagViewSet.as_view({'post': 'create'}) self.delete_view = TagViewSet.as_view({'delete': 'destroy'}) self.detail_view = TagViewSet.as_view({'get': 'retrieve'}) self.list_view = TagViewSet.as_view({'get': 'list'}) self.update_view = TagViewSet.as_view({'put': 'update'}) detail_url = reverse(self.url_route + '-detail', args=(self.tag.id, )) list_url = reverse(self.url_route + '-list') self.create_request = self.factory.post( list_url, { 'name': self.unsaved_tag.name, 'description': self.unsaved_tag.description }) self.delete_request = self.factory.delete(detail_url) self.detail_request = self.factory.get(detail_url) self.list_request = self.factory.get(list_url) self.update_request = self.factory.put( detail_url, { 'name': self.updated_tag_data['name'], 'description': self.updated_tag_data['description'] })
def test_tournament_insert(self): """Test that we can insert a Tournament""" tournament = TournamentFactory(users=[UserFactory()]) assert Tournament.objects.count() == 1 assert tournament.name is not None assert self.is_valid_generated_tournament_name(tournament.name) assert tournament.start_date is not None assert tournament.start_date < datetime.now(tz=pytz.timezone('UTC')) assert tournament.creator is not None assert tournament.users is not None assert TournamentUser.objects.count() == 1 for user in tournament.users.all(): if not UserTests.is_valid_generated_username(user.username): assert False
def test_external_accounts_are_created(self): """ Sanity check that configuration results in call to create_new_accounts. """ user = UserFactory() url = reverse('api:v1:profile') view = Profile.as_view() factory = APIRequestFactory() request = factory.get(url) force_authenticate(request, user=user) with mock.patch( "api.v1.views.profile.create_new_accounts" ) as mock_create_new_accounts: view(request) mock_create_new_accounts.assert_called_once()
def test_external_accounts_are_not_created_for_invalid_user(self): """ Accounts are NOT created when when the user is invalid """ user = UserFactory() url = reverse('api:v1:profile') view = Profile.as_view() factory = APIRequestFactory() request = factory.get(url) force_authenticate(request, user=user) # Patch the user so that they are invalid with mock.patch.object(AtmosphereUser, 'is_valid', return_value=False), \ mock.patch("api.v1.views.profile.create_new_accounts") \ as mock_create_new_accounts: view(request) mock_create_new_accounts.assert_not_called()
def test_email_from_admin(self): """ Assert that emails from admin to user correctly set from, to, and cc fields """ UserFactory( username="******", first_name="First", last_name="Last", email="*****@*****.**" ) with mock.patch('core.tasks.EmailMessage') as MockMessage, \ override_settings(ATMO_DAEMON=('AtmoAdmin', '*****@*****.**')): email_from_admin("user0", 'Subject', 'Body') kwargs = MockMessage.call_args[1] MockMessage.assert_called_with( to=['First Last <*****@*****.**>'], from_email='AtmoAdmin <*****@*****.**>', cc=['AtmoAdmin <*****@*****.**>'], subject=kwargs['subject'], body=kwargs['body'], )
def default_user(): return UserFactory()
def user() -> User: return UserFactory()
def setUp(self): self.user = UserFactory() self.token = Token.objects.get(user_id=self.user.user_id) self.tournament = TournamentFactory() self.url = reverse('tournament-detail', kwargs={'pk': self.tournament.tournament_id})
def user2() -> Schema: return UserFactory(username="******", password="******")