|
| 1 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 2 | +# you may not use this file except in compliance with the License. |
| 3 | +# You may obtain a copy of the License at |
| 4 | +# |
| 5 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | +# |
| 7 | +# Unless required by applicable law or agreed to in writing, software |
| 8 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 9 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 10 | +# See the License for the specific language governing permissions and |
| 11 | +# limitations under the License. |
| 12 | + |
| 13 | +import datetime |
| 14 | + |
| 15 | +import factory |
| 16 | +import factory.fuzzy |
| 17 | + |
| 18 | +from warehouse.malware.models import ( |
| 19 | + MalwareCheck, |
| 20 | + MalwareCheckObjectType, |
| 21 | + MalwareCheckState, |
| 22 | + MalwareCheckType, |
| 23 | + MalwareVerdict, |
| 24 | + VerdictClassification, |
| 25 | + VerdictConfidence, |
| 26 | +) |
| 27 | + |
| 28 | +from .base import WarehouseFactory |
| 29 | +from .packaging import FileFactory |
| 30 | + |
| 31 | + |
| 32 | +class MalwareCheckFactory(WarehouseFactory): |
| 33 | + class Meta: |
| 34 | + model = MalwareCheck |
| 35 | + |
| 36 | + name = factory.fuzzy.FuzzyText(length=12) |
| 37 | + version = 1 |
| 38 | + short_description = factory.fuzzy.FuzzyText(length=80) |
| 39 | + long_description = factory.fuzzy.FuzzyText(length=300) |
| 40 | + check_type = factory.fuzzy.FuzzyChoice(list(MalwareCheckType)) |
| 41 | + hooked_object = factory.fuzzy.FuzzyChoice(list(MalwareCheckObjectType)) |
| 42 | + schedule = {"minute": "*/10"} |
| 43 | + state = factory.fuzzy.FuzzyChoice(list(MalwareCheckState)) |
| 44 | + created = factory.fuzzy.FuzzyNaiveDateTime( |
| 45 | + datetime.datetime.utcnow() - datetime.timedelta(days=7) |
| 46 | + ) |
| 47 | + |
| 48 | + |
| 49 | +class MalwareVerdictFactory(WarehouseFactory): |
| 50 | + class Meta: |
| 51 | + model = MalwareVerdict |
| 52 | + |
| 53 | + check = factory.SubFactory(MalwareCheckFactory) |
| 54 | + release_file = factory.SubFactory(FileFactory) |
| 55 | + release = None |
| 56 | + project = None |
| 57 | + manually_reviewed = True |
| 58 | + reviewer_verdict = factory.fuzzy.FuzzyChoice(list(VerdictClassification)) |
| 59 | + classification = factory.fuzzy.FuzzyChoice(list(VerdictClassification)) |
| 60 | + confidence = factory.fuzzy.FuzzyChoice(list(VerdictConfidence)) |
| 61 | + message = factory.fuzzy.FuzzyText(length=80) |
| 62 | + full_report_link = None |
| 63 | + details = None |
0 commit comments