Exemplo n.º 1
0
 def test_post_adds_points_to_project(self):
     user = self.make_user('chris')
     user.add_auth_id('email:[email protected]')
     self.app.post('/api/v1/github', self.POST)
     p_key = Project.make_key('http://github.com/defunkt/github')
     p = p_key.get()
     self.assertEqual(p.total, 12)
Exemplo n.º 2
0
 def test_post_adds_points_to_project(self):
     user = self.make_user('marcus')
     user.add_auth_id('email:[email protected]')
     self.app.post('/api/v1/bitbucket', self.POST)
     p_key = Project.make_key('https://some.other.org/marcus/project-x/')
     p = p_key.get()
     self.assertEqual(p.total, 11)
Exemplo n.º 3
0
 def test_post_adds_points_to_project(self):
     user = self.make_user('marcus')
     user.add_auth_id('email:[email protected]')
     self.app.post('/api/v1/bitbucket', self.POST)
     p_key = Project.make_key('https://bitbucket.org/marcus/project-x/')
     p = p_key.get()
     self.assertEqual(p.total, 11)
Exemplo n.º 4
0
 def test_post_adds_points_to_project(self):
     user = self.make_user('chris')
     user.add_auth_id('email:[email protected]')
     self.app.post('/api/v1/github', self.POST)
     p_key = Project.make_key('http://github.com/defunkt/github')
     p = p_key.get()
     self.assertEqual(p.total, 12)
Exemplo n.º 5
0
 def test_testing_mode_off(self):
     settings.TESTING = False
     user = self.make_user('chris')
     user.add_auth_id('email:[email protected]')
     self.app.post('/api/v1/github', self.POST)
     p_key = Project.make_key('http://github.com/defunkt/github')
     # project should not be created
     self.assertEqual(p_key.get(), None)
Exemplo n.º 6
0
 def test_testing_mode_off(self):
     settings.TESTING = False
     user = self.make_user('chris')
     user.add_auth_id('email:[email protected]')
     self.app.post('/api/v1/github', self.POST)
     p_key = Project.make_key('http://github.com/defunkt/github')
     # project should not be created
     self.assertEqual(p_key.get(), None)
Exemplo n.º 7
0
 def test_testing_mode_off(self):
     settings.TESTING = False
     user = self.make_user('marcus')
     user.add_auth_id('email:[email protected]')
     self.app.post('/api/v1/bitbucket', self.POST)
     u = User.get_by_auth_id('email:[email protected]')
     p_key = Project.make_key('https://bitbucket.org/marcus/project-x/')
     # project should not be created
     self.assertEqual(p_key.get(), None)
Exemplo n.º 8
0
 def test_testing_mode_off(self):
     settings.TESTING = False
     user = self.make_user('marcus')
     user.add_auth_id('email:[email protected]')
     self.app.post('/api/v1/bitbucket', self.POST)
     u = User.get_by_auth_id('email:[email protected]')
     p_key = Project.make_key('https://bitbucket.org/marcus/project-x/')
     # project should not be created
     self.assertEqual(p_key.get(), None)
Exemplo n.º 9
0
    def post(self):
        """Create a project from the api.
        
        Example::
        
            {
                "url": "http://github.com/defunkt/github",
                "name": "github",
                "description": "You're lookin' at it.",
                "watchers": 5,
                "forks": 2,
                "private": 1,
                "email": "*****@*****.**",
                "account": "twitter_name",
            },
        """
        form = self.parse_form()
        if not form.is_valid():
            return self.respond_json(form.errors, status_code=400)

        # Lookup the user by email or account
        email = form.cleaned_data.pop('email', None)
        account = form.cleaned_data.pop('account', None)
        user = None
        if email:
            user = User.get_by_auth_id('email:%s' % email)
        elif account:
            user = User.get_by_auth_id('twitter:%s' % account)

        created = False
        project_url = form.cleaned_data['url']
        project_key = Project.make_key(project_url)
        project = project_key.get()

        if project is None:
            created = True
            project = Project(key=project_key, **form.cleaned_data)
            project.put()

        @ndb.transactional
        def txn():
            count = getattr(user, 'total', 0)
            projects = set(getattr(user, 'projects', []))
            user.total = count + 10
            user.projects = list(projects.add(project_url))
            user.put()
            return user

        if created and user:
            txn()

        self.respond_json({'project': self.serialize(project)},
                          status_code=201 if created else 200)
Exemplo n.º 10
0
 def post(self):
     """Create a project from the api.
     
     Example::
     
         {
             "url": "http://github.com/defunkt/github",
             "name": "github",
             "description": "You're lookin' at it.",
             "watchers": 5,
             "forks": 2,
             "private": 1,
             "email": "*****@*****.**",
             "account": "twitter_name",
         },
     """
     form = self.parse_form()
     if not form.is_valid():
         return self.respond_json(form.errors, status_code=400)
     
     # Lookup the user by email or account
     email = form.cleaned_data.pop('email', None)
     account = form.cleaned_data.pop('account', None)
     user = None
     if email:
         user = User.get_by_auth_id('email:%s' % email)
     elif account:
         user = User.get_by_auth_id('twitter:%s' % account)
     
     created = False
     project_url = form.cleaned_data['url']
     project_key = Project.make_key(project_url)
     project = project_key.get()
     
     if project is None:
         created = True
         project = Project(key=project_key, **form.cleaned_data)
         project.put()
     
     @ndb.transactional    
     def txn():
         count = getattr(user, 'total', 0)
         projects = set(getattr(user, 'projects', []))
         user.total = count + 10
         user.projects = list(projects.add(project_url))
         user.put()
         return user
     
     if created and user:
         txn()
     
     self.respond_json({'project': self.serialize(project)}, status_code=201 if created else 200)
Exemplo n.º 11
0
def people_projects(request, username):
    user = User.get_by_auth_id('own:%s' % username)
    if user == None:
        raise Http404("User not found")
    
    if getattr(user, 'projects', None) == None:
        projects = [] 
    else: 
        projects = user.projects
        projects = ndb.get_multi([Project.make_key(project) for project in projects])

    return render_to_response('people/people_projects.html', 
        {"projects":projects, 'profile':user}, 
        context_instance=RequestContext(request))