##// END OF EJS Templates
tests: update test_api_create_repo with better coverage of create_repo api...
Mads Kiilerich -
r8727:1d1fe8c2 stable
parent child Browse files
Show More
@@ -16,6 +16,7 b''
16 Tests for the JSON-RPC web api.
16 Tests for the JSON-RPC web api.
17 """
17 """
18
18
19 import datetime
19 import os
20 import os
20 import random
21 import random
21 import re
22 import re
@@ -783,24 +784,73 b' class _BaseTestApi(object):'
783 finally:
784 finally:
784 RepoModel().revoke_user_permission(self.REPO, self.TEST_USER_LOGIN)
785 RepoModel().revoke_user_permission(self.REPO, self.TEST_USER_LOGIN)
785
786
786 def test_api_create_repo(self):
787 @base.parametrize('changing_attr,updates', [
787 repo_name = 'api-repo'
788 ('owner', {'owner': base.TEST_USER_REGULAR_LOGIN}),
789 ('description', {'description': 'new description'}),
790 ('clone_uri', {'clone_uri': 'http://example.com/repo'}), # will fail - pulling from non-existing repo should fail
791 ('clone_uri', {'clone_uri': '/repo'}), # will fail - pulling from local repo was a misfeature - it would bypass access control
792 ('clone_uri', {'clone_uri': None}),
793 ('landing_rev', {'landing_rev': 'branch:master'}),
794 ('private', {'private': True}),
795 #('enable_statistics', {'enable_statistics': True}), # currently broken
796 #('enable_downloads', {'enable_downloads': True}), # currently broken
797 ('repo_group', {'group': 'test_group_for_update'}),
798 ])
799 def test_api_create_repo(self, changing_attr, updates):
800 repo_name = repo_name_full = 'new_repo'
801
802 if changing_attr == 'repo_group':
803 group_name = updates['group']
804 fixture.create_repo_group(group_name)
805 repo_name_full = '/'.join([group_name, repo_name])
806 updates = {}
807
788 id_, params = _build_data(self.apikey, 'create_repo',
808 id_, params = _build_data(self.apikey, 'create_repo',
789 repo_name=repo_name,
809 repo_type=self.REPO_TYPE, repo_name=repo_name_full, **updates)
790 owner=base.TEST_USER_ADMIN_LOGIN,
791 repo_type=self.REPO_TYPE,
792 )
793 response = api_call(self, params)
810 response = api_call(self, params)
794
811
795 repo = RepoModel().get_by_repo_name(repo_name)
812 try:
796 assert repo is not None
813 expected = {
797 ret = {
814 'msg': 'Created new repository `%s`' % repo_name_full,
798 'msg': 'Created new repository `%s`' % repo_name,
815 'success': True}
799 'success': True,
816 if changing_attr == 'clone_uri' and updates['clone_uri']:
800 }
817 expected = 'failed to create repository `%s`' % repo_name
801 expected = ret
818 self._compare_error(id_, expected, given=response.body)
802 self._compare_ok(id_, expected, given=response.body)
819 return
803 fixture.destroy_repo(repo_name)
820 else:
821 self._compare_ok(id_, expected, given=response.body)
822
823 repo = db.Repository.get_by_repo_name(repo_name_full)
824 assert repo is not None
825
826 expected_data = {
827 'clone_uri': None,
828 'created_on': repo.created_on,
829 'description': repo_name,
830 'enable_downloads': False,
831 'enable_statistics': False,
832 'fork_of': None,
833 'landing_rev': ['rev', 'tip'],
834 'last_changeset': {'author': '',
835 'date': datetime.datetime(1970, 1, 1, 0, 0),
836 'message': '',
837 'raw_id': '0000000000000000000000000000000000000000',
838 'revision': -1,
839 'short_id': '000000000000'},
840 'owner': 'test_admin',
841 'private': False,
842 'repo_id': repo.repo_id,
843 'repo_name': repo_name_full,
844 'repo_type': self.REPO_TYPE,
845 }
846 expected_data.update(updates)
847 if changing_attr == 'landing_rev':
848 expected_data['landing_rev'] = expected_data['landing_rev'].split(':', 1)
849 assert repo.get_api_data() == expected_data
850 finally:
851 fixture.destroy_repo(repo_name_full)
852 if changing_attr == 'repo_group':
853 fixture.destroy_repo_group(group_name)
804
854
805 @base.parametrize('repo_name', [
855 @base.parametrize('repo_name', [
806 '',
856 '',
General Comments 0
You need to be logged in to leave comments. Login now