| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent f6b6e18 commit e5affc8
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,6 +15,7 @@ | |||
| 15 | 15 | # You should have received a copy of the GNU Lesser General Public License | |
| 16 | 16 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
| 17 | 17 | ||
| 18 | + import copy | ||
| 18 | 19 | import importlib | |
| 19 | 20 | import pprint | |
| 20 | 21 | import textwrap | |
@@ -243,10 +244,11 @@ def encoded_id(self) -> Optional[Union[int, str]]: | |||
| 243 | 244 | ||
| 244 | 245 | @property | |
| 245 | 246 | def attributes(self) -> Dict[str, Any]: | |
| 246 | - d = self.__dict__["_updated_attrs"].copy() | ||
| 247 | - d.update(self.__dict__["_attrs"]) | ||
| 248 | - d.update(self.__dict__["_parent_attrs"]) | ||
| 249 | - return d | ||
| 247 | + data = {} | ||
| 248 | + data.update(copy.deepcopy(self._parent_attrs)) | ||
| 249 | + data.update(copy.deepcopy(self._attrs)) | ||
| 250 | + data.update(copy.deepcopy(self._updated_attrs)) | ||
| 251 | + return data | ||
| 250 | 252 | ||
| 251 | 253 | ||
| 252 | 254 | class RESTObjectList: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -46,6 +46,11 @@ def fake_manager(fake_gitlab): | |||
| 46 | 46 | return FakeManager(fake_gitlab) | |
| 47 | 47 | ||
| 48 | 48 | ||
| 49 | + @pytest.fixture | ||
| 50 | + def fake_object(fake_manager): | ||
| 51 | + return FakeObject(fake_manager, {"attr1": [1, 2, 3]}) | ||
| 52 | + | ||
| 53 | + | ||
| 49 | 54 | class TestRESTManager: | |
| 50 | 55 | def test_computed_path_simple(self): | |
| 51 | 56 | class MGR(base.RESTManager): | |
@@ -306,3 +311,24 @@ def test_repr(self, fake_manager): | |||
| 306 | 311 | ||
| 307 | 312 | FakeObject._id_attr = None | |
| 308 | 313 | assert repr(obj) == "<FakeObject>" | |
| 314 | + | ||
| 315 | + def test_attributes_get(self, fake_object): | ||
| 316 | + assert fake_object.attr1 == [1, 2, 3] | ||
| 317 | + result = fake_object.attributes | ||
| 318 | + assert result == {"attr1": [1, 2, 3]} | ||
| 319 | + | ||
| 320 | + def test_attributes_shows_updates(self, fake_object): | ||
| 321 | + # Updated attribute value is reflected in `attributes` | ||
| 322 | + fake_object.attr1 = "hello" | ||
| 323 | + assert fake_object.attributes == {"attr1": "hello"} | ||
| 324 | + assert fake_object.attr1 == "hello" | ||
| 325 | + # New attribute is in `attributes` | ||
| 326 | + fake_object.new_attrib = "spam" | ||
| 327 | + assert fake_object.attributes == {"attr1": "hello", "new_attrib": "spam"} | ||
| 328 | + | ||
| 329 | + def test_attributes_is_copy(self, fake_object): | ||
| 330 | + # Modifying the dictionary does not cause modifications to the object | ||
| 331 | + result = fake_object.attributes | ||
| 332 | + result["attr1"].append(10) | ||
| 333 | + assert result == {"attr1": [1, 2, 3, 10]} | ||
| 334 | + assert fake_object.attributes == {"attr1": [1, 2, 3]} | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments