def reset(self, request): reset_to_level = (int(request.data["level"]) if "level" in request.data else None) if reset_to_level is None: return HttpResponseBadRequest("You must pass a level to reset to.") reset_user(request.user, reset_to_level) return Response({"message": "Your account has been reset"})
def test_when_user_resets_their_account_we_remove_all_reviews_and_then_unlock_their_current_level(self): self.user.profile.unlocked_levels.get_or_create(level=1) new_review = create_review(create_vocab("arbitrary word"), self.user) new_review.needs_review = True new_review.save() self.assertEqual(get_users_current_reviews(self.user).count(), 2) mock_vocab_list_response_with_single_vocabulary(self.user) mock_user_info_response(self.user.profile.api_key) reset_user(self.user, 1) self.user.refresh_from_db() self.user.profile.refresh_from_db() self.assertEqual(get_users_lessons(self.user).count(), 0) self.assertEqual(self.user.profile.level, 5)
def test_when_user_resets_their_account_we_remove_all_reviews_and_then_unlock_their_current_level( self): return self.user.profile.unlocked_levels.get_or_create(level=1) new_review = create_review(create_vocab("arbitrary word"), self.user) new_review.needs_review = True new_review.save() self.assertEqual(get_users_current_reviews(self.user).count(), 2) # TODO Fill with V2 mocks. reset_user(self.user, 1) self.user.refresh_from_db() self.user.profile.refresh_from_db() self.assertEqual(get_users_lessons(self.user).count(), 0) self.assertEqual(self.user.profile.level, 5)
def test_when_user_resets_their_account_we_remove_all_reviews_and_then_unlock_their_current_level( self ): self.user.profile.unlocked_levels.get_or_create(level=1) new_review = create_review(create_vocab("arbitrary word"), self.user) new_review.needs_review = True new_review.save() self.assertEqual(get_users_current_reviews(self.user).count(), 2) mock_vocab_list_response_with_single_vocabulary(self.user, self.user.profile.level) mock_user_info_response(self.user.profile.api_key) reset_user(self.user, 1) self.user.refresh_from_db() self.user.profile.refresh_from_db() self.assertEqual(get_users_lessons(self.user).count(), 0) self.assertEqual(self.user.profile.level, 5)
def reset(self, request): reset_to_level = int(request.data["level"]) if "level" in request.data else None if reset_to_level is None: return HttpResponseBadRequest("You must pass a level to reset to.") reset_user(request.user, reset_to_level) return Response({"message": "Your account has been reset"})