=========
Mirroring
=========

One of the most important features of MYPYPI is to mirror packages from PyPi.
PyPi mostly works but when it does not, life stops.
The solution is to store packages on our server. On our MYPYPI server.

Basic tests will use the manager user for now:

  >>> from zope.testbrowser.testing import Browser
  >>> browser = Browser()
  >>> browser.addHeader('Authorization', 'Basic mgr:mgrpw')
  >>> browser.handleErrors = False

  >>> browser.open('http://localhost')

We'll add a single mirror package:

  >>> browser.getLink('Mirror Package').click()

We have some sample data form z3c.form, so use that package:

  >>> browser.getControl(name='form.widgets.__name__').value = u'z3c.form'

We could set a different source server, but we leave it now at std PyPi:

  >>> browser.getControl(name="form.widgets.pypiURL").value = u'https://pypi.org/pypi'

Add the mirror package:

  >>> browser.getControl(name="form.buttons.add").click()

MYPYPI goes and grabs the package:

  >>> print browser.contents
  <!DOCTYPE html...
  ...X...Mirror...Published...Package...Source...Created...Modified...
  ...Yes...http://localhost/z3c.form/releases.html...z3c.form...
  ...https://pypi.org/pypi...link...

  >>> browser.getLink('z3c.form').click()

It will download all possible versions:

  >>> print browser.contents
  <!DOCTYPE html...
  ...X...Mirror...Published...Release...Source...Created...Modified...
  ...Yes...http://localhost/z3c.form/1.0.0/files.html">1.0.0...
  ...https://pypi.org/pypi/z3c.form/1.0.0">link...
  ...http://localhost/z3c.form/1.0c1/files.html">...
  ...http://localhost/z3c.form/1.0c2/files.html">...
  ...http://localhost/z3c.form/1.1.0/files.html">...
  ...http://localhost/z3c.form/1.2.0/files.html">...
  ...http://localhost/z3c.form/1.3.0/files.html">...
  ...http://localhost/z3c.form/1.4.0/files.html">...
  ...http://localhost/z3c.form/1.4.0b1/files.html">...
  ...http://localhost/z3c.form/1.5.0/files.html">...
  ...http://localhost/z3c.form/1.5.0b1/files.html">...
  ...http://localhost/z3c.form/1.6.0/files.html">...
  ...http://localhost/z3c.form/1.7.0/files.html">...
  ...http://localhost/z3c.form/1.8.0/files.html">...
  ...http://localhost/z3c.form/1.8.1/files.html">...
  ...http://localhost/z3c.form/1.8.2/files.html">...
  ...http://localhost/z3c.form/1.9.0/files.html">...

Let's check one specific version:

  >>> browser.getLink('1.9.0').click()

  >>> browser.open('http://localhost/z3c.form/1.9.0/files.html')
  >>> print browser.contents
  <!DOCTYPE html...
  ...X...Mirror...Published...Name...Source...Created...Modified...
  ...Yes...http://localhost/z3c.form/1.9.0/z3c.form-1.9.0.tar.gz">z3c.form-1.9.0.tar.gz...
  ...https://pypi.org/packages/source/z/z3c.form/z3c.form-1.9.0.tar.gz">link...

Download one specific file from here:

  >>> browser.getLink('z3c.form-1.9.0.tar.gz').click()
  >>> print browser.contents
  TGZ--PACKAGE--Z3C.FORM--1.9.0--ENDTGZ

Let's check the simple index:

  >>> browser.open('http://localhost/simple')

It has the package:

  >>> print browser.contents
  <html>
  <head><title>PYPISite</title>
  </head>
  <body>
  <h1>PYPISite</h1>
  <a href="http://localhost/simple/z3c.form">z3c.form</a>
  </body>
  </html>
  <BLANKLINE>

