Skip to content

Commit 596a371

Browse files
shaluchandwanijoshuaocero
authored andcommitted
CV3-76-story(defaultlocation):make default location for new users as kigali (#516)
- write logic to run functionality - add tests for the same [Delivers CV3-76]
1 parent bac40b8 commit 596a371

File tree

5 files changed

+18
-54
lines changed

5 files changed

+18
-54
lines changed

api/user/models.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ class User(Base, Utility):
3232
lazy="joined")
3333

3434
__table_args__ = (
35-
Index(
36-
'ix_unique_user_content',
37-
'name',
38-
unique=True,
39-
postgresql_where=(state == 'active')),
40-
)
35+
Index(
36+
'ix_unique_user_content',
37+
'name',
38+
unique=True,
39+
postgresql_where=(state == 'active')),
40+
)
4141

4242
# TODO Refactor this section after
4343
# reorganising the User <> Location
@@ -49,3 +49,4 @@ def __init__(self, **kwargs):
4949
self.email = kwargs['email']
5050
self.name = kwargs['name']
5151
self.picture = kwargs['picture']
52+
self.location = kwargs.get('location', 'Kigali')

api/user/schema.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -160,18 +160,10 @@ class Arguments:
160160
@Auth.user_roles('Admin', 'Super Admin', 'Default User')
161161
def mutate(self, info, **kwargs):
162162
logged_in_user = get_user_from_db()
163-
location_id = kwargs['location_id']
164163
query_user = User.get_query(info)
165164
user = query_user.filter(UserModel.id == logged_in_user.id).first()
166165
if user.location:
167166
raise GraphQLError('This user already has a location set.')
168-
new_location = LocationModel.query.filter_by(
169-
id=location_id, state="active").first()
170-
if not new_location:
171-
raise GraphQLError('The location supplied does not exist')
172-
user.location = new_location.name
173-
user.save()
174-
return SetUserLocation(user=user)
175167

176168

177169
class CreateUserRole(graphene.Mutation):

fixtures/user/user_fixture.py

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44
mutation {
55
createUser(email: "[email protected]"
66
name: "this user"
7+
location:"Lagos"
78
picture: "www.andela.com/user"){
89
user {
910
email,
1011
name,
11-
picture
12+
picture,
13+
location
1214
}
1315
}
1416
}
@@ -20,7 +22,8 @@
2022
"user": {
2123
"email": "[email protected]",
2224
"name": "this user",
23-
"picture": "www.andela.com/user"
25+
"picture": "www.andela.com/user",
26+
"location": "Lagos"
2427
}
2528
}
2629
}
@@ -245,7 +248,7 @@
245248
'users': [
246249
{
247250
'name': 'Peter Adeoye',
248-
'location': None
251+
'location': 'Lagos'
249252
}
250253
]
251254
}
@@ -344,7 +347,6 @@
344347
}
345348
'''
346349

347-
348350
change_user_location_invalid_user_response = {
349351
"errors": [
350352
{
@@ -470,29 +472,7 @@
470472
}
471473
'''
472474

473-
set_user_location_exists_invalid_location = '''
474-
mutation {
475-
setUserLocation(locationId: 10000){
476-
user{
477-
email
478-
location
479-
}
480-
}
481-
}
482-
'''
483-
484475
set_user_location_mutation_response = {
485-
"data": {
486-
"setUserLocation": {
487-
"user": {
488-
"email": "[email protected]",
489-
"location": "Nairobi"
490-
}
491-
}
492-
}
493-
}
494-
495-
set_location_for_user_with_location_response = {
496476
"errors": [
497477
{
498478
"message": "This user already has a location set.",
@@ -512,10 +492,10 @@
512492
}
513493
}
514494

515-
set_user_location_exists_invalid_location_response = {
495+
set_location_for_user_with_location_response = {
516496
"errors": [
517497
{
518-
"message": "The location supplied does not exist",
498+
"message": "This user already has a location set.",
519499
"locations": [
520500
{
521501
"line": 3,

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,6 @@ virtualenv==15.2.0
3636
Flask-Testing==0.7.1
3737
typing==3.6.4
3838
flake8==3.5.0
39-
coveralls
39+
coveralls==1.8.2
4040
validators==0.12.4
41+
graphql-core==2.2.1

tests/test_user/test_set_user_location.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,12 @@
33
set_user_location_mutation,
44
set_user_location_mutation_response,
55
set_user_location_exists_mutation,
6-
set_location_for_user_with_location_response,
7-
set_user_location_exists_invalid_location,
8-
set_user_location_exists_invalid_location_response
6+
set_location_for_user_with_location_response
97

108
)
119

1210

1311
class TestSetUserLocation(BaseTestCase):
14-
def test_change_user_location_invalid_location_id(self):
15-
"""
16-
Test that the supplied location must exist in the database
17-
"""
18-
CommonTestCases.lagos_admin_token_assert_equal(
19-
self, set_user_location_exists_invalid_location,
20-
set_user_location_exists_invalid_location_response
21-
)
2212

2313
def test_set_user_location(self):
2414
"""

0 commit comments

Comments
 (0)