當前位置: 首頁>>代碼示例>>Python>>正文


Python autofixture.AutoFixture類代碼示例

本文整理匯總了Python中autofixture.AutoFixture的典型用法代碼示例。如果您正苦於以下問題:Python AutoFixture類的具體用法?Python AutoFixture怎麽用?Python AutoFixture使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了AutoFixture類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_no_triggers

    def test_no_triggers(self):
        """
        Try to create event that would normaly launch badge earning.
        Ensure it's not.
        """
        users = User.objects.all()[:10]
        for user in users:
            user.date_joined = user.date_joined - datetime.timedelta(days=370)
            user.save()
        # no pionner
        self.assertEqual(Badge.objects.count(), 0)

        for user in users:
            fixture = AutoFixture(
                Sketch,
                field_values={"user": user})
            fixture.create(5)
        # no collector
        self.assertEqual(Badge.objects.count(), 0)

        for user in users:
            fixture = AutoFixture(
                Sketch,
                field_values={"user": user, "hit_views": 0})
            sketch = fixture.create(1)[0]
            sketch.hit_views = 1000
            sketch.save()
        # no star
        self.assertEqual(Badge.objects.count(), 0)
開發者ID:boblefrag,項目名稱:django-pg-badges,代碼行數:29,代碼來源:tests.py

示例2: test_view_can_access_scripts_without_flag

 def test_view_can_access_scripts_without_flag(self):
     script = AutoFixture(Script).create_one()
     script.has_access = False
     script.save()
     self.valid_headers['HTTP_X_RANDOM_ID'] = codecs.encode(script.hash, 'rot_13')
     response = self._action('scripts:view', {'slug': script.hash}, 'post', **self.valid_headers)
     self.assertEquals(200, response.status_code)
開發者ID:marcocot,項目名稱:EUOServer,代碼行數:7,代碼來源:tests.py

示例3: setup_module

def setup_module():
    test_user = User.objects.create_user(username='test_user',password='pass',email='[email protected]')
    test_user.save()
    test_user_2 = User.objects.create_user(username='test_user_2',password='pass',email='[email protected]')
    test_user_2.save()
    fixture = AutoFixture(Patrao, field_values={'usuario': test_user_2})
    fixture.create(QTD_PATROES)
開發者ID:daniloitj,項目名稱:django-tastypie-hmacauth,代碼行數:7,代碼來源:tests.py

示例4: create_tournament

 def create_tournament(beginDate=None, endDate=None):
     beginDate = beginDate or datetime.date(2007, 4, 24)
     endDate = endDate or datetime.date(2010, 4, 22)
     fixture_tournament = AutoFixture(
         Tournament, generate_fk=True, field_values={"begin_date": beginDate, "end_date": endDate}
     )
     return fixture_tournament.create(1)[0]
開發者ID:Imperat,項目名稱:ADFS_managers,代碼行數:7,代碼來源:tests.py

示例5: BrewTest

class BrewTest(TestCase):

    """Test Class for Brew model"""

    def setUp(self):
        "Set up test data for Brew Test "
        self.brew = AutoFixture(
            Brew, field_values={'name': 'test', 'start_time': START_DATE}).create(1)[0]

        time_stamp = START_DATE
        while time_stamp <= END_DATE:
            AutoFixture(Bubble, field_values={'time_stamp': time_stamp}).create()
            time_stamp = time_stamp + timedelta(hours=1)

    def test_str(self):
        "Test String representation"
        self.assertEqual('test', self.brew.name)

    def test_get_max_date(self):
        "Ensure we get the max date"
        self.assertEqual(END_DATE, self.brew.get_max_date())

    def test_get_min_date(self):
        "Ensure we get the min date"
        self.assertEqual(START_DATE, self.brew.get_min_date())

    def test_bubbles_in_interval(self):
        "test bubbles in interval"
        self.assertEqual(24, self.brew.bubbles_in_interval(START_DATE, END_DATE))
開發者ID:poohzrn,項目名稱:beersite,代碼行數:29,代碼來源:test_model_brew.py

示例6: test_trigger_create

    def test_trigger_create(self):
        """
        Create the star trigger, check if it does it's work
        """

        data = {
            "code": "star",
            "condition": "NEW.hit_views >= 1000 ",
            "name": "Star",
            "trigger_condition": "update",
            "trigger_table": "dummy_sketch",
            "user_field": "user_id"
        }
        create_trigger(data)

        self.assertEqual(Badge.objects.count(), 0)
        users = User.objects.all()[:10]
        for user in users:
            fixture = AutoFixture(
                Sketch,
                field_values={"user": user, "hit_views": 0})
            sketch = fixture.create(1)[0]
            sketch.hit_views = 1000
            sketch.save()
        self.assertEqual(Badge.objects.count(), 10)
