Skip to content

Commit

Permalink
Add a travis suite to run the staging store tests (#602)
Browse files Browse the repository at this point in the history
In order to do this, the store tests need to handle an empty password.
As travis only sets the encrypted environment variable for the team branches,
the personal PRs will run against the fake store.

LP: #1596072
  • Loading branch information
come-maiz authored and sergiusens committed Jul 4, 2016
1 parent 3cd7907 commit 1fafdda
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 34 deletions.
10 changes: 5 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ env:
global:
# Encrypted test user password. Generated with the travis gem:
# travis encrypt -r ubuntu-core/snapcraft TEST_USER_PASSWORD=$password
- secure: "H58yffyxq1y5RxbEBroXgdkmfc2ttvD8Y6ARh1HCNv0AvAfJ6FA5/Ly2rzBMh/ghXnwumkLHKUYa9dGnbJl0R26U4b7w4YkmSKsrWgNWL1M3iqXdiVsZRJ3K3RaVRya3m9k9DL6b3gR2ZVhz6FeDlaKuOZqCeFxRgXGTB71NrFUKSwXqqE5w10u3woItG3upqr2fPDjJ4bIaffpINpX2MabghfboBB9VbKdLvWiEkH7kEJKNh9zNHZJ4FK5LVt/GAR7CHQhuQsJVQOO+dPE7ZL7FlvqYg33b4ly75kpoo30muzSRXbs+qoSaBe6K41vbVhGdBmtJ9SXxYeuVGunFq8hKOGrSq00vIcPyOonTIZmkWVA/oxuo6viIzuzP1BlU5ulEmQjIbJj5trEzLo3Nd5o8WF19fLpp5MYuU0w28F/TzjarWYU9mw/sPkTJTrV5wHP5jGa/2mcExJBg+MgH60Q8I/uObz9EdovOjLKb1d8x2NSlWozXDyLYVTWIecetEPArhNVuOaGFLpGorDVVTvcrvkLR/rnvY+iqxthuQWuzfEsmkafWFwxgEO/G1mZUI66aq7UdtkToLKCcwi6FCYASQ7AA0mzizWI76teUXr3iJ/HFh7+BfKblfbkgS+eYIjLuAJBxp0NXY6J+eO0gG6n2Pp0emy+PFDJ4xD0XkR0="
- secure: "gqtqTji8cie0Q2O+sRhE4MbTXGI0qTq8yPgRGFd9XlT/lB/EttFQKu72qycr/jyrvt809wjWM13QVqa5/71SoJd+Xzrmr1/leevx9Z/Wnv+IYkRAuGHW7iIDQb7MhQvpq3tw8hbGJzGxw03cUmjKJ89AAlGbwaURMat47lPsRXus8R7pl9S6r5owhBbmrQNaP9io0oPQDOAUf4pmJma1FTHAjXg0EdUwdXFUWToj15c7UJtB/MQNNTfjlwGA+/sPDqgthUEAzXmvUfXAZWnjQFZmq4ebvBIJEOQEPdLCXWGYdN2DAL7zp7WthrwFfgFFZb579rOBh0ETIMebUgBLoVSiPcn/bfzdYHcYKGf7lTJpoug5QENl+kZcuVyK7GUjf8O9tamhkYeMtUOy5Ubrcnv+Lfy9NsDPhKY05n+7tzzUVB1dePTrMHPuRZLl4OKku1AUN/S3A2xMrLO8vsWPVxcfxeb+4Y5ikYiHHpOozJHHDdPmj5raRIf3IH87W2PX0nJhg+gEgNHV1v3HBoyeqOPl4hl6/Fb9sCS/JAbbfcixkC54MHHI+opNSgZRvY0RORGHmuhHRGvfMxnwHmeOD51oV+SRGJS6A7qUq6GlBIy3/YlAY3LqqkWrHwm4EYttd4yM1FZ5s9pVnoSSJkgQ5vYK7A8a9AgZJlCcZnbzXtA="
matrix:
- TEST_SUITE=static DEPENDENCIES="apt install -y python3-flake8 python3-mccabe"
- TEST_SUITE=unit DEPENDENCIES="apt build-dep -y ./ && apt install -y python3-coverage"
- TEST_SUITE=integration DEPENDENCIES="apt build-dep -y ./ && apt install -y bzr git mercurial python3-pexpect subversion sudo"
- TEST_SUITE=static DEPENDENCIES="apt install -y python3-flake8 python3-mccabe"
- TEST_SUITE=unit DEPENDENCIES="apt build-dep -y ./ && apt install -y python3-coverage"
- TEST_SUITE=integration DEPENDENCIES="apt build-dep -y ./ && apt install -y bzr git mercurial python3-pexpect subversion sudo"

install:
- sudo apt-get -qq update
- sudo apt-get install -y python3-coverage
script:
- docker run -v $(pwd):$(pwd) -t ubuntu:xenial sh -c "export LC_ALL=en_US.UTF-8 && locale-gen en_US.UTF-8 && apt update && cd $(pwd) && $DEPENDENCIES && ./runtests.sh $TEST_SUITE"
- docker run -e TEST_USER_PASSWORD=$TEST_USER_PASSWORD -v $(pwd):$(pwd) -t ubuntu:xenial sh -c "export LC_ALL=en_US.UTF-8 && locale-gen en_US.UTF-8 && apt update && cd $(pwd) && $DEPENDENCIES && ./runtests.sh $TEST_SUITE"
after_success:
- pip install coveralls
- coveralls
11 changes: 9 additions & 2 deletions integration_tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import os
import shutil
import subprocess
import time

import fixtures
import pexpect
Expand Down Expand Up @@ -61,7 +62,7 @@ def run_snapcraft(self, command, project_dir=None):
cwd = None
try:
return subprocess.check_output(
[self.snapcraft_command] + command, cwd=cwd,
[self.snapcraft_command, '-d'] + command, cwd=cwd,
stderr=subprocess.STDOUT, universal_newlines=True)
except subprocess.CalledProcessError as e:
self.addDetail('output', content.text_content(e.output))
Expand All @@ -88,7 +89,7 @@ def login(self, email=None,
email = email or os.getenv(
'TEST_USER_EMAIL', 'u1test+snapcraft@canonical.com')
password = password or os.getenv(
'TEST_USER_PASSWORD', 'test correct password')
'TEST_USER_PASSWORD', None) or 'test correct password'

process = pexpect.spawn(self.snapcraft_command, ['login'])

Expand All @@ -111,3 +112,9 @@ def logout(self):
expected = ('Clearing credentials for Ubuntu One SSO.\n'
'Credentials cleared.\n')
self.assertEqual(expected, output)

def register(self, snap_name):
self.run_snapcraft(['register', snap_name])
# sleep a few seconds to avoid hitting the store restriction on
# following registrations.
time.sleep(10)
46 changes: 26 additions & 20 deletions integration_tests/test_clean_dependents.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

from testtools.matchers import (
DirExists,
EndsWith,
Not
)

Expand Down Expand Up @@ -113,10 +114,11 @@ def test_clean_dependent_without_nested_dependents_raises(self):
exception = self.assertRaises(
subprocess.CalledProcessError, self.run_snapcraft, ['clean', 'p2'],
self.project_dir)
self.assertEqual(
"Requested clean of 'p2' but 'p3' and 'p4' depend upon it. Please "
"add each to the clean command if that's what you intended.",
exception.output.replace('\n', ' ').strip())
self.assertThat(
exception.output,
EndsWith(
"Requested clean of 'p2' but 'p3' and 'p4' depend upon it. Please "
"add each to the clean command if that's what you intended.\n"))
self.assert_not_clean(['p1', 'p2', 'p3', 'p4'], True)

def test_clean_dependent_without_nested_dependent_raises(self):
Expand All @@ -125,10 +127,11 @@ def test_clean_dependent_without_nested_dependent_raises(self):
exception = self.assertRaises(
subprocess.CalledProcessError, self.run_snapcraft,
['clean', 'p2', 'p3'], self.project_dir)
self.assertEqual(
"Requested clean of 'p2' but 'p3' and 'p4' depend upon it. Please "
"add each to the clean command if that's what you intended.",
exception.output.replace('\n', ' ').strip())
self.assertThat(
exception.output,
EndsWith(
"Requested clean of 'p2' but 'p3' and 'p4' depend upon it. Please "
"add each to the clean command if that's what you intended.\n"))
self.assert_not_clean(['p1', 'p2', 'p3', 'p4'], True)

def test_clean_main_without_any_dependent_raises(self):
Expand All @@ -137,10 +140,11 @@ def test_clean_main_without_any_dependent_raises(self):
exception = self.assertRaises(
subprocess.CalledProcessError, self.run_snapcraft, ['clean', 'p1'],
self.project_dir)
self.assertEqual(
"Requested clean of 'p1' but 'p2' depends upon it. Please add "
"each to the clean command if that's what you intended.",
exception.output.replace('\n', ' ').strip())
self.assertThat(
exception.output,
EndsWith(
"Requested clean of 'p1' but 'p2' depends upon it. Please add "
"each to the clean command if that's what you intended.\n"))
self.assert_not_clean(['p1', 'p2', 'p3', 'p4'], True)

def test_clean_main_without_dependent_raises(self):
Expand All @@ -149,10 +153,11 @@ def test_clean_main_without_dependent_raises(self):
exception = self.assertRaises(
subprocess.CalledProcessError, self.run_snapcraft,
['clean', 'p1', 'p3', 'p4'], self.project_dir)
self.assertEqual(
"Requested clean of 'p1' but 'p2' depends upon it. Please add "
"each to the clean command if that's what you intended.",
exception.output.replace('\n', ' ').strip())
self.assertThat(
exception.output,
EndsWith(
"Requested clean of 'p1' but 'p2' depends upon it. Please add "
"each to the clean command if that's what you intended.\n"))
self.assert_not_clean(['p1', 'p2', 'p3', 'p4'], True)

def test_clean_main_without_nested_dependent_raises(self):
Expand All @@ -162,8 +167,9 @@ def test_clean_main_without_nested_dependent_raises(self):
exception = self.assertRaises(
subprocess.CalledProcessError, self.run_snapcraft,
['clean', 'p1', 'p2'], self.project_dir)
self.assertEqual(
"Requested clean of 'p2' but 'p3' and 'p4' depend upon it. Please "
"add each to the clean command if that's what you intended.",
exception.output.replace('\n', ' ').strip())
self.assertThat(
exception.output,
EndsWith(
"Requested clean of 'p2' but 'p3' and 'p4' depend upon it. Please "
"add each to the clean command if that's what you intended.\n"))
self.assert_not_clean(['p1', 'p2', 'p3', 'p4'], True)
3 changes: 2 additions & 1 deletion integration_tests/test_snap.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import fixtures
import testtools
from testtools.matchers import (
EndsWith,
FileContains,
FileExists,
Not,
Expand Down Expand Up @@ -134,7 +135,7 @@ def test_error_with_unexistent_build_package(self):
expected = (
"Could not find a required package in 'build-packages': "
'"The cache has no package named \'inexistent-package\'"\n')
self.assertEqual(expected, exception.output)
self.assertThat(exception.output, EndsWith(expected))

def test_snap_with_exposed_files(self):
project_dir = 'nil-plugin-pkgfilter'
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/test_store_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class DownloadTestCase(integration_tests.TestCase):

def setUp(self):
super().setUp()
if os.getenv('TEST_USER_PASSWORD', None) is None:
if not os.getenv('TEST_USER_PASSWORD', None):
self.useFixture(fixture_setup.FakeStore())
else:
self.skipTest('There is no ubuntu-core snap in the staging server')
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/test_store_login_logout.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class LoginLogoutTestCase(integration_tests.TestCase):

def setUp(self):
super().setUp()
if os.getenv('TEST_USER_PASSWORD', None) is None:
if not os.getenv('TEST_USER_PASSWORD', None):
self.useFixture(fixture_setup.FakeStore())
else:
self.useFixture(fixture_setup.StagingStore())
Expand Down
4 changes: 2 additions & 2 deletions integration_tests/test_store_register.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ class RegisterTestCase(integration_tests.TestCase):

def setUp(self):
super().setUp()
if os.getenv('TEST_USER_PASSWORD', None) is None:
if not os.getenv('TEST_USER_PASSWORD', None):
self.useFixture(fixture_setup.FakeStore())
else:
self.useFixture(fixture_setup.StagingStore())

def test_successful_registration(self):
self.login(expect_success=True)
snap_name = 'u1test{}'.format(uuid.uuid4().int)
self.run_snapcraft(['register', snap_name])
self.register(snap_name)

def test_failed_registration(self):
self.login(expect_success=True)
Expand Down
4 changes: 2 additions & 2 deletions integration_tests/test_store_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def test_upload_without_login(self):
'login"?', str(error.output))

def test_upload_with_login(self):
if os.getenv('TEST_USER_PASSWORD', None) is None:
if not os.getenv('TEST_USER_PASSWORD', None):
self.useFixture(fixture_setup.FakeStore())
else:
self.useFixture(fixture_setup.StagingStore())
Expand All @@ -88,7 +88,7 @@ def test_upload_with_login(self):
self.run_snapcraft('snap', project_dir)

# Register the snap
self.run_snapcraft(['register', new_name])
self.register(new_name)
# Upload the snap
snap_file_path = '{}_{}_{}.snap'.format(
new_name, new_version, self.deb_arch)
Expand Down

0 comments on commit 1fafdda

Please sign in to comment.