def test_create_local_project(self): project_data = { 'title': 'My new local project', 'description': 'description', 'currency': create_currency_object(id=1), 'budget': create_budget_object(minimum=10), 'jobs': [create_job_object(id=1)], 'location': create_location_object(create_country_object('Australia'), 'Sydney', -33.875461, 151.201678) } self.session.session.post = Mock() self.session.session.post.return_value = FakeProjectPostResponse() p = create_local_project(self.session, **project_data) project_data.update(local=True) self.session.session.post.assert_called_once_with( 'https://fake-fln.com/api/projects/0.1/projects/', json=project_data, verify=True) self.assertEquals(p.url, 'https://fake-fln.com/projects/java/foo')
def sample_create_local_project(): oauth_token = os.environ.get('FLN_OAUTH_TOKEN') url = os.environ.get('FLN_URL') session = Session(oauth_token=oauth_token, url=url) project_data = { 'title': 'My new local project', 'description': 'description', 'currency': create_currency_object(id=1), 'budget': create_budget_object(minimum=10), 'jobs': [create_job_object(id=649)], # Must be a local job 'location': create_location_object(create_country_object('Australia'), 'Sydney', -33.875461, 151.201678) } try: p = create_local_project(session, **project_data) except ProjectNotCreatedException as e: print(('Error message: %s' % e.message)) print(('Error code: %s' % e.error_code)) return None else: return p
def post_project(): if request.method == "GET": return render_template("create_project.html") data = { 'title': "Need someone to buy and bring me a beer ASAP.", 'description': json.loads(request.data)['description'], 'budget': create_budget_object( minimum=10, maximum=25, ), 'currency': create_currency_object(id=3), 'jobs': [create_job_object(id=632)], 'location': create_location_object( country=create_country_object('Australia'), city='Sydney', latitude=-33.8744101, longitude=151.2028132, full_address="Sydney, NSW, Australia", ) } result = None try: # TODO: Make this an app level attribute instead s = Session(oauth_token=h["Freelancer-OAuth-V1"], url=base_url) result = create_local_project(s, **data) except ProjectNotCreatedException as e: print(('Error message: %s' % e.message)) print(('Error code: %s' % e.error_code)) return jsonify(result) else: user_id = User.query.filter_by(name=session['name']).first().id project = Project(result.id, user_id) db.session.add(project) db.session.commit() result = {'result': {'id': result.id, 'seo_url': result.seo_url}} return jsonify(result)