mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-10-26 19:01:39 -04:00
Archive alternatives must have a URL.
This commit is contained in:
parent
c5538222ef
commit
7db4ea73f2
3 changed files with 31 additions and 5 deletions
|
|
@ -137,6 +137,7 @@ class Archive(Base, ModelHelper):
|
|||
alternatives = list(session.query(Archive).filter(
|
||||
Archive.id != self.id,
|
||||
Archive.url == self.url,
|
||||
Archive.url != None,
|
||||
).order_by(Archive.archive_datetime))
|
||||
return alternatives
|
||||
|
||||
|
|
|
|||
|
|
@ -106,9 +106,7 @@ def test_archives_search_no_query(test_session, archive_factory, test_client):
|
|||
|
||||
|
||||
def test_archive_and_domain_crud(test_session, test_client, archive_factory):
|
||||
"""
|
||||
Getting an Archive returns it's File. Testing deleting Archives.
|
||||
"""
|
||||
"""Getting an Archive returns it's File. Testing deleting Archives."""
|
||||
# Can get empty results.
|
||||
request, response = test_client.get(f'/api/archive/1')
|
||||
assert response.status_code == HTTPStatus.NOT_FOUND
|
||||
|
|
@ -116,8 +114,8 @@ def test_archive_and_domain_crud(test_session, test_client, archive_factory):
|
|||
assert response.status_code == HTTPStatus.OK
|
||||
assert response.json['domains'] == []
|
||||
|
||||
archive1 = archive_factory(domain='example.com')
|
||||
archive2 = archive_factory(domain='example.com')
|
||||
archive1 = archive_factory(domain='example.com', url='https://example.com/1')
|
||||
archive2 = archive_factory(domain='example.com', url='https://example.com/1')
|
||||
test_session.commit()
|
||||
|
||||
# Archive1 has Archive2 as alternative.
|
||||
|
|
|
|||
|
|
@ -686,3 +686,30 @@ async def test_archive_download_index(test_session, test_directory, image_file):
|
|||
and archive.readability_json_file.associated \
|
||||
and archive.readability_file.associated \
|
||||
and archive.screenshot_file.associated, 'Archive files must be associated'
|
||||
|
||||
|
||||
def test_archive_alternatives(test_session, archive_factory):
|
||||
"""Archive's that share a URL are alternatives.
|
||||
|
||||
Archive's with an empty URL are not associated."""
|
||||
archive1 = archive_factory(url='https://example.com/1')
|
||||
archive2 = archive_factory(url='https://example.com/1')
|
||||
archive3 = archive_factory(url='https://example.com/2')
|
||||
archive4 = archive_factory()
|
||||
archive5 = archive_factory()
|
||||
|
||||
assert archive1 in archive2.alternatives, 'archive1 is an alternative for archive2'
|
||||
assert archive2 in archive1.alternatives, 'archive2 is an alternative for archive2'
|
||||
assert archive3 not in archive1.alternatives and archive3 not in archive2.alternatives, 'archive3 is unique'
|
||||
assert not archive3.alternatives, 'archive3 has no alternatives'
|
||||
assert not archive4.alternatives, 'archive4 has no alternatives'
|
||||
assert not archive5.alternatives, 'archive5 has no alternatives'
|
||||
|
||||
test_session.commit()
|
||||
|
||||
assert archive1 in archive2.alternatives, 'archive1 is an alternative for archive2'
|
||||
assert archive2 in archive1.alternatives, 'archive2 is an alternative for archive2'
|
||||
assert archive3 not in archive1.alternatives and archive3 not in archive2.alternatives, 'archive3 is unique'
|
||||
assert not archive3.alternatives, 'archive3 has no alternatives'
|
||||
assert not archive4.alternatives, 'archive4 has no alternatives'
|
||||
assert not archive5.alternatives, 'archive5 has no alternatives'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue