def test_user_passes_test_mixin(self): # non dev can neither update ... self.client.force_login(self.user2) user_doesnt_pass_test_and_gets_404(self, 'integration:slack:update', address_kwargs={ 'pk': 1, 'project': self.short }, get_kwargs={'channel': 'foo'}) si = SlackIntegration.objects.get(pk=self.si.pk) self.assertEqual(si.channel, 'channel') # ... nor delete the integration user_doesnt_pass_test_and_gets_404(self, 'integration:slack:delete', address_kwargs={ 'pk': 1, 'project': self.short }, get_kwargs={'delete': True}) si = SlackIntegration.objects.get(pk=self.si.pk) self.assertEqual(si.channel, 'channel') # TODO TESTCASE # TODO only devs are allowed to edit an integration # TODO how about creation of integrations? pass
def test_user_passes_test_mixin(self): proj_name = "project" proj_short = "cccc" project = Project(name=proj_name, name_short=proj_short, creator=self.user) project.save() proj_name2 = "project2" proj_short2 = "dddd" project2 = Project(name=proj_name2, name_short=proj_short2, creator=self.user) project2.save() # we neither add the user as manager nor as developer so there are not the necessary rights to manipulate tags user_doesnt_pass_test_and_gets_404(self, 'tag:tag', address_kwargs={'project': proj_short}) # developer is good project.developer.add(self.user) project.save() response = self.client.get(reverse('tag:tag', kwargs={'project': proj_short}), follow=True) self.assertNotContains(response, "Your account doesn't have access to this page. To proceed, please " + "login with an account that has access.") # manager is good project2.manager.add(self.user) project2.save() response = self.client.get(reverse('tag:tag', kwargs={'project': proj_short2}), follow=True) self.assertNotContains(response, "Your account doesn't have access to this page. To proceed, please " + "login with an account that has access.")
def test_edit_and_delete_as_other_user(self): response = self.client.post(reverse('issue:log', kwargs={"project": self.issue.project.name_short, "sqn_i": self.issue.number}), {'time': '1h30m', 'created_at': self.time}) self.assertEqual(str(Timelog.objects.filter(issue=self.issue)[0].time), "1:30:00") # test to edit or delete as other user - should not be possible self.client.logout() self.client.force_login(self.user2) user_doesnt_pass_test_and_gets_404(self, 'issue:logedit', address_kwargs=self.sqn_l1_address_kwarg) self.assertEqual(str(Timelog.objects.filter(issue=self.issue)[0].time), "1:30:00") user_doesnt_pass_test_and_gets_404(self, 'issue:logdelete', address_kwargs=self.sqn_l1_address_kwarg) self.assertEqual(str(Timelog.objects.filter(issue=self.issue)[0].time), "1:30:00")
def test_cant_delete_col_as_dev(self): self.client.force_login(self.user2) pre_cols = list(KanbanColumn.objects.filter(project=self.project)) user_doesnt_pass_test_and_gets_404(self, 'kanbancol:delete', address_kwargs={ 'position': 3, 'project': self.short }, get_kwargs={'delete': 'true'}) current_cols = list(KanbanColumn.objects.filter(project=self.project)) self.assertEqual(current_cols, pre_cols) self.client.force_login(self.user)
def test_notification_insufficient_project_permissions(self): # check project existing check; fails at the UserPassesTestMixin wrong_project = self.enable_NewIssue.copy() wrong_project['shn_p'] = 'PP' user_doesnt_pass_test_and_gets_404(self, 'user_profile:toggle_notification', address_kwargs={"username": '******'}, get_kwargs=wrong_project) # check project membership check; fails at the UserPassesTestMixin wrong_project['shn_p'] = 'PRO' user_doesnt_pass_test_and_gets_404(self, 'user_profile:toggle_notification', address_kwargs={"username": '******'}, get_kwargs=wrong_project)
def test_cant_create_new_col_as_dev(self): self.client.force_login(self.user2) vals = { 'name': "Testcolumn", 'type': 'ToDo', 'project': self.project.pk } pre_num_cols = KanbanColumn.objects.count() user_doesnt_pass_test_and_gets_404( self, 'kanbancol:create', address_kwargs={'project': self.short}, get_kwargs=vals) self.assertEqual(KanbanColumn.objects.count(), pre_num_cols) self.client.force_login(self.user)
def test_create_project_change_project_manager(self): user2 = get_user_model().objects.create_user('test2', '*****@*****.**', 'test1234') project = project_settings.copy() project['developer'] = (self.user.pk, user2.pk) response = self.client.post(reverse('project:create'), project) self.assertRedirects(response, reverse('project:detail', kwargs={'project': project['name_short']})) project['manager'] = (user2.pk) response = self.client.post(reverse('project:edit', kwargs={'project': project['name_short']}), project) self.assertEqual(response.status_code, 302) # logged in user isn't manager anymore user_doesnt_pass_test_and_gets_404(self, 'project:edit', address_kwargs={'project': project['name_short']}) self.client.logout() self.client.force_login(user2) response = self.client.get(reverse('project:edit', kwargs={'project': project['name_short']})) self.assertEqual(response.status_code, 200) # new manager gets the edit page
def test_cant_update_col_as_dev(self): self.client.force_login(self.user2) vals = { 'name': "Testmodification", 'type': 'ToDo', } pre_cols = list(KanbanColumn.objects.filter(project=self.project)) user_doesnt_pass_test_and_gets_404(self, 'kanbancol:update', address_kwargs={ 'position': 3, 'project': self.short }, get_kwargs=vals) current_cols = list(KanbanColumn.objects.filter(project=self.project)) self.assertEqual(current_cols, pre_cols) self.client.force_login(self.user)
def test_share_with_project(self): expression = 'User.username ~ "a"' SearchFrontend.query(expression, self.user) # we now should have a non-persistent search self.assertEqual(Search.objects.filter(creator=self.user).count(), 1) search = Search.objects.first() search.persistent = True search.shared_with.add(self.project) search.save() self.client.force_login(self.user2) user_doesnt_pass_test_and_gets_404(self, 'project:search', address_kwargs={'project': 'PRJ'}) self.assertEqual( Search.objects.filter(creator=self.user, persistent=True).count(), 1)
def test_change_persistence(self): SearchFrontend.query('Project.name_short == "PRJ"', self.user) # we now should have a non-persistent search self.assertEqual(Search.objects.filter(creator=self.user).count(), 1) self.client.force_login(self.user) response = self.client.post(reverse('search:makepersistent'), {'pk': '1'}) self.assertRedirects(response, reverse('search:advanced')) self.assertEqual( Search.objects.filter(creator=self.user, persistent=True).count(), 1) # try using already persistent object (should lead to 404) response = self.client.post(reverse('search:makepersistent'), {'pk': '1'}) self.assertEqual(response.status_code, 404) # should also work for missing pks user_doesnt_pass_test_and_gets_404(self, 'search:makepersistent', get_kwargs={'pk': '2'}) # test deleting persistent items response = self.client.post(reverse('search:delpersistent'), {'pk': '1'}) self.assertRedirects(response, reverse('search:advanced')) self.assertEqual(Search.objects.filter(creator=self.user).count(), 0) # try deleting non-persistent item (should lead to 404) SearchFrontend.query('Project.name_short == "PRJ"', self.user) self.assertEqual(Search.objects.get(pk='2').persistent, False) response = self.client.post(reverse('search:delpersistent'), {'pk': '2'}) self.assertEqual(response.status_code, 404) # try deleting non-present pk user_doesnt_pass_test_and_gets_404(self, 'search:delpersistent', get_kwargs={'pk': '3'})
def test_cant_move_col_as_dev(self): self.client.force_login(self.user2) pre_cols = list(KanbanColumn.objects.filter(project=self.project)) user_doesnt_pass_test_and_gets_404(self, 'kanbancol:movedown', address_kwargs={ 'project': self.short, 'position': 0 }) current_cols = list(KanbanColumn.objects.filter(project=self.project)) self.assertEqual(current_cols, pre_cols) user_doesnt_pass_test_and_gets_404(self, 'kanbancol:moveup', address_kwargs={ 'project': self.short, 'position': 1 }) current_cols = list(KanbanColumn.objects.filter(project=self.project)) self.assertEqual(current_cols, pre_cols) self.client.force_login(self.user)
def test_redirect_to_login_and_login_required(self): # TODO TESTCASE simplify this testcase verify how much of this code can be used with # redirect_to_login_required() since some different status codes are used here self.client.force_login(self.user2) project = Project(creator=self.user, name_short='PRJ') project.save() project.developer.add(self.user2) # try to delete as developer => should fail user_doesnt_pass_test_and_gets_404(self, 'project:delete', address_kwargs={'project': 'PRJ'}, get_kwargs={'delete': 'true'}) self.assertEqual(Project.objects.filter(name_short='PRJ').count(), 1) # try to leave as non-member project.developer.clear() user_doesnt_pass_test_and_gets_404(self, 'project:leave', address_kwargs={'project': 'PRJ'}, get_kwargs={'delete': 'true'}) # detail view only accessible for members user_doesnt_pass_test_and_gets_404(self, 'project:detail', address_kwargs={'project': 'PRJ'}) # usertimelog not accessible for non-members # NOTE dispatch() is called before test_func(), so we receive 404 here response = self.client.post(reverse('project:usertimelog', kwargs={'project': 'PRJ', 'username': '******'} ), follow=True) self.assertEqual(response.status_code, 404) # timelog not accessible for non-members # NOTE dispatch() is called before test_func(), so we receive 404 here response = self.client.post(reverse('project:timelog', kwargs={'project': 'PRJ'} ), follow=True) self.assertEqual(response.status_code, 404) # add user2 as manager and try delete -> keep => no deletion project.manager.add(self.user2) response = self.client.post(reverse('project:delete', kwargs={'project': 'PRJ'}), {'keep': 'true'}, follow=True) self.assertEqual(response.status_code, 200) self.assertNotContains(response, "Your account doesn't have access to this page") self.assertEqual(Project.objects.filter(name_short='PRJ').count(), 1) # try leave -> keep response = self.client.post(reverse('project:leave', kwargs={'project': 'PRJ'}), {'keep': 'true'}, follow=True) self.assertEqual(response.status_code, 200) self.assertNotContains(response, "Your account doesn't have access to this page") project.refresh_from_db() self.assertEqual(project.manager.count(), 1) self.client.force_login(self.user)
def test_other_user_edit_page_not_accassible_user_passes_test_mixin(self): self.client.logout() self.client.force_login(self.user2) user_doesnt_pass_test_and_gets_404(self, 'user_profile:edit_profile', address_kwargs={"username": user_name})
def test_clone_and_import(self): repo_path = '/tmp/gitpythonrepo' self.project.manager.add(self.user) self.project.developer.add(self.user2) self.project.save() filecontent1 = 'Hello World File 1' tmp1 = tempfile.NamedTemporaryFile(delete=False) tmp1.write(filecontent1.encode()) tmp1.close() filecontent2 = 'Hello World File 2' tmp2 = tempfile.NamedTemporaryFile(delete=False) tmp2.write(filecontent2.encode()) tmp2.close() with open(tmp1.name, 'r') as f1: with open(tmp2.name, 'r') as f2: response = self.client.post(reverse( 'project:gitintegration:create', kwargs={'project': self.project.name_short}), { 'url': 'http://im-a-dum.my/repo/path', 'rsa_priv_path': f1, 'rsa_pub_path': f2, }, follow=True) self.assertNotContains( response, "Your account doesn't have access to this page") self.project.refresh_from_db() self.assertEqual(self.project.repos.count(), 1) repo = self.project.repos.first() self.assertEqual(repo.url, 'http://im-a-dum.my/repo/path') # set correct repo path. This is not possible via request due to validators repo.url = repo_path repo.save() self.assertEqual(repo.url, repo_path) self.assertIn(filecontent1, repo.rsa_priv_path.read().decode()) self.assertIn(filecontent2, repo.rsa_pub_path.read().decode()) # read() opened the file repo.rsa_priv_path.close() repo.rsa_pub_path.close() # try importing without valid remote repository shutil.rmtree(repo_path, ignore_errors=True) shutil.rmtree(repo.get_local_repo_path(), ignore_errors=True) import_commits() repo.refresh_from_db() self.assertEqual(repo.conn_ok, False) # create a local repo initial_file = repo_path + '/initial' remote_repo = Repo.init(repo_path) f_open = open(initial_file, 'wb') f_open.write('Content in first file\n'.encode()) f_open.close() remote_repo.index.add([initial_file]) remote_repo_master = remote_repo.index.commit("initial commit") initial_sha = remote_repo_master.hexsha # try import again, connection should now work, but no commit to import Frontend.import_new_commits(repo) repo.refresh_from_db() self.assertEqual(repo.conn_ok, True) self.assertEqual(repo.last_commit_processed, remote_repo_master.hexsha) self.assertEqual(Commit.objects.count(), 0) # create commit with issue identifier in message f = repo_path + '/file1' open(f, 'wb').close() remote_repo.index.add([f]) remote_repo_master = remote_repo.index.commit(self.project.name_short + "-1 commit body") # import again, self.issue should now have a commit associated, activity shoud have increased activity = len(json.loads(repo.project.activity)) Frontend.import_new_commits(repo) repo.refresh_from_db() self.assertGreater(len(json.loads(repo.project.activity)), activity) self.assertEqual(repo.conn_ok, True) self.assertEqual(repo.last_commit_processed, remote_repo_master.hexsha) self.assertEqual(Commit.objects.count(), 1) self.assertEqual(self.issue.commits.count(), 1) # examine commit c = self.issue.commits.first() self.assertNotEqual(c.author, '') self.assertEqual(c.name, remote_repo_master.hexsha) self.assertEqual(c.repository, repo) self.assertEqual(c.message, "commit body") self.assertEqual(len(c.get_tags()), 0) firstchange = c.get_changes()['file1'] self.assertEqual(firstchange['lines'], 0) self.assertEqual(firstchange['insertions'], 0) self.assertEqual(firstchange['deletions'], 0) # empty changes, get_changes() must not crash savedchanges = c.get_changes() c.changes = "" c.save() c.get_changes() c.set_changes(savedchanges) self.assertEqual(c.get_changes(), remote_repo_master.stats.files) # permissions checks maps to project's functions self.assertEqual(c.user_has_read_permissions(self.user), True) self.assertEqual(c.user_has_read_permissions(self.user2), True) self.assertEqual(c.user_has_write_permissions(self.user), True) self.assertEqual(c.user_has_write_permissions(self.user2), False) # reset last_commit_processed and try again: no duplicates should appear in Commits repo.last_commit_processed = '' repo.save() Frontend.import_new_commits(repo) repo.refresh_from_db() self.assertEqual(repo.conn_ok, True) self.assertEqual(repo.last_commit_processed, remote_repo_master.hexsha) self.assertEqual(Commit.objects.count(), 1) self.assertEqual(self.issue.commits.count(), 1) # commit with invalid issue id f = repo_path + '/file2' open(f, 'wb').close() remote_repo.index.add([f]) remote_repo_master = remote_repo.index.commit( self.project.name_short + "-42 commit body with invalid issue id") # activity should not change activity = len(json.loads(repo.project.activity)) Frontend.import_new_commits(repo) repo.refresh_from_db() self.assertEqual(len(json.loads(repo.project.activity)), activity) self.assertEqual(repo.conn_ok, True) self.assertEqual(repo.last_commit_processed, remote_repo_master.hexsha) self.assertEqual(Commit.objects.count(), 1) self.assertEqual(self.issue.commits.count(), 1) # create commit with issue identifier in message f = repo_path + '/file3' f_open = open(f, 'wb') f_open.write('Fancy file content\nEven with newline\n'.encode()) f_open.close() remote_repo.index.add([f]) remote_repo_master = remote_repo.index.commit( self.project.name_short + "-1 commit body for file 3\n" + "This time with longer commit message") tag = remote_repo.create_tag('Test-Tag', ref=remote_repo_master) # import again, self.issue should now have 2 commits associated activity = len(json.loads(repo.project.activity)) Frontend.import_new_commits(repo) repo.refresh_from_db() self.assertGreater(len(json.loads(repo.project.activity)), activity) self.assertEqual(repo.conn_ok, True) self.assertEqual(repo.last_commit_processed, remote_repo_master.hexsha) self.assertEqual(Commit.objects.count(), 2) self.assertEqual(self.issue.commits.count(), 2) # examine newest commit c = self.issue.commits.get(name=remote_repo_master.hexsha) self.assertNotEqual(c.author, '') self.assertEqual(c.name, remote_repo_master.hexsha) self.assertEqual(c.repository, repo) self.assertEqual( c.message, "commit body for file 3\nThis time with longer commit message") self.assertEqual(c.get_title(), "commit body for file 3") self.assertEqual(c.get_name_short(), remote_repo_master.hexsha[:7]) firstchange = c.get_changes()['file3'] self.assertEqual(firstchange['lines'], 2) self.assertEqual(firstchange['insertions'], 2) self.assertEqual(firstchange['deletions'], 0) self.assertEqual(c.__str__(), "Commit " + remote_repo_master.hexsha) self.assertEqual(len(c.get_tags()), 1) self.assertEqual(c.get_tags()[0], 'Test-Tag') # test file diff view diff = '@@ -0,0 +1,2 @@\n+Fancy file content\n+Even with newline\n'.splitlines( ) response = self.client.post( reverse('issue:commit_diff', kwargs={ 'project': self.project.name_short, 'sqn_i': c.issue.number, }), { 'filename': list(c.get_changes().keys())[0], 'repository': repo.pk, 'commit_sha': c.get_name_short(), }, ) self.assertNotContains( response, "Your account doesn't have access to this page") self.assertEqual(response.context_data['diff'], diff) self.assertEqual(response.context_data['filename'], list(c.get_changes().keys())[0]) self.assertEqual(response.context_data['commit_sha'], c.get_name_short()) # add another tag to an already imported commit tag = remote_repo.create_tag('Another_tag', ref=remote_repo_master) activity = len(json.loads(repo.project.activity)) Frontend.import_new_commits(repo) repo.refresh_from_db() self.assertGreater(len(json.loads(repo.project.activity)), activity) c = self.issue.commits.get(name=remote_repo_master.hexsha) self.assertEqual(len(c.get_tags()), 2) self.assertIn('Test-Tag', c.get_tags()) self.assertIn('Another_tag', c.get_tags()) # check with insufficient privileges self.project.manager.clear() user_doesnt_pass_test_and_gets_404( self, 'issue:commit_diff', address_kwargs={ 'project': self.project.name_short, 'sqn_i': c.issue.number, }, get_kwargs={ 'filename': list(c.get_changes().keys())[0], 'repository': repo.pk, 'commit_sha': c.get_name_short(), }, ) self.project.manager.add(self.user) # post broken data to view response = self.client.post(reverse('issue:commit_diff', kwargs={ 'project': self.project.name_short, 'sqn_i': c.issue.number, }), { 'filename': 'blabla', 'repository': repo.pk, 'commit_sha': 'blubber', }, follow=True) self.assertEqual(response.context_data['diff'], ''.splitlines()) self.assertEqual(response.context_data['filename'], 'blabla') self.assertEqual(response.context_data['commit_sha'], 'blubber') # check that commits are searchable sr = SearchFrontend.query('commit body', self.user) self.assertEqual(len(sr), 2) sr = SearchFrontend.query('Commit.message ~ "commit message"', self.user) self.assertEqual(len(sr), 1) self.assertEqual(sr[0][0], "(" + c.get_name_short() + ") commit body for file 3") # examine file diffs f = repo_path + '/file4' f_open = open(f, 'wb') f_open.write('Fancy file content\n'.encode()) f_open.close() remote_repo.index.add([f]) remote_repo_master = remote_repo.index.commit('file4') Frontend.import_new_commits(repo) diff = Frontend.get_diff(repo, remote_repo_master.hexsha, 'file4') repo.refresh_from_db() self.assertEqual(repo.conn_ok, True) self.assertEqual(diff, "@@ -0,0 +1 @@\n+Fancy file content\n") # check that commit changes are searchable sr = SearchFrontend.query('file', self.user) self.assertEqual(len(sr), 1) # check with first commit diff = Frontend.get_diff(repo, initial_sha, 'initial') repo.refresh_from_db() self.assertEqual(repo.conn_ok, True) # TODO TESTCASE we're currently expecting an empty result because gitpython is broken as f**k self.assertEqual(diff, "") # self.assertEqual(diff, "@@ -0,0 +1 @@\n+Content in first file\n") # try with invalid filename diff = Frontend.get_diff(repo, c.get_name_short(), 'invalid') repo.refresh_from_db() self.assertEqual(repo.conn_ok, True) self.assertEqual(diff, "") # try with invalid commit sha diff = Frontend.get_diff(repo, '1234567', 'invalid') repo.refresh_from_db() self.assertEqual(repo.conn_ok, True) self.assertEqual(diff, "") # try with broken repo path (not yet checked out prj_name_short = self.project.name_short self.project.name_short = 'AAA' self.project.save() diff = Frontend.get_diff(repo, initial_sha, 'initial') repo.refresh_from_db() self.assertEqual(repo.conn_ok, False) self.assertEqual(diff, "") self.project.name_short = prj_name_short self.project.save() # delete the key files from the server os.unlink(repo.rsa_priv_path.path) os.unlink(repo.rsa_pub_path.path) # delete the key files locally os.unlink(tmp1.name) os.unlink(tmp2.name) # clean up locally shutil.rmtree(repo_path, ignore_errors=True) shutil.rmtree(repo.get_local_repo_path(), ignore_errors=True)
def test_notification_all_parameters_are_required(self): self.client.post(reverse('user_profile:toggle_notification', kwargs={"username": '******'}), self.enable_NewIssue, follow=False) pref = self.user.get_preference("notify_mail") # Only enabled for NewIssue self.assertEqual(pref, '{"PRJ": ["NewIssue"]}') # all parameters must be set; fails at the UserPassesTestMixin user_doesnt_pass_test_and_gets_404(self, 'user_profile:toggle_notification', address_kwargs=self.address_kwargs, get_kwargs={}) user_doesnt_pass_test_and_gets_404(self, 'user_profile:toggle_notification', address_kwargs=self.address_kwargs, get_kwargs={'shn_p': 'BLUB'}) # missing enabled missing_enabled = self.enable_NewIssue.copy() # it is fine to have ['enabled'] set to something other than 1 or 0 but it gets ignored then missing_enabled.pop('enabled') user_doesnt_pass_test_and_gets_404(self, 'user_profile:toggle_notification', address_kwargs=self.address_kwargs, get_kwargs=missing_enabled) self.assertEqual(pref, '{"PRJ": ["NewIssue"]}') # missing notitype missing_notitype = self.enable_NewIssue.copy() missing_notitype['notitype'] = '' user_doesnt_pass_test_and_gets_404(self, 'user_profile:toggle_notification', address_kwargs=self.address_kwargs, get_kwargs=missing_notitype) missing_notitype.pop('notitype') user_doesnt_pass_test_and_gets_404(self, 'user_profile:toggle_notification', address_kwargs=self.address_kwargs, get_kwargs=missing_notitype) self.assertEqual(pref, '{"PRJ": ["NewIssue"]}') # missing notiway missing_notiway = self.enable_NewIssue.copy() # it is fine to have ['notiway'] set to something other than 'mail' but it gets ignored then # because we want further options in the future missing_notiway.pop('notiway') user_doesnt_pass_test_and_gets_404(self, 'user_profile:toggle_notification', address_kwargs=self.address_kwargs, get_kwargs=missing_notiway) self.assertEqual(pref, '{"PRJ": ["NewIssue"]}') # missing shn_p missing_shn_p = self.enable_NewIssue.copy() missing_shn_p['shn_p'] = '' user_doesnt_pass_test_and_gets_404(self, 'user_profile:toggle_notification', address_kwargs=self.address_kwargs, get_kwargs=missing_shn_p) missing_shn_p.pop('shn_p') user_doesnt_pass_test_and_gets_404(self, 'user_profile:toggle_notification', address_kwargs=self.address_kwargs, get_kwargs=missing_shn_p) self.assertEqual(pref, '{"PRJ": ["NewIssue"]}')
def test_views_not_allowed_for_non_project_member(self): filecontent1 = 'Hello World File 1' tmp1 = tempfile.NamedTemporaryFile(delete=False) tmp1.write(filecontent1.encode()) tmp1.close() filecontent2 = 'Hello World File 2' tmp2 = tempfile.NamedTemporaryFile(delete=False) tmp2.write(filecontent2.encode()) tmp2.close() repo = Repository(project=self.project, url='blub-url') with open(tmp1.name, 'r') as f1: with open(tmp2.name, 'r') as f2: repo.rsa_priv_path = File(f1) repo.rsa_pub_path = File(f2) repo.save() response = self.client.get(reverse( 'project:gitintegration:list', kwargs={'project': self.project.name_short}), follow=True) self.assertEqual(response.status_code, 404) user_doesnt_pass_test_and_gets_404(self, 'project:gitintegration:detail', address_kwargs={ 'project': self.project.name_short, 'repository': repo.pk }) user_doesnt_pass_test_and_gets_404( self, 'project:gitintegration:create', address_kwargs={'project': self.project.name_short}, get_kwargs={ 'url': 'blubber', 'rsa_priv_path': '', 'rsa_pub_path': '' }) user_doesnt_pass_test_and_gets_404(self, 'project:gitintegration:edit', address_kwargs={ 'project': self.project.name_short, 'repository': repo.pk }, get_kwargs={ 'url': 'blubber', 'rsa_priv_path': '', 'rsa_pub_path': '' }) user_doesnt_pass_test_and_gets_404(self, 'project:gitintegration:delete', address_kwargs={ 'project': self.project.name_short, 'repository': repo.pk }, get_kwargs={'delete': 'true'}) # delete the key files from the server os.unlink(repo.rsa_priv_path.path) os.unlink(repo.rsa_pub_path.path) # delete the key files locally os.unlink(tmp1.name) os.unlink(tmp2.name)
def test_add_edit_delete_not_allowed_for_developer(self): self.project.manager.clear() self.project.developer.add(self.user) self.project.save() user_doesnt_pass_test_and_gets_404( self, 'project:gitintegration:create', address_kwargs={'project': self.project.name_short}, get_kwargs={ 'url': 'blubber-url', 'rsa_priv_path': '', 'rsa_pub_path': '' }) self.project.refresh_from_db() self.assertEqual(self.project.repos.count(), 0) filecontent1 = 'Hello World File 1' tmp1 = tempfile.NamedTemporaryFile(delete=False) tmp1.write(filecontent1.encode()) tmp1.close() filecontent2 = 'Hello World File 2' tmp2 = tempfile.NamedTemporaryFile(delete=False) tmp2.write(filecontent2.encode()) tmp2.close() repo = Repository(project=self.project, url='blub-url') with open(tmp1.name, 'r') as f1: with open(tmp2.name, 'r') as f2: repo.rsa_priv_path = File(f1) repo.rsa_pub_path = File(f2) repo.save() user_doesnt_pass_test_and_gets_404(self, 'project:gitintegration:edit', address_kwargs={ 'project': self.project.name_short, 'repository': '1' }, get_kwargs={ 'url': 'blubber', 'rsa_priv_path': '', 'rsa_pub_path': '', }) self.project.refresh_from_db() self.assertEqual(self.project.repos.count(), 1) self.assertEqual(self.project.repos.first().url, 'blub-url') user_doesnt_pass_test_and_gets_404(self, 'project:gitintegration:delete', address_kwargs={ 'project': self.project.name_short, 'repository': '1' }, get_kwargs={'delete': 'true'}) self.project.refresh_from_db() self.assertEqual(self.project.repos.count(), 1) self.assertEqual(self.project.repos.first().url, 'blub-url') # delete the key files from the server repo = self.project.repos.first() os.unlink(repo.rsa_priv_path.path) os.unlink(repo.rsa_pub_path.path) # delete the key files locally os.unlink(tmp1.name) os.unlink(tmp2.name)
def test_share_with_project_0(self): expression = 'User.username ~ "a"' SearchFrontend.query(expression, self.user) # we now should have a non-persistent search self.assertEqual(Search.objects.filter(creator=self.user).count(), 1) self.client.force_login(self.user) response = self.client.post(reverse('search:makepersistent'), {'pk': '1'}) self.assertRedirects(response, reverse('search:advanced')) self.assertEqual( Search.objects.filter(creator=self.user, persistent=True).count(), 1) search = Search.objects.first() search.shared_with.add(self.project) # we are creator of search, modifying should work description = 'new description' response = self.client.post( reverse('search:edit', kwargs={'sqn_sh': '1'}), { 'description': description, 'searchexpression': expression }, ) self.assertRedirects(response, reverse('search:advanced')) search.refresh_from_db() self.assertEqual(search.description, description) # try with different creator, should not work search.creator = self.user2 search.save() description = 'another description' user_doesnt_pass_test_and_gets_404(self, 'search:edit', address_kwargs={'sqn_sh': '1'}, get_kwargs={ 'description': description, 'searchexpression': expression }) search.refresh_from_db() self.assertNotEqual(search.description, description) # make user a manager for the project the search is shared with => should work search.shared_with.add(self.project) self.project.manager.add(self.user) description = 'even another description' response = self.client.post( reverse('search:edit', kwargs={'sqn_sh': '1'}), { 'description': description, 'searchexpression': expression }, follow=True, ) self.assertRedirects(response, reverse('search:advanced')) search.refresh_from_db() self.assertEqual(search.description, description)