#232 Adjust the validators so they return the value validated
Merged 7 years ago by pingou. Opened 7 years ago by pingou.
pingou/fedora-hubs fix_validators  into  develop

file modified
+21 -7
@@ -1,6 +1,7 @@ 

  import kitchen.text.converters

  

  import hubs.models

+ import httplib

  

  

  def required(session, value):
@@ -22,7 +23,9 @@ 

  

  

  def username(session, value):

-     return hubs.models.User.by_username(session, value) is not None

+     if hubs.models.User.by_username(session, value) is not None:

+         return value

+     raise ValueError('Invalid username')

  

  

  def github_organization(session, value):
@@ -32,14 +35,25 @@ 

  

  def fmn_context(session, value):

      # TODO get this from the fedmsg config.

-     return value in [

-         'irc', 'email', 'android', 'desktop', 'hubs',

-     ]

+     if value in [

+         'irc', 'email', 'android', 'desktop', 'hubs',]:

+         return value

+     raise ValueError('Invalid FMN context')

  

  

  def pagure_repo(session, value):

-     return value

+     conn = httplib.HTTPSConnection("pagure.io")

+     conn.request("GET", "/%s" % value)

+     response = conn.getresponse()

+     if response.status == 200:

+         return value

+     raise ValueError('Invalid pagure repo')

+ 

  

  def fedorahosted_project(session, value):

-     # TODO -- implement this.

-     return value

+     conn = httplib.HTTPSConnection("fedorahosted.org")

+     conn.request("GET", "/%s" % value)

+     response = conn.getresponse()

+     if response.status == 200:

+         return value

+     raise ValueError('Invalid fedorahosted project')

no initial comment

Pull-Request has been merged by pingou

7 years ago
Metadata