def test_destroy_app(self):
     app1 = Application.get(1)
     Application.destroy(app1)
     appsFromDB = Application.all()
     app2 = Application.get(2)
     assert appsFromDB == [app2]
     assert len(appsFromDB) == 1
    def test_applications_PUT(self):
        app = Application.get(1)
        expected_app_name = 'It is now changed'
        app.name = expected_app_name

        self.req.swagger_data = {'id': 1, 'application': app}
        httpApps = Applications(self.req)
        response = httpApps.applications_PUT()

        assert Application.get(1).name == expected_app_name
    def test_applications_PUT_ids_must_match(self):
        app = Application.get(1)
        self.req.swagger_data = {'id': 42, 'application': app}
        httpApps = Applications(self.req)
        response = httpApps.applications_PUT()

        assert response.status_code == 400
    def test_applications_PUT_exists(self):
        app = Application.get(1)
        self.req.swagger_data = {'id': 1, 'application': app}
        httpApps = Applications(self.req)
        response = httpApps.applications_PUT()

        assert response == app.as_dict()
    def test_applications_PUT(self):
        expected_name = 'Veri specil'

        self.req.swagger_data = {'application': Application(name=expected_name)}
        httpApps = Applications(self.req)
        httpApps.applications_POST()

        app = Application.get_by('name', expected_name)
        apikey = app.apikey
        id = app.id
        self.req.swagger_data = {'id': app.id, 'application': Application(name='', apikey=apikey, id=id)}
        httpApps.applications_PUT()

        name_now = Application.get(id).name
        assert name_now == expected_name
    def test_data_for_app_GET(self):
        from toolz import assoc, concat
        self.req.swagger_data = {'id': 1}
        httpApps = Applications(self.req)
        response = httpApps.data_for_app_GET()

        app = Application.get(1)
        configurationkeys = app.configurationkeys
        ranges = list(concat(list(map(lambda _: _.rangeconstraints, configurationkeys))))

        app_data = app.as_dict()
        app_data = assoc(app_data, 'configurationkeys', list(map(lambda _: _.as_dict(), configurationkeys)))
        app_data = assoc(app_data, 'rangeconstraints', list(map(lambda _: _.as_dict(), ranges)))
        app_data = assoc(app_data, 'exclusionconstraints', list(map(lambda _: _.as_dict(), httpApps.get_app_exclusionconstraints(1))))

        assert response == app_data
    def test_destroy_app_does_not_delete_dataitems(self):
        Application.save(Application(id=47, name='App to delete'))
        app = Application.get(47)
        Experiment.save(Experiment(id=78, application=app, name='Apperture'))
        exp = Experiment.get(78)
        ExperimentGroup.save(ExperimentGroup(id=67, name='GlaDos', experiment=exp))
        eg = ExperimentGroup.get(67)
        Client.save(Client(id=76, clientname='Chell', experimentgroups=[eg]))
        client = Client.get(76)
        DataItem.save(DataItem(key='key1',
               value=10,
               startDatetime=strToDatetime('2016-01-01 00:00:00'),
               endDatetime=strToDatetime('2016-01-01 01:01:01'),
               client=client))

        dataitem_count_before = DataItem.query().count()
        Application.destroy(app)
        dataitem_count_now = DataItem.query().count()

        assert dataitem_count_before == dataitem_count_now
 def test_get_confkeys_of_app(self):
     assert len(Application.get(1).configurationkeys) == 2
     ck = Application.get(1).configurationkeys[0]
     assert ck.name == 'highscore'
 def test_get_app(self):
     app1 = Application.get(1)
     app2 = Application.get(2)
     assert app1.id == 1 and app1.name == 'App 1'
     assert app2.id == 2 and app2.name == 'App 2'
 def test_applications_GET_one(self):
     self.req.swagger_data = {'id': 1}
     httpApps = Applications(self.req)
     response = httpApps.applications_GET_one()
     expected = Application.get(1).as_dict()
     assert response == expected