예제 #1
0
    def test_are_requests_correct_after_sample_creation(self):
        system = mixer.blend(AnalysisSystem,
                             tag_filter_expression='sample-type:ipsample')
        ipsample = mixer.blend(IPSample, tags=['sample-type:ipsample'])
        urisample = mixer.blend(URISample, tags=['sample-type:urisample'])

        self._are_requests_correct(ipsample, urisample, system)
예제 #2
0
 def test_transitive_graph(self):
     sample1 = mixer.blend(Sample)
     sample2 = mixer.blend(Sample)
     sample3 = mixer.blend(Sample)
     rel1 = mixer.blend(SampleRelation, sample=sample1, other=sample2)
     rel2 = mixer.blend(SampleRelation, sample=sample2, other=sample3)
     self.assertGraphEqual(sample1, {rel1, rel2})
예제 #3
0
 def test_is_repr_and_str_correct(self):
     system = mixer.blend(AnalysisSystem, identifier_name='RequestTestSystem')
     sample = mixer.blend(Sample, id='55c863b79b65210a5625411a')
     obj = mixer.blend(AnalysisRequest, sample=sample, analysis_system=system)
     obj.save()
     self.assertEqual(obj.__repr__(), '[AnalysisRequest] 55c863b79b65210a5625411a on RequestTestSystem')
     self.assertEqual(obj.__str__(), '[AnalysisRequest] 55c863b79b65210a5625411a on RequestTestSystem')
 def test_is_update_last_seen_working(self):
     system = mixer.blend(AnalysisSystem, identifier_name='InstanceTestSystem')
     obj = mixer.blend(AnalysisSystemInstance, uuid='e25b2339-23d4-4544-8c99-f2968a935319', analysis_system=system)
     obj.last_seen = TimeFunctions.get_timestamp() - datetime.timedelta(minutes=1)
     obj.save()
     self.assertFalse(TimeFunctions.get_timestamp() - obj.last_seen < datetime.timedelta(seconds=1))
     obj.update_last_seen()
     self.assertTrue(TimeFunctions.get_timestamp() - obj.last_seen < datetime.timedelta(seconds=1))
예제 #5
0
 def test_depth_parameter(self):
     sample1 = mixer.blend(Sample)
     sample2 = mixer.blend(Sample)
     sample3 = mixer.blend(Sample)
     rel1 = mixer.blend(SampleRelation, sample=sample1, other=sample2)
     rel2 = mixer.blend(SampleRelation, sample=sample2, other=sample3)
     self.assertGraphEqual(sample1, {rel1}, depth=1)
     self.assertGraphEqual(sample1, {rel1, rel2}, depth=2)
예제 #6
0
    def test_relation(self):
        from mixer.backend.mongoengine import mixer

        post = mixer.blend('tests.test_mongoengine.Post',
                           author__username='******')
        self.assertEqual(post.author.username, 'foo')

        bookmark = mixer.blend(Bookmark)
        self.assertTrue(bookmark.bookmark)
예제 #7
0
    def test_relation(self):
        from mixer.backend.mongoengine import mixer

        post = mixer.blend(
            'tests.test_mongoengine.Post', author__username='******')
        self.assertEqual(post.author.username, 'foo')

        bookmark = mixer.blend(Bookmark)
        self.assertTrue(bookmark.bookmark)
예제 #8
0
 def test_is_repr_and_str_correct(self):
     system = mixer.blend(AnalysisSystem,
                          identifier_name='ReportTestSystem')
     sample = mixer.blend(Sample, id='55cdd8e89b65211708b7da46')
     obj = mixer.blend(Report, sample=sample, analysis_system=system)
     self.assertEqual(
         obj.__repr__(),
         '[Report] 55cdd8e89b65211708b7da46 on ReportTestSystem')
     self.assertEqual(
         obj.__str__(),
         '[Report] 55cdd8e89b65211708b7da46 on ReportTestSystem')
예제 #9
0
    def test_are_requests_correct_after_analysis_system_creation(self):
        ipsample = mixer.blend(IPSample, tags=['sample-type:ipsample'])
        urisample = mixer.blend(URISample, tags=['sample-type:urisample'])
        system = mixer.blend(AnalysisSystem,
                             tag_filter_expression='sample-type:ipsample')

        # Refresh samples from DB, to reload the dispatched_to field
        ipsample = IPSample.objects.get(id=ipsample.id)
        urisample = URISample.objects.get(id=urisample.id)

        self._are_requests_correct(ipsample, urisample, system)
예제 #10
0
    def test_base(self):
        from mixer.backend.mongoengine import mixer

        self.assertTrue(mixer)

        user = mixer.blend(User)
        self.assertTrue(user.id)
예제 #11
0
    def test_base(self):
        from mixer.backend.mongoengine import mixer

        self.assertTrue(mixer)

        user = mixer.blend(User)
        self.assertTrue(user.id)
예제 #12
0
 def test_triangle(self):
     sample1 = mixer.blend(Sample)
     sample2 = mixer.blend(Sample)
     sample3 = mixer.blend(Sample)
     rel1 = mixer.blend(SampleRelation, sample=sample1, other=sample2)
     rel2 = mixer.blend(SampleRelation, sample=sample2, other=sample3)
     rel3 = mixer.blend(SampleRelation, sample=sample3, other=sample1)
     self.assertGraphEqual(sample1, {rel1, rel2, rel3})