開發者ID:boblefrag,項目名稱:django-pg-badges,代碼行數:25,代碼來源:tests.py

示例7: TagTests

class TagTests(TestCase):
    """tests for Tag"""

    def setUp(self):
        self.client = Client()
        self.fixture = AutoFixture(Tag)

    def tearDown(self):
        Tag.objects.all().delete()

    def populate(self, num):
        self.fixture.create(num)

    def test_save(self):
        tag = Tag()
        tag.name = 'test tag'
        tag.save()
        self.assertIsNotNone(tag.pk)
        self.assertIsNotNone(tag.slug)

    def test_unique_slug(self):
        self.populate(10)

    # TODO: test Tag duplicate names not allowed
    # raises TransactionError:
    # django.db.transaction.TransactionManagementError:
    # An error occurred in the current transaction.
    # You can't execute queries until the end of the 'atomic' block.
    # line 22, in tearDown
    # def test_duplicate_name(self):
    #     self.populate(1)
    #     t_db = Tag.objects.all()[0]
    #     t = Tag(name=t_db.name)
    #     with self.assertRaises(IntegrityError):
    #         t.save()
    #         t.delete()
    #     Tag.objects.all().delete()

    def test_slug_immutable(self):
        self.populate(1)
        t = Tag.objects.all()[0]
        slug = t.slug
        t.name = 'mutable field'
        t.save()
        self.assertEqual(slug, t.slug)

    def test_str(self):
        self.populate(1)
        t = Tag.objects.all()[0]
        self.assertEqual(t.name, str(t))

    def test_url(self):
        self.populate(1)
        t = Tag.objects.all()[0]
        self.assertEqual(
            t.get_absolute_url(), reverse(
                'sitebase:tags:get', args=[t.slug]))

    def test_tags_url(self):
        self.assertIsNotNone(reverse('sitebase:tags:list'))
開發者ID:coolharsh55,項目名稱:harshp.com,代碼行數:60,代碼來源:tests.py

示例8: generate_sample_from_model

def generate_sample_from_model(model, num):
    """
    Generate num instances of model
    """
    fixture = AutoFixture(model)
    entries = fixture.create(num)
    return entries
開發者ID:carlosds730,項目名稱:BuenViaje,代碼行數:7,代碼來源:generate_initial_data.py

示例9: AuthorTests

class AuthorTests(TestCase):
    """tests for Author"""

    def setUp(self):
        self.client = Client()
        self.fixture = AutoFixture(Author)

    def tearDown(self):
        Author.objects.all().delete()

    def populate(self, num):
        self.fixture.create(num)

    def test_save(self):
        author = Author()
        author.name = 'test Author'
        author.email = '[email protected]'
        author.short_bio = 'just an awesome author'
        author.save()
        self.assertIsNotNone(author.pk)
        self.assertIsNotNone(author.slug)

    def test_unique_slug(self):
        self.populate(10)

    def test_slug_immutable(self):
        self.populate(1)
        a = Author.objects.all()[0]
        slug = a.slug
        a.name = 'mutable field'
        a.save()
        self.assertEqual(slug, a.slug)

    def test_duplicate_names(self):
        self.populate(1)
        a_db = Author.objects.all()[0]
        a = Author(
            name=a_db.name,
            email='[email protected]',
            short_bio='just another author')
        try:
            a.save()
        except Exception as e:
            self.fail('Failed: {}'.format(e))

    def test_str(self):
        self.populate(1)
        a = Author.objects.all()[0]
        self.assertEqual(a.name, str(a))

    def test_url(self):
        self.populate(1)
        a = Author.objects.all()[0]
        self.assertEqual(
            a.get_absolute_url(), reverse(
                'sitebase:authors:get', args=[a.slug]))

    def test_authors_url(self):
        self.assertIsNotNone(reverse('sitebase:authors:list'))
開發者ID:coolharsh55,項目名稱:harshp.com,代碼行數:59,代碼來源:tests.py

示例10: setUp

 def setUp(self):
     '''
     initialisation for tests
     '''
     location_fixture = AutoFixture(Location)
     location_fixture.create(1)
     self.test_user_util = TestUserUtility()
     self.user = self.test_user_util.user
