3
3
from django .contrib .auth .models import Permission , User
4
4
from django .test import Client , TestCase
5
5
6
- from meshapi .models import Building , Install , Member
6
+ from meshapi .models import Building , Install , Link , Member , Sector
7
7
from meshapi .tests .sample_data import sample_building , sample_install , sample_member
8
8
9
9
@@ -25,6 +25,8 @@ def setup_objects():
25
25
install_obj = Install (** inst )
26
26
install_obj .save ()
27
27
28
+ return member_obj , building_obj , install_obj
29
+
28
30
29
31
class TestViewsGetLimitedPermissions (TestCase ):
30
32
c = Client ()
@@ -68,6 +70,9 @@ def test_views_get_install(self):
68
70
"zip_code" : "11111" ,
69
71
"invalid" : False ,
70
72
"address_truth_sources" : "['NYCPlanningLabs']" ,
73
+ "links_from" : [],
74
+ "links_to" : [],
75
+ "sectors" : [],
71
76
"latitude" : 0.0 ,
72
77
"longitude" : 0.0 ,
73
78
"altitude" : 0.0 ,
@@ -186,6 +191,9 @@ def test_views_get_install(self):
186
191
"zip_code" : "11111" ,
187
192
"invalid" : False ,
188
193
"address_truth_sources" : "['NYCPlanningLabs']" ,
194
+ "links_from" : [],
195
+ "links_to" : [],
196
+ "sectors" : [],
189
197
"latitude" : 0.0 ,
190
198
"longitude" : 0.0 ,
191
199
"altitude" : 0.0 ,
@@ -216,6 +224,9 @@ def test_views_get_member(self):
216
224
"zip_code" : "11111" ,
217
225
"invalid" : False ,
218
226
"address_truth_sources" : "['NYCPlanningLabs']" ,
227
+ "links_from" : [],
228
+ "links_to" : [],
229
+ "sectors" : [],
219
230
"latitude" : 0.0 ,
220
231
"longitude" : 0.0 ,
221
232
"altitude" : 0.0 ,
@@ -276,6 +287,211 @@ def test_views_get_building(self):
276
287
)
277
288
278
289
290
+ class TestMonsterQuery (TestCase ):
291
+ c = Client ()
292
+
293
+ def setUp (self ):
294
+ # Create sample data
295
+ member_obj_1 , building_obj_1 , install_obj_1 = setup_objects ()
296
+
297
+ member_obj_2 = Member (id = 2 , ** sample_member )
298
+ member_obj_2 .name = "Donald Smith"
299
+ member_obj_2 .save ()
300
+
301
+ building = sample_building .copy ()
302
+ building ["primary_nn" ] = None
303
+ building_obj_2 = Building (id = 2 , ** building )
304
+ building_obj_2 .save ()
305
+ inst = sample_install .copy ()
306
+
307
+ if inst ["abandon_date" ] == "" :
308
+ inst ["abandon_date" ] = None
309
+
310
+ inst ["building" ] = building_obj_2
311
+ inst ["member" ] = member_obj_2
312
+ inst ["install_number" ] = 2001
313
+ install_obj_2 = Install (** inst )
314
+ install_obj_2 .save ()
315
+
316
+ sector_1 = Sector (
317
+ id = 1 ,
318
+ name = "Vernon" ,
319
+ device_name = "LAP-120" ,
320
+ building = building_obj_1 ,
321
+ status = "Active" ,
322
+ azimuth = 0 ,
323
+ width = 120 ,
324
+ radius = 0.3 ,
325
+ )
326
+ sector_1 .save ()
327
+
328
+ sector_2 = Sector (
329
+ id = 2 ,
330
+ name = "Vernon" ,
331
+ device_name = "LAP-120" ,
332
+ building = building_obj_2 ,
333
+ status = "Active" ,
334
+ azimuth = 0 ,
335
+ width = 120 ,
336
+ radius = 0.3 ,
337
+ )
338
+ sector_2 .save ()
339
+
340
+ link = Link (
341
+ id = 1 ,
342
+ from_building = building_obj_1 ,
343
+ to_building = building_obj_2 ,
344
+ status = Link .LinkStatus .ACTIVE ,
345
+ )
346
+ link .save ()
347
+
348
+ self .admin_user = User .objects .create_superuser (
349
+ username = "admin" , password = "admin_password" , email = "admin@example.com"
350
+ )
351
+
352
+ def test_views_get_link (self ):
353
+ self .maxDiff = None
354
+ self .c .login (username = "admin" , password = "admin_password" )
355
+
356
+ response = self .c .get (f"/api/v1/links/1/" )
357
+
358
+ code = 200
359
+ self .assertEqual (
360
+ code ,
361
+ response .status_code ,
362
+ f"status code incorrect. Should be { code } , but got { response .status_code } " ,
363
+ )
364
+
365
+ response_obj = json .loads (response .content )
366
+ self .assertEqual (response_obj ["status" ], "Active" )
367
+ self .assertEqual (
368
+ response_obj ["from_building" ],
369
+ {
370
+ "id" : 1 ,
371
+ "installs" : [
372
+ {
373
+ "install_number" : 2000 ,
374
+ "member" : {
375
+ "id" : 1 ,
376
+ "name" : "John Smith" ,
377
+ "primary_email_address" : "john.smith@example.com" ,
378
+ "stripe_email_address" : None ,
379
+ "additional_email_addresses" : [],
380
+ "all_email_addresses" : ["john.smith@example.com" ],
381
+ "phone_number" : "555-555-5555" ,
382
+ "slack_handle" : "@jsmith" ,
383
+ "invalid" : False ,
384
+ "contact_notes" : None ,
385
+ },
386
+ "network_number" : 2000 ,
387
+ "install_status" : "Active" ,
388
+ "ticket_id" : 69 ,
389
+ "request_date" : "2022-02-27" ,
390
+ "install_date" : "2022-03-01" ,
391
+ "abandon_date" : "9999-01-01" ,
392
+ "unit" : "3" ,
393
+ "roof_access" : True ,
394
+ "referral" : None ,
395
+ "notes" : "Referral: Read about it on the internet" ,
396
+ "diy" : None ,
397
+ }
398
+ ],
399
+ "sectors" : [
400
+ {
401
+ "id" : 1 ,
402
+ "name" : "Vernon" ,
403
+ "radius" : 0.3 ,
404
+ "azimuth" : 0 ,
405
+ "width" : 120 ,
406
+ "status" : "Active" ,
407
+ "install_date" : None ,
408
+ "abandon_date" : None ,
409
+ "device_name" : "LAP-120" ,
410
+ "ssid" : None ,
411
+ "notes" : None ,
412
+ }
413
+ ],
414
+ "bin" : 8888 ,
415
+ "building_status" : "Active" ,
416
+ "street_address" : "3333 Chom St" ,
417
+ "city" : "Brooklyn" ,
418
+ "state" : "NY" ,
419
+ "zip_code" : "11111" ,
420
+ "invalid" : False ,
421
+ "address_truth_sources" : "['NYCPlanningLabs']" ,
422
+ "latitude" : 0.0 ,
423
+ "longitude" : 0.0 ,
424
+ "altitude" : 0.0 ,
425
+ "primary_nn" : None ,
426
+ "node_name" : None ,
427
+ "notes" : None ,
428
+ },
429
+ )
430
+ self .assertEqual (
431
+ response_obj ["to_building" ],
432
+ {
433
+ "id" : 2 ,
434
+ "installs" : [
435
+ {
436
+ "install_number" : 2001 ,
437
+ "member" : {
438
+ "id" : 2 ,
439
+ "name" : "Donald Smith" ,
440
+ "primary_email_address" : "john.smith@example.com" ,
441
+ "stripe_email_address" : None ,
442
+ "additional_email_addresses" : [],
443
+ "all_email_addresses" : ["john.smith@example.com" ],
444
+ "phone_number" : "555-555-5555" ,
445
+ "slack_handle" : "@jsmith" ,
446
+ "invalid" : False ,
447
+ "contact_notes" : None ,
448
+ },
449
+ "network_number" : 2000 ,
450
+ "install_status" : "Active" ,
451
+ "ticket_id" : 69 ,
452
+ "request_date" : "2022-02-27" ,
453
+ "install_date" : "2022-03-01" ,
454
+ "abandon_date" : "9999-01-01" ,
455
+ "unit" : "3" ,
456
+ "roof_access" : True ,
457
+ "referral" : None ,
458
+ "notes" : "Referral: Read about it on the internet" ,
459
+ "diy" : None ,
460
+ }
461
+ ],
462
+ "sectors" : [
463
+ {
464
+ "id" : 2 ,
465
+ "name" : "Vernon" ,
466
+ "radius" : 0.3 ,
467
+ "azimuth" : 0 ,
468
+ "width" : 120 ,
469
+ "status" : "Active" ,
470
+ "install_date" : None ,
471
+ "abandon_date" : None ,
472
+ "device_name" : "LAP-120" ,
473
+ "ssid" : None ,
474
+ "notes" : None ,
475
+ }
476
+ ],
477
+ "bin" : 8888 ,
478
+ "building_status" : "Active" ,
479
+ "street_address" : "3333 Chom St" ,
480
+ "city" : "Brooklyn" ,
481
+ "state" : "NY" ,
482
+ "zip_code" : "11111" ,
483
+ "invalid" : False ,
484
+ "address_truth_sources" : "['NYCPlanningLabs']" ,
485
+ "latitude" : 0.0 ,
486
+ "longitude" : 0.0 ,
487
+ "altitude" : 0.0 ,
488
+ "primary_nn" : None ,
489
+ "node_name" : None ,
490
+ "notes" : None ,
491
+ },
492
+ )
493
+
494
+
279
495
class TestViewsPutAdmin (TestCase ):
280
496
c = Client ()
281
497
0 commit comments