예제 #13
0
def generate_posts(n):
    """Generates dummy posts for development server.
    
    Import this function into the Python shell and then pass in the number
    of posts to generate.

    Example that adds five new posts to the database:
    from codeselfstudy.fixtures.posts import generate_posts
    generate_posts(5)
    """
    for _ in range(n):
        post = mixer.blend(Post)

    print('Generated {} posts.'.format(n))
예제 #14
0
 def test_foreign_reference_sample_relation(self):
     sample1 = mixer.blend(Sample)
     sample1.save()
     sample2 = mixer.blend(Sample)
     sample2.save()
     input_data = {
         'sample':
         url_for('mass_flask_api.sample_detail',
                 id=sample1.id,
                 _external=True),
         'other':
         url_for('mass_flask_api.sample_detail',
                 id=sample2.id,
                 _external=True)
     }
     with self.app.test_request_context(
             url_for('mass_flask_api.sample_relation')):
         schema = SampleRelationSchema().load(input_data)
         if schema.errors:
             self.fail('Schema validation failed!' + str(schema.errors))
         relation = schema.data
         print(relation)
         self.assertEqual(relation.sample, sample1)
         self.assertEqual(relation.other, sample2)
예제 #15
0
 def test_foreign_reference_analysis_system(self):
     system = mixer.blend(AnalysisSystem, identifier_name='testsystem')
     system.save()
     input_data = {
         'analysis_system':
         url_for('mass_flask_api.analysis_system_detail',
                 identifier_name='testsystem',
                 _external=True),
         'uuid':
         '9e1502c8-56ad-4ffd-bc03-caa34cb6c768'
     }
     with self.app.test_request_context(
             url_for('mass_flask_api.analysis_system_instance')):
         schema = AnalysisSystemInstanceSchema().load(input_data)
         if schema.errors:
             self.fail('Schema validation failed!')
         instance = schema.data
         self.assertEqual(instance.analysis_system, system)
         self.assertEqual(instance.uuid, input_data['uuid'])
예제 #16
0
 def assertInvalidTag(self, tag):
     with self.assertRaises(ValidationError):
         sample = mixer.blend(Sample, tags=[tag])
예제 #17
0
 def test_is_comment_correct(self):
     sample = mixer.blend(Sample, comment='Some comment')
     self.assertEqual(sample.comment, 'Some comment')
예제 #18
0
 def test_is_repr_and_str_correct(self):
     sample = mixer.blend(Sample, id='55c863b79b65210a5625411a')
     self.assertEqual(sample.__repr__(),
                      '[Sample] 55c863b79b65210a5625411a')
     self.assertEqual(sample.__str__(), '[Sample] 55c863b79b65210a5625411a')
예제 #19
0
 def test_is_short_name_forbidden(self):
     with self.assertRaises(ValidationError):
         mixer.blend(AnalysisSystem, identifier_name='aa')
예제 #20
0
 def test_is_repr_and_str_correct(self):
     obj = mixer.blend(AnalysisSystem, identifier_name='Test')
     self.assertEqual(obj.__repr__(), '[AnalysisSystem] Test')
     self.assertEqual(obj.__str__(), '[AnalysisSystem] Test')
 def test_is_repr_and_str_correct(self):
     system = mixer.blend(AnalysisSystem, identifier_name='InstanceTestSystem')
     instance = mixer.blend(AnalysisSystemInstance, uuid='e25b2339-23d4-4544-8c99-f2968a935319', analysis_system=system)
     self.assertEqual(instance.__repr__(), '[AnalysisSystemInstance] InstanceTestSystem e25b2339-23d4-4544-8c99-f2968a935319')
     self.assertEqual(instance.__str__(), '[AnalysisSystemInstance] InstanceTestSystem e25b2339-23d4-4544-8c99-f2968a935319')
예제 #22
0
 def test_is_system_name_unique(self):
     with self.assertRaises(NotUniqueError):
         a1 = mixer.blend(AnalysisSystem, identifier_name='duplicate')
         a1.save()
         a2 = mixer.blend(AnalysisSystem, identifier_name='duplicate')
         a2.save()
예제 #23
0
 def test_is_long_comment_correct(self):
     sample = mixer.blend(Sample, long_comment='Some long comment')
     self.assertEqual(sample.long_comment, 'Some long comment')
 def test_is_uuid_unique(self):
     system = mixer.blend(AnalysisSystem, identifier_name='InstanceTestSystem')
     mixer.blend(AnalysisSystemInstance, uuid='e25b2339-23d4-4544-8c99-f2968a935319', analysis_system=system)
     # Create another system with the same name, expect that it fails
     with self.assertRaises(NotUniqueError):
         mixer.blend(AnalysisSystemInstance, uuid='e25b2339-23d4-4544-8c99-f2968a935319', analysis_system=system)
예제 #25
0
 def setupUser(self, is_superuser=False, is_staff=False):
     self.user = mixer.blend(models.MongoUser,
                             is_superuser=is_superuser,
                             is_staff=is_staff)
     return self.user
예제 #26
0
 def test_simple_graph(self):
     sample1 = mixer.blend(Sample)
     sample2 = mixer.blend(Sample)
     rel1 = mixer.blend(SampleRelation, sample=sample1, other=sample2)
     self.assertGraphEqual(sample1, {rel1})
예제 #27
0
 def assertValidTag(self, tag):
     try:
         mixer.blend(Sample, tags=[tag])
     except ValidationError:
         self.fail('Validation of a valid tag failed!')