kopia lustrzana https://github.com/Langenfeld/py-gitea
updated tests file to use proper setup for the tests
rodzic
caed956b67
commit
e1b499599d
|
@ -5,17 +5,20 @@ from gitea import Gitea, User, Organization, Team, Repository, Issue
|
||||||
from gitea import NotFoundException, AlreadyExistsException
|
from gitea import NotFoundException, AlreadyExistsException
|
||||||
|
|
||||||
# put a ".token" file into your directory containg only the token for gitea
|
# put a ".token" file into your directory containg only the token for gitea
|
||||||
try:
|
@pytest.fixture
|
||||||
instance = Gitea("http://localhost:3000", open(".token", "r").read().strip())
|
def instance(scope="module"):
|
||||||
print("Gitea Version: " + instance.get_version())
|
try:
|
||||||
print("API-Token belongs to user: " + instance.get_user().username)
|
g = Gitea("http://localhost:3000", open(".token", "r").read().strip())
|
||||||
except:
|
print("Gitea Version: " + g.get_version())
|
||||||
assert (
|
print("API-Token belongs to user: " + g.get_user().username)
|
||||||
False
|
return g
|
||||||
), "Gitea could not load. \
|
except:
|
||||||
- Instance running at http://localhost:3000 \
|
assert (
|
||||||
- Token at .token \
|
False
|
||||||
?"
|
), "Gitea could not load. \
|
||||||
|
- Instance running at http://localhost:3000 \
|
||||||
|
- Token at .token \
|
||||||
|
?"
|
||||||
|
|
||||||
# make up some fresh names for the tests run
|
# make up some fresh names for the tests run
|
||||||
test_org = "org_" + uuid.uuid4().hex[:8]
|
test_org = "org_" + uuid.uuid4().hex[:8]
|
||||||
|
@ -24,32 +27,32 @@ test_team = "team_" + uuid.uuid4().hex[:8] # team names seem to have a rather l
|
||||||
test_repo = "repo_" + uuid.uuid4().hex[:8]
|
test_repo = "repo_" + uuid.uuid4().hex[:8]
|
||||||
|
|
||||||
|
|
||||||
def test_token_owner():
|
def test_token_owner(instance):
|
||||||
user = instance.get_user()
|
user = instance.get_user()
|
||||||
assert user.username == "tests", "Token user not 'tests'."
|
assert user.username == "test", "Token user not 'tests'."
|
||||||
assert user.is_admin, "Testuser is not Admin - Tests may fail"
|
assert user.is_admin, "Testuser is not Admin - Tests may fail"
|
||||||
|
|
||||||
|
|
||||||
def test_gitea_version():
|
def test_gitea_version(instance):
|
||||||
assert instance.get_version() == "1.10.0", "Version changed. Updated?"
|
assert instance.get_version().startswith("1."), "No Version String returned"
|
||||||
|
|
||||||
|
|
||||||
def test_fail_get_non_existent_user():
|
def test_fail_get_non_existent_user(instance):
|
||||||
with pytest.raises(NotFoundException) as e:
|
with pytest.raises(NotFoundException) as e:
|
||||||
User.request(instance, test_user)
|
User.request(instance, test_user)
|
||||||
|
|
||||||
|
|
||||||
def test_fail_get_non_existent_org():
|
def test_fail_get_non_existent_org(instance):
|
||||||
with pytest.raises(NotFoundException) as e:
|
with pytest.raises(NotFoundException) as e:
|
||||||
Organization.request(instance, test_org)
|
Organization.request(instance, test_org)
|
||||||
|
|
||||||
|
|
||||||
def test_fail_get_non_existent_repo():
|
def test_fail_get_non_existent_repo(instance):
|
||||||
with pytest.raises(NotFoundException) as e:
|
with pytest.raises(NotFoundException) as e:
|
||||||
Repository.request(instance, test_user, test_repo)
|
Repository.request(instance, test_user, test_repo)
|
||||||
|
|
||||||
|
|
||||||
def test_create_user():
|
def test_create_user(instance):
|
||||||
email = test_user + "@example.org"
|
email = test_user + "@example.org"
|
||||||
user = instance.create_user(test_user, email, "abcdefg1.23AB")
|
user = instance.create_user(test_user, email, "abcdefg1.23AB")
|
||||||
assert user.username == test_user
|
assert user.username == test_user
|
||||||
|
@ -59,7 +62,7 @@ def test_create_user():
|
||||||
assert not user.is_admin
|
assert not user.is_admin
|
||||||
|
|
||||||
|
|
||||||
def test_create_org():
|
def test_create_org(instance):
|
||||||
user = instance.get_user()
|
user = instance.get_user()
|
||||||
org = instance.create_org(user, test_org, "some-desc", "loc")
|
org = instance.create_org(user, test_org, "some-desc", "loc")
|
||||||
assert org.get_members() == [user]
|
assert org.get_members() == [user]
|
||||||
|
@ -70,13 +73,13 @@ def test_create_org():
|
||||||
assert not org.full_name
|
assert not org.full_name
|
||||||
|
|
||||||
|
|
||||||
def test_non_changable_field():
|
def test_non_changable_field(instance):
|
||||||
org = Organization.request(instance, test_org)
|
org = Organization.request(instance, test_org)
|
||||||
with pytest.raises(AttributeError) as e:
|
with pytest.raises(AttributeError) as e:
|
||||||
org.id = 55
|
org.id = 55
|
||||||
|
|
||||||
|
|
||||||
def test_create_repo_userowned():
|
def test_create_repo_userowned(instance):
|
||||||
org = User.request(instance, test_user)
|
org = User.request(instance, test_user)
|
||||||
repo = instance.create_repo(org, test_repo, "user owned repo")
|
repo = instance.create_repo(org, test_repo, "user owned repo")
|
||||||
assert repo.description == "user owned repo"
|
assert repo.description == "user owned repo"
|
||||||
|
@ -85,7 +88,7 @@ def test_create_repo_userowned():
|
||||||
assert not repo.private
|
assert not repo.private
|
||||||
|
|
||||||
|
|
||||||
def test_edit_org_fields_and_commit():
|
def test_edit_org_fields_and_commit(instance):
|
||||||
org = Organization.request(instance, test_org)
|
org = Organization.request(instance, test_org)
|
||||||
org.description = "some thing other man"
|
org.description = "some thing other man"
|
||||||
org.location = "somewehre new"
|
org.location = "somewehre new"
|
||||||
|
@ -100,7 +103,7 @@ def test_edit_org_fields_and_commit():
|
||||||
assert org2.website == "http:\\\\testurl.com"
|
assert org2.website == "http:\\\\testurl.com"
|
||||||
|
|
||||||
|
|
||||||
def test_create_repo_orgowned():
|
def test_create_repo_orgowned(instance):
|
||||||
org = Organization.request(instance, test_org)
|
org = Organization.request(instance, test_org)
|
||||||
repo = instance.create_repo(org, test_repo, "descr")
|
repo = instance.create_repo(org, test_repo, "descr")
|
||||||
assert repo.description == "descr"
|
assert repo.description == "descr"
|
||||||
|
@ -109,7 +112,7 @@ def test_create_repo_orgowned():
|
||||||
assert not repo.private
|
assert not repo.private
|
||||||
|
|
||||||
|
|
||||||
def test_create_team():
|
def test_create_team(instance):
|
||||||
org = Organization.request(instance, test_org)
|
org = Organization.request(instance, test_org)
|
||||||
team = instance.create_team(org, test_team, "descr")
|
team = instance.create_team(org, test_team, "descr")
|
||||||
assert team.name == test_team
|
assert team.name == test_team
|
||||||
|
@ -117,7 +120,7 @@ def test_create_team():
|
||||||
assert team.organization == org
|
assert team.organization == org
|
||||||
|
|
||||||
|
|
||||||
def test_create_issue():
|
def test_create_issue(instance):
|
||||||
org = Organization.request(instance, test_org)
|
org = Organization.request(instance, test_org)
|
||||||
repo = Repository.request(instance, org.username, test_repo)
|
repo = Repository.request(instance, org.username, test_repo)
|
||||||
issue = Issue.create_issue(instance, repo, "TestIssue", "Body text with this issue")
|
issue = Issue.create_issue(instance, repo, "TestIssue", "Body text with this issue")
|
||||||
|
@ -126,7 +129,7 @@ def test_create_issue():
|
||||||
assert issue.body == "Body text with this issue"
|
assert issue.body == "Body text with this issue"
|
||||||
|
|
||||||
|
|
||||||
def test_delete_repo_userowned():
|
def test_delete_repo_userowned(instance):
|
||||||
user = User.request(instance, test_user)
|
user = User.request(instance, test_user)
|
||||||
repo = Repository.request(instance, user.username, test_repo)
|
repo = Repository.request(instance, user.username, test_repo)
|
||||||
repo.delete()
|
repo.delete()
|
||||||
|
@ -134,14 +137,14 @@ def test_delete_repo_userowned():
|
||||||
Repository.request(instance, test_user, test_repo)
|
Repository.request(instance, test_user, test_repo)
|
||||||
|
|
||||||
|
|
||||||
def test_secundary_email():
|
def test_secundary_email(instance):
|
||||||
SECONDARYMAIL = "secondarytest@tests.org" # set up with real email
|
SECONDARYMAIL = "secondarytest@test.org" # set up with real email
|
||||||
sec_user = instance.get_user_by_email(SECONDARYMAIL)
|
sec_user = instance.get_user_by_email(SECONDARYMAIL)
|
||||||
assert SECONDARYMAIL in sec_user.emails
|
assert SECONDARYMAIL in sec_user.emails
|
||||||
assert sec_user.username == "tests"
|
assert sec_user.username == "test"
|
||||||
|
|
||||||
|
|
||||||
def test_delete_repo_orgowned():
|
def test_delete_repo_orgowned(instance):
|
||||||
org = Organization.request(instance, test_org)
|
org = Organization.request(instance, test_org)
|
||||||
repo = Repository.request(instance, org.username, test_repo)
|
repo = Repository.request(instance, org.username, test_repo)
|
||||||
repo.delete()
|
repo.delete()
|
||||||
|
@ -149,7 +152,7 @@ def test_delete_repo_orgowned():
|
||||||
Repository.request(instance, test_user, test_repo)
|
Repository.request(instance, test_user, test_repo)
|
||||||
|
|
||||||
|
|
||||||
def test_delete_team():
|
def test_delete_team(instance):
|
||||||
org = Organization.request(instance, test_org)
|
org = Organization.request(instance, test_org)
|
||||||
team = org.get_team(test_team)
|
team = org.get_team(test_team)
|
||||||
team.delete()
|
team.delete()
|
||||||
|
@ -157,14 +160,14 @@ def test_delete_team():
|
||||||
team = org.get_team(test_team)
|
team = org.get_team(test_team)
|
||||||
|
|
||||||
|
|
||||||
def test_delete_org():
|
def test_delete_org(instance):
|
||||||
org = Organization.request(instance, test_org)
|
org = Organization.request(instance, test_org)
|
||||||
org.delete()
|
org.delete()
|
||||||
with pytest.raises(NotFoundException) as e:
|
with pytest.raises(NotFoundException) as e:
|
||||||
Organization.request(instance, test_org)
|
Organization.request(instance, test_org)
|
||||||
|
|
||||||
|
|
||||||
def test_delete_user():
|
def test_delete_user(instance):
|
||||||
user = User.request(instance, test_user)
|
user = User.request(instance, test_user)
|
||||||
user.delete()
|
user.delete()
|
||||||
with pytest.raises(NotFoundException) as e:
|
with pytest.raises(NotFoundException) as e:
|
||||||
|
|
Ładowanie…
Reference in New Issue