Exemplo n.º 1
0
    def testCreateComp(self):
        """Test creating a new competition"""
        self.login()
        post_form = {
            'name': 'Test Competition',
            'start_time': int(time.time()),
            'problems': '[{"label": "A", "pid": 1}]',
            'closed': False,
            'length': 10,
        }

        response = json.loads(test_app.post('/api/competitions',
                              data=post_form).data.decode())

        self.assertEqual(200, response['status'])

        cid = response['data']['cid']
        comp = (session.query(Competition)
            .filter_by(cid=cid).
            first()
        )
        self.assertIsNotNone(comp)

        comp_problems = session.query(CompProblem).filter_by(cid=cid).all()
        for comp_problem in comp_problems:
            session.delete(comp_problem)
        session.delete(comp)
        session.commit()
Exemplo n.º 2
0
    def testCreate(self):
        """Test creating a new blog post"""
        post = {
            'title': 'Test Post',
            'subtitle': 'Testy',
            'body': 'In test we trust',
            'username': self.username
        }
        self.login()

        response = json.loads(test_app.post('/api/blog', data=post)
                              .data.decode())
        self.assertEqual(200, response['status'])
        post_response = response['data']

        for key in post:
            if key == 'username':
                self.assertEqual(post[key], post_response['author'][key])
            else:
                self.assertEqual(post[key], post_response[key])

        # Delete the post from the test database
        session.flush()
        post = session.query(BlogPost).filter(
            BlogPost.id == post_response['id']).first()
        session.delete(post)
        session.commit()
Exemplo n.º 3
0
 def login(self):
     """Log the test user into the app"""
     response = json.loads(test_app.post(
         '/api/login',
         data=dict(username=self.username, password=self.password)
     ).data.decode())
     assert 200 == response['status']
Exemplo n.º 4
0
def _login():
    username = app.config["TEST_USERNAME"]
    password = app.config["TEST_PASSWORD"]
    rv = json.loads(test_app.post("/api/login", data=dict(username=username, password=password)).data)
    assert 200 == rv["status"]