From 6c69fb38c64dd1a1f1b3a0c4ec0a4e143ada6fc8 Mon Sep 17 00:00:00 2001 From: Shubham Garg Date: Wed, 11 Dec 2024 14:02:28 -0500 Subject: [PATCH] #250 Cleaning bad data (#253) * #250 data cleanup * user choices migrations --------- Co-authored-by: aakashshankar --- .../0010_alter_customuser_user_type.py | 22 +++++++++++++++++++ src/accounts/models.py | 2 +- src/accounts/views.py | 5 ++++- src/requirements.txt | 2 +- src/services/tests.py | 8 +++---- 5 files changed, 32 insertions(+), 7 deletions(-) create mode 100644 src/accounts/migrations/0010_alter_customuser_user_type.py diff --git a/src/accounts/migrations/0010_alter_customuser_user_type.py b/src/accounts/migrations/0010_alter_customuser_user_type.py new file mode 100644 index 0000000..854823e --- /dev/null +++ b/src/accounts/migrations/0010_alter_customuser_user_type.py @@ -0,0 +1,22 @@ +# Generated by Django 5.1.1 on 2024-12-11 18:52 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("accounts", "0009_customuser_profile_image_url"), + ] + + operations = [ + migrations.AlterField( + model_name="customuser", + name="user_type", + field=models.CharField( + choices=[("user", "User"), ("service_provider", "Service Provider")], + default="user", + max_length=20, + ), + ), + ] diff --git a/src/accounts/models.py b/src/accounts/models.py index 6483e34..9476d74 100644 --- a/src/accounts/models.py +++ b/src/accounts/models.py @@ -4,8 +4,8 @@ class CustomUser(AbstractUser): USER_TYPE_CHOICES = ( - ("service_provider", "Service Provider"), ("user", "User"), + ("service_provider", "Service Provider"), ) email = models.EmailField(unique=True) diff --git a/src/accounts/views.py b/src/accounts/views.py index 79afdf5..d1d2544 100644 --- a/src/accounts/views.py +++ b/src/accounts/views.py @@ -16,7 +16,7 @@ import uuid import boto3 from botocore.exceptions import ClientError - +from django.contrib.auth import login from accounts.models import CustomUser from forum.models import Post @@ -69,6 +69,9 @@ def register(request): return render(request, "register.html", {"form": form}) user.save() # Now save to DB login(request, user, backend="django.contrib.auth.backends.ModelBackend") + + login(request, user, backend="django.contrib.auth.backends.ModelBackend") + if user.user_type == "service_provider": return redirect("services:list") else: diff --git a/src/requirements.txt b/src/requirements.txt index df47fd5..849fba9 100644 --- a/src/requirements.txt +++ b/src/requirements.txt @@ -57,7 +57,7 @@ pycodestyle==2.12.1 pycparser==2.22 pyflakes==3.2.0 Pygments==2.18.0 -PyJWT==2.9.0 +PyJWT==2.10.1 python-dateutil==2.9.0.post0 python-decouple==3.8 pytz==2024.2 diff --git a/src/services/tests.py b/src/services/tests.py index 7d82c5e..5b8ebdb 100644 --- a/src/services/tests.py +++ b/src/services/tests.py @@ -466,7 +466,7 @@ def setUp(self): name="Test Service", address="123 Test St", category="Mental Health Center", - provider_id="test_provider_id", + provider_id="-1", latitude=Decimal("40.7128"), longitude=Decimal("-74.0060"), ratings=Decimal("4.5"), @@ -483,12 +483,12 @@ def test_get_services_by_provider(self, mock_get_services_by_provider): mock_get_services_by_provider.return_value = [self.sample_service] # Act - result = self.service_repo.get_services_by_provider("test_provider_id") + result = self.service_repo.get_services_by_provider(-1) # Assert self.assertEqual(len(result), 1) self.assertEqual(result[0].name, "Test Service") - mock_get_services_by_provider.assert_called_once_with("test_provider_id") + mock_get_services_by_provider.assert_called_once_with(-1) @patch("services.repositories.ServiceRepository.get_service") def test_get_service(self, mock_get_service): @@ -1557,7 +1557,7 @@ def setUp(self): name="Test Service", address="123 Test St", category="Mental Health Center", - provider_id="test_provider_id", + provider_id="-1", latitude=Decimal("40.7128"), longitude=Decimal("-74.0060"), ratings=Decimal("4.5"),