def test_update_link_external(self): existing_link = Link( name='Wikimapia', description='A great mapping application', destination='https://wikimapia.org', owner=self.logged_in_user, is_external=False) existing_link.save() response = self.app.get( reverse('link-edit', kwargs={'pk': existing_link.pk})) form = response.form self.assertEquals(response.html.h1.get_text(strip=True), 'ToolEdit %s' % existing_link.name) self.assertEquals(form['name'].value, 'Wikimapia') self.assertEquals(form['description'].value, 'A great mapping application') self.assertEquals(form['destination'].value, 'https://wikimapia.org') self.assertEqual(form['is_external'].value, 'False') form['is_external'].select('True') response = form.submit().follow() self.assertIn('Wikimapia', response.html.find('h1').text) self.assertIn('External', response.html.find(id="is_external").text)
def test_edit_link_submit(self): existing_link = Link(name='Wikimapia', description='A great mapping application', destination='https://wikimapia.org', owner=self.logged_in_user) existing_link.save() form = self.app.get( reverse('link-edit', kwargs={'pk': existing_link.pk})).form self.assertEquals(form['name'].value, 'Wikimapia') self.assertEquals(form['description'].value, 'A great mapping application') self.assertEquals(form['destination'].value, 'https://wikimapia.org') form['name'].value = 'Bing Maps' form['description'].value = 'Another great mapping application' form['destination'].value = 'https://maps.bing.com' response = form.submit() self.assertEquals( 'http://localhost:80%s' % reverse('link-detail', kwargs={'pk': existing_link.pk}), response.location) response = response.follow() self.assertIn('Bing Maps', response) self.assertNotIn('Wikimapia', response) self.assertIn('Another great mapping application', response) self.assertNotIn('A great mapping application', response) self.assertIn('https://maps.bing.com', response) self.assertNotIn('https://wikimapia.org', response)
def test_update_link_external(self): existing_link = Link(name='Wikimapia', description='A great mapping application', destination='https://wikimapia.org', owner=self.logged_in_user, is_external=False) existing_link.save() response = self.app.get( reverse('link-edit', kwargs={'pk': existing_link.pk})) form = response.form self.assertEquals(response.html.h1.get_text(strip=True), 'ToolEdit %s' % existing_link.name) self.assertEquals(form['name'].value, 'Wikimapia') self.assertEquals(form['description'].value, 'A great mapping application') self.assertEquals(form['destination'].value, 'https://wikimapia.org') self.assertEqual(form['is_external'].value, 'False') form['is_external'].select('True') response = form.submit().follow() self.assertIn('Wikimapia', response.html.find('h1').text) self.assertIn('External', response.html.find(id="is_external").text)
class CategorisedLinksWithCategoriesUpdateTest(WebTest): def setUp(self): self.logged_in_user = make_user() self.assertTrue(login_user(self, self.logged_in_user)) self.existing_link = Link( name='Tweetbot', description='A great twitter application', destination='https://tweetbot.com', owner=self.logged_in_user,) self.existing_link.save() self.existing_link.categories.add('social') self.existing_link.categories.add('imagery') self.existing_link.save() def test_update_link_with_existing_categories_render(self): form = self.app.get( reverse('link-edit', kwargs={'pk': self.existing_link.pk})).form self.assertTrue(form.get('categories', index=1).checked) self.assertIn( 'Social', form.html.findAll( 'label', {'class': 'link-category-label'} )[0].text, ) self.assertTrue(form.get('categories', index=1).checked) self.assertIn( 'Imagery', form.html.findAll( 'label', {'class': 'link-category-label'} )[1].text, ) self.assertEquals(form.get('categories', index=2).value, '') def test_update_link_with_existing_categories_submit(self): form = self.app.get( reverse('link-edit', kwargs={'pk': self.existing_link.pk})).form form.get('categories', index=1).checked = False # Imagery response = form.submit().follow() self.assertIn('Tweetbot', response.html.find('h1').text) self.assertIn( 'Fake Fakerly', response.html.find(id='link_owner').text, ) # To find all the categories. then map to get `text` categories = [element.text for element in response.html.findAll( None, {"class": "link-category"}) ] assert "Social" in categories assert "Imagery" not in categories self.assertEquals(len(categories), 1)
class LinksWithInterstitialTest(WebTest): def setUp(self): self.logged_in_user = make_user() self.assertTrue(login_user(self, self.logged_in_user)) self.external_link = Link( name='Tweetbot', description='A great twitter application', destination='https://tweetbot.com', owner=self.logged_in_user, is_external=True,) self.external_link.save() self.internal_link = Link( name='Not Wikimapia', description='Pretend this is not Wikimapia', destination='https://wikimapia.org', owner=self.logged_in_user, is_external=False,) self.internal_link.save() def test_external_link_goes_to_interstitial(self): response = self.app.get( reverse('link-detail', kwargs={'pk': self.external_link.pk})) response = response.click(linkid="link_follow_button").follow() confirm_button = response.html.find(id="confirm_redirect_button") cancel_button = response.html.find(id="cancel_button") self.assertEquals( confirm_button.attrs['data-href'], self.external_link.destination ) self.assertEquals( cancel_button.attrs['href'], reverse('link-detail', kwargs={'pk': self.external_link.pk}) ) self.assertIsNotNone(confirm_button) def test_internal_link_does_not_go_to_interstitial(self): response = self.app.get( reverse('link-detail', kwargs={'pk': self.internal_link.pk})) response = response.click(linkid="link_follow_button").follow() confirm_button = response.html.find(id="confirm_redirect_button") cancel_button = response.html.find(id="cancel_button") self.assertIsNone(cancel_button) self.assertIsNone(confirm_button)
class LinksWithInterstitialTest(WebTest): def setUp(self): self.logged_in_user = make_user() self.assertTrue(login_user(self, self.logged_in_user)) self.external_link = Link( name='Tweetbot', description='A great twitter application', destination='https://tweetbot.com', owner=self.logged_in_user, is_external=True, ) self.external_link.save() self.internal_link = Link( name='Not Wikimapia', description='Pretend this is not Wikimapia', destination='https://wikimapia.org', owner=self.logged_in_user, is_external=False, ) self.internal_link.save() def test_external_link_goes_to_interstitial(self): response = self.app.get( reverse('link-detail', kwargs={'pk': self.external_link.pk})) response = response.click(linkid="link_follow_button").follow() confirm_button = response.html.find(id="confirm_redirect_button") cancel_button = response.html.find(id="cancel_button") self.assertEquals(confirm_button.attrs['data-href'], self.external_link.destination) self.assertEquals( cancel_button.attrs['href'], reverse('link-detail', kwargs={'pk': self.external_link.pk})) self.assertIsNotNone(confirm_button) def test_internal_link_does_not_go_to_interstitial(self): response = self.app.get( reverse('link-detail', kwargs={'pk': self.internal_link.pk})) response = response.click(linkid="link_follow_button").follow() confirm_button = response.html.find(id="confirm_redirect_button") cancel_button = response.html.find(id="cancel_button") self.assertIsNone(cancel_button) self.assertIsNone(confirm_button)
def setUp(self): self.logged_in_user = make_user() self.assertTrue(login_user(self, self.logged_in_user)) existing_link = Link( name='Tweetbot', description='A great twitter application', destination='https://tweetbot.com', owner=self.logged_in_user,) existing_link.save() existing_link.categories.add('social') existing_link.categories.add('imagery') existing_link.save()
def test_update_link_button(self): existing_link = Link(name='Wikimapia', description='A great mapping application', destination='https://wikimapia.org', owner=self.logged_in_user, is_external=False) existing_link.save() response = self.app.get( reverse('link-detail', kwargs={'pk': existing_link.pk})) edit_button = response.html.find(None, {"id": "edit-button"}) self.assertIsNotNone(edit_button) self.assertEqual(reverse('link-edit', kwargs={'pk': existing_link.pk}), edit_button.get('href'))
def test_edit_link_render(self): existing_link = Link(name='Wikimapia', description='A great mapping application', destination='https://wikimapia.org', owner=self.logged_in_user) existing_link.save() form = self.app.get( reverse('link-edit', kwargs={'pk': existing_link.pk})).form self.assertEquals(form['name'].value, 'Wikimapia') self.assertEquals(form['description'].value, 'A great mapping application') self.assertEquals(form['destination'].value, 'https://wikimapia.org')
def setUp(self): self.logged_in_user = make_user() self.assertTrue(login_user(self, self.logged_in_user)) existing_link = Link( name='Tweetbot', description='A great twitter application', destination='https://tweetbot.com', owner=self.logged_in_user, ) existing_link.save() existing_link.categories.add('social') existing_link.categories.add('imagery') existing_link.save()
def generate_fake_links(owner, start=1, count=1, is_external=False): for i in range(start, start + count): if is_external: url = "https://testsite%d.com" % i else: url = "https://testsite%d.dstl.gov.uk" % i link = Link( name="Test Tool %d" % i, description='How do you describe a tool like tool %d?' % i, destination=url, owner=owner, is_external=is_external ) link.save() yield link
def test_edit_link_render(self): existing_link = Link( name='Wikimapia', description='A great mapping application', destination='https://wikimapia.org', owner=self.logged_in_user) existing_link.save() form = self.app.get( reverse('link-edit', kwargs={'pk': existing_link.pk})).form self.assertEquals(form['name'].value, 'Wikimapia') self.assertEquals(form['description'].value, 'A great mapping application') self.assertEquals(form['destination'].value, 'https://wikimapia.org')
def test_update_to_empty_link(self): existing_link = Link( name='Wikimapia', description='A great mapping application', destination='https://wikimapia.org', owner=self.logged_in_user) existing_link.save() form = self.app.get( reverse('link-edit', kwargs={'pk': existing_link.pk})).form self.assertEquals(form['name'].value, 'Wikimapia') self.assertEquals(form['description'].value, 'A great mapping application') self.assertEquals(form['destination'].value, 'https://wikimapia.org') form['name'].value = '' form['description'].value = 'Another great mapping application' form['destination'].value = 'https://maps.bing.com' response = form.submit() error_list = response.html.find('ul', {'class': 'form-error-list'}) self.assertIsNotNone(error_list) self.assertEqual(len(error_list.findChildren('li')), 1) self.assertEqual(len(error_list.findChildren('a')), 1) self.assertIsNotNone(error_list.findChildren('a')[0].attrs['href']) self.assertEqual( error_list.findChildren('a')[0].attrs['href'], '#id_name_group' ) name_group = response.html.find(id='id_name_group') self.assertIsNotNone(name_group) name_errors = response.html.find(id='id_name_error_list') self.assertIsNotNone(name_errors) self.assertEqual(len(name_errors.findChildren()), 1) form = response.form self.assertEquals(form['name'].value, '') self.assertEquals(form['description'].value, 'Another great mapping application') self.assertEquals(form['destination'].value, 'https://maps.bing.com') self.assertEquals(form['categories'].value, '')
def test_update_link_button(self): existing_link = Link( name='Wikimapia', description='A great mapping application', destination='https://wikimapia.org', owner=self.logged_in_user, is_external=False) existing_link.save() response = self.app.get( reverse('link-detail', kwargs={'pk': existing_link.pk})) edit_button = response.html.find(None, {"id": "edit-button"}) self.assertIsNotNone(edit_button) self.assertEqual( reverse('link-edit', kwargs={'pk': existing_link.pk}), edit_button.get('href') )
def test_update_to_empty_link(self): existing_link = Link(name='Wikimapia', description='A great mapping application', destination='https://wikimapia.org', owner=self.logged_in_user) existing_link.save() form = self.app.get( reverse('link-edit', kwargs={'pk': existing_link.pk})).form self.assertEquals(form['name'].value, 'Wikimapia') self.assertEquals(form['description'].value, 'A great mapping application') self.assertEquals(form['destination'].value, 'https://wikimapia.org') form['name'].value = '' form['description'].value = 'Another great mapping application' form['destination'].value = 'https://maps.bing.com' response = form.submit() error_list = response.html.find('ul', {'class': 'form-error-list'}) self.assertIsNotNone(error_list) self.assertEqual(len(error_list.findChildren('li')), 1) self.assertEqual(len(error_list.findChildren('a')), 1) self.assertIsNotNone(error_list.findChildren('a')[0].attrs['href']) self.assertEqual( error_list.findChildren('a')[0].attrs['href'], '#id_name_group') name_group = response.html.find(id='id_name_group') self.assertIsNotNone(name_group) name_errors = response.html.find(id='id_name_error_list') self.assertIsNotNone(name_errors) self.assertEqual(len(name_errors.findChildren()), 1) form = response.form self.assertEquals(form['name'].value, '') self.assertEquals(form['description'].value, 'Another great mapping application') self.assertEquals(form['destination'].value, 'https://maps.bing.com') self.assertEquals(form['categories'].value, '')
def test_edit_link_submit(self): existing_link = Link( name='Wikimapia', description='A great mapping application', destination='https://wikimapia.org', owner=self.logged_in_user) existing_link.save() form = self.app.get( reverse('link-edit', kwargs={'pk': existing_link.pk})).form self.assertEquals(form['name'].value, 'Wikimapia') self.assertEquals(form['description'].value, 'A great mapping application') self.assertEquals(form['destination'].value, 'https://wikimapia.org') form['name'].value = 'Bing Maps' form['description'].value = 'Another great mapping application' form['destination'].value = 'https://maps.bing.com' response = form.submit() self.assertEquals( 'http://localhost:80%s' % reverse( 'link-detail', kwargs={'pk': existing_link.pk}), response.location ) response = response.follow() self.assertIn('Bing Maps', response) self.assertNotIn('Wikimapia', response) self.assertIn('Another great mapping application', response) self.assertNotIn('A great mapping application', response) self.assertIn('https://maps.bing.com', response) self.assertNotIn('https://wikimapia.org', response)
class LinkNotLoggedInTest(WebTest): def setUp(self): self.complete_user = make_user() self.complete_user.best_way_to_find = 'Whatever' self.complete_user.best_way_to_contact = 'Whatever' o = Organisation.objects.create(name='Whatever') t = Team.objects.create(name='Whatever', organisation=o) self.complete_user.teams.add(t) self.complete_user.save() self.incomplete_user = make_user( userid='*****@*****.**', email='*****@*****.**', name='Fake2 Fakerly') self.incomplete_user.teams.add(t) self.incomplete_user.save() self.teamless_user = make_user( userid='*****@*****.**', email='*****@*****.**', name='Fake3 Fakerly') self.teamless_user.best_way_to_find = 'Whatever' self.teamless_user.best_way_to_contact = 'Whatever' self.teamless_user.save() self.existing_link = Link( name='Wikimapia', description='A great mapping application', destination='https://wikimapia.org', owner=self.complete_user) self.existing_link.save() def test_create_link_redirects_to_login(self): response = self.app.get(reverse('link-create')).follow() self.assertEqual( response.html.find( 'label', {"for": "id_userid"} ).text.strip(' \n'), 'Login with ID.' ) self.assertIn('next=%s' % reverse('link-create'), response.request.url) return response def test_login_but_follows_when_logged_in_for_completed_user(self): response = self.test_create_link_redirects_to_login() form = response.form form['userid'] = self.complete_user.userid response = form.submit().follow() self.assertNotIn( 'next=%s' % reverse('link-create'), response.request.url ) self.assertIn(reverse('link-create'), response.request.url) def test_login_but_follows_when_logged_in_for_incomplete_user(self): response = self.test_create_link_redirects_to_login() form = response.form form['userid'] = self.incomplete_user.userid response = form.submit().follow() self.assertNotIn( 'next=%s' % reverse('link-create'), response.request.url ) self.assertIn(reverse('link-create'), response.request.url) def test_login_but_follows_when_logged_in_for_teamless_user(self): response = self.test_create_link_redirects_to_login() form = response.form form['userid'] = self.teamless_user.userid response = form.submit().follow() self.assertNotIn( 'next=%s' % reverse('link-create'), response.request.url ) self.assertIn(reverse('link-create'), response.request.url) def test_update_link_redirects_to_login(self): link_update_url = reverse( 'link-edit', kwargs={'pk': self.existing_link.pk} ) response = self.app.get(link_update_url).follow() self.assertEqual( response.html.find( 'label', {"for": "id_userid"} ).text.strip(' \n'), 'Login with ID.' ) self.assertIn( 'next=%s' % link_update_url, response.request.url )
class LinkTest(WebTest): def setUp(self): self.owner_user = make_user( userid='owner', email='*****@*****.**', name='Owner User') self.existing_link = Link( name='Wikimapia', description='A great mapping application', destination='https://wikimapia.org', owner=self.owner_user) self.existing_link.save() self.first_editor = make_user( userid='first_editor', email='*****@*****.**', name='First Editor') self.second_editor = make_user( userid='second_editor', email='*****@*****.**') self.assertTrue(login_user(self, self.first_editor)) def test_edit_link_button_is_visible_to_non_owner(self): response = self.app.get( reverse('link-detail', kwargs={'pk': self.existing_link.pk})) edit_button = response.html.find(None, {'id': 'edit-button'}) self.assertIsNotNone(edit_button) def test_edit_link_submit_works(self): form = self.app.get( reverse('link-edit', kwargs={'pk': self.existing_link.pk})).form self.assertEquals(form['name'].value, 'Wikimapia') self.assertEquals(form['description'].value, 'A great mapping application') self.assertEquals(form['destination'].value, 'https://wikimapia.org') form['name'].value = 'Bing Maps' form['description'].value = 'A brilliant free mapping application' form['destination'].value = 'https://maps.bing.com' response = form.submit().follow() self.assertIn('Bing Maps', response) self.assertNotIn('Wikimapia', response) self.assertIn('A brilliant free mapping application', response) self.assertNotIn('A great mapping application', response) self.assertIn('https://maps.bing.com', response) self.assertNotIn('https://wikimapia.org', response) owner_element = response.html.find(None, {'id': 'link_owner'}) self.assertIn(self.owner_user.name, owner_element.text) self.assertIn(self.first_editor.name, owner_element.text) def test_editor_stack_stored(self): form = self.app.get( reverse('link-edit', kwargs={'pk': self.existing_link.pk})).form # Edit with the first editor self.assertEquals(form['name'].value, 'Wikimapia') self.assertEquals(form['description'].value, 'A great mapping application') self.assertEquals(form['destination'].value, 'https://wikimapia.org') form['name'].value = 'Bing Maps' form['description'].value = 'A brilliant free mapping application' form['destination'].value = 'https://maps.bing.com' response = form.submit() # Login as the second editor self.assertTrue(login_user(self, self.second_editor)) form = self.app.get( reverse('link-edit', kwargs={'pk': self.existing_link.pk})).form # Edit with the second editor form['name'].value = 'Panoramio' form['description'].value = 'A super free mapping application' form['destination'].value = 'https://panoramio.com' # So we can make sure it works in both cases form['is_external'].select('True') response = form.submit().follow() self.assertIn('Panoramio', response) self.assertNotIn('Bing Maps', response) self.assertIn('A super free mapping application', response) self.assertNotIn('A brilliant mapping application', response) self.assertIn('https://panoramio.com', response) self.assertNotIn('https://maps.bing.com', response) owner_element = response.html.find(None, {'id': 'link_owner'}) # Only show the most recent edit's author self.assertIn(str(self.owner_user), owner_element.text) self.assertNotIn(str(self.first_editor), owner_element.text) self.assertIn(str(self.second_editor), owner_element.text) # Store all the edits edits_oldest_first = self.existing_link.edits.order_by('date').all() self.assertEqual(edits_oldest_first[0].user, self.first_editor) self.assertEqual(edits_oldest_first[1].user, self.second_editor) self.assertTrue( edits_oldest_first[1].date > edits_oldest_first[0].date )
def test_top_teams_and_orgs(self): # Create three orgs o1 = Organisation(name='org0001') o1.save() o2 = Organisation(name='org0002') o2.save() o3 = Organisation(name='org0003') o3.save() # Create SEVEN teams!!! Grouped into organistions t1 = Team(name='team0001', organisation=o1) t1.save() t2 = Team(name='team0002', organisation=o1) t2.save() t3 = Team(name='team0003', organisation=o1) t3.save() t4 = Team(name='team0004', organisation=o2) t4.save() t5 = Team(name='team0005', organisation=o2) t5.save() t6 = Team(name='team0006', organisation=o3) t6.save() t7 = Team(name='team0007', organisation=o3) t7.save() # Now we need three users, and throw them into teams u1 = get_user_model().objects.create_user(userid='user0001') u1.save() u1.teams.add(t2, t3, t4) u1.save() u2 = get_user_model().objects.create_user(userid='user0002') u2.save() u2.teams.add(t5, t6) u2.save() u3 = get_user_model().objects.create_user(userid='user0003') u3.save() u3.teams.add(t3, t5, t6, t7) u3.save() # Last and not least we need a tool for everyone to use l1 = Link(name='link0001', is_external=True, owner=u1, destination='http://google.com') l1.save() # Now we need to log the activity of each user. # # User 1, is going to use the tool 4 times. for i in range(0, 4): l1.register_usage(user=u1, force_new=True) # User 2, is going to use the tool 2 times. for i in range(0, 2): l1.register_usage(user=u2, force_new=True) # User 3, is going to use the tool 5 times. for i in range(0, 5): l1.register_usage(user=u3, force_new=True) # Login as the first user form = self.app.get(reverse('login')).form form['userid'] = 'user0001' form.submit() # Now lets go an have a look at the details page, and check # out the teams and organisations usage count. details_page = self.app.get( reverse('link-detail', kwargs={'pk': l1.pk})) # Due to the counting above, we know the teams have used the tool # the following amount, so lets check for that... # t1:0, t2:4, t3:9, t4:4, t5:7, t6:7, t7:5 # i.e. there are no members is team 1. # only user 1 is in team 2. # users 1 & 3 are in team 3. usage_by_teams = details_page.html.find( 'ul', id='usage-by-teams').findAll('li') self.assertEquals(usage_by_teams[0].text, 'team0003 have collectively used the tool 9 times') self.assertEquals(usage_by_teams[1].text, 'team0005 have collectively used the tool 7 times') self.assertEquals(usage_by_teams[2].text, 'team0006 have collectively used the tool 7 times') self.assertEquals(usage_by_teams[3].text, 'team0007 have collectively used the tool 5 times') self.assertEquals(usage_by_teams[4].text, 'team0002 have collectively used the tool 4 times') # We do a similar thing with organisations, which are tricky # because user 1 is in team 2 & 3, so both those teams get the # 4 times user 1 used the tool. But teams 2 & 3 are both in org 1, # and the code has made sure to only count the useage once, rather # than 4 times from team 2 and 4 again from team 3. This checks # that based on the numbers above the results are as follows. # o1:9, o2:11, o3:7. Ordered that's o2,o1,o3. used_by_organisations = details_page.html.find( 'ul', id='usage-by-organisations').findAll('li') self.assertEquals(used_by_organisations[0].text, 'org0002 have collectively used the tool 11 times') self.assertEquals(used_by_organisations[1].text, 'org0001 have collectively used the tool 9 times') self.assertEquals(used_by_organisations[2].text, 'org0003 have collectively used the tool 7 times')
class LinkTest(WebTest): def setUp(self): self.owner_user = make_user(userid='owner', email='*****@*****.**', name='Owner User') self.existing_link = Link(name='Wikimapia', description='A great mapping application', destination='https://wikimapia.org', owner=self.owner_user) self.existing_link.save() self.first_editor = make_user(userid='first_editor', email='*****@*****.**', name='First Editor') self.second_editor = make_user(userid='second_editor', email='*****@*****.**') self.assertTrue(login_user(self, self.first_editor)) def test_edit_link_button_is_visible_to_non_owner(self): response = self.app.get( reverse('link-detail', kwargs={'pk': self.existing_link.pk})) edit_button = response.html.find(None, {'id': 'edit-button'}) self.assertIsNotNone(edit_button) def test_edit_link_submit_works(self): form = self.app.get( reverse('link-edit', kwargs={'pk': self.existing_link.pk})).form self.assertEquals(form['name'].value, 'Wikimapia') self.assertEquals(form['description'].value, 'A great mapping application') self.assertEquals(form['destination'].value, 'https://wikimapia.org') form['name'].value = 'Bing Maps' form['description'].value = 'A brilliant free mapping application' form['destination'].value = 'https://maps.bing.com' response = form.submit().follow() self.assertIn('Bing Maps', response) self.assertNotIn('Wikimapia', response) self.assertIn('A brilliant free mapping application', response) self.assertNotIn('A great mapping application', response) self.assertIn('https://maps.bing.com', response) self.assertNotIn('https://wikimapia.org', response) owner_element = response.html.find(None, {'id': 'link_owner'}) self.assertIn(self.owner_user.name, owner_element.text) self.assertIn(self.first_editor.name, owner_element.text) def test_editor_stack_stored(self): form = self.app.get( reverse('link-edit', kwargs={'pk': self.existing_link.pk})).form # Edit with the first editor self.assertEquals(form['name'].value, 'Wikimapia') self.assertEquals(form['description'].value, 'A great mapping application') self.assertEquals(form['destination'].value, 'https://wikimapia.org') form['name'].value = 'Bing Maps' form['description'].value = 'A brilliant free mapping application' form['destination'].value = 'https://maps.bing.com' response = form.submit() # Login as the second editor self.assertTrue(login_user(self, self.second_editor)) form = self.app.get( reverse('link-edit', kwargs={'pk': self.existing_link.pk})).form # Edit with the second editor form['name'].value = 'Panoramio' form['description'].value = 'A super free mapping application' form['destination'].value = 'https://panoramio.com' # So we can make sure it works in both cases form['is_external'].select('True') response = form.submit().follow() self.assertIn('Panoramio', response) self.assertNotIn('Bing Maps', response) self.assertIn('A super free mapping application', response) self.assertNotIn('A brilliant mapping application', response) self.assertIn('https://panoramio.com', response) self.assertNotIn('https://maps.bing.com', response) owner_element = response.html.find(None, {'id': 'link_owner'}) # Only show the most recent edit's author self.assertIn(str(self.owner_user), owner_element.text) self.assertNotIn(str(self.first_editor), owner_element.text) self.assertIn(str(self.second_editor), owner_element.text) # Store all the edits edits_oldest_first = self.existing_link.edits.order_by('date').all() self.assertEqual(edits_oldest_first[0].user, self.first_editor) self.assertEqual(edits_oldest_first[1].user, self.second_editor) self.assertTrue( edits_oldest_first[1].date > edits_oldest_first[0].date)
def test_top_teams_and_orgs(self): # Create three orgs o1 = Organisation(name='org0001') o1.save() o2 = Organisation(name='org0002') o2.save() o3 = Organisation(name='org0003') o3.save() # Create SEVEN teams!!! Grouped into organistions t1 = Team(name='team0001', organisation=o1) t1.save() t2 = Team(name='team0002', organisation=o1) t2.save() t3 = Team(name='team0003', organisation=o1) t3.save() t4 = Team(name='team0004', organisation=o2) t4.save() t5 = Team(name='team0005', organisation=o2) t5.save() t6 = Team(name='team0006', organisation=o3) t6.save() t7 = Team(name='team0007', organisation=o3) t7.save() # Now we need three users, and throw them into teams u1 = get_user_model().objects.create_user(userid='user0001') u1.save() u1.teams.add(t2, t3, t4) u1.save() u2 = get_user_model().objects.create_user(userid='user0002') u2.save() u2.teams.add(t5, t6) u2.save() u3 = get_user_model().objects.create_user(userid='user0003') u3.save() u3.teams.add(t3, t5, t6, t7) u3.save() # Last and not least we need a tool for everyone to use l1 = Link( name='link0001', is_external=True, owner=u1, destination='http://google.com' ) l1.save() # Now we need to log the activity of each user. # # User 1, is going to use the tool 4 times. for i in range(0, 4): l1.register_usage(user=u1, force_new=True) # User 2, is going to use the tool 2 times. for i in range(0, 2): l1.register_usage(user=u2, force_new=True) # User 3, is going to use the tool 5 times. for i in range(0, 5): l1.register_usage(user=u3, force_new=True) # Login as the first user form = self.app.get(reverse('login')).form form['userid'] = 'user0001' form.submit() # Now lets go an have a look at the details page, and check # out the teams and organisations usage count. details_page = self.app.get( reverse('link-detail', kwargs={'pk': l1.pk})) # Due to the counting above, we know the teams have used the tool # the following amount, so lets check for that... # t1:0, t2:4, t3:9, t4:4, t5:7, t6:7, t7:5 # i.e. there are no members is team 1. # only user 1 is in team 2. # users 1 & 3 are in team 3. usage_by_teams = details_page.html.find( 'ul', id='usage-by-teams' ).findAll('li') self.assertEquals(usage_by_teams[0].text, 'team0003 have collectively used the tool 9 times') self.assertEquals(usage_by_teams[1].text, 'team0005 have collectively used the tool 7 times') self.assertEquals(usage_by_teams[2].text, 'team0006 have collectively used the tool 7 times') self.assertEquals(usage_by_teams[3].text, 'team0007 have collectively used the tool 5 times') self.assertEquals(usage_by_teams[4].text, 'team0002 have collectively used the tool 4 times') # We do a similar thing with organisations, which are tricky # because user 1 is in team 2 & 3, so both those teams get the # 4 times user 1 used the tool. But teams 2 & 3 are both in org 1, # and the code has made sure to only count the useage once, rather # than 4 times from team 2 and 4 again from team 3. This checks # that based on the numbers above the results are as follows. # o1:9, o2:11, o3:7. Ordered that's o2,o1,o3. used_by_organisations = details_page.html.find( 'ul', id='usage-by-organisations' ).findAll('li') self.assertEquals(used_by_organisations[0].text, 'org0002 have collectively used the tool 11 times') self.assertEquals(used_by_organisations[1].text, 'org0001 have collectively used the tool 9 times') self.assertEquals(used_by_organisations[2].text, 'org0003 have collectively used the tool 7 times')