Esempio n. 1
0
 def test_deserialize_a_category(self):
     """ Test deserialization of a category """
     data = {"category_name": "AAA"}
     category = Category()
     category.deserialize(data)
     self.assertNotEqual(category, None)
     self.assertEqual(category.category_name, "AAA")
Esempio n. 2
0
 def setUp(self):
     self.app = service.app.test_client()
     service.initialize_logging(logging.INFO)
     Category.init_db("test")
     service.data_reset()
     service.data_load({"category_name": "A"})
     service.data_load({"category_name": "B"})
Esempio n. 3
0
 def get(self):
     """ Returns all of the categories """
     app.logger.info('Request for categories lists')
     categories = []
     args = category_args.parse_args()
     target_word = args['target_word']
     number = args['number']
     if target_word is not None:
         if number is not None:
             res = SimilarityModel.top_k_similarity(target_word, number)
         else:
             res = SimilarityModel.top_k_similarity(target_word, 5)
         for word in res:
             categories.append(Category(category_name=word))
     else:
         categories = Category.all()
     results = [e.serialize() for e in categories]
     return results, status.HTTP_200_OK
Esempio n. 4
0
 def delete(self, id):
     """
     Delete a category
     This endpoint will delete a category based on the id specified
     in the path
     """
     app.logger.info('Request to delete category with id: %s', id)
     category = Category.find(id)
     if category:
         category.delete()
     return '', status.HTTP_204_NO_CONTENT
Esempio n. 5
0
 def get(self, id):
     """
     Retrieve a single category
     This endpoint will return a category based on it's id
     """
     app.logger.info('Request for category with id: %s', id)
     category = Category.find(id)
     if not category:
         api.abort(
             status.HTTP_404_NOT_FOUND, "Category with id '{}' was not \
                   found.".format(id))
     return category.serialize(), status.HTTP_200_OK
Esempio n. 6
0
 def post(self):
     """
     Creates a Category
     This endpoint will create a Category based
     the data in the body that is posted
     """
     app.logger.info('Request to create a category')
     check_content_type('application/json')
     category = Category()
     app.logger.debug('Payload = %s', api.payload)
     category.deserialize(api.payload)
     category.save()
     location_url = api.url_for(CategoryResource,
                                id=category.id,
                                _external=True)
     return category.serialize(), status.HTTP_201_CREATED, \
     {'Location': location_url}
Esempio n. 7
0
def db_drop(dbname):
    """ Removes all categories from the database """
    Category.drop(dbname)
Esempio n. 8
0
 def test_disconnect(self):
     """ Test Disconnet """
     Category.disconnect()
     category = Category("CCC")
     self.assertRaises(AttributeError, category.save)
Esempio n. 9
0
 def test_find_a_category(self):
     """ Find a category by id """
     category = Category(category_name='AAA')
     category.save()
     new_category = Category.find(category.id)
     self.assertEqual(new_category.category_name, "AAA")
Esempio n. 10
0
 def test_serialize_a_category(self):
     """ Test serialization of a category """
     category = Category(category_name='AAA')
     data = category.serialize()
     self.assertNotEqual(category, None)
     self.assertEqual(data['category_name'], "AAA")
Esempio n. 11
0
 def test_create_a_category(self):
     """ Create a category and assert that it exists """
     category = Category(category_name='AAA')
     self.assertNotEqual(category, None)
     self.assertEqual(category.category_name, "AAA")
Esempio n. 12
0
 def test_find_by_category_name(self):
     """ Find category by category_name"""
     Category(category_name='AAA').save()
     category = Category.find_by_category_name("AAA")
     self.assertEqual(len(category), 1)
Esempio n. 13
0
 def setUp(self):
     """ Initialize the Cloudant database """
     Category.init_db("test")
     Category.remove_all()
Esempio n. 14
0
def category_reset():
    """ Removes all categories """
    Category.remove_all()
    return make_response('', status.HTTP_200_OK)
Esempio n. 15
0
def data_reset():
    """ Removes all categories from the database """
    Category.remove_all()
Esempio n. 16
0
def data_load(payload):
    """ Loads a category into the database """
    category = Category(payload['category_name'])
    category.save()
Esempio n. 17
0
def init_db(dbname):
    """ Initlaize the model """
    Category.init_db(dbname)