コード例 #1
0
    def create_partner(self):
        """Create a new random partner"""
        partner = Partner()

        partner.is_active = random.random() < 0.75
        partner.name = "{} {}".format(_faker.company(),
                                      _faker.company_suffix())
        partner.slug = _faker.slug()
        partner.link = _faker.uri()

        igen = IconGenerator(5, 5)  # 5x5 blocks
        icon = igen.generate(
            partner.name,
            480,
            480,
            padding=(10, 10, 10, 10),
            output_format="jpeg",
        )  # 620x620 pixels, with 10 pixels padding on each side
        partner.logo.save(partner.name + ".jpeg", ContentFile(icon))

        partner.address = _faker.street_address()
        partner.zip_code = _faker.postcode()
        partner.city = _faker.city()

        partner.save()
コード例 #2
0
 def create(self, validated_data):
     request = self.context['request']
     instance = Partner(**validated_data)
     instance.save()
     for i in request.FILES.getlist('file'):
         f = PartnerFile(partner=instance, file=i)
         f.save()
     return instance
コード例 #3
0
class TestEquipments:
    def setup(self):
        self.equipment = Equipment()
        self.partner = Partner(name='partner')
        self.equipment.save()
        self.partner.save()

    def test_borrow_equipment_get(self, client):
        response = client.get('equipment/borrow_equipment/', follow=True)
        response.status_code == 200

    def test_list_equipment_get(self, client):
        response = client.get('equipment/list_equipment/', follow=True)
        response.status_code == 200

    def test_register_equipment_get(self, client):
        response = client.get('equipment/registerequipment/', follow=True)
        response.status_code == 200

    def test_register_equipment_post(self, client):
        response = client.post('equipment/registerequipment/', {
            'equipment_name': 'test_equipment',
        },
                               follow=True)
        response.status_code == 200

    def test_equipment(self, client):
        response = client.get('equipment/borrow_equipment/', follow=True)
        response.status_code == 200

    def test_list_equipment(self, client):
        response = client.get('equipment/list_equipment/', follow=True)
        response.status_code == 200

    def test_equipment_states(self):

        self.equipment.start_state()
        self.equipment.borrow_equipment(self.partner)
        assert (type(self.equipment.state) == type(BorrowedEquipment()))
        assert (self.equipment.state.partner == self.partner)

        self.equipment.take_back_equipment()
        assert (type(self.equipment.state) == type(AvailableEquipment()))

        self.equipment.disable_equipment()
        assert (type(self.equipment.state) == type(BrokenEquipment()))

        self.equipment.fix_equipment()
        assert (type(self.equipment.state) == type(AvailableEquipment()))
コード例 #4
0
# with open('play.json') as f:
#     play_json = json.load(f)

# for play in play_json:
#     play = Play(name=play['play'])
#     play.save()

with open('2019_June_partners.json') as f:
    partners_json = json.load(f)

for partner in partners_json:
    partner = Partner(name=partner['name'],
                      type=partner['type'],
                      act_id=partner['act_id'],
                      active=partner['active'])
    partner.save()

with open('2019_June_Oxy_rigs.json') as f:
    rigs_json = json.load(f)

for rig in rigs_json:
    rig = Rig(name=rig['name'],
              partner=Partner.objects.get(pk=int(rig['partner'])),
              company=rig['company'],
              active=rig['active'])
    rig.save()

with open('districts.json') as f:
    districts_json = json.load(f)

for district in districts_json: