From 63307a83882a8101a6d5194911a6a0f32b7e2953 Mon Sep 17 00:00:00 2001 From: s460930 Date: Tue, 1 Dec 2020 22:49:16 +0100 Subject: [PATCH 1/5] SMART-37 implemented registration view --- .../__pycache__/__init__.cpython-38.pyc | Bin 167 -> 167 bytes .../__pycache__/settings.cpython-38.pyc | Bin 3500 -> 3500 bytes .../__pycache__/urls.cpython-38.pyc | Bin 1015 -> 1015 bytes .../__pycache__/wsgi.cpython-38.pyc | Bin 580 -> 580 bytes .../user/__pycache__/__init__.cpython-38.pyc | Bin 176 -> 176 bytes .../app/user/__pycache__/admin.cpython-38.pyc | Bin 217 -> 217 bytes .../user/__pycache__/models.cpython-38.pyc | Bin 2416 -> 2416 bytes .../__pycache__/0001_initial.cpython-38.pyc | Bin 1014 -> 1028 bytes .../0002_auto_20201130_2119.cpython-38.pyc | Bin 530 -> 545 bytes .../__pycache__/__init__.cpython-38.pyc | Bin 187 -> 187 bytes rest-app/smartpicasso/app/user/views.py | 25 ++++++++++++++++-- .../__pycache__/__init__.cpython-38.pyc | Bin 184 -> 184 bytes .../__pycache__/admin.cpython-38.pyc | Bin 225 -> 225 bytes .../__pycache__/models.cpython-38.pyc | Bin 1124 -> 1124 bytes .../__pycache__/0001_initial.cpython-38.pyc | Bin 1055 -> 1055 bytes .../__pycache__/__init__.cpython-38.pyc | Bin 195 -> 195 bytes 16 files changed, 23 insertions(+), 2 deletions(-) diff --git a/rest-app/smartpicasso/__pycache__/__init__.cpython-38.pyc b/rest-app/smartpicasso/__pycache__/__init__.cpython-38.pyc index 012896bbc20f5d4a2a54117c3a8d274e2ed8f6c9..f266be55a92b525670bd494536412d9b5c46ee9b 100644 GIT binary patch delta 19 ZcmZ3^xSWwYl$V!_0SG4a9Gl2J2LLKa1n&R< delta 19 ZcmZ3^xSWwYl$V!_0SNL7j!xvB0{|%U1hD`B diff --git a/rest-app/smartpicasso/__pycache__/settings.cpython-38.pyc b/rest-app/smartpicasso/__pycache__/settings.cpython-38.pyc index 092397f13661cccec3c5de43c5143dd0e5eb6f30..5b5865037fe9425e9bf83e0e5d76b99d6948d776 100644 GIT binary patch delta 19 ZcmZ1@y+)cVl$V!_0SG4aY~)(R3ji$_1egE- delta 19 ZcmZ1@y+)cVl$V!_0SIPQZsc0T3ji$i1djj! diff --git a/rest-app/smartpicasso/__pycache__/urls.cpython-38.pyc b/rest-app/smartpicasso/__pycache__/urls.cpython-38.pyc index b91070ceaba81f431aa2fd768ea100840d2e7b35..74b3fd52bd0832a495c073c74b9c2eb2b89b19cf 100644 GIT binary patch delta 19 Zcmey){+*pGl$V!_0SG4aY~*^&3;;EU1xEk? delta 19 Zcmey){+*pGl$V!_0SK;?Z{&K*3;;H^1$F=c diff --git a/rest-app/smartpicasso/__pycache__/wsgi.cpython-38.pyc b/rest-app/smartpicasso/__pycache__/wsgi.cpython-38.pyc index 4baa4a5ae6837441d900fe45ca887580f1f3b0eb..269351cdcfc2ff197e546f0837801c5067288685 100644 GIT binary patch delta 20 acmX@Ya)gCDl$V!_0SG4a9NWlk$pip1tpx4> delta 20 acmX@Ya)gCDl$V!_0SNL7j&9_(WC8#(83eEZ diff --git a/rest-app/smartpicasso/app/user/__pycache__/__init__.cpython-38.pyc b/rest-app/smartpicasso/app/user/__pycache__/__init__.cpython-38.pyc index 81428760ad4de6ca3747d79c685cf37d3156d47f..7a008fc13de5ed1c5ad00761da70068fc00e5ca8 100644 GIT binary patch delta 19 ZcmdnMxPg&7l$V!_0SG4a9Gl3!6aXug1quKF delta 19 ZcmdnMxPg&7l$V!_0SNL7j!xuW3IHlU1k3;c diff --git a/rest-app/smartpicasso/app/user/__pycache__/admin.cpython-38.pyc b/rest-app/smartpicasso/app/user/__pycache__/admin.cpython-38.pyc index 6218ee92be423cd4c0f009c0106558dcf4e1bdd5..01cd26348969e76516a1d59a4483c163e0a13e48 100644 GIT binary patch delta 19 Zcmcb~c$1Mkl$V!_0SG4a9Gl2}4gfKN1%&_r delta 19 Zcmcb~c$1Mkl$V!_0SNL7j!xu02LLcE1xEk? diff --git a/rest-app/smartpicasso/app/user/__pycache__/models.cpython-38.pyc b/rest-app/smartpicasso/app/user/__pycache__/models.cpython-38.pyc index b3aaace9242176886bcd1e533c65e587c5d749cd..7a0885a1992fa49bbf138578eaa7b11a4409d5c5 100644 GIT binary patch delta 19 Zcmew$^g)O#l$V!_0SG4aY~)Jg1OPPo1kL~e delta 19 Zcmew$^g)O#l$V!_0SK12ZRASh1OPQ<1m6Gv diff --git a/rest-app/smartpicasso/app/user/migrations/__pycache__/0001_initial.cpython-38.pyc b/rest-app/smartpicasso/app/user/migrations/__pycache__/0001_initial.cpython-38.pyc index 5119f86eece0e378c9ed1e26dd37c451de62457e..fccce74770a732773fa9c1f8727fbc1f9a1107c3 100644 GIT binary patch delta 284 zcmeyy-on8b%FD~e00etCAB$&UnaI~xzX-@nWr$)-VTfW%VT@ut#-7j1ou@ z4`$GmxW(z4nO>Awl9`|9HrbgmY4S40O^kw*Bbij$*%C|gb2F1C*D`go=>Yvxq%)a^ fxtLuA$mC#RncTu`C#4P&W&z8g61tP`FiQadNDx3E delta 255 zcmZqS_{Po`%FD~e00j93N8>**PvmQ>p9kcnGDI<^Fhnt>Fh((_GeohZvSzWRFr_f3 zvS)Fmu%s}ju=X;gF{Q8p`J5??K**lL(aQ`J;RK3srE+KSq;LU6xl*`$S%9KEKvCWl zUZ4nH3O`t#08oSv$QSHo1j-A6d0b!~CsT?rggaS*QB;UOMLd{6Q{onlWAY?sJ1I4gAPZOqmC%{| HidhN(PMtXj diff --git a/rest-app/smartpicasso/app/user/migrations/__pycache__/0002_auto_20201130_2119.cpython-38.pyc b/rest-app/smartpicasso/app/user/migrations/__pycache__/0002_auto_20201130_2119.cpython-38.pyc index 1cde8a2dec2561a8ba3094c61c8bac141b00dbc5..34c4c8a626f4a77737187501670febe8e5d44858 100644 GIT binary patch delta 162 zcmbQlvXF&0l$V!_0SNYPJ{Ipek+;Y~4aiAlh+<4(h+;}%jABkNoCDqOJN2= zmR=B_J%u%xL6hwkr*CF@QDRAEexBRJO*)Jm6Ys0Cvn7_~=Vm5PW@a>I;|Cg6#6Q`F sv5s8;$mC#RnY^D-TLU5tmIDzWsaqU2x%nxjIjMHcKwdEuklel#uTX3%84#p#=wUX)mpnV&atyAC7!#3!ng1sRRl_<;J0_$GTY*0F+^9Fxy6YHL6Q d!7?C%A4uHdu*uC&Da}c>V+QhynScZjGXPix9)$n^ diff --git a/rest-app/smartpicasso/app/user/migrations/__pycache__/__init__.cpython-38.pyc b/rest-app/smartpicasso/app/user/migrations/__pycache__/__init__.cpython-38.pyc index e34e9eb8b6ebb15e714d8cd8fc7d57071078ba4c..62d8e5b70e88d3ed03a0201522c41878e50f7972 100644 GIT binary patch delta 19 ZcmdnZxSNqXl$V!_0SG4a9Gl3!0RSy51uFmm delta 19 ZcmdnZxSNqXl$V!_0SNL7j!xv>001l21nmF- diff --git a/rest-app/smartpicasso/app/user/views.py b/rest-app/smartpicasso/app/user/views.py index a303436..ecb0a57 100644 --- a/rest-app/smartpicasso/app/user/views.py +++ b/rest-app/smartpicasso/app/user/views.py @@ -1,9 +1,9 @@ from rest_framework import status -from rest_framework.generics import RetrieveAPIView +from rest_framework.generics import RetrieveAPIView, CreateAPIView from rest_framework.permissions import AllowAny from rest_framework.response import Response -from smartpicasso.app.user.serializers import UserLoginSerializer +from smartpicasso.app.user.serializers import UserLoginSerializer, UserRegistrationSerializer class UserLoginView(RetrieveAPIView): @@ -25,3 +25,24 @@ class UserLoginView(RetrieveAPIView): status_code = status.HTTP_200_OK return Response(response, status=status_code) + + +class UserRegistrationView(CreateAPIView): + """ + View for user registration + """ + permission_classes = (AllowAny,) + serializer_class = UserRegistrationSerializer + + def post(self, request): + serializer = self.serializer_class(data=request.data) + serializer.is_valid(raise_exception=True) + serializer.save() + status_code = status.HTTP_201_CREATED + response = { + 'success': 'True', + 'status_code': status_code, + 'message': 'User registered successfully' + } + + return Response(response, status=status_code) diff --git a/rest-app/smartpicasso/app/user_profile/__pycache__/__init__.cpython-38.pyc b/rest-app/smartpicasso/app/user_profile/__pycache__/__init__.cpython-38.pyc index 90b0343ccc4d3e9778e309b6320731bc96ac7b80..6b25f622f576112f60d3465b4d8354ac09c3b4a4 100644 GIT binary patch delta 19 ZcmdnNxPy^9l$V!_0SG4a9Gl3!762^01tI_d delta 19 ZcmdnNxPy^9l$V!_0SNL7j!xuW3jix;1mpk! diff --git a/rest-app/smartpicasso/app/user_profile/__pycache__/admin.cpython-38.pyc b/rest-app/smartpicasso/app/user_profile/__pycache__/admin.cpython-38.pyc index 1f0e3406b910ba802ec1a8c794a459e4c3f8e00e..08118cc5d5a0f51ce01cebee94ac4fc8b24ff034 100644 GIT binary patch delta 19 ZcmaFJ_>hr1l$V!_0SG4a9Gl2}4FEE#1)Tr@ delta 19 ZcmaFJ_>hr1l$V!_0SNL7j!xvh1^_Ws1z!LF diff --git a/rest-app/smartpicasso/app/user_profile/__pycache__/models.cpython-38.pyc b/rest-app/smartpicasso/app/user_profile/__pycache__/models.cpython-38.pyc index 48150205b2012ba1a9396a13b501d41f5c364aa8..11e4dc95008ce57200a2532838a01292fa9dce43 100644 GIT binary patch delta 20 acmaFD@q~jrl$V!_0SG4a9NWkp$pQd5KLuC- delta 20 acmaFD@q~jrl$V!_0SNL7j&9_RWB~v-s|6YW diff --git a/rest-app/smartpicasso/app/user_profile/migrations/__pycache__/0001_initial.cpython-38.pyc b/rest-app/smartpicasso/app/user_profile/migrations/__pycache__/0001_initial.cpython-38.pyc index e354c63832b91e1970d5603f142b2c1144e77107..94e7772ebae22bca859d004989044af2256d95ce 100644 GIT binary patch delta 20 acmbQwF`t7wl$V!_0SG4a9NWk(!U6y;cLa$5 delta 20 acmbQwF`t7wl$V!_0SNL7j&9@@VF3Uv;{;0p diff --git a/rest-app/smartpicasso/app/user_profile/migrations/__pycache__/__init__.cpython-38.pyc b/rest-app/smartpicasso/app/user_profile/migrations/__pycache__/__init__.cpython-38.pyc index 8f1df471de95c7aae8e37b5f4d0ad1686c189f50..48eab08fa8b1530035b9522ce27a0f16441013b1 100644 GIT binary patch delta 19 ZcmX@ic$kqpl$V!_0SG4a9Gl3!0{|{m1w#M; delta 19 ZcmX@ic$kqpl$V!_0SNL7j!xv>0RSxi1qA>A -- 2.20.1 From 516365cbc6d971df330c9b1e68e56b077fdb7e20 Mon Sep 17 00:00:00 2001 From: s460930 Date: Tue, 1 Dec 2020 22:51:14 +0100 Subject: [PATCH 2/5] SMART-38 register registration endpoint --- rest-app/smartpicasso/app/user/urls.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/rest-app/smartpicasso/app/user/urls.py b/rest-app/smartpicasso/app/user/urls.py index f12a788..390985a 100644 --- a/rest-app/smartpicasso/app/user/urls.py +++ b/rest-app/smartpicasso/app/user/urls.py @@ -4,8 +4,9 @@ from django.conf.urls import url -from smartpicasso.app.user.views import UserLoginView +from smartpicasso.app.user.views import UserLoginView, UserRegistrationView urlpatterns = [ - url(r'^authenticate', UserLoginView.as_view(), name='authenticate') + url(r'^authenticate', UserLoginView.as_view(), name='authenticate'), + url(r'^register', UserRegistrationView.as_view(), name='register') ] -- 2.20.1 From 18957651b8def3d3dce690923a41ecf6f0d2bace Mon Sep 17 00:00:00 2001 From: s460930 Date: Tue, 1 Dec 2020 23:00:42 +0100 Subject: [PATCH 3/5] SMART-38 removed one field in user profile --- rest-app/db.sqlite3 | Bin 155648 -> 167936 bytes rest-app/smartpicasso/app/user/serializers.py | 5 ++--- .../__pycache__/models.cpython-38.pyc | Bin 1124 -> 1060 bytes .../0002_remove_userprofile_phone_number.py | 19 ++++++++++++++++++ .../smartpicasso/app/user_profile/models.py | 1 - 5 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 rest-app/smartpicasso/app/user_profile/migrations/0002_remove_userprofile_phone_number.py diff --git a/rest-app/db.sqlite3 b/rest-app/db.sqlite3 index 6fe1bbc27b8def94acec1f68e49cddbb9556980c..02b81c542748fab5512fe98010b55b876000b0f2 100644 GIT binary patch delta 973 zcmaiy%}*0S7{>R52HKL296+iPF=>@rsWa2v*|tfQ3Th~n770R|n6jUMw7aFWe0ZTn z60Z~vJ!+zfiAh76CXjgY;>DBRIdJpnpMYC5u|!QXd6LOHljr?C^G@lLwe-feceTe$ zQIyBjO;fC?smdKc?X54o18koydC+;u%h;0jvfDNt@3TYPA5Akin&oQ4=~4Hb(*W#Scj7WbB@mrXT5B9Y?nQ(wd{$+!q%>? zoV227IK8$cVxG7#B4$9>rnJ5|m71EIc^K7Q*Hiws zyT*p;3q&oC#Qt^Ig3I)?g7x5=(c9=L{Q!-@(kZCy1+0wu_1&gi=jH0z8Qs}ocC4A* z-h!EF+7fd*V}h)SC?H}*3ldJ0M2VBJDr)A`uq-K%B+kb*c0Rjy;g2pcr(m$18Uq6Z2*ZH)L>*&BwT%f&_?bnyR!wFX(B9Zs!L@mnRH!JUXp_M< z14b3nfOEhi>6wr$^)z^Kc`!oa}fx3STSiK|J?j$K?;m9d3?`o?TVSw@xV z=d&5xB?~h0^HSsUN^_G^io{-JR%dBQ@ z58|0Is&2oK$7nKqc8vTaDJw>+gS>j?(k24AkU-%lzPs<|9rDx!Cih9 T31)N7$rtlQ7fn!Dv_Jp=UMWB7 diff --git a/rest-app/smartpicasso/app/user/serializers.py b/rest-app/smartpicasso/app/user/serializers.py index e5dee9f..cb69e9d 100644 --- a/rest-app/smartpicasso/app/user/serializers.py +++ b/rest-app/smartpicasso/app/user/serializers.py @@ -20,7 +20,7 @@ class UserSerializer(serializers.ModelSerializer): class Meta: model = UserProfile - fields = ('first_name', 'last_name', 'phone_number') + fields = ('first_name', 'last_name') class UserRegistrationSerializer(serializers.ModelSerializer): @@ -40,8 +40,7 @@ class UserRegistrationSerializer(serializers.ModelSerializer): UserProfile.objects.create( user=user, first_name=profile_data['first_name'], - last_name=profile_data['last_name'], - phone_number=profile_data['phone_number'], + last_name=profile_data['last_name'] ) return user diff --git a/rest-app/smartpicasso/app/user_profile/__pycache__/models.cpython-38.pyc b/rest-app/smartpicasso/app/user_profile/__pycache__/models.cpython-38.pyc index 11e4dc95008ce57200a2532838a01292fa9dce43..1aa4d7255859d909c737419499fb3717e8bdf01b 100644 GIT binary patch delta 209 zcmaFDv4n#+l$V!_0SMZ6AB#_!$UBRR707V_;^Mf88~sJx8B#b?xLO!exSE-w1X8$z z88mq&t1-@<{E+b&n=nvWk?`cTOlfK$W-$wp;9z87E)oSY{4@oN_&^HyL4*K^5S(nu zoaqRbErRF;iGo=oAQnhJ$T7t{Kmuft5Tg(yA0r@H~OokvSjh5aHcS)FaaS~FH4kw zJ3|V03Qr3|3Qsdrlwb;PFoP!FWD&->axX#VXtES>1F0e&AaRQ&uQVs;7Hd*YVqW&- zjf}_G#6VJFlWUpM)I@;HViq95!N|f~BmrdjX$lnyf)ogW2w@N*GMSS(Gcby$AR|97 zH9oI2Hz~CUthNYZ5=af0B@SYNOar;0m=8#Rj1^)OV&nrtAttb#CPxv-)*`9No0**j L&`p@k#v%s*KGibI diff --git a/rest-app/smartpicasso/app/user_profile/migrations/0002_remove_userprofile_phone_number.py b/rest-app/smartpicasso/app/user_profile/migrations/0002_remove_userprofile_phone_number.py new file mode 100644 index 0000000..7ee8a6a --- /dev/null +++ b/rest-app/smartpicasso/app/user_profile/migrations/0002_remove_userprofile_phone_number.py @@ -0,0 +1,19 @@ +# Generated by Django 3.1.3 on 2020-12-01 21:54 + +from django.db import migrations + + +class Migration(migrations.Migration): + + atomic = False + + dependencies = [ + ('user_profile', '0001_initial'), + ] + + operations = [ + migrations.RemoveField( + model_name='userprofile', + name='phone_number', + ), + ] diff --git a/rest-app/smartpicasso/app/user_profile/models.py b/rest-app/smartpicasso/app/user_profile/models.py index 1c0c2df..4da1ccf 100644 --- a/rest-app/smartpicasso/app/user_profile/models.py +++ b/rest-app/smartpicasso/app/user_profile/models.py @@ -15,7 +15,6 @@ class UserProfile(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE, related_name='profile') first_name = models.CharField(max_length=50, unique=False) last_name = models.CharField(max_length=50, unique=False) - phone_number = models.CharField(max_length=10, unique=False, null=True, blank=True) class Meta: """ -- 2.20.1 From 041587217304425545447a3b6704b7a73cc332ff Mon Sep 17 00:00:00 2001 From: s460930 Date: Tue, 1 Dec 2020 23:25:45 +0100 Subject: [PATCH 4/5] SMART-39 tests for UserLoginSerializer --- rest-app/smartpicasso/app/user/tests.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/rest-app/smartpicasso/app/user/tests.py b/rest-app/smartpicasso/app/user/tests.py index a33d137..cc52c1c 100644 --- a/rest-app/smartpicasso/app/user/tests.py +++ b/rest-app/smartpicasso/app/user/tests.py @@ -4,6 +4,8 @@ from rest_framework import status from rest_framework.test import APITestCase, APIClient from smartpicasso.app.user.models import User +from smartpicasso.app.user.serializers import UserLoginSerializer +from rest_framework import serializers class UserApiTest(APITestCase): @@ -29,3 +31,18 @@ class UserTest(TestCase): email = 'test@test.com' user = User.objects.create_user(email=email, password='test') self.assertEqual(str(user), email) + + +class UserLoginSerializerTest(TestCase): + serializer = UserLoginSerializer() + + def test_validate_wrong_credentials(self): + data = {'email': 'test@test.com', 'password': '123'} + self.assertRaises(serializers.ValidationError, self.serializer.validate, data) + + def test_validate_success(self): + User.objects.create_user(email='test@test.com', password='test') + data = {'email': 'test@test.com', 'password': 'test'} + result = self.serializer.validate(data) + self.assertEqual(result['email'], 'test@test.com') + self.assertIn('token', result) -- 2.20.1 From 4298190701022677d15b9942f8702fe6c4d48240 Mon Sep 17 00:00:00 2001 From: s460930 Date: Sat, 5 Dec 2020 19:07:25 +0100 Subject: [PATCH 5/5] SMART-39 tests for UserRegistrationSerializer --- rest-app/db.sqlite3 | Bin 167936 -> 167936 bytes .../user/__pycache__/models.cpython-38.pyc | Bin 2416 -> 2416 bytes rest-app/smartpicasso/app/user/tests.py | 45 ++++++++++++++++-- 3 files changed, 42 insertions(+), 3 deletions(-) diff --git a/rest-app/db.sqlite3 b/rest-app/db.sqlite3 index 02b81c542748fab5512fe98010b55b876000b0f2..0aeefde76f76489d795545caff8a5e92ce52c00a 100644 GIT binary patch delta 526 zcmZozz}2vTYl1YR-b5K^M!m*_tqF`v{`0W#<}&by^Bv`rz#U<3tJv}g~TqPs0vM{tPG~L<2qRKGY+px;Q-MGx4#3G>5!ooDW&@0W`w7Aqb zti&}W+t$dy$UxW7NY}tr!O+~w)ZEI*OwZ85!o=7h(agfwIN8+DIL+M5B-zl+GS$c| zDJ9Lq#M02%!YI`wB|j&zBvG#*v81SyC)?N|JvT8kM=v=)ce^AX(`!Z^7Ji^(C-L9m z-_8$mEWf4-vo9kdLs>wIra#DMQkcF?p2-hr$OH!dQ~YcBC-6VtELhOMKYgt}lOPY0 zZ7kb?BH;!cO#D#{Ky^_Y8~yl$1DRNTB_(|gEYeI<%~C84%#BS<5|a{>Ow!T}ERs`A zEK^bq4NQ^)KyJ@=0eggy%cif*X9@?}vYi3wp*ujgtman*IhK$eOw;ewGig9H0>c8V Pk*J_xQfBt$1P28G#FdqT delta 166 zcmZozz}2vTYl1YR_Cy(HM(xIgtqF`v{&O+&Niy(<^Bv`r+}Oy?$K0sNJiUOINp8Cp zAJZvDE@u8o4E&S$@9=NmELhOO&!WQY%Q*c(K9j=qZSqWhK