def setUp(self): self.databaseFd, APP.config['DATABASE'] = mkstemp(suffix='test.db') APP.config['TESTING'] = True self.app = APP.test_client() with APP.app_context(): ayeaye.initializeDatabase(APP.config['DATABASE']) self.database = sqlite3.connect(APP.config['DATABASE'])
def setUp(self): """ Set up test data """ self.app = APP.test_client() self.app.testing = True self.sample_user = { 'id': uuid.uuid4().hex, 'username': '******', 'email': '*****@*****.**', 'password': '******', 'confirm_password': '******' } self.exist_user = { 'id': uuid.uuid4().hex, 'username': '******', 'email': '*****@*****.**', 'password': '******', 'confirm_password': '******' } self.business_data = { 'id': uuid.uuid4().hex, 'name': 'Inzora rooftop coffee', 'description': 'We have best coffee for you,', 'country': 'Kenya', 'city': 'Nairobi' } save_user = User() save_user.save({ 'id': self.sample_user['id'], 'username': self.sample_user['username'], 'email': self.sample_user['email'], 'password': self.sample_user['password'], 'confirm_password': self.sample_user['confirm_password'] }) # Save business for reviews testing self.rev_business_data = { 'id': uuid.uuid4().hex, 'name': 'KFC', 'description': 'Finger lickin\' good', 'country': 'Kenya', 'city': 'Nairobi' } # Add user(owner) to the business data dict self.rev_business_data['user_id'] = self.sample_user['id'] # Save business in the storage list for testing Business.save(self.rev_business_data) with APP.test_request_context(): # Orphan id: User id that will be used to create an orphan token orphan_id = uuid.uuid4().hex save_user.save({ 'id': orphan_id, 'username': "******", 'email': "*****@*****.**", 'password': self.exist_user['password'], 'confirm_password': self.exist_user['confirm_password'] }) # Issue a token the the test user (sample_user) # Store test token in auth storage auth_token list token = get_token(self.sample_user['id']) # Orphan token: User token that do not have any registered business orphan_token = get_token(orphan_id) expired_token = get_token(self.sample_user['id'], -3600) # Create bad signature token # Bad signature: #nt secret key from the one used in our API used # to hash tokens other_signature_token = get_token(self.sample_user['id'], 3600, 'other_signature') User().add_token(token) User().add_token(expired_token) User().add_token(orphan_token) User().add_token(other_signature_token) self.test_token = token self.expired_test_token = expired_token self.other_signature_token = other_signature_token self.orphan_test_token = orphan_token
def setUp(self): disable_custom_logging() APP.testing = True self.client = APP.test_client()