예제 #1
0
    def post(self):
        data = self.parser.parse_args()
        lat = data.get('latitude')
        lon = data.get('longitude')
        if (lat and not lon) or (not lat and lon):
            raise BadRequest('latitude and longitude must both be empty, or both provided')

        # query the mine tables and check if that mine name exists
        _throw_error_if_mine_exists(data.get('mine_name'))
        mine = Mine(
            mine_no=generate_mine_no(),
            mine_name=data.get('mine_name'),
            mine_note=data.get('mine_note'),
            major_mine_ind=data.get('major_mine_ind'),
            mine_region=data.get('mine_region'),
            ohsc_ind=data.get('ohsc_ind'),
            union_ind=data.get('union_ind'),
            latitude=lat,
            longitude=lon)

        mine_status = _mine_status_processor(data.get('mine_status'), data.get('status_date'), mine)
        mine.save()

        # Clear and rebuild the cache after committing changes to db
        if lat and lon:
            cache.delete(MINE_MAP_CACHE)
            MineMapResource.rebuild_map_cache_async()

        # generate & set hybrid_properties to include in response payload
        mine.init_on_load()
        return mine
예제 #2
0
def test_generate_mine_no(test_client):
    random_mine_no = generate_mine_no()
    assert 'B' in random_mine_no
    assert len(random_mine_no) == 7
예제 #3
0
def test_generate_mine_no(db_session):
    random_mine_no = generate_mine_no()
    assert 'B' in random_mine_no
    assert len(random_mine_no) == 7