Ejemplo n.º 1
0
class TestScoreAbstract(unittest.TestCase):
    def setUp(self):
        self.score = Score()
        self.week = 1

    def tearDown(self):
        pass

    def test_initial(self):
        self.assertIsNone(
            self.score.next,
            "Testing initial state")

    def test_fetch_is_not_implemented(self):
        with self.assertRaises(NotImplementedError):
            self.score.fetch(self.week),

    def test_protected_fetch_is_unimplemented(self):
        with self.assertRaises(NotImplementedError):
            self.score._fetch_score(self.week)

    def test_save_is_not_implemented(self):
        data = {}

        with self.assertRaises(NotImplementedError):
            self.score.save(self.week, data),


    def test_protected_save_is_unimplemented(self):
        data = {}

        with self.assertRaises(NotImplementedError):
            self.score._save_score(self.week, data)
Ejemplo n.º 2
0
 def post(self):
     args = Dict(parser.parse_args())
     new_score = Score(name=args.name,
                       score=args.score,
                       added_time=datetime.now())
     new_score.save()
     return {
         'success': 1,
         'message': 'New score added successfully',
         'data': {
             'score': new_score.score,
             'name': new_score.name
         }
     }
Ejemplo n.º 3
0
    def post(self):
        # 1. Get data from json body
        json_score = request.get_json()
        name = json_score["name"]  # dictionary
        score = json_score["score"]
        added_time = datetime.now()

        # 2. Add name, score into database
        new_score = Score()
        new_score.name = name
        new_score.score = score
        new_score.added_time = added_time
        new_score.save()

        return {
            'success': 1,
            'data': {
                'name': new_score.name,
                'score': new_score.score
            }
        }
Ejemplo n.º 4
0
from mlab import mlab_connect
from models.score import Score
from datetime import datetime, timedelta
from random import randint

mlab_connect()

for i in range(10):
    score = Score()
    score.name = "past"
    score.score = 120
    score.added_time = datetime.now() - timedelta(days=randint(1, 5))
    score.save()