def setUp(self): self.logged_in_user = make_user() self.other_user = make_user( userid='other_user', email='*****@*****.**', name='Fake2 Fakerly') self.assertTrue(login_user(self, self.logged_in_user))
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 setUp(self): self.logged_in_user = make_user() (self.el1, self.el2, self.el3,) = generate_fake_links( self.logged_in_user, count=3 ) self.el1.categories.add('mapping') self.el1.save() self.el2.categories.add('mapping') self.el2.save() self.el3.categories.add('social') self.el3.save() self.el3.name = 'Unique' self.el3.save() self.logged_in_user.favourites.add(self.el2) self.logged_in_user.favourites.add(self.el3) self.assertTrue(login_user(self, self.logged_in_user)) rebuild_index.Command().handle(interactive=False, verbosity=0)
def setUp(self): self.user = make_user() (self.el1, self.el2, self.el3, self.el4, self.el5, self.el6, self.el7, self.el8) = generate_fake_links(self.user, count=8) self.el1.categories.add('great') self.el2.categories.add('great') self.el3.categories.add('great') self.el4.categories.add('great') self.el5.categories.add('great') self.el6.categories.add('great') self.el7.is_external = True self.el7.save() self.el8.is_external = True self.el8.save() self.assertTrue(login_user(self, self.user)) self.unfound_link_1 = Link.objects.create( name='Google Translate', destination='https://mail.google.com', description='Internet translation', owner=self.user, ) self.unfound_link_2 = Link.objects.create( name='Google Mail', destination='https://translate.google.com', description='Internet email', owner=self.user, ) rebuild_index.Command().handle(interactive=False, verbosity=0)
def test_lighthouse_has_first_links(self): """ Ensure that the migrations responsible for the creation of the Lighthouse links have captured the first two links """ user = make_user() (l1, l2) = generate_fake_links(owner=user, count=2) all_links = Link.objects.all() self.assertEqual(len(all_links), 4) lighthouse = Link.objects.get(pk=1) self.assertEqual(lighthouse.name, 'Lighthouse') self.assertEqual(lighthouse.destination, '/') self.assertEqual( lighthouse.description, 'Web application for finding useful tools, data and techniques' ) lighthouse_api = Link.objects.get(pk=2) self.assertEqual(lighthouse_api.name, 'Lighthouse API') self.assertEqual(lighthouse_api.destination, '/api/') exp = 'The API for this application.\n\n' exp += 'Documentation for using the API can ' exp += 'be found at [/api/](/api/).' self.assertEqual( lighthouse_api.description, exp )
def test_lighthouse_has_first_links(self): """ Ensure that the migrations responsible for the creation of the Lighthouse links have captured the first two links """ user = make_user() (l1, l2) = generate_fake_links(owner=user, count=2) all_links = Link.objects.all() self.assertEqual(len(all_links), 4) lighthouse = Link.objects.get(pk=1) self.assertEqual(lighthouse.name, 'Lighthouse') self.assertEqual(lighthouse.destination, '/') self.assertEqual( lighthouse.description, 'Web application for finding useful tools, data and techniques') lighthouse_api = Link.objects.get(pk=2) self.assertEqual(lighthouse_api.name, 'Lighthouse API') self.assertEqual(lighthouse_api.destination, '/api/') exp = 'The API for this application.\n\n' exp += 'Documentation for using the API can ' exp += 'be found at [/api/](/api/).' self.assertEqual(lighthouse_api.description, exp)
def setUp(self): self.logged_in_user = make_user() ( self.el1, self.el2, self.el3, ) = generate_fake_links(self.logged_in_user, count=3) self.el1.categories.add('mapping') self.el1.save() self.el2.categories.add('mapping') self.el2.save() self.el3.categories.add('social') self.el3.save() self.el3.name = 'Unique' self.el3.save() self.logged_in_user.favourites.add(self.el2) self.logged_in_user.favourites.add(self.el3) self.assertTrue(login_user(self, self.logged_in_user)) rebuild_index.Command().handle(interactive=False, verbosity=0)
def setUp(self): self.user = make_user() self.link = Link.objects.create( name='Link Linkerly', destination='link.com', owner=self.user, is_external=False, )
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 setUpTestData(cls): cls.user = make_user() now_time = now() cls.search_term_1 = SearchTerm.objects.create(query='mail') cls.search_term_2 = SearchTerm.objects.create(query='steve') cls.search_term_3 = SearchTerm.objects.create(query='cheese') cls.search_term_4 = SearchTerm.objects.create(query='google') cls.search_term_5 = SearchTerm.objects.create(query='internet') for t in range(0, 7): cls.search_q_1 = SearchQuery.objects.create( term=cls.search_term_1, user=cls.user, when=now_time - timedelta(days=t), results_length=8 - t # Going back in time, little less each day ) for t in range(0, 6): cls.search_q_2 = SearchQuery.objects.create(term=cls.search_term_2, user=cls.user, when=now_time - timedelta(days=t), results_length=0) for t in range(0, 5): cls.search_q_3 = SearchQuery.objects.create(term=cls.search_term_3, user=cls.user, when=now_time - timedelta(days=t), results_length=0) for t in range(0, 4): cls.search_q_4 = SearchQuery.objects.create( term=cls.search_term_4, user=cls.user, when=now_time - timedelta(days=t), results_length=5 - t # Going back in time, little less each day ) for t in range(0, 3): cls.search_q_5 = SearchQuery.objects.create(term=cls.search_term_5, user=cls.user, when=now_time - timedelta(days=t), results_length=0) # Throw in a query over 30 days ago which DID return some results, as # if the results had been deleted since then. Will count as unfulfilled with mock.patch('django.utils.timezone.now') as mock_now: # register usage 50 days ago mock_now.return_value = now_time - timedelta(days=50) cls.search_q_6 = SearchQuery.objects.create(term=cls.search_term_5, user=cls.user, results_length=2)
def setUp(self): self.user = make_user(userid='*****@*****.**', email='*****@*****.**', name='Ant Anterton') self.box_user = make_user(userid='*****@*****.**', email='*****@*****.**', name='Box Boxerly') self.chair_user = make_user(userid='*****@*****.**', email='*****@*****.**', name='Chair Chairington') self.first_desk_user = make_user(userid='*****@*****.**', email='*****@*****.**', name='Desk Deskworth') self.second_desk_user = make_user(userid='*****@*****.**', email='*****@*****.**', name='Desk Desker') self.eagle_user = make_user(userid='*****@*****.**', email='*****@*****.**', name='Eagle Eagerly') self.feather_user = make_user(userid='featherfeatherly', email='*****@*****.**', name='') self.assertTrue(login_user(self, self.user)) rebuild_index.Command().handle(interactive=False, verbosity=0)
def setUp(self): self.logged_in_user = make_user() self.assertTrue(login_user(self, self.logged_in_user)) self.el1, = generate_fake_links( self.logged_in_user, count=1, is_external=True )
def setUp(self): self.logged_in_user = make_user() self.assertTrue(login_user(self, self.logged_in_user)) self.el1, self.el2, = generate_fake_links(self.logged_in_user, count=2, is_external=True) self.logged_in_user.favourites.add(self.el1) self.logged_in_user.favourites.add(self.el2)
def setUp(self): self.logged_in_user = make_user() el1, el2 = generate_fake_links(self.logged_in_user, count=2) self.existing_link_1 = el1 self.existing_link_2 = el2 self.assertTrue(login_user(self, self.logged_in_user))
def test_update_different_user_doesnt_cause_duration(self): self.assertEquals(self.link.usage_total(), 0) self.assertEquals(self.other_link.usage_total(), 0) new_user = make_user(userid='*****@*****.**') self.link.register_usage(self.user) self.link.register_usage(new_user) self.assertEquals(self.link.usage_today(), 2) self.assertEquals(self.link.usage_total(), 2) self.assertEquals(self.other_link.usage_total(), 0)
def test_lighthouse_api_edit_page_has_no_destination_box(self): self.logged_in_user = make_user() self.app.get(reverse('login')) self.assertTrue(login_user(self, self.logged_in_user)) response = self.app.get(reverse('link-edit', kwargs={'pk': 2})) dest_input = response.html.find('input', {'name': 'destination'}) self.assertEqual(dest_input.attrs['type'], 'hidden')
def test_normal_edit_page_has_destination_box(self): self.logged_in_user = make_user() self.app.get(reverse('login')) link, = generate_fake_links(owner=self.logged_in_user) self.assertTrue(login_user(self, self.logged_in_user)) response = self.app.get(reverse('link-edit', kwargs={'pk': link.id})) dest_input = response.html.find('input', {'name': 'destination'}) self.assertEqual(dest_input.attrs['type'], 'url')
def setUp(self): self.logged_in_user = make_user() self.assertTrue(login_user(self, self.logged_in_user)) self.el1, self.el2, = generate_fake_links( self.logged_in_user, count=2, is_external=True ) self.logged_in_user.favourites.add(self.el1) self.logged_in_user.favourites.add(self.el2)
def test_description_summary_with_markdown(self): user = make_user() desc = '* A summary is something that summarises something longer' desc += '\n* Summaries are really useful' desc += '\n\n## Header 1' link = Link.objects.create(name='Markdown', description=desc, owner=user) expected = 'A summary is something that summarises something longer' self.assertEqual(link.description_summary, expected)
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_lighthouse_api_page_has_no_goto_link(self): self.logged_in_user = make_user() self.app.get(reverse('login')) self.assertTrue(login_user(self, self.logged_in_user)) response = self.app.get(reverse('link-detail', kwargs={'pk': 2})) goto_button = response.html.find(None, {'id': 'link_follow_button'}) goto_url = response.html.find(None, {'id': 'link_follow_url'}) self.assertIsNone(goto_button) self.assertIsNone(goto_url)
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 setUp(self): self.logged_in_user = make_user() el1, el2 = generate_fake_links( self.logged_in_user, count=2 ) self.existing_link_1 = el1 self.existing_link_2 = el2 self.assertTrue(login_user(self, self.logged_in_user))
def setUp(self): self.user = make_user() self.link = Link.objects.create( name='Link Linkerly', destination='link.com', owner=self.user, is_external=False, ) self.other_link = Link.objects.create( name='Other Link', destination='otherlink.com', owner=self.user, is_external=True, ) self.now = now()
def test_description_summary_with_markdown(self): user = make_user() desc = '* A summary is something that summarises something longer' desc += '\n* Summaries are really useful' desc += '\n\n## Header 1' link = Link.objects.create( name='Markdown', description=desc, owner=user) expected = 'A summary is something that summarises something longer' self.assertEqual( link.description_summary, expected )
def setUp(self): self.logged_in_user = make_user() (self.el1, ) = generate_fake_links(self.logged_in_user, count=1) (self.el2, ) = generate_fake_links(self.logged_in_user, is_external=True, count=1) self.el1.categories.add('social') self.el1.save() self.el2.categories.add('mapping') self.el2.save() self.assertTrue(login_user(self, self.logged_in_user))
def test_description_summary_with_very_long_line(self): user = make_user() desc = '* A summary is something that summarises something longer' desc += ' than what it is meant to be. Something very, very long might' desc += ' want to be shortened to make it easier to read in a list,' desc += ' for example.' desc += '\n\n## Header 1' link = Link.objects.create(name='Markdown', description=desc, owner=user) expected = 'A summary is something that summarises something longer' expected += ' than what it is meant to be. Something very, very long' expected += ' might want to be shortened to...' self.assertEqual(link.description_summary, expected)
def setUp(self): self.user = make_user() self.assertTrue(login_user(self, self.user)) self.link = Link.objects.create( name='Link Linkerly', destination='https://here/', owner=self.user, is_external=False, ) self.other_link = Link.objects.create( name='Other Link', destination='https://here/links', owner=self.user, is_external=True, ) self.now = now()
def setUp(self): self.user = make_user() self.link = Link.objects.create( name='Google', destination='https://google.com', description='Internet search', owner=self.user, is_external=False, ) self.link.categories.add('search') self.other_link = Link.objects.create( name='Google Mail', destination='https://mail.google.com', description='Internet email', owner=self.user, is_external=True, ) self.other_link.categories.add('email') self.other_link.categories.add('search') self.third_link = Link.objects.create( name='Google Chat', destination='https://chat.google.com', description='Internet chat', owner=self.user, is_external=True, ) self.third_link.categories.add('chat') self.fourth_link = Link.objects.create( name='Bing Translate', destination='https://translate.bing.com', description="Bing's a pretty good translation service. Run, yeah?", owner=self.user, is_external=True, ) self.fourth_link.categories.add('language') self.assertTrue(login_user(self, self.user)) rebuild_index.Command().handle(interactive=False, verbosity=0)
def test_api_posts_generate_usage(self): user = make_user() link = Link.objects.create( name='Link Linkerly', destination='link.com', owner=user, is_external=False, ) link_api_url = '%s%s' % ( self.live_server_url, reverse('api-link-usage', kwargs={'pk': link.pk}), ) requests.post(link_api_url, data={'user': user.slug}) self.assertEquals(link.usage_total(), 1) api = Link.objects.get(pk=2) self.assertEquals(api.usage_total(), 1)
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_every_authenticated_page_hit_generates_usage(self): self.logged_in_user = make_user() # This should not create usage, since they aren't logged in self.app.get(reverse('login')) # Three usages here self.assertTrue(login_user(self, self.logged_in_user)) self.app.get(reverse('user-list')) self.app.get(reverse('link-list')) lighthouse_link = Link.objects.get(pk=1) self.assertEqual(lighthouse_link.name, 'Lighthouse') all_usage = LinkUsage.objects.all() self.assertEqual(len(all_usage), 1) self.assertEqual(all_usage[0].link, lighthouse_link) self.assertEqual(all_usage[0].user, self.logged_in_user)
def test_lighthouse_api_edit_page_can_submit(self): self.logged_in_user = make_user() self.app.get(reverse('login')) self.assertTrue(login_user(self, self.logged_in_user)) response = self.app.get(reverse('link-edit', kwargs={'pk': 2})) form = response.form new_desc = 'I love the Lighthouse API' form['description'] = new_desc response = form.submit().follow() error_summary = response.html.find('div', {"class": "error-summary"}) self.assertIsNone(error_summary) description = response.html.find('div', {"class": "markdown-content"}) self.assertIn(new_desc, description.text)
def test_description_summary_with_very_long_line(self): user = make_user() desc = '* A summary is something that summarises something longer' desc += ' than what it is meant to be. Something very, very long might' desc += ' want to be shortened to make it easier to read in a list,' desc += ' for example.' desc += '\n\n## Header 1' link = Link.objects.create( name='Markdown', description=desc, owner=user) expected = 'A summary is something that summarises something longer' expected += ' than what it is meant to be. Something very, very long' expected += ' might want to be shortened to...' self.assertEqual( link.description_summary, expected )
def setUp(self): self.logged_in_user = make_user() (self.el1,) = generate_fake_links( self.logged_in_user, count=1 ) (self.el2,) = generate_fake_links( self.logged_in_user, is_external=True, count=1 ) self.el1.categories.add('social') self.el1.save() self.el2.categories.add('mapping') self.el2.save() self.assertTrue(login_user(self, self.logged_in_user))
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_lighthouse_api_edit_page_can_submit(self): self.logged_in_user = make_user() self.app.get(reverse('login')) self.assertTrue(login_user(self, self.logged_in_user)) response = self.app.get(reverse('link-edit', kwargs={'pk': 2})) form = response.form new_desc = 'I love the Lighthouse API' form['description'] = new_desc response = form.submit().follow() error_summary = response.html.find('div', {"class": "error-summary"}) self.assertIsNone(error_summary) description = response.html.find( 'div', {"class": "markdown-content"}) self.assertIn(new_desc, description.text)
def setUp(self): self.logged_in_user = make_user() (self.el1, self.el2, self.el3, self.el4, self.el5, self.el6) = generate_fake_links( self.logged_in_user, count=6 ) self.el7, = generate_fake_links( self.logged_in_user, start=7, count=1, is_external=True, ) self.el1.categories.add('mapping') self.el1.categories.add('social') self.el1.save() self.el2.categories.add('mapping') self.el2.save() self.el3.categories.add('social') self.el3.save() self.el4.categories.add('geospatial') self.el4.save() self.el5.categories.add('imagery') self.el5.save() self.el6.categories.add('geospatial') self.el6.categories.add('mapping') self.el6.save() self.assertTrue(login_user(self, self.logged_in_user)) rebuild_index.Command().handle(interactive=False, verbosity=0)
def setUp(self): self.user = make_user() (self.el1, self.el2, self.el3, self.el4, self.el5, self.el6, self.el7, self.el8) = generate_fake_links( self.user, count=8 ) self.el1.categories.add('great') self.el2.categories.add('great') self.el3.categories.add('great') self.el4.categories.add('great') self.el5.categories.add('great') self.el6.categories.add('great') self.el7.is_external = True self.el7.save() self.el8.is_external = True self.el8.save() self.assertTrue(login_user(self, self.user)) self.unfound_link_1 = Link.objects.create( name='Google Translate', destination='https://mail.google.com', description='Internet translation', owner=self.user, ) self.unfound_link_2 = Link.objects.create( name='Google Mail', destination='https://translate.google.com', description='Internet email', owner=self.user, ) rebuild_index.Command().handle(interactive=False, verbosity=0)
def setUp(self): self.logged_in_user = make_user() self.el1, self.el2, self.el3 = generate_fake_links(self.logged_in_user, count=3, is_external=True) self.el4, self.el5 = generate_fake_links(self.logged_in_user, start=4, count=2) # Note: the generator expects to send out a tuple, so allow that. (self.el6,) = generate_fake_links(self.logged_in_user, start=6, count=1, is_external=True) (self.el7,) = generate_fake_links(self.logged_in_user, start=7, count=1) self.el1.categories.add("mapping") self.el1.categories.add("social") self.el1.save() self.el2.categories.add("mapping") self.el2.save() self.el3.categories.add("social") self.el3.save() self.el4.categories.add("geospatial") self.el4.save() self.el5.categories.add("imagery") self.el5.save() self.el6.categories.add("geospatial") self.el6.categories.add("mapping") self.el6.save() self.el7.categories.add("social") self.el7.categories.add("mapping") self.el7.save() self.assertTrue(login_user(self, self.logged_in_user))
def setUp(self): self.user = make_user( userid='*****@*****.**', email='*****@*****.**', name='Ant Anterton') self.box_user = make_user( userid='*****@*****.**', email='*****@*****.**', name='Box Boxerly') self.chair_user = make_user( userid='*****@*****.**', email='*****@*****.**', name='Chair Chairington') self.first_desk_user = make_user( userid='*****@*****.**', email='*****@*****.**', name='Desk Deskworth') self.second_desk_user = make_user( userid='*****@*****.**', email='*****@*****.**', name='Desk Desker') self.eagle_user = make_user( userid='*****@*****.**', email='*****@*****.**', name='Eagle Eagerly') self.feather_user = make_user( userid='featherfeatherly', email='*****@*****.**', name='') self.assertTrue(login_user(self, self.user)) rebuild_index.Command().handle(interactive=False, verbosity=0)
def setUp(self): self.logged_in_user = make_user() (self.el1, self.el2, self.el3, self.el4, self.el5, self.el6) = generate_fake_links(self.logged_in_user, count=6) self.el7, = generate_fake_links( self.logged_in_user, start=7, count=1, is_external=True, ) self.el1.categories.add('mapping') self.el1.categories.add('social') self.el1.save() self.el2.categories.add('mapping') self.el2.save() self.el3.categories.add('social') self.el3.save() self.el4.categories.add('geospatial') self.el4.save() self.el5.categories.add('imagery') self.el5.save() self.el6.categories.add('geospatial') self.el6.categories.add('mapping') self.el6.save() self.assertTrue(login_user(self, self.logged_in_user)) rebuild_index.Command().handle(interactive=False, verbosity=0)
def setUp(self): self.user = make_user()
def make_user(userid='*****@*****.**', email='*****@*****.**', name='Fake Fakerly'): return common.make_user(userid, email, name)
def setUp(self): self.logged_in_user = make_user() self.other_user = make_user(userid='other_user', email='*****@*****.**', name='Fake2 Fakerly') self.assertTrue(login_user(self, self.logged_in_user))
def make_user( userid='*****@*****.**', email='*****@*****.**', name='Fake Fakerly'): return common.make_user(userid, email, name)
def setUp(self): self.logged_in_user = make_user() self.assertTrue(login_user(self, self.logged_in_user))