Skip to content

Commit

Permalink
Fixes bug 1331726 - fix assertion in test_public_api_navigation (mozi…
Browse files Browse the repository at this point in the history
…lla-services#3660)

This fixes the assertion that we should have at least one signature first date
for each signature--that turns out to not necessarily be the case. I changed it
to make sure it's > 0. Hopefully we don't eventually find ourselves in a
situation where it's 0, though I suspect that's possible.

While doing that, I changed some variable names to make the code easier to read
and I added comments to summarize what's about to happen so it's easier to
verify the test is doing what it should be doing.
  • Loading branch information
willkg authored Jan 24, 2017
1 parent 0855d7f commit 21582a4
Showing 1 changed file with 23 additions and 19 deletions.
42 changes: 23 additions & 19 deletions e2e-tests/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

class TestAPI:

@pytest.mark.skip('Bug 1331726 - test_public_api_navigation is sporadically failing')
@pytest.mark.nondestructive
def test_public_api_navigation(self, base_url):
# Request a list of all the products and versions
response = requests.get(base_url + '/api/ProductVersions/', {
'active': True,
})
Expand All @@ -22,7 +22,9 @@ def test_public_api_navigation(self, base_url):
for hit in response.json()['hits']:
product_versions[hit['product']].append(hit['version'])

uuids = {}
# For each product, do a supersearch for all versions getting the uuid
# for a single crash for that product
product_to_uuid = {}
for product, versions in product_versions.items():
response = requests.get(base_url + '/api/SuperSearch/', {
'_columns': ['uuid'],
Expand All @@ -37,20 +39,21 @@ def test_public_api_navigation(self, base_url):
assert not results['errors'], results['errors']
assert results['facets']
for hit in results['hits']:
uuids[product] = hit['uuid']
product_to_uuid[product] = hit['uuid']

response = requests.get(base_url + '/api/ProductBuildTypes/', {
'product': product,
})
assert response.status_code == 200
assert response.json()['hits']

assert len(uuids) == len(product_versions)
# Assert we have at least one crash for every product
assert len(product_to_uuid) == len(product_versions)

# Look up each raw crashh and processed crash and record all
# found signatures.
signatures = {}
for uuid in uuids.values():
# Fetch the raw crash and processed crash for each uuid and verify we
# can't get the unredacted processed crash
uuid_to_signature = {}
for uuid in product_to_uuid.values():
response = requests.get(base_url + '/api/RawCrash/', {
'crash_id': uuid,
})
Expand All @@ -62,7 +65,7 @@ def test_public_api_navigation(self, base_url):
assert response.status_code == 200
processed_crash = response.json()
assert processed_crash
signatures[uuid] = processed_crash['signature']
uuid_to_signature[uuid] = processed_crash['signature']

# UnredactedProcessedCrash should not be allowed
response = requests.get(
Expand All @@ -73,32 +76,33 @@ def test_public_api_navigation(self, base_url):
)
assert response.status_code == 403

assert len(signatures) == len(product_versions)
assert len(uuid_to_signature) == len(product_versions)

# Check that we can fetch the "signature first date" for each
# signature.
# signature--some don't have one, so we try to roll with that
response = requests.get(base_url + '/api/SignatureFirstDate/', {
'signatures': signatures.values(),
'signatures': uuid_to_signature.values(),
})
assert response.status_code == 200
results = response.json()
first_dates = {}

signature_to_first_date = {}
for hit in results['hits']:
first_dates[hit['signature']] = hit['first_date']
signature_to_first_date[hit['signature']] = hit['first_date']

assert len(first_dates) == len(signatures)
assert 0 < len(signature_to_first_date) <= len(uuid_to_signature)

# Find all bug IDs for these signatures
response = requests.get(base_url + '/api/Bugs/', {
'signatures': signatures.values(),
'signatures': uuid_to_signature.values(),
})
assert response.status_code == 200
results = response.json()
bug_ids = defaultdict(list)
signature_to_bug_ids = defaultdict(list)
for hit in results['hits']:
bug_ids[hit['signature']].append(hit['id'])
signature_to_bug_ids[hit['signature']].append(hit['id'])

for signature, ids in bug_ids.items():
for signature, ids in signature_to_bug_ids.items():
response = requests.get(base_url + '/api/SignaturesByBugs/', {
'bug_ids': ids,
})
Expand Down

0 comments on commit 21582a4

Please sign in to comment.