def test_category_creation_reraises_occured_errors(self): # Emulate Server Error bypassing internal validaitons for missed fields original = Category.required_attributes def fake(): return set() Category.required_attributes = staticmethod(fake) with vcr.use_cassette( 'fixtures/vcr_cassettes/category_create_invalid.json'): with self.assertRaises(errors.InternalServerError): Category.create(user=self.get_me(), isDefault=False) Category.required_attributes = staticmethod(original)
def test_category_creation_returns_category_instance(self): with vcr.use_cassette( 'fixtures/vcr_cassettes/category_create_valid.json'): category = Category.create( user=self.get_me(), name='Test Category', ) self.assertIsInstance(category, Category) self.assertEqual('Test Category', category['name'])
def test_no_need_to_refresh_categories_after_creation(self): user = self.get_me() with vcr.use_cassette('fixtures/vcr_cassettes/categories.json'): initial_size = len(user.categories()) with vcr.use_cassette( 'fixtures/vcr_cassettes/category_create_valid.json'): category = Category.create(user=user, name='Test Category') self.assertTrue(category in user.categories())
def test_new_category_could_be_deleted_permanently_after_creation(self): user = self.get_me() with vcr.use_cassette( 'fixtures/vcr_cassettes/category_create_for_delete2.json'): Category.create(user=user, name='Delete me2') with vcr.use_cassette( 'fixtures/vcr_cassettes/categories_after_new_one_created2.json' ): category = user.categories(refresh=True)[-1] self.assertEqual('Delete me2', category['name']) with vcr.use_cassette( 'fixtures/vcr_cassettes/category_destroy_valid2.json'): category.destroy() with vcr.use_cassette( 'fixtures/vcr_cassettes/categories_after_new_one_deleted2.json' ): categories = user.categories(refresh=True) self.assertFalse( category['id'] in map(lambda cat: cat['id'], categories))
def categories(self, refresh=False, include_deleted=False): """Return a remote or cached categories list for user.""" if not self.categories_list or refresh: params = { 'includeDeleted': str(include_deleted).lower(), } categories_data = request.get(url=CONSTANTS.get('CATEGORIES_URL'), session=self.session(), params=params) self.categories_list = [ Category(data_dict=category, user=self) for category in categories_data ] result = self.categories_list if not include_deleted: result = [cat for cat in result if not cat['isDeleted']] return result
def test_category_creation_checks_required_fields(self): with vcr.use_cassette('fixtures/vcr_cassettes/fake.json', record_mode='none'): with self.assertRaises(errors.ModelAttributeError): Category.create(user=self.get_me(), isDefault=False)