def add_reading_rooms(contactable, reading_rooms): for link_text, url in reading_rooms: existing_room = ReadingRoomUrls.objects.filter( link_text=link_text, url=url) existing_room = list(existing_room) if len(existing_room) > 0: contactable.reading_room_urls.add(*existing_room) else: r = ReadingRoomUrls(link_text=link_text, url=url) r.save() contactable.reading_room_urls.add(r) return contactable
def update_reading_rooms(contactable, data): """ This ensures that the reading rooms indicated in `data` are added to the contactable (agency, office). If the contactable already has reading rooms, those are deleted first. """ # Delete all existing reading rooms, because we'll re-add them. contactable.reading_room_urls.all().delete() for link_text, url in data.get('reading_rooms', []): rru = ReadingRoomUrls( content_object=contactable, link_text=link_text, url=url) rru.save()
def add_reading_rooms(contactable, reading_rooms): for link_text, url in reading_rooms: existing_room = ReadingRoomUrls.objects.filter(link_text=link_text, url=url) existing_room = list(existing_room) if len(existing_room) > 0: contactable.reading_room_urls.add(*existing_room) else: r = ReadingRoomUrls(link_text=link_text, url=url) r.save() contactable.reading_room_urls.add(r) return contactable
def update_reading_rooms(contactable, data): """ This ensures that the reading rooms indicated in `data` are added to the contactable (agency, office). If the contactable already has reading rooms, those are deleted first. """ # Delete all existing reading rooms, because we'll re-add them. contactable.reading_room_urls.all().delete() for link_text, url in data.get('reading_rooms', []): rru = ReadingRoomUrls(content_object=contactable, link_text=link_text, url=url) rru.save()
def test_reading_room_preparer(self): """ Ensure reading room urls are serialized correctly. """ census = Office.objects.get( slug='department-of-commerce--census-bureau') rone = ReadingRoomUrls(content_object=census, link_text='Url One', url='http://urlone.gov') rone.save() rtwo = ReadingRoomUrls(content_object=census, link_text='Url Two', url='http://urltwo.gov') rtwo.save() data = foia_libraries_preparer(census) serialized_rooms = { 'foia_libraries': [{ 'link_text': 'Url One', 'url': 'http://urlone.gov' }, { 'link_text': 'Url Two', 'url': 'http://urltwo.gov' }] } self.assertEqual(serialized_rooms, data)
def test_reading_rooms(self): census = Office.objects.get( slug='department-of-commerce--census-bureau') rone = ReadingRoomUrls( content_object=census, link_text='Url One', url='http://urlone.gov') rone.save() rtwo = ReadingRoomUrls( content_object=census, link_text='Url Two', url='http://urltwo.gov') rtwo.save() response = self.client.get( reverse( 'contact_landing', args=['department-of-commerce--census-bureau'])) self.assertTrue(200, response.status_code) content = response.content.decode('utf-8') self.assertTrue("Browse the agency's" in content) self.assertTrue('Url One' in content) self.assertTrue('Url Two' in content)
def test_reading_rooms(self): rone = ReadingRoomUrls(link_text='Url One', url='http://urlone.gov') rone.save() rtwo = ReadingRoomUrls(link_text='Url Two', url='http://urltwo.gov') rtwo.save() census = Office.objects.get( slug='department-of-commerce--census-bureau') census.reading_room_urls.add(rone, rtwo) response = self.client.get( reverse( 'contact_landing', args=['department-of-commerce--census-bureau'])) self.assertTrue(200, response.status_code) content = response.content.decode('utf-8') self.assertTrue('FOIA Libraries' in content) self.assertTrue('Url One' in content) self.assertTrue('Url Two' in content)
def test_reading_rooms(self): census = Office.objects.get( slug='department-of-commerce--census-bureau') rone = ReadingRoomUrls(content_object=census, link_text='Url One', url='http://urlone.gov') rone.save() rtwo = ReadingRoomUrls(content_object=census, link_text='Url Two', url='http://urltwo.gov') rtwo.save() response = self.client.get( reverse('contact_landing', args=['department-of-commerce--census-bureau'])) self.assertTrue(200, response.status_code) content = response.content.decode('utf-8') self.assertTrue("Browse the agency's" in content) self.assertTrue('Url One' in content) self.assertTrue('Url Two' in content)
def test_reading_room_preparer(self): """ Ensure reading room urls are serialized correctly. """ rone = ReadingRoomUrls(link_text='Url One', url='http://urlone.gov') rone.save() rtwo = ReadingRoomUrls(link_text='Url Two', url='http://urltwo.gov') rtwo.save() census = Office.objects.get( slug='department-of-commerce--census-bureau') census.reading_room_urls.add(rone, rtwo) data = foia_libraries_preparer(census) serialized_rooms = {'foia_libraries': [ {'link_text': 'Url One', 'url': 'http://urlone.gov'}, {'link_text': 'Url Two', 'url': 'http://urltwo.gov'}]} self.assertEqual(serialized_rooms, data)
def test_str_output(self): r = ReadingRoomUrls(link_text='Link One', url='http://one.gov') self.assertEqual(str(r), 'Link One http://one.gov')