Skip to content

Commit

Permalink
updating tests to allow recent changes in preapi (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
robermorales committed Nov 1, 2017
1 parent 946fb64 commit 96cb526
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 57 deletions.
12 changes: 6 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
language: python
python:
- "2.7"
- "3.3"
- "3.4"
- "3.5"
- "3.6"
- '2.7'
- '3.3'
- '3.4'
- '3.5'
- '3.6'
install:
- pip install -r requirements.txt
- pip install -r requirements-test.txt
Expand All @@ -18,7 +18,7 @@ deploy:
provider: pypi
user: robermorales
password:
secure: OovDKTJraZdQRqCmqFM3O03emqxsXeIs9o5m8ttC+fhDCXSEDmQNO/XepXCunPG778JhfQCy9wRO3qbXAOj9kZu2uELouA9P5SuLwOHjb83vk6bcppyH9XzWOOe8IUkx7/LoSDRDIYJovSGcqmdR9wnk0AQ0sQEM0oSoxzKsvvNqKkF+QuOEz+UerZupYZdxWZpTTEaBJO9lket8JsDuNE67UQwlBBOfRTxit8pezQ8vWHHYGa+y0/npGRGaoH3aOEZT2erLNoR2th4YQfB+RwApdTyut5RDeJB9FZSzzO2qIhEH6nEfYTkNYDPvy1PhKZSoYmlFuS7dv+WPfH7BQNEenc3TLV4078vYUy8foHsf+O+8byYUBExWIxqpeF4aaz1+dkpm5Cv1S2Ljz59xui/wnlJxvgXx7eb6ieRlRNJkT3WKrQ2CUL8EiRiWHyx8M7ZyDRECsO6c4t23fzm+JDhj2D6hFq3Fvc3Nm1am0jfd+Mn+muLEZIq1OhmablflRfFOEfYdvwYFGRp5spvI4DVGONiz2MPfE5ojAO2TB2NqYG+0+I+BoP1X5lZHNT8yNBey01ipTJ7YTmFJIX5AALzEFTcfD+mY+YwryATVAC2mBN/Ym/64xyiUZT7AXT009FdGF+BG9vE7CfkffZN/wi+u1+kILm/CVPJLGJSMxD0=
secure: KtJo1mA5/JzOyaNlkvelrIZQkI1sMInV33zAExXlWuRqAvzK5c9l3DdouTMI3AjgGq1F3/wRbWG4AKzQojJ9P96nHOuNVBmSFj9p4mL/CVn8W+rlQ8TXht8skrRnfMhL3vg85h4Wds2fMxLYQPZ49KZzK0tsQwBjDXZ9IxABEoriJGeAorh2EokGsHFiLZn+k9p9F4WFov1NVWiaoUvSOAsgavxoFNIRYTftd9tPQ7eBSbsfUX41AUaucPH7qvZvWt9jZm4lksMbtJ84/cjI0+Gm8MaRdgWaHSBB9k76Y2RODqOiUP7JSPnERHPXjqRMUEa1jvVcRgehZqb2e8pteGUURToLq0jkB364gX3n0IGIwjDUAdQ5UkLkRKo12+2AgswrXCMj18S1Io6+r75Fltnyc0dN+NqWMLjvwHB0ggDeKaTcxbCcapDfqraVWY08Ywgs+hBqvNuWTJ80q8xYkoBqqEGYWInTkdhWP8EfZdHO+/u760+R41sFfk40r9ExbfCKqiCci9bEwM9rqgEyQDJUHnksLHhGaaVgO8ke4taMBvX4ePOTYUCSMIjgR4vTaCuRkHd4Tfd5efmTEwBdXsMfufwUc02Fm/1UgnVmblcsajyAcUha/PwDodilCaledXkZ4BzEC01vtmiXpi7UDLuSAmnvUq673UVVgeknAL4=
distributions: bdist_wheel
on:
python: 3.6
Expand Down
8 changes: 8 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,11 @@ Deployment
==========

If you are trying to use travis as a pypi deployment tool, please note that there is no documented way of using passwords with special characters.

Then you can try

.. code-block:: bash
echo -n "password" | travis encrypt --org --add deploy.password --repo rstorsauce/alfredo-python-sdk
and be sure that your pypi user is the same than the ``deploy.user`` and that you have permissions to deploy ``alfredo-python``.
4 changes: 3 additions & 1 deletion alfredo/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import os
import sys

import os
import ruamel.yaml as yaml

from alfredo import descriptions
from alfredo.resource import HttpPropertyResource

__version__ = '0.0.2.post2'


def represent_unicode(self, data):
return self.represent_str(data.encode('utf-8'))

Expand All @@ -23,6 +24,7 @@ def ruote(token=None):
root.headers = dict(Authorization="Token %s" % token)
return root


def virgo():
virgo_root = os.getenv('VIRGO_ROOT', 'http://virgo.teamjamon.com')
return HttpPropertyResource(None, virgo_root, descriptions.virgo)
39 changes: 14 additions & 25 deletions tests/cli/tests_cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import sys
import tempfile
import uuid
from os.path import basename
from unittest.case import TestCase

import ruamel.yaml as yaml
Expand All @@ -15,8 +16,8 @@

class AlfredoCLITest(TestCase):
def setUp(self):
self.email = "%s@example.com" % (uuid.uuid4().hex,)
self.password = 'pass!@#$%964'
self.email = os.environ['TEST_USER']
self.password = os.environ['TEST_PASSWORD']

@classmethod
def fake_exit(cls, exit_code):
Expand Down Expand Up @@ -62,20 +63,17 @@ def test_can_do_a_complete_flow(self):
except RuntimeError:
pass

user_created = self.sh("ruote", "users", "-C", "-i", repr({"email": self.email, "password": self.password}))
self.assertIsInstance(user_created['id'], int)

token = self.sh("ruote", "sso", "token_by_email", "-C", "-i", repr({"email": self.email, "password": self.password}))["token"]
token = self.sh("ruote", "sso", "token_by_email", "-C", "-i",
repr({"email": self.email, "password": self.password}))["token"]
self.assertEqual(len(token), 40)

self.sh("login", "-i", repr({"email": self.email, "password": self.password}))

me = self.sh("ruote", "users", "me")
self.assertEqual(me['email'], self.email)
self.assertEqual(me['id'], user_created['id'])
self.assertNotIn('missing_attribute', me)

first_name = 'Bob'
first_name = 'Bob %s' % uuid.uuid4().hex[6:8]
payload = yaml.safe_dump({"first_name": first_name})
changed_name = self.sh("ruote", "users", "me", "-U", "-i", payload)
self.assertEqual(changed_name['first_name'], first_name)
Expand All @@ -89,25 +87,16 @@ def test_can_do_a_complete_flow(self):
queue_q = self.sh("ruote", "queues", "-C", "-i", repr({"name": "q", "cluster": cluster_created['id']}))
self.assertEqual(queue_q['cluster'], cluster_created['id'])

for f in self.sh("ruote", "files"):
self.sh("ruote", "files", "id:{}".format(f['id']), "-D")

files = self.sh("ruote", "files")
self.assertEqual(len(files), 0)
uploaded_file = tempfile.NamedTemporaryFile()

file_created = self.sh("ruote", "files", "-C", "-i", repr({'name': uuid.uuid4().hex, "file": __file__}))
file_created = self.sh("ruote", "files", "-C", "-i",
repr({'name': uuid.uuid4().hex, "file": uploaded_file.name}))
self.assertIsInstance(file_created['id'], int)
self.assertEqual(file_created['name'], basename(__file__))

with self.assertRaisesRegexp(RuntimeError, 'already.*uploaded'):
self.sh("ruote", "files", "-C", "-i", repr({'name': uuid.uuid4().hex, "file": __file__}))

files = self.sh("ruote", "files")
self.assertEqual(len(files), 1)
self.assertEqual(file_created['name'], uploaded_file.name.split('/')[-1])

for f in self.sh("ruote", "files"):
self.sh("ruote", "files", "id:{}".format(f['id']), "-D")
self.sh("ruote", "files", "id:{}".format(file_created['id']), "-D")

app_created = self.sh("ruote", "apps", "-C", "-i",
repr({"name": 'app', "container_checksum": '000', "container_url": 'http://example.com/app'}))
repr({"name": 'app', "container_checksum": '000',
"container_url": 'http://example.com/app'}))
self.assertIsInstance(app_created['id'], int)
34 changes: 9 additions & 25 deletions tests/unit/tests_ruote.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import os
import tempfile
import uuid
from os.path import basename
from unittest.case import TestCase
Expand All @@ -7,13 +9,10 @@

