Commit 03804122a7e14638a478ee6e0b8dcbdd7bef4da3
Exists in
master
Merge branch 'master' of https://git.ucsd.edu/110swag/flashy-backend
Adding uwsgi as a requirement.
Showing 4 changed files Side-by-side Diff
README.md
View file @
0380412
flashcards/api.py
View file @
0380412
... | ... | @@ -43,8 +43,10 @@ |
43 | 43 | raise ValidationError('Email is required') |
44 | 44 | if 'password' not in request.data: |
45 | 45 | raise ValidationError('Password is required') |
46 | - | |
47 | 46 | email = request.data['email'] |
47 | + existing_users = User.objects.filter(email=email) | |
48 | + if existing_users.exists(): | |
49 | + raise ValidationError("An account with this email already exists") | |
48 | 50 | user = User.objects.create_user(email, email=email, password=request.data['password']) |
49 | 51 | |
50 | 52 | body = ''' |
... | ... | @@ -58,7 +60,7 @@ |
58 | 60 | login(request, user) |
59 | 61 | return Response(UserSerializer(user).data, status=HTTP_201_CREATED) |
60 | 62 | |
61 | - def delete(self, request, format=None): | |
63 | + def delete(self, request): | |
62 | 64 | request.user.delete() |
63 | 65 | return Response(status=HTTP_204_NO_CONTENT) |
64 | 66 |
flashcards/tests/test_api.py
View file @
0380412
... | ... | @@ -34,6 +34,18 @@ |
34 | 34 | response = self.client.post(url, data, format='json') |
35 | 35 | self.assertEqual(response.status_code, HTTP_201_CREATED) |
36 | 36 | |
37 | + data = {'email': 'none@none.com', 'password': '1234'} | |
38 | + response = self.client.post('/api/login', data, format='json') | |
39 | + self.assertEqual(response.status_code, HTTP_200_OK) | |
40 | + | |
41 | + | |
42 | + data = {'email': 'none@none.com'} | |
43 | + response = self.client.post(url, data, format='json') | |
44 | + self.assertContains(response, 'Password is required', status_code=400) | |
45 | + | |
46 | + data = {'password': '1234'} | |
47 | + response = self.client.post(url, data, format='json') | |
48 | + self.assertContains(response, 'Email is required', status_code=400) | |
37 | 49 | |
38 | 50 | class ProfileViewTest(APITestCase): |
39 | 51 | def test_get_me(self): |