def test_sees_log_events_on_watched_projects(self): # Another user has a public project u2 = UserFactory(username='******', fullname='Bono') key = ApiKeyFactory() u2.api_keys.append(key) u2.save() project = ProjectFactory(creator=u2, is_public=True) project.add_contributor(u2) auth = Auth(user=u2, api_key=key) # A file was added to the project project.add_file(auth=auth, file_name='test.html', content='123', size=2, content_type='text/html') project.save() # User watches the project watch_config = WatchConfigFactory(node=project) self.user.watch(watch_config) self.user.save() # Goes to her dashboard, already logged in res = self.app.get('/dashboard/', auth=self.auth, auto_follow=True) # Sees logs for the watched project assert_in('Watched Projects', res) # Watched Projects header # The log action is in the feed assert_in('added file test.html', res) assert_in(project.title, res)
def setUp(self): super(TestWatching, self).setUp() self.user = UserFactory() self.project = ProjectFactory(creator=self.user) # add some log objects api_key = ApiKeyFactory() self.user.api_keys.append(api_key) self.user.save() self.consolidate_auth = Auth(user=self.user, api_key=api_key) # Clear project logs self.project.logs = [] self.project.save() # A log added 100 days ago self.project.add_log( 'project_created', params={'project': self.project._primary_key}, auth=self.consolidate_auth, log_date=dt.datetime.utcnow() - dt.timedelta(days=100), save=True, ) # Set the ObjectId to correspond with the log date # A log added now self.last_log = self.project.add_log( 'tag_added', params={'project': self.project._primary_key}, auth=self.consolidate_auth, log_date=dt.datetime.utcnow(), save=True, ) # Clear watched list self.user.watched = [] self.user.save()
def setUp(self): super(TestAUser, self).setUp() self.user = AuthUserFactory() self.user.set_password('science') # Add an API key for quicker authentication api_key = ApiKeyFactory() self.user.api_keys.append(api_key) self.user.save() self.auth = ('test', api_key._primary_key)
def setUp(self): super(TestSearching, self).setUp() import website.search.search as search search.delete_all() self.user = UserFactory() # Add an API key for quicker authentication api_key = ApiKeyFactory() self.user.api_keys.append(api_key) self.user.save() self.auth = ('test', api_key._primary_key)
def setUp(self): super(TestWikiCompare, self).setUp() self.project = ProjectFactory(is_public=True) api_key = ApiKeyFactory() self.project.creator.api_keys.append(api_key) self.project.creator.save() self.consolidate_auth = Auth(user=self.project.creator, api_key=api_key) self.auth = ('test', api_key._primary_key) self.project.update_node_wiki('home', 'hello world', self.consolidate_auth) self.wiki = self.project.get_wiki_page('home')
def setUp(self): super(TestWikiDelete, self).setUp() self.project = ProjectFactory(is_public=True) api_key = ApiKeyFactory() self.project.creator.api_keys.append(api_key) self.project.creator.save() self.consolidate_auth = Auth(user=self.project.creator, api_key=api_key) self.auth = ('test', api_key._primary_key) self.project.update_node_wiki('Elephants', 'Hello Elephants', self.consolidate_auth) self.project.update_node_wiki('Lions', 'Hello Lions', self.consolidate_auth) self.elephant_wiki = self.project.get_wiki_page('Elephants') self.lion_wiki = self.project.get_wiki_page('Lions')
def setUp(self): super(TestRegistrations, self).setUp() ensure_schemas() self.user = UserFactory() # Add an API key for quicker authentication api_key = ApiKeyFactory() self.user.api_keys.append(api_key) self.user.save() self.auth = ('test', api_key._primary_key) self.original = ProjectFactory(creator=self.user, is_public=True) # A registration self.project = RegistrationFactory( creator=self.user, project=self.original, user=self.user, )
def setUp(self): super(TestShortUrls, self).setUp() self.user = UserFactory() # Add an API key for quicker authentication api_key = ApiKeyFactory() self.user.api_keys.append(api_key) self.user.save() self.auth = ('test', api_key._primary_key) self.consolidate_auth = Auth(user=self.user, api_key=api_key) self.project = ProjectFactory(creator=self.user) # A non-project componenet self.component = NodeFactory(category='hypothesis', creator=self.user) self.project.nodes.append(self.component) self.component.save() # Hack: Add some logs to component; should be unnecessary pending # improvements to factories from @rliebz self.component.set_privacy('public', auth=self.consolidate_auth) self.component.set_privacy('private', auth=self.consolidate_auth) self.wiki = NodeWikiFactory(user=self.user, node=self.component)
def test_user_with_claim_url_registers_new_account(self, mock_session): # Assume that the unregistered user data is already stored in the session mock_session.data = { 'unreg_user': { 'uid': self.user._primary_key, 'pid': self.project._primary_key, 'token': self.user.get_unclaimed_record( self.project._primary_key)['token'] } } res2 = self.app.get('/account/') # Fills in Register form form = res2.forms['registerForm'] form['register-fullname'] = 'tester' form['register-username'] = '******' form['register-username2'] = '*****@*****.**' form['register-password'] = '******' form['register-password2'] = 'testing' res3 = form.submit() assert_in('Registration successful.', res3.body) assert_in('Successfully claimed contributor', res3.body) u = User.find(Q('username', 'eq', '*****@*****.**'))[0] key = ApiKeyFactory() u.api_keys.append(key) u.save() u.auth = ('test', key._primary_key) self.app.get( u.get_confirmation_url('*****@*****.**')).follow(auth=u.auth) # Confirms their email address self.project.reload() self.user.reload() u.reload() assert_not_in(self.user._primary_key, self.project.contributors) assert_equal(2, len(self.project.contributors)) # user is now a contributor to self.project assert_in(u._primary_key, self.project.contributors)
def setUp(self): super(TestWikiRename, self).setUp() self.project = ProjectFactory(is_public=True) api_key = ApiKeyFactory() self.project.creator.api_keys.append(api_key) self.project.creator.save() self.consolidate_auth = Auth(user=self.project.creator, api_key=api_key) self.auth = ('test', api_key._primary_key) self.project.update_node_wiki('home', 'Hello world', self.consolidate_auth) self.page_name = 'page2' self.project.update_node_wiki(self.page_name, 'content', self.consolidate_auth) self.project.save() self.page = self.project.get_wiki_page(self.page_name) self.wiki = self.project.get_wiki_page('home') self.url = self.project.api_url_for( 'project_wiki_rename', wname=self.page_name, )