def test_job_category_route(self): user_1 = self.get_auth_token_for("*****@*****.**", "test", "test user") category = JobCategory(name="Kitchen") category.save(commit=True) job_type = JobType(name="Barista", category=category) job_type.save(commit=True) category_request = self.app.test_client().get( '/api/jobs/categories', content_type="application/json", headers={'Authorization': 'Bearer {0}'.format(user_1)}) _json = json.loads(category_request.data.decode()) self.assertEqual(len(_json['categories']), 1) self.assertEqual(_json['categories'][0]['id'], 1)
def test_job_list(self): token = self.get_auth_token_for("*****@*****.**", "test", "test user") job_list_response = self.app.test_client().get( '/api/jobs/list', headers={'Authorization': "Bearer {0}".format(token)}) self.assertEqual(job_list_response.status_code, 200) _json = json.loads(job_list_response.data.decode()) self.assertEqual(len(_json['jobs']), 0) # Now add a job to the list and see if we can see it. category = JobCategory(name="Test Cat") category.save() job_type = JobType(name="Test Type", category=category) job_type.save(commit=True) job_post_response = self.post_job("Title", "Description", "-1", "1", token, category=category.name, job_type=job_type.name) self.assertEqual(job_post_response.status_code, 200) job_list_response = self.app.test_client().get( '/api/jobs/list/all', headers={'Authorization': "Bearer {0}".format(token)}) _json = json.loads(job_list_response.data.decode()) self.assertGreaterEqual(len(_json['jobs']), 1) job_list_response = self.app.test_client().get( '/api/jobs/list/applied', headers={'Authorization': "Bearer {0}".format(token)}) _json = json.loads(job_list_response.data.decode()) self.assertGreaterEqual(len(_json['jobs']), 0)
try: print("Creating database, please wait.") db.create_all(app=application) except: print("Database exists; Operation resumed") # With so we have the app context. with application.app_context(): # Query database first and see if the items exist # if the database is populated with items, exit script # otherwise insert the default values. for key, value in job_type_categories.items(): category = JobCategory.query.filter_by(name=key).first() if category is None: category = JobCategory(name=key) category.save(commit=True) else: print("! Category {0} ALREADY EXISTS".format(key)) # Iterate value as its a list for job_type in value: _type = JobType.query.filter_by(name=job_type).first() if _type is None: _type = JobType(name=job_type, category=category) _type.save(commit=True) print("+ {0} in {1}".format(_type.name, category.name))