|
14 | 14 |
|
15 | 15 | from readthedocs.builds.models import Version
|
16 | 16 | from readthedocs.projects.models import Project, Domain
|
17 |
| -from readthedocs.projects.tasks import symlink_project |
| 17 | +from readthedocs.projects.tasks import symlink_project, remove_orphan_symlinks |
18 | 18 | from readthedocs.core.symlink import PublicSymlink, PrivateSymlink
|
19 | 19 |
|
20 | 20 |
|
@@ -166,6 +166,79 @@ def test_symlink_cname(self):
|
166 | 166 | filesystem['private_web_root'] = public_root
|
167 | 167 | self.assertFilesystem(filesystem)
|
168 | 168 |
|
| 169 | + def test_symlink_remove_orphan_symlinks(self): |
| 170 | + self.domain = get(Domain, project=self.project, domain='woot.com', |
| 171 | + url='http://woot.com', cname=True) |
| 172 | + self.symlink.symlink_cnames() |
| 173 | + |
| 174 | + # Editing the Domain and calling save will symlink the new domain and |
| 175 | + # leave the old one as orphan. |
| 176 | + self.domain.domain = 'foobar.com' |
| 177 | + self.domain.save() |
| 178 | + |
| 179 | + filesystem = { |
| 180 | + 'private_cname_project': { |
| 181 | + 'foobar.com': {'type': 'link', 'target': 'user_builds/kong'}, |
| 182 | + 'woot.com': {'type': 'link', 'target': 'user_builds/kong'}, |
| 183 | + }, |
| 184 | + 'private_cname_root': { |
| 185 | + 'foobar.com': {'type': 'link', 'target': 'private_web_root/kong'}, |
| 186 | + 'woot.com': {'type': 'link', 'target': 'private_web_root/kong'}, |
| 187 | + }, |
| 188 | + 'private_web_root': {'kong': {'en': {}}}, |
| 189 | + 'public_cname_project': { |
| 190 | + 'foobar.com': {'type': 'link', 'target': 'user_builds/kong'}, |
| 191 | + 'woot.com': {'type': 'link', 'target': 'user_builds/kong'}, |
| 192 | + }, |
| 193 | + 'public_cname_root': { |
| 194 | + 'foobar.com': {'type': 'link', 'target': 'public_web_root/kong'}, |
| 195 | + 'woot.com': {'type': 'link', 'target': 'public_web_root/kong'}, |
| 196 | + }, |
| 197 | + 'public_web_root': { |
| 198 | + 'kong': {'en': {'latest': { |
| 199 | + 'type': 'link', |
| 200 | + 'target': 'user_builds/kong/rtd-builds/latest', |
| 201 | + }}} |
| 202 | + } |
| 203 | + } |
| 204 | + if self.privacy == 'private': |
| 205 | + public_root = filesystem['public_web_root'].copy() |
| 206 | + private_root = filesystem['private_web_root'].copy() |
| 207 | + filesystem['public_web_root'] = private_root |
| 208 | + filesystem['private_web_root'] = public_root |
| 209 | + self.assertFilesystem(filesystem) |
| 210 | + |
| 211 | + remove_orphan_symlinks() |
| 212 | + filesystem = { |
| 213 | + 'private_cname_project': { |
| 214 | + 'foobar.com': {'type': 'link', 'target': 'user_builds/kong'}, |
| 215 | + }, |
| 216 | + 'private_cname_root': { |
| 217 | + 'foobar.com': {'type': 'link', 'target': 'private_web_root/kong'}, |
| 218 | + }, |
| 219 | + 'private_web_root': {'kong': {'en': {}}}, |
| 220 | + 'public_cname_project': { |
| 221 | + 'foobar.com': {'type': 'link', 'target': 'user_builds/kong'}, |
| 222 | + }, |
| 223 | + 'public_cname_root': { |
| 224 | + 'foobar.com': {'type': 'link', 'target': 'public_web_root/kong'}, |
| 225 | + }, |
| 226 | + 'public_web_root': { |
| 227 | + 'kong': {'en': {'latest': { |
| 228 | + 'type': 'link', |
| 229 | + 'target': 'user_builds/kong/rtd-builds/latest', |
| 230 | + }}}, |
| 231 | + }, |
| 232 | + } |
| 233 | + if self.privacy == 'private': |
| 234 | + public_root = filesystem['public_web_root'].copy() |
| 235 | + private_root = filesystem['private_web_root'].copy() |
| 236 | + filesystem['public_web_root'] = private_root |
| 237 | + filesystem['private_web_root'] = public_root |
| 238 | + |
| 239 | + self.assertFilesystem(filesystem) |
| 240 | + |
| 241 | + |
169 | 242 | def test_symlink_cname_dont_link_missing_domains(self):
|
170 | 243 | """Domains should be relinked after deletion"""
|
171 | 244 | self.domain = get(Domain, project=self.project, domain='woot.com',
|
|
0 commit comments