Skip to content

Commit

Permalink
Split [pypi] tests (badges#3704)
Browse files Browse the repository at this point in the history
* Split [pypi] tests

* Changed filenames to match previous class names
  • Loading branch information
PyvesB authored and calebcartwright committed Jul 13, 2019
1 parent 6cbc7b5 commit 102db63
Show file tree
Hide file tree
Showing 11 changed files with 244 additions and 236 deletions.
File renamed without changes.
33 changes: 33 additions & 0 deletions services/pypi/pypi-django-versions.tester.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
'use strict'

const Joi = require('@hapi/joi')
const t = (module.exports = require('../tester').createServiceTester())

const isPipeSeparatedDjangoVersions = Joi.string().regex(
/^([0-9]+\.[0-9]+(?: \| )?)+$/
)

t.create('supported django versions (valid, package version in request)')
.get('/djangorestframework/3.7.3.json')
.expectBadge({
label: 'django versions',
message: isPipeSeparatedDjangoVersions,
})

t.create('supported django versions (valid, no package version specified)')
.get('/djangorestframework.json')
.expectBadge({
label: 'django versions',
message: isPipeSeparatedDjangoVersions,
})

t.create('supported django versions (no versions specified)')
.get('/django/1.11.json')
.expectBadge({ label: 'django versions', message: 'missing' })

t.create('supported django versions (invalid)')
.get('/not-a-package.json')
.expectBadge({
label: 'django versions',
message: 'package or version not found',
})
32 changes: 32 additions & 0 deletions services/pypi/pypi-downloads.tester.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
'use strict'

const t = (module.exports = require('../tester').createServiceTester())
const { isMetricOverTimePeriod } = require('../test-validators')

t.create('daily downloads (valid)')
.get('/dd/djangorestframework.json')
.expectBadge({ label: 'downloads', message: isMetricOverTimePeriod })

t.create('weekly downloads (valid)')
.get('/dw/djangorestframework.json')
.expectBadge({ label: 'downloads', message: isMetricOverTimePeriod })

t.create('monthly downloads (valid)')
.get('/dm/djangorestframework.json')
.expectBadge({ label: 'downloads', message: isMetricOverTimePeriod })

t.create('downloads (mixed-case package name)')
.get('/dd/DjangoRestFramework.json')
.expectBadge({ label: 'downloads', message: isMetricOverTimePeriod })

t.create('daily downloads (not found)')
.get('/dd/not-a-package.json')
.expectBadge({ label: 'downloads', message: 'package not found' })

t.create('weekly downloads (not found)')
.get('/dw/not-a-package.json')
.expectBadge({ label: 'downloads', message: 'package not found' })

t.create('monthly downloads (not found)')
.get('/dm/not-a-package.json')
.expectBadge({ label: 'downloads', message: 'package not found' })
23 changes: 23 additions & 0 deletions services/pypi/pypi-format.tester.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict'

const t = (module.exports = require('../tester').createServiceTester())

t.create('format (wheel, package version in request)')
.get('/requests/2.18.4.json')
.expectBadge({ label: 'format', message: 'wheel' })

t.create('format (wheel, no package version specified)')
.get('/requests.json')
.expectBadge({ label: 'format', message: 'wheel' })

t.create('format (source)')
.get('/chai/1.1.2.json')
.expectBadge({ label: 'format', message: 'source' })

t.create('format (egg)')
.get('/virtualenv/0.8.2.json')
.expectBadge({ label: 'format', message: 'egg' })

t.create('format (invalid)')
.get('/not-a-package.json')
.expectBadge({ label: 'format', message: 'package or version not found' })
22 changes: 22 additions & 0 deletions services/pypi/pypi-implementation.tester.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict'

const t = (module.exports = require('../tester').createServiceTester())

t.create('implementation (valid, package version in request)')
.get('/beehive/1.0.json')
.expectBadge({ label: 'implementation', message: 'cpython | jython | pypy' })

t.create('implementation (valid, no package version specified)')
.get('/numpy.json')
.expectBadge({ label: 'implementation', message: 'cpython' })

t.create('implementation (not specified)')
.get('/chai/1.1.2.json')
.expectBadge({ label: 'implementation', message: 'cpython' })

t.create('implementation (invalid)')
.get('/not-a-package.json')
.expectBadge({
label: 'implementation',
message: 'package or version not found',
})
File renamed without changes.
39 changes: 39 additions & 0 deletions services/pypi/pypi-python-versions.tester.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
'use strict'

const Joi = require('@hapi/joi')
const t = (module.exports = require('../tester').createServiceTester())

// These regexes are the same, but declared separately for clarity.
const isPipeSeparatedPythonVersions = Joi.string().regex(
/^([0-9]+\.[0-9]+(?: \| )?)+$/
)

t.create('python versions (valid, package version in request)')
.get('/requests/2.18.4.json')
.expectBadge({
label: 'python',
message: isPipeSeparatedPythonVersions,
})

t.create('python versions (valid, no package version specified)')
.get('/requests.json')
.expectBadge({
label: 'python',
message: isPipeSeparatedPythonVersions,
})

t.create('python versions ("Only" and others)')
.get('/uvloop/0.12.1.json')
.expectBadge({ label: 'python', message: '3.5 | 3.6 | 3.7' })

t.create('python versions ("Only" only)')
.get('/hashpipe/0.9.1.json')
.expectBadge({ label: 'python', message: '3' })

t.create('python versions (no versions specified)')
.get('/pyshp/1.2.12.json')
.expectBadge({ label: 'python', message: 'missing' })

t.create('python versions (invalid)')
.get('/not-a-package.json')
.expectBadge({ label: 'python', message: 'package or version not found' })
19 changes: 19 additions & 0 deletions services/pypi/pypi-status.tester.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use strict'

const t = (module.exports = require('../tester').createServiceTester())

t.create('status (valid, stable, package version in request)')
.get('/django/1.11.json')
.expectBadge({ label: 'status', message: 'stable' })

t.create('status (valid, no package version specified)')
.get('/typing.json')
.expectBadge({ label: 'status', message: 'stable' })

t.create('status (valid, beta)')
.get('/django/2.0rc1.json')
.expectBadge({ label: 'status', message: 'beta' })

t.create('status (invalid)')
.get('/not-a-package.json')
.expectBadge({ label: 'status', message: 'package or version not found' })
57 changes: 57 additions & 0 deletions services/pypi/pypi-version.tester.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
'use strict'

const Joi = require('@hapi/joi')
const t = (module.exports = require('../tester').createServiceTester())
const { isSemver } = require('../test-validators')

const isPsycopg2Version = Joi.string().regex(/^v([0-9][.]?)+$/)

/*
Note:
Not all project on PyPi follow SemVer
Versions strings like
- 2.7.3.2
- 2.0rc1
- 0.1.30b10
are perfectly legal.
We'll run this test against a project that follows SemVer...
*/
t.create('version (semver)')
.get('/requests.json')
.expectBadge({
label: 'pypi',
message: isSemver,
})

// ..whereas this project does not folow SemVer
t.create('version (not semver)')
.get('/psycopg2.json')
.expectBadge({
label: 'pypi',
message: isPsycopg2Version,
})

t.create('version (invalid)')
.get('/not-a-package.json')
.expectBadge({ label: 'pypi', message: 'package or version not found' })

t.create('no trove classifiers')
.get('/mapi.json')
.intercept(nock =>
nock('https://pypi.org')
.get('/pypi/mapi/json')
.reply(200, {
info: {
version: '1.2.3',
license: 'foo',
classifiers: [],
},
releases: {},
})
)
.expectBadge({
label: 'pypi',
message: 'v1.2.3',
})
19 changes: 19 additions & 0 deletions services/pypi/pypi-wheel.tester.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use strict'

const t = (module.exports = require('../tester').createServiceTester())

t.create('wheel (has wheel, package version in request)')
.get('/requests/2.18.4.json')
.expectBadge({ label: 'wheel', message: 'yes' })

t.create('wheel (has wheel, no package version specified)')
.get('/requests.json')
.expectBadge({ label: 'wheel', message: 'yes' })

t.create('wheel (no wheel)')
.get('/chai/1.1.2.json')
.expectBadge({ label: 'wheel', message: 'no' })

t.create('wheel (invalid)')
.get('/not-a-package.json')
.expectBadge({ label: 'wheel', message: 'package or version not found' })
Loading

0 comments on commit 102db63

Please sign in to comment.