|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +from lmfdb.base import LmfdbTest |
| 3 | + |
| 4 | +class ApiTest(LmfdbTest): |
| 5 | + |
| 6 | + |
| 7 | + def test_api_home(self): |
| 8 | + r""" |
| 9 | + Check that the top-level api page works |
| 10 | + """ |
| 11 | + data = self.tc.get("/api", follow_redirects=True).data |
| 12 | + assert "API for accessing the LMFDB Database" in data |
| 13 | + |
| 14 | + def test_api_databases(self): |
| 15 | + r""" |
| 16 | + Check that one collection from each database works |
| 17 | + """ |
| 18 | + dbs = [ ['HTPicard','picard'], ['Lattices','lat'], |
| 19 | + ['Lfunctions','Lfunctions'], |
| 20 | + ['MaassWaveForms','Coefficients'], |
| 21 | + ['SL2Zsubgroups','groups'], ['abvar','fq_isog'], |
| 22 | + ['artin','representations'], ['bmfs','forms'], |
| 23 | + ['curve_automorphisms','passports'], |
| 24 | + ['elliptic_curves','curves'], |
| 25 | + ['genus2_curves','curves'], |
| 26 | + ['halfintegralmf','forms'], ['hgm','motives'], |
| 27 | + ['hmfs','forms'], ['localfields','fields'], |
| 28 | + ['mod_l_eigenvalues','modlmf'], |
| 29 | + ['mod_l_galois','reps'], |
| 30 | + ['modularforms2','dimension_table'], |
| 31 | + ['numberfields','fields'], |
| 32 | + ['sato_tate_groups','st_groups'], |
| 33 | + ['siegel_modular_forms','dimensions'],['transitivegroups','groups'], |
| 34 | + ['characters','Dirichlet_char_modl'], |
| 35 | + ['finite_fields','finite_fields'], |
| 36 | + ['hecke_algebras','hecke_algebras'], |
| 37 | + ['embedded_mfs','mfs'], ['belyi','passports']] |
| 38 | + for db, coll in dbs: |
| 39 | + data = self.tc.get("/api/{}/{}".format(db,coll), follow_redirects=True).data |
| 40 | + assert "JSON" in data |
| 41 | + |
| 42 | + def test_api_examples_html(self): |
| 43 | + r""" |
| 44 | + Check that the sample queries on the top page all work (html output) |
| 45 | + """ |
| 46 | + queries = ['elliptic_curves/curves/?rank=i2&torsion=i5', |
| 47 | + #'elliptic_curves/curves/?isogeny_matrix=py[[1,13],[13,1]]', # no index on isogeny_matrix |
| 48 | + 'elliptic_curves/curves/?xainvs=cs-1215&torsion_structure=ls2;2&_delim=;', |
| 49 | + 'knowledge/knowls/?_fields=authors,last_author', |
| 50 | + 'knowledge/knowls/?_fields=content,authors&_sort=timestamp'] |
| 51 | + for query in queries: |
| 52 | + data = self.tc.get("/api/{}".format(query), follow_redirects=True).data |
| 53 | + assert 'Query: <code><a href="/api/' in data |
| 54 | + assert not "Error:" in data |
| 55 | + |
| 56 | + def test_api_examples_yaml(self): |
| 57 | + r""" |
| 58 | + Check that the sample queries on the top page all work (yaml output) |
| 59 | + """ |
| 60 | + queries = [#'elliptic_curves/curves/?ainvs=ls0;1;1;-840;39800&_format=yaml&_delim=;', # no index on ainvs |
| 61 | + 'elliptic_curves/curves/?xainvs=s[0,1,1,-840,39800]&_format=yaml'] |
| 62 | + for query in queries: |
| 63 | + data = self.tc.get("/api/{}".format(query), follow_redirects=True).data |
| 64 | + assert "!!python/unicode 'x-coordinates_of_integral_points': !!python/unicode '[-42,-39,-21,0,15,21,24,42,77,126,231,302,420,609,1560,3444,14595]'" in data |
| 65 | + assert not "Error:" in data |
| 66 | + |
| 67 | + def test_api_examples_json(self): |
| 68 | + r""" |
| 69 | + Check that the sample queries on the top page all work (json output) |
| 70 | + """ |
| 71 | + query = 'numberfields/fields/?signature=s2,5&_format=json' |
| 72 | + data = self.tc.get("/api/{}".format(query), follow_redirects=True).data |
| 73 | + assert '"label": "12.2.167630295667.1"' in data |
| 74 | + |
| 75 | + |
| 76 | + def test_api_usage(self): |
| 77 | + r""" |
| 78 | + Check that the queries used by ODK demo all work |
| 79 | + """ |
| 80 | + queries = ['transitivegroups/groups?_format=json&label=1T1', |
| 81 | + 'transitivegroups/groups?_format=json&label=8T3', |
| 82 | + 'elliptic_curves/curves?_format=json&label=11a1'] |
| 83 | + for query in queries: |
| 84 | + data = self.tc.get("/api/{}".format(query), follow_redirects=True).data |
| 85 | + if '1T1' in query: |
| 86 | + assert '"name": "Trivial group"' in data |
| 87 | + if '8T3' in query: |
| 88 | + assert '"name": "E(8)=2[x]2[x]2"' in data |
| 89 | + if '11a1' in query: |
| 90 | + assert '"equation": "\\\\( y^2 + y = x^{3} - x^{2} - 10 x - 20 \\\\)"' in data |
0 commit comments