##// END OF EJS Templates
Added more tests for web based file edit and add
marcink -
r3839:9dec8704 beta
parent child Browse files
Show More
@@ -303,7 +303,7 b' class FilesController(BaseRepoController'
303 first_line = sl[0] if sl else ''
303 first_line = sl[0] if sl else ''
304 # modes: 0 - Unix, 1 - Mac, 2 - DOS
304 # modes: 0 - Unix, 1 - Mac, 2 - DOS
305 mode = detect_mode(first_line, 0)
305 mode = detect_mode(first_line, 0)
306 content = convert_line_endings(r_post.get('content'), mode)
306 content = convert_line_endings(r_post.get('content', ''), mode)
307
307
308 message = r_post.get('message') or c.default_message
308 message = r_post.get('message') or c.default_message
309 author = self.rhodecode_user.full_contact
309 author = self.rhodecode_user.full_contact
@@ -352,11 +352,11 b' class FilesController(BaseRepoController'
352
352
353 if r_post:
353 if r_post:
354 unix_mode = 0
354 unix_mode = 0
355 content = convert_line_endings(r_post.get('content'), unix_mode)
355 content = convert_line_endings(r_post.get('content', ''), unix_mode)
356
356
357 message = r_post.get('message') or c.default_message
357 message = r_post.get('message') or c.default_message
358 filename = r_post.get('filename')
358 filename = r_post.get('filename')
359 location = r_post.get('location')
359 location = r_post.get('location', '')
360 file_obj = r_post.get('upload_file', None)
360 file_obj = r_post.get('upload_file', None)
361
361
362 if file_obj is not None and hasattr(file_obj, 'filename'):
362 if file_obj is not None and hasattr(file_obj, 'filename'):
@@ -1,6 +1,10 b''
1 import os
1 from rhodecode.tests import *
2 from rhodecode.tests import *
2 from rhodecode.model.db import Repository
3 from rhodecode.model.db import Repository
3 from rhodecode.model.meta import Session
4 from rhodecode.model.meta import Session
5 from rhodecode.tests.fixture import Fixture
6
7 fixture = Fixture()
4
8
5 ARCHIVE_SPECS = {
9 ARCHIVE_SPECS = {
6 '.tar.bz2': ('application/x-bzip2', 'tbz2', ''),
10 '.tar.bz2': ('application/x-bzip2', 'tbz2', ''),
@@ -442,26 +446,290 b' removed extra unicode conversion in diff'
442 )
446 )
443 response.mustcontain("vcs/web/simplevcs/views/repository.py")
447 response.mustcontain("vcs/web/simplevcs/views/repository.py")
444
448
449 #HG - ADD FILE
445 def test_add_file_view_hg(self):
450 def test_add_file_view_hg(self):
446 self.log_user()
451 self.log_user()
447 response = self.app.get(url('files_add_home',
452 response = self.app.get(url('files_add_home',
448 repo_name=HG_REPO,
453 repo_name=HG_REPO,
449 revision='tip', f_path='/'))
454 revision='tip', f_path='/'))
450
455
456 def test_add_file_into_hg_missing_content(self):
457 self.log_user()
458 response = self.app.post(url('files_add_home',
459 repo_name=HG_REPO,
460 revision='tip', f_path='/'),
461 params={
462 ''
463 },
464 status=302)
465
466 self.checkSessionFlash(response, 'No content')
467
468 def test_add_file_into_hg_missing_filename(self):
469 self.log_user()
470 response = self.app.post(url('files_add_home',
471 repo_name=HG_REPO,
472 revision='tip', f_path='/'),
473 params={
474 'content': "foo"
475 },
476 status=302)
477
478 self.checkSessionFlash(response, 'No filename')
479
480 @parameterized.expand([
481 ('/abs', 'foo'),
482 ('../rel', 'foo'),
483 ('file/../foo', 'foo'),
484 ])
485 def test_add_file_into_hg_bad_filenames(self, location, filename):
486 self.log_user()
487 response = self.app.post(url('files_add_home',
488 repo_name=HG_REPO,
489 revision='tip', f_path='/'),
490 params={
491 'content': "foo",
492 'filename': filename,
493 'location': location
494 },
495 status=302)
496
497 self.checkSessionFlash(response, 'Location must be relative path and must not contain .. in path')
498
499 @parameterized.expand([
500 (1, '', 'foo.txt'),
501 (2, 'dir', 'foo.rst'),
502 (3, 'rel/dir', 'foo.bar'),
503 ])
504 def test_add_file_into_hg(self, cnt, location, filename):
505 self.log_user()
506 repo = fixture.create_repo('commit-test-%s' % cnt, repo_type='hg')
507 response = self.app.post(url('files_add_home',
508 repo_name=repo.repo_name,
509 revision='tip', f_path='/'),
510 params={
511 'content': "foo",
512 'filename': filename,
513 'location': location
514 },
515 status=302)
516 try:
517 self.checkSessionFlash(response, 'Successfully committed to %s'
518 % os.path.join(location, filename))
519 finally:
520 fixture.destroy_repo(repo.repo_name)
521
522 ##GIT - ADD FILE
451 def test_add_file_view_git(self):
523 def test_add_file_view_git(self):
452 self.log_user()
524 self.log_user()
453 response = self.app.get(url('files_add_home',
525 response = self.app.get(url('files_add_home',
454 repo_name=GIT_REPO,
526 repo_name=GIT_REPO,
455 revision='tip', f_path='/'))
527 revision='tip', f_path='/'))
456
528
529 def test_add_file_into_git_missing_content(self):
530 self.log_user()
531 response = self.app.post(url('files_add_home',
532 repo_name=GIT_REPO,
533 revision='tip', f_path='/'),
534 params={
535 ''
536 },
537 status=302)
538
539 self.checkSessionFlash(response, 'No content')
540
541 def test_add_file_into_git_missing_filename(self):
542 self.log_user()
543 response = self.app.post(url('files_add_home',
544 repo_name=GIT_REPO,
545 revision='tip', f_path='/'),
546 params={
547 'content': "foo"
548 },
549 status=302)
550
551 self.checkSessionFlash(response, 'No filename')
552
553 @parameterized.expand([
554 ('/abs', 'foo'),
555 ('../rel', 'foo'),
556 ('file/../foo', 'foo'),
557 ])
558 def test_add_file_into_git_bad_filenames(self, location, filename):
559 self.log_user()
560 response = self.app.post(url('files_add_home',
561 repo_name=GIT_REPO,
562 revision='tip', f_path='/'),
563 params={
564 'content': "foo",
565 'filename': filename,
566 'location': location
567 },
568 status=302)
569
570 self.checkSessionFlash(response, 'Location must be relative path and must not contain .. in path')
571
572 @parameterized.expand([
573 (1, '', 'foo.txt'),
574 (2, 'dir', 'foo.rst'),
575 (3, 'rel/dir', 'foo.bar'),
576 ])
577 def test_add_file_into_git(self, cnt, location, filename):
578 self.log_user()
579 repo = fixture.create_repo('commit-test-%s' % cnt, repo_type='git')
580 response = self.app.post(url('files_add_home',
581 repo_name=repo.repo_name,
582 revision='tip', f_path='/'),
583 params={
584 'content': "foo",
585 'filename': filename,
586 'location': location
587 },
588 status=302)
589 try:
590 self.checkSessionFlash(response, 'Successfully committed to %s'
591 % os.path.join(location, filename))
592 finally:
593 fixture.destroy_repo(repo.repo_name)
594
595 #HG - EDIT
457 def test_edit_file_view_hg(self):
596 def test_edit_file_view_hg(self):
458 self.log_user()
597 self.log_user()
459 response = self.app.get(url('files_edit_home',
598 response = self.app.get(url('files_edit_home',
460 repo_name=HG_REPO,
599 repo_name=HG_REPO,
461 revision='tip', f_path='vcs/nodes.py'))
600 revision='tip', f_path='vcs/nodes.py'))
462
601
602 def test_edit_file_view_not_on_branch_hg(self):
603 self.log_user()
604 repo = fixture.create_repo('test-edit-repo', repo_type='hg')
605
606 ## add file
607 location = 'vcs'
608 filename = 'nodes.py'
609 response = self.app.post(url('files_add_home',
610 repo_name=repo.repo_name,
611 revision='tip', f_path='/'),
612 params={
613 'content': "def py():\n print 'hello'\n",
614 'filename': filename,
615 'location': location
616 },
617 status=302)
618 response.follow()
619 try:
620 self.checkSessionFlash(response, 'Successfully committed to %s'
621 % os.path.join(location, filename))
622 response = self.app.get(url('files_edit_home',
623 repo_name=repo.repo_name,
624 revision='tip', f_path='vcs/nodes.py'),
625 status=302)
626 self.checkSessionFlash(response,
627 'You can only edit files with revision being a valid branch')
628 finally:
629 fixture.destroy_repo(repo.repo_name)
630
631 def test_edit_file_view_commit_changes_hg(self):
632 self.log_user()
633 repo = fixture.create_repo('test-edit-repo', repo_type='hg')
634
635 ## add file
636 location = 'vcs'
637 filename = 'nodes.py'
638 response = self.app.post(url('files_add_home',
639 repo_name=repo.repo_name,
640 revision='tip',
641 f_path='/'),
642 params={
643 'content': "def py():\n print 'hello'\n",
644 'filename': filename,
645 'location': location
646 },
647 status=302)
648 response.follow()
649 try:
650 self.checkSessionFlash(response, 'Successfully committed to %s'
651 % os.path.join(location, filename))
652 response = self.app.post(url('files_edit_home',
653 repo_name=repo.repo_name,
654 revision=repo.scm_instance.DEFAULT_BRANCH_NAME,
655 f_path='vcs/nodes.py'),
656 params={
657 'content': "def py():\n print 'hello world'\n",
658 'message': 'i commited',
659 },
660 status=302)
661 self.checkSessionFlash(response,
662 'Successfully committed to vcs/nodes.py')
663 finally:
664 fixture.destroy_repo(repo.repo_name)
665
666 #GIT - EDIT
463 def test_edit_file_view_git(self):
667 def test_edit_file_view_git(self):
464 self.log_user()
668 self.log_user()
465 response = self.app.get(url('files_edit_home',
669 response = self.app.get(url('files_edit_home',
466 repo_name=GIT_REPO,
670 repo_name=GIT_REPO,
467 revision='tip', f_path='vcs/nodes.py'))
671 revision='tip', f_path='vcs/nodes.py'))
672
673 def test_edit_file_view_not_on_branch_git(self):
674 self.log_user()
675 repo = fixture.create_repo('test-edit-repo', repo_type='git')
676
677 ## add file
678 location = 'vcs'
679 filename = 'nodes.py'
680 response = self.app.post(url('files_add_home',
681 repo_name=repo.repo_name,
682 revision='tip', f_path='/'),
683 params={
684 'content': "def py():\n print 'hello'\n",
685 'filename': filename,
686 'location': location
687 },
688 status=302)
689 response.follow()
690 try:
691 self.checkSessionFlash(response, 'Successfully committed to %s'
692 % os.path.join(location, filename))
693 response = self.app.get(url('files_edit_home',
694 repo_name=repo.repo_name,
695 revision='tip', f_path='vcs/nodes.py'),
696 status=302)
697 self.checkSessionFlash(response,
698 'You can only edit files with revision being a valid branch')
699 finally:
700 fixture.destroy_repo(repo.repo_name)
701
702 def test_edit_file_view_commit_changes_git(self):
703 self.log_user()
704 repo = fixture.create_repo('test-edit-repo', repo_type='git')
705
706 ## add file
707 location = 'vcs'
708 filename = 'nodes.py'
709 response = self.app.post(url('files_add_home',
710 repo_name=repo.repo_name,
711 revision='tip',
712 f_path='/'),
713 params={
714 'content': "def py():\n print 'hello'\n",
715 'filename': filename,
716 'location': location
717 },
718 status=302)
719 response.follow()
720 try:
721 self.checkSessionFlash(response, 'Successfully committed to %s'
722 % os.path.join(location, filename))
723 response = self.app.post(url('files_edit_home',
724 repo_name=repo.repo_name,
725 revision=repo.scm_instance.DEFAULT_BRANCH_NAME,
726 f_path='vcs/nodes.py'),
727 params={
728 'content': "def py():\n print 'hello world'\n",
729 'message': 'i commited',
730 },
731 status=302)
732 self.checkSessionFlash(response,
733 'Successfully committed to vcs/nodes.py')
734 finally:
735 fixture.destroy_repo(repo.repo_name)
General Comments 0
You need to be logged in to leave comments. Login now