示例#1
0
    def create_project(self, **kwargs):
        """Creates a Project instance, using valid test 
        defaults unless overridden in **kwargs."""
        save = kwargs.get('save', True) 
        if kwargs.has_key('save'):
            del(kwargs['save'])

        index = self.object_index()
        defaults = dict(slug = "test-project-%s" % index,
            basecamp_url = "https://foo.basecamphq.com/projects/%s/log" % index)
        defaults.update(kwargs)
        p = Project(**defaults)

        if save:
            p.save()
            self.assert_(p.id)
        return p
示例#2
0
    def clean_basecamp_url(self):
        url = self.cleaned_data['basecamp_url']

        basecamp_id = Project.extract_basecamp_id(url)
        api_url = Project.extract_basecamp_api_url(url)
        if not basecamp_id or not api_url:
            raise forms.ValidationError("%s does not appear to be a valid basecamp url" % url)

        credentials = Project.get_credentials_for(api_url)
        if not credentials:
            raise forms.ValidationError("No credentials for %s" % api_url)

        username, password = credentials

        p = Project.BasecampProject(api_url, basecamp_id, username, password)
        try:
            p.name
        except HTTPError, e:
            raise forms.ValidationError("Error connecting to Basecamp. Does user %s have access to the project?" % username)
示例#3
0
 def test_basecamp_api_url(self):
     tests = {
         'https://foo.updatelog.com/': self.url_parsing_tests['valid'],
         'http://foo.updatelog.com/': ['http://foo.updatelog.com/projects/8130456/', ],
     }
     for domain, test_cases in tests.items():
         for case in test_cases:
             actual = Project.extract_basecamp_api_url(case)
             msg = "%s != %s for test case %s" % (domain, actual, case)
             self.assertEqual(domain, actual, msg)
示例#4
0
 def test_project_id_detection(self):
     """When given a proper URL it should be able to set it's project_id field."""
     tests = {
         2907852: self.url_parsing_tests['valid'],
         None: self.url_parsing_tests['invalid'],
     }
     
     for basecamp_id, test_cases in tests.items():
         for case in test_cases:
             actual = Project.extract_basecamp_id(case)
             msg = "%s != %s Test case: %s" % (basecamp_id, actual, case)
             self.assertEqual(basecamp_id, actual, msg)