Check the package:

  >>> browser.getLink('z3c.form').click()
  >>> print browser.contents
  <html>
  <head><title>z3c.form</title>
  </head>
  <body>
  <h1>z3c.form</h1>
  <a href="http://localhost/z3c.form/1.0.0/z3c.form-1.0.0.tar.gz">z3c.form-1.0.0.tar.gz</a><br />
  <a href="http://localhost/z3c.form/1.0c1/z3c.form-1.0c1.tar.gz">z3c.form-1.0c1.tar.gz</a><br />
  <a href="http://localhost/z3c.form/1.0c2/z3c.form-1.0c2.tar.gz">z3c.form-1.0c2.tar.gz</a><br />
  <a href="http://localhost/z3c.form/1.1.0/z3c.form-1.1.0.tar.gz">z3c.form-1.1.0.tar.gz</a><br />
  <a href="http://localhost/z3c.form/1.2.0/z3c.form-1.2.0.tar.gz">z3c.form-1.2.0.tar.gz</a><br />
  <a href="http://localhost/z3c.form/1.3.0/z3c.form-1.3.0.tar.gz">z3c.form-1.3.0.tar.gz</a><br />
  <a href="http://localhost/z3c.form/1.4.0/z3c.form-1.4.0.tar.gz">z3c.form-1.4.0.tar.gz</a><br />
  <a href="http://localhost/z3c.form/1.4.0b1/z3c.form-1.4.0b1.tar.gz">z3c.form-1.4.0b1.tar.gz</a><br />
  <a href="http://localhost/z3c.form/1.5.0/z3c.form-1.5.0.tar.gz">z3c.form-1.5.0.tar.gz</a><br />
  <a href="http://localhost/z3c.form/1.5.0b1/z3c.form-1.5.0b1.tar.gz">z3c.form-1.5.0b1.tar.gz</a><br />
  <a href="http://localhost/z3c.form/1.6.0/z3c.form-1.6.0.tar.gz">z3c.form-1.6.0.tar.gz</a><br />
  <a href="http://localhost/z3c.form/1.7.0/z3c.form-1.7.0.tar.gz">z3c.form-1.7.0.tar.gz</a><br />
  <a href="http://localhost/z3c.form/1.8.0/z3c.form-1.8.0.tar.gz">z3c.form-1.8.0.tar.gz</a><br />
  <a href="http://localhost/z3c.form/1.8.1/z3c.form-1.8.1.tar.gz">z3c.form-1.8.1.tar.gz</a><br />
  <a href="http://localhost/z3c.form/1.8.2/z3c.form-1.8.2.tar.gz">z3c.form-1.8.2.tar.gz</a><br />
  <a href="http://localhost/z3c.form/1.9.0/z3c.form-1.9.0.tar.gz">z3c.form-1.9.0.tar.gz</a>
  </body>
  </html>
  <BLANKLINE>

Download one file:

  >>> browser.getLink('z3c.form-1.9.0.tar.gz').click()
  >>> print browser.contents
  TGZ--PACKAGE--Z3C.FORM--1.9.0--ENDTGZ


Edge cases
==========

Delete the package first:

  >>> browser.open('http://localhost')

  >>> browser.getControl(name='deleteFormTable-checkbox-0-selectedItems').value = ['z3c.form']

  >>> browser.getControl('Delete').click()

  >>> 'z3c.form' in browser.contents
  False

  >>> from mypypi import testing


dash vs underscore in package name
==================================

  >>> browser.open('http://localhost')

We'll add a single mirror package:

  >>> browser.open("http://localhost/addMirrorPackage.html")

Note the package name ``wsgi-intercept`` WITH DASH

  >>> browser.getControl(name="form.widgets.__name__").value = u'wsgi-intercept'

We could set a different source server, but we leave it now at std PyPi:

  >>> browser.getControl(name="form.widgets.pypiURL").value = u'https://pypi.org/pypi'

Add the mirror package:

  >>> browser.getControl(name="form.buttons.add").click()

