[copr] bkabrda-workspace: Some initial backend api tests (0247a86)

bkabrda at fedoraproject.org bkabrda at fedoraproject.org
Wed Nov 28 10:20:42 UTC 2012


Repository : http://git.fedorahosted.org/cgit/copr.git

On branch  : bkabrda-workspace

>---------------------------------------------------------------

commit 0247a860f67655f45d85f378861bbf2a4d9086db
Author: Bohuslav Kabrda <bkabrda at redhat.com>
Date:   Wed Nov 28 11:17:29 2012 +0100

    Some initial backend api tests


>---------------------------------------------------------------

 coprs_frontend/tests/coprs_test_case.py            |   10 ++++-
 .../test_views/test_backend_ns/test_general.py     |   39 ++++++++++++++++++++
 2 files changed, 47 insertions(+), 2 deletions(-)

diff --git a/coprs_frontend/tests/coprs_test_case.py b/coprs_frontend/tests/coprs_test_case.py
index 732200e..9907051 100644
--- a/coprs_frontend/tests/coprs_test_case.py
+++ b/coprs_frontend/tests/coprs_test_case.py
@@ -1,3 +1,4 @@
+import base64
 import os
 os.environ['COPRS_ENVIRON_UNITTEST'] = '1'
 
@@ -16,6 +17,7 @@ class CoprsTestCase(object):
         self.db = coprs.db
         self.models = models
         self.helpers = helpers
+        self.backend_passwd = coprs.app.config['BACKEND_PASSWORD']
         # create datadir if it doesn't exist
         datadir = os.path.commonprefix([self.app.config['DATABASE'], self.app.config['OPENID_STORE']])
         if not os.path.exists(datadir):
@@ -28,6 +30,10 @@ class CoprsTestCase(object):
         for tbl in reversed(self.db.metadata.sorted_tables):
             self.db.engine.execute(tbl.delete())
 
+    @property
+    def auth_header(self):
+        return {'Authorization': 'Basic ' + base64.b64encode('doesntmatter:{0}'.format(self.backend_passwd))}
+
     @pytest.fixture
     def f_users(self):
         self.u1 = models.User(openid_name = 'http://user1.id.fedoraproject.org/', proven = False, mail = 'user1 at foo.bar')
@@ -48,8 +54,8 @@ class CoprsTestCase(object):
 
     @pytest.fixture
     def f_builds(self):
-        self.b1 = models.Build(copr = self.c1, user = self.u1, chroots = self.c1.chroots, submitted_on = 50)
-        self.b2 = models.Build(copr = self.c1, user = self.u2, chroots = 'fedora-17-x86_64', submitted_on = 10)
+        self.b1 = models.Build(copr = self.c1, user = self.u1, chroots = self.c1.chroots, submitted_on = 50, started_on = 100)
+        self.b2 = models.Build(copr = self.c1, user = self.u2, chroots = 'fedora-17-x86_64', submitted_on = 10, ended_on = 150)
         self.b3 = models.Build(copr = self.c2, user = self.u2, chroots = self.c2.chroots, submitted_on = 10)
         self.b4 = models.Build(copr = self.c2, user = self.u2, chroots = self.c2.chroots, submitted_on = 100)
 
diff --git a/coprs_frontend/tests/test_views/test_backend_ns/test_general.py b/coprs_frontend/tests/test_views/test_backend_ns/test_general.py
new file mode 100644
index 0000000..3a5d49e
--- /dev/null
+++ b/coprs_frontend/tests/test_views/test_backend_ns/test_general.py
@@ -0,0 +1,39 @@
+import json
+
+import flask
+
+from tests.coprs_test_case import CoprsTestCase
+
+class TestWaitingBuilds(CoprsTestCase):
+    def test_no_waiting_builds(self):
+        assert '"builds": []' in self.tc.get('/backend/waiting_builds/').data
+
+    def test_waiting_build_only_lists_not_started_or_ended(self, f_users, f_coprs, f_builds):
+        r = self.tc.get('/backend/waiting_builds/')
+        assert len(json.loads(r.data)['builds']) == 2
+
+class TestUpdateBuilds(CoprsTestCase):
+    def test_updating_requires_password(self, f_users, f_coprs, f_builds):
+        r = self.tc.post('/backend/update_builds/',
+                         content_type = 'application/json',
+                         data = '')
+        assert 'You have to provide the correct password' in r.data
+
+    def test_update_build_started(self, f_users, f_coprs, f_builds):
+        data = """
+{
+  "builds":[
+   {
+     "id": 1,
+     "copr_id": 2,
+     "results": "http://server/results/$ownername/$coprname/",
+     "started_on": 1234
+   }
+  ]
+}
+        """
+        r = self.tc.post('/backend/update_builds/',
+                         content_type='application/json',
+                         headers = self.auth_header,
+                         data = data)
+        assert r.data == '{"updated_builds": 1}'



More information about the copr-devel mailing list