Skip to content

Commit 28b2acc

Browse files
authored
SZ40X last improvements (#16)
* SZ40X last improvements added. It is done :) * SZ40X last improvements added. It is done :)
1 parent 0101490 commit 28b2acc

File tree

5 files changed

+27
-11
lines changed

5 files changed

+27
-11
lines changed

README.md

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,14 @@ Once it's done, you can check logs by running:
3737
```shell
3838
docker-compose logs -f
3939
```
40+
Wait until server is up and running. You will see this message:
41+
```
42+
ze_backend | Django version 3.0.8, using settings 'ze.config.settings'
43+
ze_backend | Starting development server at http://0.0.0.0:8000/
44+
ze_backend | Quit the server with CONTROL-C.
45+
```
4046

41-
At this point application must be running already. Access:
42-
http://localhost:8000/admin
47+
At this point application must be running already. CTRL+C to quit the logs.
4348

4449
Now we need to migrate the database schema:
4550
```shell
@@ -51,6 +56,7 @@ In case you want to login to admin you'll need a superuser. Run:
5156
docker-compose exec backend python manage.py createsuperuser
5257
```
5358
It will ask you for username, email and password.
59+
You can access admin: http://localhost:8000/admin
5460

5561
Running all unit and API tests:
5662
```shell
@@ -78,15 +84,17 @@ Now let's play around with the API: http://localhost:8000/graphql
7884

7985
### 3.1. Create a partner:
8086
Create a partner and copy the returned id so you can use it in the next Query.
87+
88+
ps: You may try to create partners with same document. It must return an error since it's unique.
8189
```
8290
mutation {
8391
partner(
8492
input: {
85-
tradingName: "Foo2",
86-
ownerName: "Bar2",
93+
tradingName: "Foo",
94+
ownerName: "Bar",
8795
document: "SP100700TO",
88-
coverageArea: {type: "MultiPolygon", coordinates: [[[[30, 20], [45, 40], [10, 40], [30, 20]]],[[[15, 5], [40, 10], [10, 20], [5, 10], [15, 5]]]]},
89-
address: {type: "Point", coordinates: [-46.57421, -21.785741]}
96+
coverageArea: {type: "MultiPolygon", coordinates: [[[[-46.65285,-23.62214],[-46.66087,-23.6175],[-46.66919,-23.61431],[-46.67681,-23.60916],[-46.68238,-23.61879],[-46.69753,-23.61244],[-46.70271,-23.62229],[-46.70967,-23.62544],[-46.72057,-23.63543],[-46.72585,-23.64278],[-46.72505,-23.65023],[-46.72014,-23.65516],[-46.72703,-23.67252],[-46.72053,-23.6773],[-46.71904,-23.68142],[-46.71394,-23.68979],[-46.70936,-23.69737],[-46.70341,-23.69991],[-46.69105,-23.70101],[-46.68075,-23.70266],[-46.67217,-23.69696],[-46.66204,-23.69677],[-46.65157,-23.69543],[-46.63441,-23.69048],[-46.62797,-23.68686],[-46.6229,-23.67696],[-46.62727,-23.67526],[-46.63078,-23.6723],[-46.63372,-23.65602],[-46.63314,-23.65139],[-46.63118,-23.64707],[-46.62985,-23.63813],[-46.62967,-23.6336],[-46.62958,-23.62914],[-46.63482,-23.62981],[-46.64152,-23.6293],[-46.64392,-23.63054],[-46.64598,-23.63088],[-46.64736,-23.62903],[-46.64847,-23.62658],[-46.6498,-23.62405],[-46.65285,-23.62214]]]]},
97+
address: {type: "Point", coordinates: [-46.66771, -23.659363]}
9098
},
9199
)
92100
{
@@ -135,7 +143,7 @@ After saving some partners you can query by location (lat/long).
135143
The search ensures to find the nearest partner which the coverage area includes the location.
136144
```
137145
query {
138-
partner (location: {lat: 9.055862678251549, long: 7.493147848993504}) {
146+
partner (location: {lat: -46.66700, long: -23.659300}) {
139147
id
140148
tradingName
141149
ownerName
@@ -153,7 +161,7 @@ query {
153161
```
154162

155163
### 3.4. Search all partners:
156-
In case you want to search all partners.
164+
Just in case you want to search all partners.
157165
```
158166
query {
159167
allPartners {

ze/graphql/schema.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ class Mutation(ObjectType):
1818
partner = PartnerMutation.Field()
1919

2020

21-
schema = Schema(query=Query, mutation=Mutation)
21+
schema = Schema(query=Query, mutation=Mutation) # noqa

ze/partner/tests/test_apis.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def test_query_search_partner_by_location(self):
7474
}
7575
}
7676
''',
77-
variables={'location': {'lat': -38.59825, 'long': -3.774185}}
77+
variables={'location': {'lat': -38.59825, 'long': -3.774185}} # near to partner 3 and in its coverage area
7878
)
7979
self.assertFields(result, partner, partner_global_id)
8080

ze/partner/tests/test_models.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ def test_partner_found_for_point(self):
2424
self.assertTrue(Partner.objects.filter(coverage_area__contains=point).exists())
2525
self.assertEquals(Partner.objects.get(coverage_area__intersects=point).document, self.partners[2].document)
2626

27+
def test_nearest_partner_from_location(self):
28+
point = Point((-46.66770, -23.659360)) # this point is nearby 2 partners ids 9 and 29, but nearest to 9
29+
partner_documents = Partner.objects.filter(coverage_area__intersects=point).values_list('document', flat=True)
30+
self.assertGreater(partner_documents.count(), 1)
31+
self.assertIn(self.partners[8].document, partner_documents)
32+
self.assertIn(self.partners[28].document, partner_documents)
33+
self.assertEquals(Partner.objects.search_nearest_from_location(point).document, self.partners[8].document)
34+
2735
def test_document_must_be_unique(self):
2836
with self.assertRaises(IntegrityError):
2937
mommy.make(Partner,

ze/partner/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
def load_partner_test_data():
1515
"""
16-
Load test data from JSON file.
16+
Load test data from JSON file. For testing purpose only.
1717
:return:
1818
"""
1919
pdvs_file_path = os.path.join(settings.BASE_DIR, 'partner/tests/files/pdvs.json')

0 commit comments

Comments
 (0)