def test_location_widget_returns_two_levels_in_the_location_hierarchy_given_two_levels( self): village = LocationType.objects.create(name='Village', parent=self.city, slug='village') LocationTypeDetails.objects.create(location_type=village, country=self.uganda) Location.objects.create(name='Bukoto', parent=self.kampala_city, type=village) some_type = LocationType.objects.create(name='Sometype', parent=village, slug='sometype') LocationTypeDetails.objects.create(location_type=some_type, country=self.uganda) location_widget = LocationWidget(selected_location=self.kampala_city, level=3) widget_data = location_widget.get_widget_data() self.assertEqual(2, len(widget_data.keys())) self.assertNotIn('country', widget_data.keys()) self.assertNotIn('sometype', widget_data.keys()) self.assertIn('village', widget_data.keys()) self.assertIn(self.kampala_city, widget_data['city'])
def test_gets_second_level_location_ie_below_country_if_no_selected_location_given_excluding_the_lowest_level(self): village = LocationType.objects.create(name='Village', slug='village') LocationTypeDetails.objects.create(location_type=village, country=self.uganda) Location.objects.create(name="Kyanja", tree_parent=self.kampala_city, type=village) location_widget = LocationWidget(None) widget_data = location_widget.get_widget_data() self.assertEqual(2, len(widget_data.keys())) self.assertNotIn('country', widget_data.keys()) self.assertNotIn("village", widget_data.keys()) self.assertIn(self.kampala, widget_data['district']) self.assertEqual([], widget_data['city'])
def test_gets_location_sorted_by_hierarchy_given_a_location_with_parents(self): village = LocationType.objects.create(name='Village', slug='village') LocationTypeDetails.objects.create(location_type=village, country=self.uganda) kyanja = Location.objects.create(name="Kyanja", tree_parent=self.kampala_city, type=village) Location.objects.create(name="Kyanja child", tree_parent=kyanja, type=village) location_widget = LocationWidget(selected_location=self.kampala_city) widget_data = location_widget.get_widget_data() self.assertEqual(2, len(widget_data.keys())) self.assertIn(self.kampala_city, widget_data['city']) self.assertIn(self.kampala, widget_data['district']) self.assertNotIn("village", widget_data.keys()) self.assertNotIn('country', widget_data.keys())
def test_location_widget_returns_two_levels_in_the_location_hierarchy_given_two_levels(self): village = LocationType.objects.create(name='Village', slug='village') LocationTypeDetails.objects.create(location_type=village, country=self.uganda) Location.objects.create(name='Bukoto', tree_parent=self.kampala_city, type=village) some_type = LocationType.objects.create(name='Sometype', slug='sometype') LocationTypeDetails.objects.create(location_type=some_type, country=self.uganda) location_widget = LocationWidget(selected_location=self.kampala_city, level=3) widget_data = location_widget.get_widget_data() self.assertEqual(2, len(widget_data.keys())) self.assertNotIn('country', widget_data.keys()) self.assertNotIn('sometype', widget_data.keys()) self.assertNotIn('village', widget_data.keys()) self.assertIn(self.kampala, widget_data['district']) self.assertIn(self.kampala_city, widget_data['city'])
def test_location_widget_truncate_lowest_level_location_type(self): village = LocationType.objects.create(name='Village', slug='village') LocationTypeDetails.objects.create(location_type=village, country=self.uganda) bukoto = Location.objects.create(name='Bukoto', tree_parent=self.kampala_city, type=village) some_type = LocationType.objects.create(name='Sometype', slug='sometype') LocationTypeDetails.objects.create(location_type=some_type, country=self.uganda) location_widget = LocationWidget(selected_location=self.kampala_city) widget_data = location_widget.get_widget_data() self.assertEqual(3, len(widget_data.keys())) self.assertNotIn('country', widget_data.keys()) self.assertNotIn('sometype', widget_data.keys()) self.assertIn(self.kampala, widget_data['district']) self.assertIn(self.kampala_city, widget_data['city']) self.assertIn(bukoto, widget_data['village'])
def test_gets_second_level_location_ie_below_country_if_no_selected_location_given_excluding_the_lowest_level( self): village = LocationType.objects.create(name='Village', slug='village') LocationTypeDetails.objects.create(location_type=village, country=self.uganda) Location.objects.create(name="Kyanja", tree_parent=self.kampala_city, type=village) location_widget = LocationWidget(None) widget_data = location_widget.get_widget_data() self.assertEqual(2, len(widget_data.keys())) self.assertNotIn('country', widget_data.keys()) self.assertNotIn("village", widget_data.keys()) self.assertIn(self.kampala, widget_data['district']) self.assertEqual([], widget_data['city'])
def test_gets_location_sorted_by_hierarchy_given_a_location_with_parents( self): village = LocationType.objects.create(name='Village', slug='village') LocationTypeDetails.objects.create(location_type=village, country=self.uganda) kyanja = Location.objects.create(name="Kyanja", tree_parent=self.kampala_city, type=village) Location.objects.create(name="Kyanja child", tree_parent=kyanja, type=village) location_widget = LocationWidget(selected_location=self.kampala_city) widget_data = location_widget.get_widget_data() self.assertEqual(2, len(widget_data.keys())) self.assertIn(self.kampala_city, widget_data['city']) self.assertIn(self.kampala, widget_data['district']) self.assertNotIn("village", widget_data.keys()) self.assertNotIn('country', widget_data.keys())
def test_location_widget_truncate_lowest_level_location_type(self): village = LocationType.objects.create(name='Village', slug='village') LocationTypeDetails.objects.create(location_type=village, country=self.uganda) bukoto = Location.objects.create(name='Bukoto', tree_parent=self.kampala_city, type=village) some_type = LocationType.objects.create(name='Sometype', slug='sometype') LocationTypeDetails.objects.create(location_type=some_type, country=self.uganda) location_widget = LocationWidget(selected_location=self.kampala_city) widget_data = location_widget.get_widget_data() self.assertEqual(3, len(widget_data.keys())) self.assertNotIn('country', widget_data.keys()) self.assertNotIn('sometype', widget_data.keys()) self.assertIn(self.kampala, widget_data['district']) self.assertIn(self.kampala_city, widget_data['city']) self.assertIn(bukoto, widget_data['village'])