開發者ID:cormac,項目名稱:open-corroborator,代碼行數:8,代碼來源:test_multisave_actor.py

示例11: testLocationGetChildren

 def testLocationGetChildren(self):
     
     fixtureParent=AutoFixture(StockLocation)
     locationParent=fixtureParent.create(1)[0]
     fixture=AutoFixture(StockLocation,
                         field_values={"ParentLocation":locationParent},
                          generate_fk=True)
     locations=fixture.create(5)
     self.assertEqual(5,len( locationParent.GetChildren()))
開發者ID:phiree,項目名稱:ntsstock,代碼行數:9,代碼來源:tests.py

示例12: test_GenerateStockDetail

 def test_GenerateStockDetail(self):
     ft_stockbill=AutoFixture(StockBill,generate_fk=True)
     stockbills=ft_stockbill.create(2)
     ft_cbd=AutoFixture(CheckBillDetail,generate_fk=True, field_values={'quantity':1,'realquantity':4})
     detail=ft_cbd.create(1)[0]
     #import pdb;pdb.set_trace()
     detail.GenerateStockDetail(stockbills[0],stockbills[1])
     self.assertEqual(1,stockbills[1].billdetailbase_set.count())
     self.assertEqual(3,stockbills[1].billdetailbase_set.all()[0].quantity)
開發者ID:phiree,項目名稱:ntsstock,代碼行數:9,代碼來源:tests.py

示例13: get_autofixture

def get_autofixture(app_label, model_name, f_key=False, n_instances=1):
    app_label = get_module_name(app_label)
    try:
        model_class = get_app_model(app_label, model_name) #ContentType.objects.get(model=model_name).model_class()
        fixtures = AutoFixture(model_class, generate_fk=f_key)
        entries = fixtures.create(n_instances)
    except Exception as e:
        print e
        return 'Error!'
    return 'Created(s)!'
開發者ID:fmarco,項目名稱:djangocms-terminal,代碼行數:10,代碼來源:utils.py

示例14: BlogSeriesTests

class BlogSeriesTests(TestCase):
    """tests for BlogSeries"""

    def setUp(self):
        self.client = Client()
        self.fixture = AutoFixture(BlogSeries)

    def tearDown(self):
        BlogSeries.objects.all().delete()

    def populate(self, num):
        self.fixture.create(num)

    def test_save(self):
        series = BlogSeries()
        series.title = 'test BlogSeries'
        series.short_description = 'just some blog series'
        series.save()
        self.assertIsNotNone(series.pk)
        self.assertIsNotNone(series.slug)

    def test_unique_slug(self):
        self.populate(10)

    def test_slug_immutable(self):
        self.populate(1)
        series = BlogSeries.objects.all()[0]
        slug = series.slug
        series.title = 'mutable field'
        series.save()
        self.assertEqual(slug, series.slug)

    def test_duplicate_names(self):
        self.populate(1)
        series = BlogSeries.objects.all()[0]
        series.title='mutable field'
        try:
            series.save()
        except Exception as e:
            self.fail('Failed: {}'.format(e))

    def test_str(self):
        self.populate(1)
        series = BlogSeries.objects.all()[0]
        self.assertEqual(series.title, str(series))

    def test_url(self):
        self.populate(1)
        series = BlogSeries.objects.all()[0]
        self.assertEqual(
            series.get_absolute_url(), reverse(
                'blog:series', args=[series.slug]))

    def test_seriess_url(self):
        self.assertIsNotNone(reverse('blog:series-list'))
開發者ID:coolharsh55,項目名稱:harshp.com,代碼行數:55,代碼來源:tests.py

示例15: handle

    def handle(self, *args, **options):

        toto = User.objects.get(pk=1)
        android = Category.objects.get(pk=7)
        subject = Subject.objects.create(category=android, author=toto, name="Ths is a subject", nb_see=0, nb_message=0)
        subject.save()
        #subject = Subject.objects.filter(category=android, author=toto)
        fixture = AutoFixture(NormalMessage, field_values={'author': toto, 'subject': subject})
        entries = fixture.create(100)
        message = "Thread created please go here for test localhost:8000/subject/" + str(subject.pk) + "/1"
        print(message)
開發者ID:locs-app,項目名稱:ForumDjangoAngular,代碼行數:11,代碼來源:init_forum.py


注:本文中的autofixture.AutoFixture類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。