kopia lustrzana https://github.com/Langenfeld/py-gitea
black
rodzic
2c82cd2983
commit
254bb2a1aa
62
example.py
62
example.py
|
@ -3,7 +3,7 @@ import os
|
||||||
from gitea import Gitea, User, Organization, Team, Repository, version
|
from gitea import Gitea, User, Organization, Team, Repository, version
|
||||||
from gitea import NotFoundException, AlreadyExistsException
|
from gitea import NotFoundException, AlreadyExistsException
|
||||||
|
|
||||||
assert version >= '0.4.0'
|
assert version >= "0.4.0"
|
||||||
|
|
||||||
|
|
||||||
# Testing a localhost instance for API-functionality.
|
# Testing a localhost instance for API-functionality.
|
||||||
|
@ -84,75 +84,77 @@ def test_before_team():
|
||||||
|
|
||||||
|
|
||||||
def test_create_user():
|
def test_create_user():
|
||||||
user = gitea.create_user('test-user', 'testmail@example.org', 'pw1234')
|
user = gitea.create_user("test-user", "testmail@example.org", "pw1234")
|
||||||
user.update_mail()
|
user.update_mail()
|
||||||
assert user.username == 'test-user'
|
assert user.username == "test-user"
|
||||||
assert user.login == 'test-user'
|
assert user.login == "test-user"
|
||||||
assert user.email == 'testmail@example.org'
|
assert user.email == "testmail@example.org"
|
||||||
assert not user.is_admin
|
assert not user.is_admin
|
||||||
|
|
||||||
|
|
||||||
def test_create_org():
|
def test_create_org():
|
||||||
user = gitea.get_user()
|
user = gitea.get_user()
|
||||||
org = gitea.create_org(user, 'test-org', 'some-desc', 'loc')
|
org = gitea.create_org(user, "test-org", "some-desc", "loc")
|
||||||
assert org.get_members() == [user]
|
assert org.get_members() == [user]
|
||||||
assert org.description == 'some-desc'
|
assert org.description == "some-desc"
|
||||||
assert org.username == 'test-org'
|
assert org.username == "test-org"
|
||||||
assert org.location == 'loc'
|
assert org.location == "loc"
|
||||||
assert not org.website
|
assert not org.website
|
||||||
assert not org.full_name
|
assert not org.full_name
|
||||||
|
|
||||||
|
|
||||||
def test_create_repo():
|
def test_create_repo():
|
||||||
org = Organization(gitea, 'test-org')
|
org = Organization(gitea, "test-org")
|
||||||
repo = gitea.create_repo(org, 'test-repo', 'descr')
|
repo = gitea.create_repo(org, "test-repo", "descr")
|
||||||
assert repo.description == 'descr'
|
assert repo.description == "descr"
|
||||||
assert repo.owner == org
|
assert repo.owner == org
|
||||||
assert repo.name == 'test-repo'
|
assert repo.name == "test-repo"
|
||||||
assert not repo.private
|
assert not repo.private
|
||||||
|
|
||||||
|
|
||||||
def test_create_team():
|
def test_create_team():
|
||||||
org = Organization(gitea, 'test-org')
|
org = Organization(gitea, "test-org")
|
||||||
team = gitea.create_team(org, 'test-team', 'descr')
|
team = gitea.create_team(org, "test-team", "descr")
|
||||||
assert team.name == 'test-team'
|
assert team.name == "test-team"
|
||||||
assert team.description == 'descr'
|
assert team.description == "descr"
|
||||||
assert team.organization == org
|
assert team.organization == org
|
||||||
|
|
||||||
|
|
||||||
def test_full():
|
def test_full():
|
||||||
user = User(gitea, 'test-user')
|
user = User(gitea, "test-user")
|
||||||
user.update_mail()
|
user.update_mail()
|
||||||
org = Organization(gitea, 'test-org')
|
org = Organization(gitea, "test-org")
|
||||||
team = Team(org, 'test-team')
|
team = Team(org, "test-team")
|
||||||
assert team.get_members() == []
|
assert team.get_members() == []
|
||||||
team.add(user)
|
team.add(user)
|
||||||
assert team.get_members() == [user]
|
assert team.get_members() == [user]
|
||||||
repo = Repository(gitea, org, 'test-repo')
|
repo = Repository(gitea, org, "test-repo")
|
||||||
assert team.get_repos() == []
|
assert team.get_repos() == []
|
||||||
team.add(repo)
|
team.add(repo)
|
||||||
assert team.get_repos() == [repo]
|
assert team.get_repos() == [repo]
|
||||||
|
|
||||||
|
|
||||||
def test_delete_repo():
|
def test_delete_repo():
|
||||||
org = Organization(gitea, 'test-org')
|
org = Organization(gitea, "test-org")
|
||||||
repo = Repository(gitea, org, 'test-repo')
|
repo = Repository(gitea, org, "test-repo")
|
||||||
repo.delete()
|
repo.delete()
|
||||||
assert expect_not_exist(
|
assert expect_not_exist(
|
||||||
lambda: Repository(gitea, User(gitea, "test-user"), "test-repo"),
|
lambda: Repository(gitea, User(gitea, "test-user"), "test-repo"),
|
||||||
(NotFoundException),
|
(NotFoundException),
|
||||||
), "Repository test-repo should not exist"
|
), "Repository test-repo should not exist"
|
||||||
|
|
||||||
|
|
||||||
def test_delete_team():
|
def test_delete_team():
|
||||||
org = Organization(gitea, 'test-org')
|
org = Organization(gitea, "test-org")
|
||||||
team = Team(org, 'test-team')
|
team = Team(org, "test-team")
|
||||||
team.delete()
|
team.delete()
|
||||||
assert expect_not_exist(
|
assert expect_not_exist(
|
||||||
lambda: Team(org, "test-team"),
|
lambda: Team(org, "test-team"), (NotFoundException)
|
||||||
(NotFoundException),
|
|
||||||
), "Team test-team should not exist"
|
), "Team test-team should not exist"
|
||||||
|
|
||||||
|
|
||||||
def test_delete_org():
|
def test_delete_org():
|
||||||
org = Organization(gitea, 'test-org')
|
org = Organization(gitea, "test-org")
|
||||||
org.delete()
|
org.delete()
|
||||||
assert expect_not_exist(
|
assert expect_not_exist(
|
||||||
lambda: Organization(gitea, "test-org"), (NotFoundException)
|
lambda: Organization(gitea, "test-org"), (NotFoundException)
|
||||||
|
@ -160,10 +162,8 @@ def test_delete_org():
|
||||||
|
|
||||||
|
|
||||||
def test_delete_user():
|
def test_delete_user():
|
||||||
user = User(gitea, 'test-user')
|
user = User(gitea, "test-user")
|
||||||
user.delete()
|
user.delete()
|
||||||
assert expect_not_exist(
|
assert expect_not_exist(
|
||||||
lambda: User(gitea, "test-user"), (NotFoundException)
|
lambda: User(gitea, "test-user"), (NotFoundException)
|
||||||
), "User test-user should not exist"
|
), "User test-user should not exist"
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1 +1,11 @@
|
||||||
from .gitea import Gitea, User, Organization, Team, Repository, Branch, version, NotFoundException, AlreadyExistsException
|
from .gitea import (
|
||||||
|
Gitea,
|
||||||
|
User,
|
||||||
|
Organization,
|
||||||
|
Team,
|
||||||
|
Repository,
|
||||||
|
Branch,
|
||||||
|
version,
|
||||||
|
NotFoundException,
|
||||||
|
AlreadyExistsException,
|
||||||
|
)
|
||||||
|
|
|
@ -3,7 +3,7 @@ import requests
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
logging = logging.getLogger("gitea")
|
logging = logging.getLogger("gitea")
|
||||||
version = '0.4.0'
|
version = "0.4.0"
|
||||||
|
|
||||||
|
|
||||||
class AlreadyExistsException(Exception):
|
class AlreadyExistsException(Exception):
|
||||||
|
@ -250,7 +250,7 @@ class User:
|
||||||
self.__initialize_user(self.username, result)
|
self.__initialize_user(self.username, result)
|
||||||
|
|
||||||
def delete(self):
|
def delete(self):
|
||||||
""" Deletes this user. Also deletes all Repositories he owns.
|
""" Deletes this User. Also deletes all Repositories he owns.
|
||||||
|
|
||||||
Warning:
|
Warning:
|
||||||
Invalidates this Objects Data.
|
Invalidates this Objects Data.
|
||||||
|
@ -350,7 +350,9 @@ class Repository:
|
||||||
Returns: int
|
Returns: int
|
||||||
Accumulated time the user worked in this Repository.
|
Accumulated time the user worked in this Repository.
|
||||||
"""
|
"""
|
||||||
results = self.gitea.requests_get(Repository.REPO_USER_TIME % (self.owner.username, self.name, username))
|
results = self.gitea.requests_get(
|
||||||
|
Repository.REPO_USER_TIME % (self.owner.username, self.name, username)
|
||||||
|
)
|
||||||
return results["time"]
|
return results["time"]
|
||||||
|
|
||||||
def delete(self):
|
def delete(self):
|
||||||
|
@ -518,7 +520,9 @@ class Team:
|
||||||
A list of Users in this Team.
|
A list of Users in this Team.
|
||||||
"""
|
"""
|
||||||
results = self.gitea.requests_get(Team.GET_MEMBERS % self.id)
|
results = self.gitea.requests_get(Team.GET_MEMBERS % self.id)
|
||||||
return [User(self.gitea, result["username"], initJson=result) for result in results]
|
return [
|
||||||
|
User(self.gitea, result["username"], initJson=result) for result in results
|
||||||
|
]
|
||||||
|
|
||||||
def get_repos(self):
|
def get_repos(self):
|
||||||
""" Get all repos of this Team.
|
""" Get all repos of this Team.
|
||||||
|
@ -527,9 +531,10 @@ class Team:
|
||||||
A list of Repositories of this Team
|
A list of Repositories of this Team
|
||||||
"""
|
"""
|
||||||
results = self.gitea.requests_get(Team.GET_REPOS % self.id)
|
results = self.gitea.requests_get(Team.GET_REPOS % self.id)
|
||||||
return [Repository(self.gitea, self.organization, result["name"], initJson=result) for result in results]
|
return [
|
||||||
|
Repository(self.gitea, self.organization, result["name"], initJson=result)
|
||||||
|
for result in results
|
||||||
|
]
|
||||||
|
|
||||||
def delete(self):
|
def delete(self):
|
||||||
""" Delete this Team.
|
""" Delete this Team.
|
||||||
|
|
Ładowanie…
Reference in New Issue