def test_experimentdistribution_can_be_set(self):
        app = Application(name='Banana', experiment_distribution='one_random')

        try:
            Application.save(app)
        except Exception as e:
            pass

        assert Application.get_by('name', 'Banana') is not None
    def test_apikey_is_unique(self):
        apikey = str(uuid.uuid4())
        app = Application(name='App with UUID', apikey=str(apikey))
        app = Application.save(app)

        app = Application(name='Another app with UUID', apikey=str(apikey))
        was_added = True
        try:
            Application.save(app)
        except Exception as e:
            was_added = False
            pass

        assert not was_added
    def test_experimentdistribution_exists(self):
        experiment_distribution_exists = False

        app = Application(name='Banana')
        Application.save(app)
        app = Application.get_by('name', 'Banana')

        try:
            experiment_distribution = app.experiment_distribution
            experiment_distribution_exists = True
        except Exception as e:
            pass

        assert experiment_distribution_exists
    def test_can_set_apikey(self):
        apikey = str(uuid.uuid4())
        app = Application(name='App with UUID', apikey=str(uuid.uuid4()))
        app = Application.save(app)

        expected = Application.get_by('apikey', apikey)

        assert expected == app
    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_save_app(self):
     app = Application(name='App 3')
     Application.save(app)
     appsFromDB = Application.all()
     assert len(appsFromDB) == 3