class AlfredoSDKTest(TestCase):
def setUp(self):
self.email = "%s@example.com" % (uuid.uuid4().hex,)
self.password = 'pass!@#$%964'
self.email = os.environ['TEST_USER']
self.password = os.environ['TEST_PASSWORD']

def test_can_do_a_complete_flow(self):
user_created = alfredo.ruote().users.create(email=self.email, password=self.password)
self.assertIsInstance(user_created.id, int)

token = alfredo.ruote().sso.token_by_email.create(email=self.email, password=self.password).token
self.assertEqual(len(token), 40)

Expand All @@ -25,7 +24,6 @@ def test_can_do_a_complete_flow(self):
self.assertTrue(bool(me))
self.assertTrue(me.ok)
self.assertEqual(me.email, self.email)
self.assertEqual(me.id, user_created.id)

with self.assertRaises(AttributeError):
print(me.missing_attribute)
Expand All @@ -49,28 +47,14 @@ def test_can_do_a_complete_flow(self):
queue_p = ruote.queues.create(cluster=cluster_created, name='p')
self.assertEqual(queue_p.cluster, cluster_created.id)

for f in ruote.files:
f.delete()

files = ruote.files
self.assertFalse(bool(files))
self.assertEqual(len(files), 0)
uploaded_file = tempfile.NamedTemporaryFile()

file_created = ruote.files.create(name=uuid.uuid4(), file=open(__file__, 'rb'))
file_created = ruote.files.create(name=uuid.uuid4(), file=uploaded_file.name)
self.assertTrue(file_created.ok, file_created)
self.assertEqual(file_created.name, basename(__file__))

file_tried = ruote.files.create(name=uuid.uuid4(), file=open(__file__, 'rb'))
self.assertFalse(file_tried.ok, file_tried)
self.assertRegexpMatches(file_tried.detail, 'already.*uploaded')

files = ruote.files
self.assertTrue(bool(files))
self.assertEqual(len(files), 1)
self.assertEqual(file_created.name, uploaded_file.name.split('/')[-1])

for f in ruote.files:
file_deleted = f.delete()
self.assertTrue(file_deleted.ok, file_deleted)
file_deleted = ruote.files.id(file_created.id).delete()
self.assertTrue(file_deleted.ok, file_deleted)

app_created = ruote.apps.create(name='app', container_checksum='000', container_url='http://example.com/app')
self.assertTrue(app_created.ok, app_created)

0 comments on commit 96cb526

Please sign in to comment.