pull/1/head
fkarg 2019-04-18 14:58:58 +02:00
rodzic 2c82cd2983
commit 254bb2a1aa
3 zmienionych plików z 54 dodań i 39 usunięć

Wyświetl plik

@ -3,7 +3,7 @@ import os
from gitea import Gitea, User, Organization, Team, Repository, version
from gitea import NotFoundException, AlreadyExistsException
assert version >= '0.4.0'
assert version >= "0.4.0"
# Testing a localhost instance for API-functionality.
@ -84,75 +84,77 @@ def test_before_team():
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()
assert user.username == 'test-user'
assert user.login == 'test-user'
assert user.email == 'testmail@example.org'
assert user.username == "test-user"
assert user.login == "test-user"
assert user.email == "testmail@example.org"
assert not user.is_admin
def test_create_org():
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.description == 'some-desc'
assert org.username == 'test-org'
assert org.location == 'loc'
assert org.description == "some-desc"
assert org.username == "test-org"
assert org.location == "loc"
assert not org.website
assert not org.full_name
def test_create_repo():
org = Organization(gitea, 'test-org')
repo = gitea.create_repo(org, 'test-repo', 'descr')
assert repo.description == 'descr'
org = Organization(gitea, "test-org")
repo = gitea.create_repo(org, "test-repo", "descr")
assert repo.description == "descr"
assert repo.owner == org
assert repo.name == 'test-repo'
assert repo.name == "test-repo"
assert not repo.private
def test_create_team():
org = Organization(gitea, 'test-org')
team = gitea.create_team(org, 'test-team', 'descr')
assert team.name == 'test-team'
assert team.description == 'descr'
org = Organization(gitea, "test-org")
team = gitea.create_team(org, "test-team", "descr")
assert team.name == "test-team"
assert team.description == "descr"
assert team.organization == org
def test_full():
user = User(gitea, 'test-user')
user = User(gitea, "test-user")
user.update_mail()
org = Organization(gitea, 'test-org')
team = Team(org, 'test-team')
org = Organization(gitea, "test-org")
team = Team(org, "test-team")
assert team.get_members() == []
team.add(user)
assert team.get_members() == [user]
repo = Repository(gitea, org, 'test-repo')
repo = Repository(gitea, org, "test-repo")
assert team.get_repos() == []
team.add(repo)
assert team.get_repos() == [repo]
def test_delete_repo():
org = Organization(gitea, 'test-org')
repo = Repository(gitea, org, 'test-repo')
org = Organization(gitea, "test-org")
repo = Repository(gitea, org, "test-repo")
repo.delete()
assert expect_not_exist(
lambda: Repository(gitea, User(gitea, "test-user"), "test-repo"),
(NotFoundException),
), "Repository test-repo should not exist"
def test_delete_team():
org = Organization(gitea, 'test-org')
team = Team(org, 'test-team')
org = Organization(gitea, "test-org")
team = Team(org, "test-team")
team.delete()
assert expect_not_exist(
lambda: Team(org, "test-team"),
(NotFoundException),
lambda: Team(org, "test-team"), (NotFoundException)
), "Team test-team should not exist"
def test_delete_org():
org = Organization(gitea, 'test-org')
org = Organization(gitea, "test-org")
org.delete()
assert expect_not_exist(
lambda: Organization(gitea, "test-org"), (NotFoundException)
@ -160,10 +162,8 @@ def test_delete_org():
def test_delete_user():
user = User(gitea, 'test-user')
user = User(gitea, "test-user")
user.delete()
assert expect_not_exist(
lambda: User(gitea, "test-user"), (NotFoundException)
), "User test-user should not exist"

Wyświetl plik

@ -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,
)

Wyświetl plik

@ -3,7 +3,7 @@ import requests
import logging
logging = logging.getLogger("gitea")
version = '0.4.0'
version = "0.4.0"
class AlreadyExistsException(Exception):
@ -250,7 +250,7 @@ class User:
self.__initialize_user(self.username, result)
def delete(self):
""" Deletes this user. Also deletes all Repositories he owns.
""" Deletes this User. Also deletes all Repositories he owns.
Warning:
Invalidates this Objects Data.
@ -350,7 +350,9 @@ class Repository:
Returns: int
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"]
def delete(self):
@ -518,7 +520,9 @@ class Team:
A list of Users in this Team.
"""
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):
""" Get all repos of this Team.
@ -527,9 +531,10 @@ class Team:
A list of Repositories of this Team
"""
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):
""" Delete this Team.