[PATCH 2/2] serve.py: add support for 'list-voted'

Simon Legner simon.legner at gmail.com
Tue Apr 3 19:19:16 UTC 2018


This command lists voted packages.
---
 aurweb/git/serve.py     | 18 ++++++++++++++++++
 test/t1200-git-serve.sh | 22 ++++++++++++++++++++++
 2 files changed, 40 insertions(+)

diff --git a/aurweb/git/serve.py b/aurweb/git/serve.py
index 01aea20..3b3967a 100755
--- a/aurweb/git/serve.py
+++ b/aurweb/git/serve.py
@@ -326,6 +326,19 @@ def pkgbase_unvote(pkgbase, user):
     conn.commit()


+def list_voted(user):
+    conn = aurweb.db.Connection()
+
+    userid = conn.fetch_userid(user)
+
+    cur = conn.execute("SELECT Name FROM PackageBases JOIN PackageVotes " +
+                       "ON ID = PackageBaseID " +
+                       "WHERE UsersID = ?", [userid])
+    for row in cur:
+        print(row[0])
+    conn.close()
+
+
 def pkgbase_set_keywords(pkgbase, keywords):
     pkgbase_id = pkgbase_from_name(pkgbase)
     if not pkgbase_id:
@@ -508,6 +521,9 @@ def serve(action, cmdargv, user, privileged, remote_addr):

         pkgbase = cmdargv[1]
         pkgbase_unvote(pkgbase, user)
+    elif action == 'list-voted':
+        checkarg(cmdargv)
+        list_voted(user)
     elif action == 'set-comaintainers':
         checkarg_atleast(cmdargv, 'repository name')

@@ -515,12 +531,14 @@ def serve(action, cmdargv, user, privileged, remote_addr):
         userlist = cmdargv[2:]
         pkgbase_set_comaintainers(pkgbase, userlist, user, privileged)
     elif action == 'help':
+        # commands in alphabetical order, git-* at the end
         cmds = {
             "adopt <name>": "Adopt a package base.",
             "disown <name>": "Disown a package base.",
             "flag <name> <comment>": "Flag a package base out-of-date.",
             "help": "Show this help message and exit.",
             "list-repos": "List all your repositories.",
+            "list-voted": "List voted packages.",
             "restore <name>": "Restore a deleted package base.",
             "set-comaintainers <name> [...]": "Set package base
co-maintainers.",
             "set-keywords <name> [...]": "Change package base keywords.",
diff --git a/test/t1200-git-serve.sh b/test/t1200-git-serve.sh
index 94a5ff6..51db399 100755
--- a/test/t1200-git-serve.sh
+++ b/test/t1200-git-serve.sh
@@ -466,6 +466,12 @@ test_expect_success "Vote for a package base." '
  EOF
  echo "SELECT NumVotes FROM PackageBases WHERE Name = \"foobar\";" | \
  sqlite3 aur.db >actual &&
+ test_cmp expected actual &&
+ SSH_ORIGINAL_COMMAND="list-voted" AUR_USER=user AUR_PRIVILEGED=0 \
+ "$GIT_SERVE" 2>&1 >actual &&
+ cat >expected <<-EOF &&
+ foobar
+ EOF
  test_cmp expected actual
 '

@@ -484,6 +490,12 @@ test_expect_success "Vote for a package base twice." '
  EOF
  echo "SELECT NumVotes FROM PackageBases WHERE Name = \"foobar\";" | \
  sqlite3 aur.db >actual &&
+ test_cmp expected actual &&
+ SSH_ORIGINAL_COMMAND="list-voted" AUR_USER=user AUR_PRIVILEGED=0 \
+ "$GIT_SERVE" 2>&1 >actual &&
+ cat >expected <<-EOF &&
+ foobar
+ EOF
  test_cmp expected actual
 '

@@ -500,6 +512,11 @@ test_expect_success "Remove vote from a package base." '
  EOF
  echo "SELECT NumVotes FROM PackageBases WHERE Name = \"foobar\";" | \
  sqlite3 aur.db >actual &&
+ test_cmp expected actual &&
+ SSH_ORIGINAL_COMMAND="list-voted" AUR_USER=user AUR_PRIVILEGED=0 \
+ "$GIT_SERVE" 2>&1 >actual &&
+ cat >expected <<-EOF &&
+ EOF
  test_cmp expected actual
 '

@@ -518,6 +535,11 @@ test_expect_success "Try to remove the vote again." '
  EOF
  echo "SELECT NumVotes FROM PackageBases WHERE Name = \"foobar\";" | \
  sqlite3 aur.db >actual &&
+ test_cmp expected actual &&
+ SSH_ORIGINAL_COMMAND="list-voted" AUR_USER=user AUR_PRIVILEGED=0 \
+ "$GIT_SERVE" 2>&1 >actual &&
+ cat >expected <<-EOF &&
+ EOF
  test_cmp expected actual
 '

-- 
2.16.3


More information about the aur-dev mailing list