Note the added package name, WITH UNDERSCORE

  >>> print browser.contents
  <!DOCTYPE html...
  ...Yes...
  ...<a href="http://localhost/wsgi_intercept/releases.html">wsgi_intercept</a>...
  ...<a href="https://pypi.org/pypi">link</a>...

Check through:

  >>> browser.getLink('wsgi_intercept').click()
  >>> print browser.url
  http://localhost/wsgi_intercept/releases.html

  >>> print browser.contents
  <!DOCTYPE html...
  ...<a href="http://localhost/wsgi_intercept/0.1/files.html">0.1</a>...
  ...<a href="http://localhost/wsgi_intercept/0.2/files.html">0.2</a>...
  ...<a href="http://localhost/wsgi_intercept/0.3/files.html">0.3</a>...

  >>> browser.getLink('0.3').click()
  >>> print browser.contents
  <!DOCTYPE html...
  ...<a href="http://localhost/wsgi_intercept/0.3/wsgi_intercept-0.3.tar.gz">wsgi_intercept-0.3.tar.gz</a>...
  ...<a href="https://pypi.org/packages/source/w/wsgi_intercept/wsgi_intercept-0.3.tar.gz">link</a>...

  >>> browser.getLink('wsgi_intercept-0.3.tar.gz').click()
  >>> print browser.contents
  TGZ--PACKAGE--WSGI_INTERCEPT--0.3--ENDTGZ



Let's check the simple index:

  >>> browser.open('http://localhost/simple')
  >>> print browser.contents
  <html>
  <head><title>PYPISite</title>
  </head>
  <body>
  <h1>PYPISite</h1>
  <a href="http://localhost/simple/wsgi_intercept">wsgi_intercept</a>
  </body>
  </html>
  <BLANKLINE>

  >>> browser.open('http://localhost/simple/wsgi_intercept/')
  >>> print browser.contents
  <html>
  <head>
  <base href="http://localhost/simple/wsgi_intercept" />
  <title>wsgi_intercept</title>
  </head>
  <body>
  <h1>wsgi_intercept</h1>
  <a href="http://localhost/wsgi_intercept/0.1/wsgi_intercept-0.1.tar.gz">wsgi_intercept-0.1.tar.gz</a><br />
  <a href="http://localhost/wsgi_intercept/0.2/wsgi_intercept-0.2.tar.gz">wsgi_intercept-0.2.tar.gz</a><br />
  <a href="http://localhost/wsgi_intercept/0.3/wsgi_intercept-0.3.tar.gz">wsgi_intercept-0.3.tar.gz</a>
  </body>
  </html>
  <BLANKLINE>

  >>> browser.getLink('wsgi_intercept-0.2.tar.gz').click()
  >>> print browser.contents
  TGZ--PACKAGE--WSGI_INTERCEPT--0.2--ENDTGZ

Now the twist is that setuptools comes with the name ``wsgi-intercept`` WITH DASH.
But we get the same listing.

  >>> browser.open('http://localhost/simple/wsgi-intercept/')
  >>> print browser.contents
  <html>
  <head>
  <base href="http://localhost/simple/wsgi-intercept" />
  <title>wsgi_intercept</title>
  </head>
  <body>
  <h1>wsgi_intercept</h1>
  <a href="http://localhost/wsgi_intercept/0.1/wsgi_intercept-0.1.tar.gz">wsgi_intercept-0.1.tar.gz</a><br />
  <a href="http://localhost/wsgi_intercept/0.2/wsgi_intercept-0.2.tar.gz">wsgi_intercept-0.2.tar.gz</a><br />
  <a href="http://localhost/wsgi_intercept/0.3/wsgi_intercept-0.3.tar.gz">wsgi_intercept-0.3.tar.gz</a>
  </body>
  </html>
  <BLANKLINE>

  >>> browser.getLink('wsgi_intercept-0.2.tar.gz').click()
  >>> print browser.contents
  TGZ--PACKAGE--WSGI_INTERCEPT--0.2--ENDTGZ
