diff --git a/rhodecode/api/tests/test_api.py b/rhodecode/api/tests/test_api.py index c50ff04b..d861bfc5 100644 --- a/rhodecode/api/tests/test_api.py +++ b/rhodecode/api/tests/test_api.py @@ -15,11 +15,14 @@ # This program is dual-licensed. If you wish to learn more about the # RhodeCode Enterprise Edition, including its added features, Support services, # and proprietary license terms, please see https://rhodecode.com/licenses/ +import json import pytest from rhodecode.api.utils import Optional, OAttr from rhodecode.api.tests.utils import build_data, api_call, assert_error, assert_ok +from rhodecode.model.db import Repository +from rhodecode.model.meta import Session @pytest.mark.usefixtures("testuser_api", "app") @@ -133,3 +136,30 @@ class TestApi(object): response = api_call(self.app, params) assert response.status == "200 OK" assert_ok(id_, expected, response.body) + + @pytest.mark.parametrize( + "is_archived", + [ + True, + False, + ], + ) + def test_api_repo_is_archived(self, backend, is_archived): + repo_name = self._create_repo(backend, is_archived) + + id_, params = build_data(apikey=self.apikey, method="get_repo", repoid=repo_name) + response = api_call(self.app, params) + + assert response.status == "200 OK" + + json_body = json.loads(response.body) + + assert json_body["result"]["archived"] == is_archived + + def _create_repo(self, backend, is_archived): + repo = backend.create_repo() + repo_name = repo.repo_name + repo = Repository.get_by_repo_name(repo_name) + repo.archived = is_archived + Session().commit() + return repo_name diff --git a/rhodecode/model/db.py b/rhodecode/model/db.py index 2bdb621b..1227902d 100644 --- a/rhodecode/model/db.py +++ b/rhodecode/model/db.py @@ -364,7 +364,7 @@ class BaseModel(object): return cls.query().all() @classmethod - def delete(cls, id_): + def delete(cls, id_): # noqa: F811 obj = cls.query().get(id_) Session().delete(obj) @@ -418,7 +418,7 @@ class RhodeCodeSetting(Base, BaseModel): @validates("_app_settings_value") def validate_settings_value(self, key, val): - assert type(val) == str + assert type(val) is str return val @hybrid_property @@ -535,7 +535,7 @@ class RepoRhodeCodeSetting(Base, BaseModel): @validates("_app_settings_value") def validate_settings_value(self, key, val): - assert type(val) == str + assert type(val) is str return val @hybrid_property @@ -2398,6 +2398,7 @@ class Repository(Base, BaseModel): "locked_by": User.get(_user_id).get_api_data(include_secrets=include_secrets) if _user_id else None, "locked_date": time_to_datetime(_time) if _time else None, "lock_reason": _reason if _reason else None, + "archived": repo.archived or False, } # TODO: mikhail: should be per-repo settings here